From: Avan Thakkar Date: Fri, 13 Sep 2024 14:11:47 +0000 (+0530) Subject: earmarking: improve error handling when getxattr fails X-Git-Tag: v20.0.0~954^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F59726%2Fhead;p=ceph.git earmarking: improve error handling when getxattr fails Signed-off-by: Avan Thakkar --- diff --git a/src/python-common/ceph/fs/earmarking.py b/src/python-common/ceph/fs/earmarking.py index 238f2d8755f13..c5d4a59a4d578 100644 --- a/src/python-common/ceph/fs/earmarking.py +++ b/src/python-common/ceph/fs/earmarking.py @@ -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