Skip to content

Commit ba199cf

Browse files
author
neeraj pratap singh
committed
mgr/vol: fix subvolume removal with retained snapshots when osd is full
The order of operation done for subvolume removal with retain-snapshot option set to true, is reversed. The metadata is updated first followed by a rename operation on the uuid directory. If the metadata update operation fails, then the remove operations is failed thereby, keeping the subvolume metadata consistent with the uuid path. Fixes: https://tracker.ceph.com/issues/67330 Signed-off-by: Neeraj Pratap Singh <[email protected]>
1 parent bafdbd6 commit ba199cf

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ def open(self, op_type):
341341
except cephfs.Error as e:
342342
raise VolumeException(-e.args[0], e.args[1])
343343

344-
def trash_incarnation_dir(self):
344+
def trash_incarnation_dir(self, subvol_path):
345345
"""rename subvolume (uuid component) to trash"""
346346
self.create_trashcan()
347347
try:
348-
bname = os.path.basename(self.path)
348+
bname = os.path.basename(subvol_path)
349349
tpath = os.path.join(self.trash_dir, bname)
350-
log.debug("trash: {0} -> {1}".format(self.path, tpath))
351-
self.fs.rename(self.path, tpath)
350+
log.debug(f"trash: {subvol_path} -> {tpath}")
351+
self.fs.rename(subvol_path, tpath)
352352
self._link_dir(tpath, bname)
353353
except cephfs.Error as e:
354354
raise VolumeException(-e.args[0], e.args[1])
@@ -378,13 +378,20 @@ def remove(self, retainsnaps=False, internal_cleanup=False):
378378
self.auth_mdata_mgr.delete_subvolume_metadata_file(self.group.groupname, self.subvolname)
379379
return
380380
if self.state != SubvolumeStates.STATE_RETAINED:
381-
self.trash_incarnation_dir()
382-
self.metadata_mgr.remove_section(MetadataManager.USER_METADATA_SECTION)
383-
self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_PATH, "")
384-
self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_STATE, SubvolumeStates.STATE_RETAINED.value)
385-
self.metadata_mgr.flush()
386-
# Delete the volume meta file, if it's not already deleted
387-
self.auth_mdata_mgr.delete_subvolume_metadata_file(self.group.groupname, self.subvolname)
381+
try:
382+
# save subvol path for later use(renaming subvolume to trash) before deleting path section from .meta
383+
subvol_path = self.path
384+
self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_PATH, "")
385+
self.metadata_mgr.update_global_section(MetadataManager.GLOBAL_META_KEY_STATE, SubvolumeStates.STATE_RETAINED.value)
386+
self.metadata_mgr.remove_section(MetadataManager.USER_METADATA_SECTION)
387+
self.metadata_mgr.flush()
388+
self.trash_incarnation_dir(subvol_path)
389+
# Delete the volume meta file, if it's not already deleted
390+
self.auth_mdata_mgr.delete_subvolume_metadata_file(self.group.groupname, self.subvolname)
391+
except MetadataMgrException as e:
392+
log.error(f"failed to write config: {e}")
393+
raise VolumeException(e.args[0], e.args[1])
394+
388395

389396
def info(self):
390397
if self.state != SubvolumeStates.STATE_RETAINED:

0 commit comments

Comments
 (0)