From ca4cc7166ebc38fd923669174ce7c9b074d6975a Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Wed, 20 Nov 2019 09:02:53 -0500 Subject: [PATCH] mgr/volumes: provide subvolume create/remove/open APIs 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 (cherry picked from commit 8a649148025620991a67ed761153f18594f5268c) --- .../mgr/volumes/fs/operations/subvolume.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/pybind/mgr/volumes/fs/operations/subvolume.py diff --git a/src/pybind/mgr/volumes/fs/operations/subvolume.py b/src/pybind/mgr/volumes/fs/operations/subvolume.py new file mode 100644 index 0000000000000..6759045b4b902 --- /dev/null +++ b/src/pybind/mgr/volumes/fs/operations/subvolume.py @@ -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 -- 2.39.5