Skip to content

Commit 0ef6da6

Browse files
mgr/vol: show clone source info in "subvolume info" cmd output
Include clone source information in output of "ceph fs subvolume info" command so that users can access this information conveniently. Fixes: https://tracker.ceph.com/issues/71266 Signed-off-by: Rishabh Dave <[email protected]>
1 parent bbacfda commit 0ef6da6

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,34 @@ def create_base_dir(self, mode):
442442
except cephfs.Error as e:
443443
raise VolumeException(-e.args[0], e.args[1])
444444

445+
def _get_clone_source(self):
446+
try:
447+
clone_source = {
448+
'volume' : self.metadata_mgr.get_option("source", "volume"),
449+
'subvolume': self.metadata_mgr.get_option("source", "subvolume"),
450+
'snapshot' : self.metadata_mgr.get_option("source", "snapshot"),
451+
}
452+
453+
try:
454+
clone_source["group"] = self.metadata_mgr.get_option("source", "group")
455+
except MetadataMgrException as me:
456+
if me.errno == -errno.ENOENT:
457+
pass
458+
else:
459+
raise
460+
except MetadataMgrException as e:
461+
if e.errno == -errno.ENOENT:
462+
clone_source = {}
463+
else:
464+
raise VolumeException(-errno.EINVAL,
465+
"error fetching subvolume metadata")
466+
return clone_source
467+
468+
def get_clone_source(self):
469+
src = self._get_clone_source()
470+
return (src['volume'], src.get('group', None), src['subvolume'],
471+
src['snapshot'])
472+
445473
def info(self):
446474
subvolpath = (self.metadata_mgr.get_global_option(
447475
MetadataManager.GLOBAL_META_KEY_PATH))
@@ -494,7 +522,8 @@ def info(self):
494522
except cephfs.NoData:
495523
casesensitive = True
496524

497-
return {'path': subvolpath,
525+
subvol_info = {
526+
'path': subvolpath,
498527
'type': etype.value,
499528
'uid': int(st["uid"]),
500529
'gid': int(st["gid"]),
@@ -517,6 +546,26 @@ def info(self):
517546
'casesensitive': casesensitive,
518547
}
519548

549+
subvol_src_info = self._get_clone_source()
550+
if subvol_src_info:
551+
if subvol_src_info.get('group', None) == None:
552+
# group name won't be saved in .meta file in case it's
553+
# default group
554+
subvol_src_info['group'] = '_nogroup'
555+
subvol_info['source'] = subvol_src_info
556+
else:
557+
# it could be that the clone was created in previous release of Ceph
558+
# where its source info used to be deleted after cloning finishes.
559+
# print "N/A" for such cases.
560+
if self.subvol_type == SubvolumeTypes.TYPE_CLONE:
561+
subvol_info['source'] = 'N/A'
562+
else:
563+
# only clones can have a source subvol, therefore don't even
564+
# print "N/A" for source info if subvolume is not a clone.
565+
pass
566+
567+
return subvol_info
568+
520569
def set_user_metadata(self, keyname, value):
521570
try:
522571
self.metadata_mgr.add_section(MetadataManager.USER_METADATA_SECTION)

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -652,30 +652,6 @@ def evict(self, volname, auth_id, timeout=30):
652652
log.error(msg)
653653
raise EvictionError(msg)
654654

655-
def _get_clone_source(self):
656-
try:
657-
clone_source = {
658-
'volume' : self.metadata_mgr.get_option("source", "volume"),
659-
'subvolume': self.metadata_mgr.get_option("source", "subvolume"),
660-
'snapshot' : self.metadata_mgr.get_option("source", "snapshot"),
661-
}
662-
663-
try:
664-
clone_source["group"] = self.metadata_mgr.get_option("source", "group")
665-
except MetadataMgrException as me:
666-
if me.errno == -errno.ENOENT:
667-
pass
668-
else:
669-
raise
670-
except MetadataMgrException:
671-
raise VolumeException(-errno.EINVAL, "error fetching subvolume metadata")
672-
return clone_source
673-
674-
def get_clone_source(self):
675-
src = self._get_clone_source()
676-
return (src['volume'], src.get('group', None), src['subvolume'],
677-
src['snapshot'])
678-
679655
def _get_clone_failure(self):
680656
clone_failure = {
681657
'errno' : self.metadata_mgr.get_option(MetadataManager.CLONE_FAILURE_SECTION, MetadataManager.CLONE_FAILURE_META_KEY_ERRNO),

0 commit comments

Comments
 (0)