]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/vol: make "subvol rm" work for subvol v3
authorRishabh Dave <ridave@redhat.com>
Sat, 29 Mar 2025 11:19:51 +0000 (16:49 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 21 Nov 2025 06:07:57 +0000 (11:37 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/volumes/fs/operations/trash.py
src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v3.py

index 80ff86a8dc1528d68a6897328b67580e5a63cb31..9e415f4caf19b3890183e7e74cce12d264fd3ae6 100644 (file)
@@ -76,7 +76,7 @@ class Trash(GroupTemplate):
         except cephfs.Error as e:
             raise VolumeException(-e.args[0], e.args[1])
 
-    def dump(self, SRC_PATH):
+    def dump(self, SRC_PATH, unique=False):
         """
         move an filesystem entity to trash can.
 
@@ -84,7 +84,12 @@ class Trash(GroupTemplate):
         :return: None
         """
         try:
-            self.fs.rename(SRC_PATH, self.unique_trash_path)
+            if unique:
+                self.fs.rename(SRC_PATH, self.unique_trash_path)
+            else:
+                uuid = os.path.basename(SRC_PATH)
+                DST_PATH = os.path.join(self.path, uuid)
+                self.fs.rename(SRC_PATH, DST_PATH)
         except cephfs.Error as e:
             raise VolumeException(-e.args[0], e.args[1])
 
index 479c25feadef65d732e16607ad73a2b9beb8c26d..53429b2e129b059d970a6b646b1a287382de75a0 100644 (file)
@@ -475,7 +475,7 @@ class SubvolumeBase(object):
     def _trash_dir(self, path):
         create_trashcan(self.fs, self.vol_spec)
         with open_trashcan(self.fs, self.vol_spec) as trashcan:
-            trashcan.dump(path)
+            trashcan.dump(path, unique=True)
             log.info("subvolume path '{0}' moved to trashcan".format(path))
 
     def _link_dir(self, path, bname):
index a117ce2940c5e4f3923e3f5c4008eda748b4dce0..bec36c22b6ab6c501816398d105c33fe627a5731 100644 (file)
@@ -6,6 +6,7 @@ from uuid import uuid4
 import cephfs
 
 from .subvolume_v2 import SubvolumeV2
+from ..trash import create_trashcan, open_trashcan
 from ...exception import VolumeException
 from ...fs_util import listdir, create_base_dir
 
@@ -154,3 +155,53 @@ class SubvolumeV3(SubvolumeV2):
             # doesn't exist
             self.auth_mdata_mgr.create_subvolume_metadata_file(
                 self.group.groupname, self.subvolname)
+
+
+    # following are methods that help or do subvol deletion
+
+
+    @property
+    def trash_dir(self):
+        raise RuntimeError('method trash_dir() shouldn\'t be called in '
+                           'subvol v3 codebase, since it doesn\'t have a '
+                           'in-subvol trash dir (which is named ".trash" in'
+                           'subvol v2)')
+
+    def create_trashcan(self):
+        raise RuntimeError('method create_trashcan() shouldn\'t be called in '
+                           'subvol v3 codebase, since it doesn\'t have a '
+                           'in-subvol trash dir (which is named ".trash" in'
+                           'subvol v2)')
+
+    def is_mnt_dir_empty(self):
+        return not listdir(self.fs, self.mnt_dir)
+
+    def are_there_other_incarnations(self):
+        if len(listdir(self.fs, self.roots_dir)) > 1:
+            return True
+        elif len(listdir(self.fs, self.roots_dir)) == 1:
+            return False
+        else:
+            raise RuntimeError('self.roots_dir can\'t have zero or less than '
+                               'zero directories in it')
+
+    def trash_subvol_dir(self):
+        create_trashcan(self.fs, self.vol_spec)
+
+        if self.is_mnt_dir_empty() and not self.are_there_other_incarnations():
+            with open_trashcan(self.fs, self.vol_spec) as trashcan:
+                trashcan.dump(self.subvol_dir)
+
+    # TODO: base dir should be deleted in subvol v3 too when no snaps are
+    # retained on any incarnation, right?
+    def trash_base_dir(self):
+        # code under _trash_subvol_dir can be move here technically but this
+        # extra layer of call has been added to indicate that in subvol v3
+        # terms
+        self.trash_subvol_dir()
+
+    # since there is not in-subvol ".trash" dir in subvol v3, this method
+    # should always return False
+    @property
+    def has_pending_purges(self):
+        return False