From: Venky Shankar Date: Thu, 16 May 2019 05:54:12 +0000 (-0400) Subject: mgr / volumes: introduce subvolume specification class X-Git-Tag: v15.1.0~2452^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=021b80495da2740fedf45793e17a258f3ebf164c;p=ceph-ci.git mgr / volumes: introduce subvolume specification class Specifications class that represents a unique subvolume identified by (subvolume-id, group-id) tuple. Provide heleper functions for fetching various subvolume specific attributes such as subvolume path, group path etc. Signed-off-by: Venky Shankar --- diff --git a/src/pybind/mgr/volumes/fs/subvolspec.py b/src/pybind/mgr/volumes/fs/subvolspec.py new file mode 100644 index 00000000000..63e5094ce83 --- /dev/null +++ b/src/pybind/mgr/volumes/fs/subvolspec.py @@ -0,0 +1,87 @@ +import os + +class SubvolumeSpec(object): + """ + Specification of a subvolume, identified by (subvolume-id, group-id) tuple. Add fields as + required... + """ + + # where shall we (by default) create subvolumes + DEFAULT_SUBVOL_PREFIX = "/volumes" + # and the default namespace + DEFAULT_NS_PREFIX = "fsvolumens_" + + # Reserved subvolume group name which we use in paths for subvolumes + # that are not assigned to a group (i.e. created with group=None) + NO_GROUP_NAME = "_nogroup" + + def __init__(self, subvolumeid, groupid, subvolume_prefix=None, pool_ns_prefix=None): + assert groupid != SubvolumeSpec.NO_GROUP_NAME + + self.subvolumeid = subvolumeid + self.groupid = groupid if groupid is not None else SubvolumeSpec.NO_GROUP_NAME + self.subvolume_prefix = subvolume_prefix if subvolume_prefix else SubvolumeSpec.DEFAULT_SUBVOL_PREFIX + self.pool_ns_prefix = pool_ns_prefix if pool_ns_prefix else SubvolumeSpec.DEFAULT_NS_PREFIX + + def is_default_group(self): + """ + Is the group the default group? + """ + return self.groupid == SubvolumeSpec.NO_GROUP_NAME + + @property + def subvolume_path(self): + """ + return the subvolume path from subvolume specification + """ + return os.path.join(self.subvolume_prefix, self.groupid, self.subvolumeid) + + @property + def group_path(self): + """ + return the group path from subvolume specification + """ + return os.path.join(self.subvolume_prefix, self.groupid) + + @property + def trash_path(self): + """ + return the trash path from subvolume specification + """ + return os.path.join(self.subvolume_prefix, "_deleting", self.subvolumeid) + + @property + def fs_namespace(self): + """ + return a filesystem namespace by stashing pool namespace prefix and subvolume-id + """ + return "{0}{1}".format(self.pool_ns_prefix, self.subvolumeid) + + @property + def group_dir(self): + """ + return the group directory path + """ + return self.subvolume_prefix + + @property + def trash_dir(self): + """ + return the trash directory path + """ + return os.path.join(self.subvolume_prefix, "_deleting") + + def make_subvol_snap_path(self, snapdir, snapname): + """ + return the subvolume snapshot path for a given snapshot name + """ + return os.path.join(self.subvolume_path, snapdir, snapname) + + def make_group_snap_path(self, snapdir, snapname): + """ + return the group snapshot path for a given snapshot name + """ + return os.path.join(self.group_path, snapdir, snapname) + + def __str__(self): + return "{0}/{1}".format(self.groupid, self.subvolumeid)