From: Jos Collin Date: Wed, 31 Jul 2024 14:38:24 +0000 (+0530) Subject: cephfs_mirror: ceph fs snapshot mirror ls command X-Git-Tag: v18.2.5~269^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=174930119de4bb857e206c1bf6b429cbba44340a;p=ceph.git cephfs_mirror: ceph fs snapshot mirror ls command Fixes: https://tracker.ceph.com/issues/67292 Signed-off-by: Jos Collin (cherry picked from commit 1c07a39a94deb7148a5061fa10612d40ea0ae469) --- diff --git a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py index 2bfb6482674..c348ce82de1 100644 --- a/src/pybind/mgr/mirroring/fs/snapshot_mirror.py +++ b/src/pybind/mgr/mirroring/fs/snapshot_mirror.py @@ -722,6 +722,20 @@ class FSSnapshotMirror: except Exception as e: return e.args[0], '', 'failed to remove directory' + def list_dirs(self, filesystem): + try: + with self.lock: + if not self.filesystem_exist(filesystem): + raise MirrorException(-errno.ENOENT, f'filesystem {filesystem} does not exist') + fspolicy = self.pool_policy.get(filesystem, None) + if not fspolicy: + raise MirrorException(-errno.EINVAL, f'filesystem {filesystem} is not mirrored') + return 0, json.dumps(list(fspolicy.policy.dir_states.keys()), indent=4, sort_keys=True), '' + except MirrorException as me: + return me.args[0], '', me.args[1] + except Exception as e: + return e.args[0], '', 'failed to list directories' + def status(self,filesystem, dir_path): try: with self.lock: diff --git a/src/pybind/mgr/mirroring/module.py b/src/pybind/mgr/mirroring/module.py index 4b4354ab2b9..67f0942147e 100644 --- a/src/pybind/mgr/mirroring/module.py +++ b/src/pybind/mgr/mirroring/module.py @@ -84,6 +84,12 @@ class Module(MgrModule): """Remove a snapshot mirrored directory""" return self.fs_snapshot_mirror.remove_dir(fs_name, path) + @CLIWriteCommand('fs snapshot mirror ls') + def snapshot_mirror_ls(self, + fs_name: str): + """List the snapshot mirrored directories""" + return self.fs_snapshot_mirror.list_dirs(fs_name) + @CLIReadCommand('fs snapshot mirror dirmap') def snapshot_mirror_dirmap(self, fs_name: str,