]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/volumes/fs/subvolspec.py
4 class SubvolumeSpec(object):
6 Specification of a subvolume, identified by (subvolume-id, group-id) tuple. Add fields as
10 # where shall we (by default) create subvolumes
11 DEFAULT_SUBVOL_PREFIX
= "/volumes"
12 # and the default namespace
13 DEFAULT_NS_PREFIX
= "fsvolumens_"
15 # Reserved subvolume group name which we use in paths for subvolumes
16 # that are not assigned to a group (i.e. created with group=None)
17 NO_GROUP_NAME
= "_nogroup"
19 def __init__(self
, subvolumeid
, groupid
, subvolume_prefix
=None, pool_ns_prefix
=None):
20 assert groupid
!= SubvolumeSpec
.NO_GROUP_NAME
22 self
.subvolumeid
= subvolumeid
23 self
.groupid
= groupid
if groupid
is not None else SubvolumeSpec
.NO_GROUP_NAME
24 self
.subvolume_prefix
= subvolume_prefix
if subvolume_prefix
else SubvolumeSpec
.DEFAULT_SUBVOL_PREFIX
25 self
.pool_ns_prefix
= pool_ns_prefix
if pool_ns_prefix
else SubvolumeSpec
.DEFAULT_NS_PREFIX
27 def is_default_group(self
):
29 Is the group the default group?
31 return self
.groupid
== SubvolumeSpec
.NO_GROUP_NAME
34 def subvolume_id(self
):
36 Return the subvolume-id from the subvolume specification
38 return self
.subvolumeid
43 Return the group-id from the subvolume secification
48 def subvolume_path(self
):
50 return the subvolume path from subvolume specification
52 return os
.path
.join(self
.group_path
, self
.subvolumeid
.encode('utf-8'))
57 return the group path from subvolume specification
59 return os
.path
.join(self
.subvolume_prefix
.encode('utf-8'), self
.groupid
.encode('utf-8'))
64 return the trash path from subvolume specification
66 return os
.path
.join(self
.subvolume_prefix
.encode('utf-8'), b
"_deleting", self
.subvolumeid
.encode('utf-8'))
69 def unique_trash_path(self
):
71 return a unique trash directory entry path
73 return os
.path
.join(self
.subvolume_prefix
.encode('utf-8'), b
"_deleting", str(uuid
.uuid4()).encode('utf-8'))
76 def fs_namespace(self
):
78 return a filesystem namespace by stashing pool namespace prefix and subvolume-id
80 return "{0}{1}".format(self
.pool_ns_prefix
, self
.subvolumeid
)
85 return the trash directory path
87 return os
.path
.join(self
.subvolume_prefix
.encode('utf-8'), b
"_deleting")
89 def make_subvol_snap_path(self
, snapdir
, snapname
):
91 return the subvolume snapshot path for a given snapshot name
93 return os
.path
.join(self
.subvolume_path
, snapdir
.encode('utf-8'), snapname
.encode('utf-8'))
95 def make_subvol_snapdir_path(self
, snapdir
):
97 return the subvolume snapdir path
99 return os
.path
.join(self
.subvolume_path
, snapdir
.encode('utf-8'))
101 def make_group_snap_path(self
, snapdir
, snapname
):
103 return the group snapshot path for a given snapshot name
105 return os
.path
.join(self
.group_path
, snapdir
.encode('utf-8'), snapname
.encode('utf-8'))
107 def make_group_snapdir_path(self
, snapdir
):
109 return the group's snapdir path
111 return os
.path
.join(self
.group_path
, snapdir
.encode('utf-8'))
114 return "{0}/{1}".format(self
.groupid
, self
.subvolumeid
)