]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: allow creation/deletion of FS subvolume group snapshots 27594/head
authorRamana Raja <rraja@redhat.com>
Tue, 30 Apr 2019 10:01:27 +0000 (15:31 +0530)
committerRamana Raja <rraja@redhat.com>
Tue, 14 May 2019 14:10:42 +0000 (19:40 +0530)
... using `ceph fs subvolumegroup snapshot create/rm` commands.

Signed-off-by: Ramana Raja <rraja@redhat.com>
src/pybind/mgr/volumes/fs/subvolume.py
src/pybind/mgr/volumes/module.py

index e86c169f8ed6e95af8e52ffb77487fbf5713e27b..40327e5c5a5453977c932f4642fee83389a2f03e 100644 (file)
@@ -299,3 +299,9 @@ class SubvolumeClient(object):
 
     def delete_subvolume_snapshot(self, subvolume_path, snapshot_name):
         return self._snapshot_delete(self._subvolume_path(subvolume_path), snapshot_name)
+
+    def create_group_snapshot(self, group_id, snapshot_name, mode=0o755):
+        return self._snapshot_create(self._group_path(group_id), snapshot_name, mode)
+
+    def delete_group_snapshot(self, group_id, snapshot_name):
+        return self._snapshot_delete(self._group_path(group_id), snapshot_name)
index e2c8f8356b00cae9faa42c3dc56dbd7a9abc3974..95e0d8e3878ed7ca7e6d67ca0691d957d9752c7c 100644 (file)
@@ -89,6 +89,23 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
                     "and optionally, in a specific subvolume group",
             'perm': 'rw'
         },
+        {
+            'cmd': 'fs subvolumegroup snapshot create '
+                   'name=vol_name,type=CephString '
+                   'name=group_name,type=CephString '
+                   'name=snap_name,type=CephString ',
+            'desc': "Create a snapshot of a CephFS subvolume group in a volume",
+            'perm': 'rw'
+        },
+        {
+            'cmd': 'fs subvolumegroup snapshot rm '
+                   'name=vol_name,type=CephString '
+                   'name=group_name,type=CephString '
+                   'name=snap_name,type=CephString '
+                   'name=force,type=CephBool,req=false ',
+                   'desc': "Delete a snapshot of a CephFS subvolume group in a volume",
+            'perm': 'rw'
+        },
         {
             'cmd': 'fs subvolume snapshot create '
                    'name=vol_name,type=CephString '
@@ -487,6 +504,55 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
                        "Subvolume '{0}' not found".format(sub_name)
         return 0, path, ""
 
+    def _cmd_fs_subvolumegroup_snapshot_create(self, inbuf, cmd):
+        vol_name = cmd['vol_name']
+        group_name = cmd['group_name']
+        snap_name = cmd['snap_name']
+
+        if not self._volume_exists(vol_name):
+            return -errno.ENOENT, "", \
+                   "Volume '{0}' not found, cannot create snapshot '{1}'".format(vol_name, snap_name)
+
+        with SubvolumeClient(self, fs_name=vol_name) as svc:
+            if group_name and not svc.get_group_path(group_name):
+                return -errno.ENOENT, "", \
+                    "Subvolume group '{0}' not found, cannot create snapshot '{1}'".format(group_name, snap_name)
+            svc.create_group_snapshot(group_name, snap_name)
+
+        return 0, "", ""
+
+    def _cmd_fs_subvolumegroup_snapshot_rm(self, inbuf, cmd):
+        vol_name = cmd['vol_name']
+        group_name = cmd['group_name']
+        snap_name = cmd['snap_name']
+
+        force = cmd.get('force', False)
+
+        if not self._volume_exists(vol_name):
+            if force:
+                return 0, "", ""
+            else:
+                return -errno.ENOENT, "", \
+                       "Volume '{0}' not found, cannot remove subvolumegroup snapshot '{1}'".format(vol_name, snap_name)
+
+        with SubvolumeClient(self, fs_name=vol_name) as svc:
+            if group_name and not svc.get_group_path(group_name):
+                if force:
+                    return 0, "", ""
+                else:
+                    return -errno.ENOENT, "", \
+                           "Subvolume group '{0}' not found, cannot remove subvolumegroup snapshot '{1}'".format(group_name, snap_name)
+            try:
+                svc.delete_group_snapshot(group_name, snap_name)
+            except cephfs.ObjectNotFound:
+                if force:
+                    return 0, "", ""
+                else:
+                    return -errno.ENOENT, "", \
+                           "Subvolume group snapshot '{0}' not found, cannot remove it".format(sub_name)
+
+        return 0, "", ""
+
     def _cmd_fs_subvolume_snapshot_create(self, inbuf, cmd):
         vol_name = cmd['vol_name']
         sub_name = cmd['sub_name']