]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: V2 Fix for test_subvolume_retain_snapshot_invalid_recreate
authorKotresh HR <khiremat@redhat.com>
Thu, 9 Jun 2022 08:00:59 +0000 (13:30 +0530)
committerDavid Galloway <dgallowa@redhat.com>
Thu, 21 Jul 2022 16:27:47 +0000 (12:27 -0400)
Signed-off-by: Kotresh HR <khiremat@redhat.com>
(cherry picked from commit 5bb46ee690591411d4890b613c6380fced9d04b4)

src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py

index 54796b5ad367587fc40e758b183c59230e109eba..91c2e7e492dedc91940aba87a3cf83227f2d4093 100644 (file)
@@ -17,6 +17,7 @@ from ...fs_util import get_ancestor_xattr
 from ...exception import MetadataMgrException, VolumeException
 from .op_sm import SubvolumeOpSm
 from .auth_metadata import AuthMetadataManager
+from .subvolume_attrs import SubvolumeStates
 
 log = logging.getLogger(__name__)
 
@@ -112,7 +113,7 @@ class SubvolumeBase(object):
     @property
     def state(self):
         """ Subvolume state, one of SubvolumeStates """
-        raise NotImplementedError
+        return SubvolumeStates.from_value(self.metadata_mgr.get_global_option(MetadataManager.GLOBAL_META_KEY_STATE))
 
     @property
     def subvol_type(self):
@@ -287,7 +288,10 @@ class SubvolumeBase(object):
             self.metadata_mgr.refresh()
             log.debug("loaded subvolume '{0}'".format(self.subvolname))
             subvolpath = self.metadata_mgr.get_global_option(MetadataManager.GLOBAL_META_KEY_PATH)
-            if not self.legacy_mode and self.base_path.decode('utf-8') != str(Path(subvolpath).parent):
+            # subvolume with retained snapshots has empty path, don't mistake it for
+            # fabricated metadata.
+            if (not self.legacy_mode and self.state != SubvolumeStates.STATE_RETAINED and
+                self.base_path.decode('utf-8') != str(Path(subvolpath).parent)):
                 raise MetadataMgrException(-errno.ENOENT, 'fabricated .meta')
         except MetadataMgrException as me:
             if me.errno in (-errno.ENOENT, -errno.EINVAL) and not self.legacy_mode:
index 42c08e04712b173fe2fbbd3a0db9c7d917f4728b..274fabab86f2a146194b0cbea84aa5a675ce736b 100644 (file)
@@ -673,7 +673,7 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate):
 
     @property
     def state(self):
-        return SubvolumeStates.from_value(self.metadata_mgr.get_global_option(MetadataManager.GLOBAL_META_KEY_STATE))
+        return super(SubvolumeV1, self).state
 
     @state.setter
     def state(self, val):