]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: allow fetching path of FS subvolumes
authorRamana Raja <rraja@redhat.com>
Tue, 23 Apr 2019 13:03:58 +0000 (18:33 +0530)
committerRamana Raja <rraja@redhat.com>
Thu, 6 Jun 2019 15:24:22 +0000 (20:54 +0530)
... using `ceph fs subvolume getpath` command.

Signed-off-by: Ramana Raja <rraja@redhat.com>
(cherry picked from commit a47239b7f260ac4dcaf6faeb856f8f5d5dac7b4b)

src/pybind/mgr/volumes/fs/subvolume.py
src/pybind/mgr/volumes/module.py

index 9827f199fa1938920ae1d6564f02499fc959c686..272358ed5ca2b6c77e4008149f72b51a5a499191 100644 (file)
@@ -230,3 +230,11 @@ class SubvolumeClient(object):
                 raise
             else:
                 return self._get_ancestor_xattr(os.path.split(path)[0], attr)
+
+    def get_subvolume_path(self, subvolume_path):
+        path = self._subvolume_path(subvolume_path)
+        try:
+            self.fs.stat(path)
+        except cephfs.ObjectNotFound:
+            return None
+        return path
index 63ece7a13da50a444a93b68a540226acfb945ae9..df4ddba6b14c739cb27bf6ca7ae9ed711fbad3bf 100644 (file)
@@ -61,6 +61,13 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             'desc': "Delete a CephFS subvolume in a volume",
             'perm': 'rw'
         },
+        {
+            'cmd': 'fs subvolume getpath '
+                   'name=vol_name,type=CephString '
+                   'name=sub_name,type=CephString ',
+            'desc': "Get the mountpath of a CephFS subvolume in a volume",
+            'perm': 'rw'
+        },
 
         # volume ls [recursive]
         # subvolume ls <volume>
@@ -349,3 +356,18 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             })
 
         return 0, json.dumps(result, indent=2), ""
+
+    def _cmd_fs_subvolume_getpath(self, inbuf, cmd):
+        vol_name = cmd['vol_name']
+        sub_name = cmd['sub_name']
+
+        if not self._volume_exists(vol_name):
+            return -errno.ENOENT, "", "Volume '{0}' not found".format(vol_name)
+
+        with SubvolumeClient(self, fs_name=vol_name) as svc:
+            svp = SubvolumePath(sub_name, sub_name)
+            path = svc.get_subvolume_path(svp)
+            if not path:
+                return -errno.ENOENT, "", \
+                       "Subvolume '{0}' not found".format(sub_name)
+        return 0, path, ""