]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: Allow forceful snapshot removal on osd full
authorKotresh HR <khiremat@redhat.com>
Wed, 6 Jul 2022 11:59:39 +0000 (17:29 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 16 Aug 2022 11:38:47 +0000 (17:08 +0530)
When the osd is full, if the snapshot has metadata set, it
can't be removed as user metadata can't be removed when osd
is full. This patch provides a way to remove the snapshot
with 'force' option while keeping the corresponding metadata
which gets removed on subvolume discover when it finds space.

Fixes: https://tracker.ceph.com/issues/55976
Signed-off-by: Kotresh HR <khiremat@redhat.com>
qa/workunits/fs/full/subvolume_snapshot_rm.sh
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py
src/pybind/mgr/volumes/fs/volume.py

index a891ab255ab2ae5e6b8ab9df67f7f5eb01e7345f..f6d0add9fda40e8b7b49d38637d5be9be7811b05 100755 (executable)
@@ -66,9 +66,11 @@ echo "After write"
 df $CEPH_MNT
 ceph osd df
 
+# Snapshot removal with force option should succeed
+ceph fs subvolume snapshot rm cephfs sub_0 snap_0 --force
+
 #Cleanup from backend
 ignore_failure sudo rm -f /tmp/error_${PID}_file
-ignore_failure sudo rmdir $CEPH_MNT/volumes/_nogroup/sub_0/.snap/snap_0
 ignore_failure sudo rm -rf $CEPH_MNT/volumes/_nogroup/sub_0
 
 #Set the ratios back for other full tests to run
index e2857cec3d184a81fef15fbe9213235d197198c2..0e2a64d48eac9d62ba624c4544d13400e654229f 100644 (file)
@@ -806,7 +806,7 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate):
 
         return pending_clones_info
 
-    def remove_snapshot(self, snapname):
+    def remove_snapshot(self, snapname, force=False):
         if self.has_pending_clones(snapname):
             raise VolumeException(-errno.EAGAIN, "snapshot '{0}' has pending clones".format(snapname))
         snappath = self.snapshot_path(snapname)
@@ -814,9 +814,16 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate):
             self.metadata_mgr.remove_section(self.get_snap_section_name(snapname))
             self.metadata_mgr.flush()
         except MetadataMgrException as me:
-            log.error(f"Failed to remove snapshot metadata on snap={snapname} subvol={self.subvol_name} "
-                      f"group={self.group_name} reason={me.args[1]}, errno:{-me.args[0]}, {os.strerror(-me.args[0])}")
-            raise VolumeException(-errno.EAGAIN, f"failed to remove snapshot metadata on snap={snapname} reason={me.args[0]} {me.args[1]}")
+            if force:
+                log.info(f"Allowing snapshot removal on failure of it's metadata removal with force on "
+                         f"snap={snapname} subvol={self.subvol_name} group={self.group_name} reason={me.args[1]}, "
+                         f"errno:{-me.args[0]}, {os.strerror(-me.args[0])}")
+                pass
+            else:
+                log.error(f"Failed to remove snapshot metadata on snap={snapname} subvol={self.subvol_name} "
+                          f"group={self.group_name} reason={me.args[1]}, errno:{-me.args[0]}, {os.strerror(-me.args[0])}")
+                raise VolumeException(-errno.EAGAIN,
+                                      f"failed to remove snapshot metadata on snap={snapname} reason={me.args[0]} {me.args[1]}")
         rmsnap(self.fs, snappath)
 
     def snapshot_info(self, snapname):
index 31d5f2443c501f49c8af1c6a23c9e9d5e819337a..03085d049713f2c24d1742455c51a805b9ce69fc 100644 (file)
@@ -385,8 +385,8 @@ class SubvolumeV2(SubvolumeV1):
 
         return {'type': self.subvol_type.value, 'features': self.features, 'state': SubvolumeStates.STATE_RETAINED.value}
 
-    def remove_snapshot(self, snapname):
-        super(SubvolumeV2, self).remove_snapshot(snapname)
+    def remove_snapshot(self, snapname, force=False):
+        super(SubvolumeV2, self).remove_snapshot(snapname, force)
         if self.purgeable:
             self.trash_base_dir()
             # tickle the volume purge job to purge this entry, using ESTALE
index cef35ad1546dab0e3a9d30caecf0882f106b1721..cfc7480d6b778fa26169488de965fdc7bd0c7d96 100644 (file)
@@ -519,7 +519,7 @@ class VolumeClient(CephfsClient["Module"]):
             with open_volume(self, volname) as fs_handle:
                 with open_group(fs_handle, self.volspec, groupname) as group:
                     with open_subvol(self.mgr, fs_handle, self.volspec, group, subvolname, SubvolumeOpType.SNAP_REMOVE) as subvolume:
-                        subvolume.remove_snapshot(snapname)
+                        subvolume.remove_snapshot(snapname, force)
         except VolumeException as ve:
             # ESTALE serves as an error to state that subvolume is currently stale due to internal removal and,
             # we should tickle the purge jobs to purge the same