]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: provide subvolume create/remove/open APIs
authorVenky Shankar <vshankar@redhat.com>
Wed, 20 Nov 2019 14:02:53 +0000 (09:02 -0500)
committerRamana Raja <rraja@redhat.com>
Wed, 12 Feb 2020 10:11:59 +0000 (05:11 -0500)
create_subvolume() creates a subvolume with the max version known
to the plugin. open_subvolume() performs version discovery by
using loader stub and returns a subvoule object.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
(cherry picked from commit 8a649148025620991a67ed761153f18594f5268c)

src/pybind/mgr/volumes/fs/operations/subvolume.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/volumes/fs/operations/subvolume.py b/src/pybind/mgr/volumes/fs/operations/subvolume.py
new file mode 100644 (file)
index 0000000..6759045
--- /dev/null
@@ -0,0 +1,57 @@
+import os
+import errno
+from contextlib import contextmanager
+
+import cephfs
+
+from .snapshot_util import mksnap, rmsnap
+from ..fs_util import listdir, get_ancestor_xattr
+from ..exception import VolumeException
+
+from .versions import loaded_subvolumes
+
+def create_subvol(fs, vol_spec, group, subvolname, size, isolate_nspace, pool, mode, uid, gid):
+    """
+    create a subvolume (create a subvolume with the max known version).
+
+    :param fs: ceph filesystem handle
+    :param vol_spec: volume specification
+    :param group: group object for the subvolume
+    :param size: In bytes, or None for no size limit
+    :param isolate_nspace: If true, use separate RADOS namespace for this subvolume
+    :param pool: the RADOS pool where the data objects of the subvolumes will be stored
+    :param mode: the user permissions
+    :param uid: the user identifier
+    :param gid: the group identifier
+    :return: None
+    """
+    subvolume = loaded_subvolumes.get_subvolume_object_max(fs, vol_spec, group, subvolname)
+    subvolume.create(size, isolate_nspace, pool, mode, uid, gid)
+
+def remove_subvol(fs, vol_spec, group, subvolname):
+    """
+    remove a subvolume.
+
+    :param fs: ceph filesystem handle
+    :param vol_spec: volume specification
+    :param group: group object for the subvolume
+    :param subvolname: subvolume name
+    :return: None
+    """
+    with open_subvol(fs, vol_spec, group, subvolname) as subvolume:
+        subvolume.remove()
+
+@contextmanager
+def open_subvol(fs, vol_spec, group, subvolname):
+    """
+    open a subvolume. This API is to be used as a context manager.
+
+    :param fs: ceph filesystem handle
+    :param vol_spec: volume specification
+    :param group: group object for the subvolume
+    :param subvolname: subvolume name
+    :return: yields a subvolume object (subclass of SubvolumeTemplate)
+    """
+    subvolume = loaded_subvolumes.get_subvolume_object(fs, vol_spec, group, subvolname)
+    subvolume.open()
+    yield subvolume