Skip to content

Commit 3850c8d

Browse files
committed
pybind/mgr/volumes: add getter and setter APIs for snapdir_visibility
Fixes: https://tracker.ceph.com/issues/71740 Signed-off-by: Dhairya Parmar <[email protected]>
1 parent 5f9eb71 commit 3850c8d

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

src/pybind/mgr/volumes/fs/operations/template.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class SubvolumeOpType(Enum):
7373
EARMARK_GET = 'earmark-get'
7474
EARMARK_SET = 'earmark-set'
7575
EARMARK_CLEAR = 'earmark-clear'
76+
SNAPSHOT_VISIBILITY = 'snapshot-visibility'
7677

7778
class SubvolumeTemplate(object):
7879
VERSION = None # type: int

src/pybind/mgr/volumes/fs/operations/versions/subvolume_base.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,62 @@ def remove_snapshot_metadata(self, snapname, keyname):
645645
f"subvolume={self.subvol_name} group={self.group_name} "
646646
f"reason={me.args[1]}, errno:{-me.args[0]}, {os.strerror(-me.args[0])}")
647647
raise VolumeException(-me.args[0], me.args[1])
648+
649+
def snapshot_visibility_set(self, value):
650+
if value not in ("true", "false"):
651+
raise VolumeException(-errno.EINVAL, "snapshot visibility value invalid")
652+
653+
subvol_root_path = os.path.dirname(self.path)
654+
subvol_v2_path = self.path
655+
snaps_visibility_vxattr = "ceph.dir.subvolume.snaps.visible"
656+
subvolume_size = 0
657+
try:
658+
self.fs.setxattr(subvol_root_path, snaps_visibility_vxattr,
659+
str(value).encode('utf-8'), 0)
660+
except cephfs.Error as e:
661+
raise VolumeException(-e.args[0], e.args[1])
662+
663+
# in case of a sized subvolume, a new srnode will be assigned to the
664+
# volumes/<group-name>/<subvolume-name>/<uuid>/ path when applying
665+
# ceph.quota.max_bytes which would assign it with the default value
666+
# of is_snapdir_visible flag and right now the child snaprealm
667+
# changes are not being compiled and sent to the client by MDS, so until
668+
# that gets addressed, as a quick fix apply the vxattr on subvol root
669+
# and the uuid path. Once the child snaprealm fix is in place, apply
670+
# the vxattr only to subvolume root.
671+
try:
672+
subvolume_size = self.fs.getxattr(
673+
subvol_v2_path, "ceph.quota.max_bytes").decode('utf-8')
674+
except cephfs.NoData:
675+
# should be non-sized subvol v2 path
676+
pass
677+
if int(subvolume_size) > 0:
678+
try:
679+
self.fs.setxattr(subvol_v2_path, snaps_visibility_vxattr,
680+
str(value).encode('utf-8'), 0)
681+
except cephfs.Error as e:
682+
raise VolumeException(-e.args[0], e.args[1])
683+
684+
try:
685+
subvol_v2_path_snapshot_visibility = self.fs.getxattr(subvol_v2_path,
686+
snaps_visibility_vxattr).decode('utf-8')
687+
if bool(subvol_v2_path_snapshot_visibility) != bool(value):
688+
raise VolumeException(-errno.EINVAL, "could not set "
689+
f"{snaps_visibility_vxattr} to {value} "
690+
f"on subvolume v2 path {subvol_v2_path}")
691+
except cephfs.Error as e:
692+
raise VolumeException(-e.args[0], e.args[1])
693+
694+
try:
695+
return self.fs.getxattr(subvol_root_path,
696+
snaps_visibility_vxattr).decode('utf-8')
697+
except cephfs.Error as e:
698+
raise VolumeException(-e.args[0], e.args[1])
699+
700+
def snapshot_visibility_get(self):
701+
subvol_parent_path = os.path.dirname(self.path)
702+
try:
703+
return self.fs.getxattr(subvol_parent_path,
704+
"ceph.dir.subvolume.snaps.visible").decode('utf-8')
705+
except cephfs.Error as e:
706+
raise VolumeException(-e.args[0], e.args[1])

src/pybind/mgr/volumes/fs/volume.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,3 +1325,38 @@ def list_subvolume_group_snapshots(self, **kwargs):
13251325
except VolumeException as ve:
13261326
ret = self.volume_exception_to_retval(ve)
13271327
return ret
1328+
1329+
def subvolume_snapshot_visibility_set(self, **kwargs):
1330+
ret = 0, "", ""
1331+
volname = kwargs['vol_name']
1332+
subvolname = kwargs['sub_name']
1333+
groupname = kwargs['group_name']
1334+
value = kwargs['value']
1335+
1336+
try:
1337+
with open_volume(self, volname) as fs_handle:
1338+
with open_group(fs_handle, self.volspec, groupname) as group:
1339+
with open_subvol(self.mgr, fs_handle, self.volspec, group, subvolname,
1340+
SubvolumeOpType.SNAPSHOT_VISIBILITY) as subvolume:
1341+
v = subvolume.snapshot_visibility_set(value)
1342+
ret = 0, v, ""
1343+
except VolumeException as ve:
1344+
ret = self.volume_exception_to_retval(ve)
1345+
return ret
1346+
1347+
def subvolume_snapshot_visibility_get(self, **kwargs):
1348+
ret = 0, "", ""
1349+
volname = kwargs['vol_name']
1350+
subvolname = kwargs['sub_name']
1351+
groupname = kwargs['group_name']
1352+
1353+
try:
1354+
with open_volume(self, volname) as fs_handle:
1355+
with open_group(fs_handle, self.volspec, groupname) as group:
1356+
with open_subvol(self.mgr, fs_handle, self.volspec, group, subvolname,
1357+
SubvolumeOpType.SNAPSHOT_VISIBILITY) as subvolume:
1358+
v = subvolume.snapshot_visibility_get()
1359+
ret = 0, v, ""
1360+
except VolumeException as ve:
1361+
ret = self.volume_exception_to_retval(ve)
1362+
return ret

src/pybind/mgr/volumes/module.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,23 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
576576
'desc': "Cancel an pending or ongoing clone operation.",
577577
'perm': 'r'
578578
},
579+
{
580+
'cmd': 'fs subvolume snapshot_visibility set'
581+
' name=vol_name,type=CephString'
582+
' name=sub_name,type=CephString'
583+
' name=value,type=CephString,req=true'
584+
' name=group_name,type=CephString,req=false',
585+
'desc': "Set snapdir visibility for subvolume",
586+
'perm': 'rw'
587+
},
588+
{
589+
'cmd': 'fs subvolume snapshot_visibility get'
590+
' name=vol_name,type=CephString'
591+
' name=sub_name,type=CephString'
592+
' name=group_name,type=CephString,req=false',
593+
'desc': "Get snapdir visibility for subvolume",
594+
'perm': 'rw'
595+
},
579596
# volume ls [recursive]
580597
# subvolume ls <volume>
581598
# volume authorize/deauthorize
@@ -1097,3 +1114,16 @@ def subvolume_info(self, vol_name, subvol, group_name):
10971114
return self.vc.subvolume_info(vol_name=vol_name,
10981115
sub_name=subvol,
10991116
group_name=group_name)
1117+
1118+
@mgr_cmd_wrap
1119+
def _cmd_fs_subvolume_snapshot_visibility_set(self, inbuf, cmd):
1120+
return self.vc.subvolume_snapshot_visibility_set(vol_name=cmd['vol_name'],
1121+
sub_name=cmd['sub_name'],
1122+
value=cmd['value'],
1123+
group_name=cmd.get('group_name', None))
1124+
1125+
@mgr_cmd_wrap
1126+
def _cmd_fs_subvolume_snapshot_visibility_get(self, inbuf, cmd):
1127+
return self.vc.subvolume_snapshot_visibility_get(vol_name=cmd['vol_name'],
1128+
sub_name=cmd['sub_name'],
1129+
group_name=cmd.get('group_name', None))

0 commit comments

Comments
 (0)