]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
earmarking: improve error handling when getxattr fails 59726/head
authorAvan Thakkar <athakkar@redhat.com>
Fri, 13 Sep 2024 14:11:47 +0000 (19:41 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Wed, 25 Sep 2024 12:06:10 +0000 (17:36 +0530)
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
src/python-common/ceph/fs/earmarking.py

index 238f2d8755f13b9f0381f275b73aaa250a0ff3c3..c5d4a59a4d57891cd49a3cf47e0976953f631e8b 100644 (file)
@@ -61,11 +61,16 @@ class CephFSVolumeEarmarking:
         if isinstance(e, ValueError):
             raise EarmarkException(errno.EINVAL, f"Invalid earmark specified: {e}") from e
         elif isinstance(e, OSError):
-            log.error(f"Error {action} earmark: {e}")
-            raise EarmarkException(-e.errno, e.strerror) from e
+            if e.errno == errno.ENODATA:
+                # Return empty string when earmark is not set
+                log.info(f"No earmark set for the path while {action}. Returning empty result.")
+                return ''
+            else:
+                log.error(f"Error {action} earmark: {e}")
+                raise EarmarkException(-e.errno, e.strerror) from e
         else:
             log.error(f"Unexpected error {action} earmark: {e}")
-            raise EarmarkException
+            raise EarmarkException(errno.EFAULT, f"Unexpected error {action} earmark: {e}") from e
 
     @staticmethod
     def parse_earmark(value: str) -> Optional[EarmarkContents]:
@@ -128,8 +133,7 @@ class CephFSVolumeEarmarking:
             )
             return earmark_value
         except Exception as e:
-            self._handle_cephfs_error(e, "getting")
-            return None
+            return self._handle_cephfs_error(e, "getting")
 
     def set_earmark(self, earmark: str):
         # Validate the earmark before attempting to set it