1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
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_id(self):
"""
Return the subvolume-id from the subvolume specification
"""
return self.subvolumeid
@property
def group_id(self):
"""
Return the group-id from the subvolume secification
"""
return self.groupid
@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)
|