Skip to content

Commit 24af1be

Browse files
committed
earmarking: improve error handling when getxattr fails
Signed-off-by: Avan Thakkar <[email protected]>
1 parent 2ab0103 commit 24af1be

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/python-common/ceph/fs/earmarking.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ def _handle_cephfs_error(self, e: Exception, action: str) -> None:
6161
if isinstance(e, ValueError):
6262
raise EarmarkException(errno.EINVAL, f"Invalid earmark specified: {e}") from e
6363
elif isinstance(e, OSError):
64-
log.error(f"Error {action} earmark: {e}")
65-
raise EarmarkException(-e.errno, e.strerror) from e
64+
if e.errno == errno.ENODATA:
65+
# Return empty string when earmark is not set
66+
log.info(f"No earmark set for the path while {action}. Returning empty result.")
67+
return ''
68+
else:
69+
log.error(f"Error {action} earmark: {e}")
70+
raise EarmarkException(-e.errno, e.strerror) from e
6671
else:
6772
log.error(f"Unexpected error {action} earmark: {e}")
68-
raise EarmarkException
73+
raise EarmarkException(errno.EFAULT, f"Unexpected error {action} earmark: {e}") from e
6974

7075
@staticmethod
7176
def parse_earmark(value: str) -> Optional[EarmarkContents]:
@@ -128,8 +133,7 @@ def get_earmark(self) -> Optional[str]:
128133
)
129134
return earmark_value
130135
except Exception as e:
131-
self._handle_cephfs_error(e, "getting")
132-
return None
136+
return self._handle_cephfs_error(e, "getting")
133137

134138
def set_earmark(self, earmark: str):
135139
# Validate the earmark before attempting to set it

0 commit comments

Comments
 (0)