Skip to content

Commit eb21831

Browse files
committed
Merge PR ceph#58966 into main
* refs/pull/58966/head: qa: test 'ceph fs snapshot mirror ls' command doc: update docs for 'fs snapshot mirror ls' command cephfs_mirror: ceph fs snapshot mirror ls command Reviewed-by: Venky Shankar <[email protected]> Reviewed-by: Dhairya Parmar <[email protected]>
2 parents 9f1311f + 6b24da7 commit eb21831

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

doc/cephfs/cephfs-mirroring.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ To configure a directory for mirroring, run a command of the following form:
189189

190190
ceph fs snapshot mirror add <fs_name> <path>
191191

192+
To list the configured directories, run a command of the following form:
193+
194+
.. prompt:: bash $
195+
196+
ceph fs snapshot mirror ls <fs_name>
197+
192198
To stop mirroring directory snapshots, run a command of the following form:
193199

194200
.. prompt:: bash $

qa/tasks/cephfs/test_mirroring.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,34 @@ def test_directory_commands(self):
432432
self.disable_mirroring(self.primary_fs_name, self.primary_fs_id)
433433
self.mount_a.run_shell(["rmdir", "d1"])
434434

435+
def test_directory_command_ls(self):
436+
dir1 = 'dls1'
437+
dir2 = 'dls2'
438+
self.mount_a.run_shell(["mkdir", dir1])
439+
self.mount_a.run_shell(["mkdir", dir2])
440+
self.enable_mirroring(self.primary_fs_name, self.primary_fs_id)
441+
try:
442+
self.add_directory(self.primary_fs_name, self.primary_fs_id, f'/{dir1}')
443+
self.add_directory(self.primary_fs_name, self.primary_fs_id, f'/{dir2}')
444+
time.sleep(10)
445+
dirs_list = json.loads(self.get_ceph_cmd_stdout("fs", "snapshot", "mirror", "ls", self.primary_fs_name))
446+
# verify via asok
447+
res = self.mirror_daemon_command(f'mirror status for fs: {self.primary_fs_name}',
448+
'fs', 'mirror', 'status', f'{self.primary_fs_name}@{self.primary_fs_id}')
449+
dir_count = res['snap_dirs']['dir_count']
450+
self.assertTrue(len(dirs_list) == dir_count and f'/{dir1}' in dirs_list and f'/{dir2}' in dirs_list)
451+
except CommandFailedError:
452+
raise RuntimeError('Error listing directories')
453+
except AssertionError:
454+
raise RuntimeError('Wrong number of directories listed')
455+
finally:
456+
self.remove_directory(self.primary_fs_name, self.primary_fs_id, f'/{dir1}')
457+
self.remove_directory(self.primary_fs_name, self.primary_fs_id, f'/{dir2}')
458+
459+
self.disable_mirroring(self.primary_fs_name, self.primary_fs_id)
460+
self.mount_a.run_shell(["rmdir", dir1])
461+
self.mount_a.run_shell(["rmdir", dir2])
462+
435463
def test_add_relative_directory_path(self):
436464
self.enable_mirroring(self.primary_fs_name, self.primary_fs_id)
437465
try:

src/pybind/mgr/mirroring/fs/snapshot_mirror.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,20 @@ def remove_dir(self, filesystem, dir_path):
722722
except Exception as e:
723723
return e.args[0], '', 'failed to remove directory'
724724

725+
def list_dirs(self, filesystem):
726+
try:
727+
with self.lock:
728+
if not self.filesystem_exist(filesystem):
729+
raise MirrorException(-errno.ENOENT, f'filesystem {filesystem} does not exist')
730+
fspolicy = self.pool_policy.get(filesystem, None)
731+
if not fspolicy:
732+
raise MirrorException(-errno.EINVAL, f'filesystem {filesystem} is not mirrored')
733+
return 0, json.dumps(list(fspolicy.policy.dir_states.keys()), indent=4, sort_keys=True), ''
734+
except MirrorException as me:
735+
return me.args[0], '', me.args[1]
736+
except Exception as e:
737+
return e.args[0], '', 'failed to list directories'
738+
725739
def status(self,filesystem, dir_path):
726740
try:
727741
with self.lock:

src/pybind/mgr/mirroring/module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def snapshot_mirror_remove_dir(self,
8484
"""Remove a snapshot mirrored directory"""
8585
return self.fs_snapshot_mirror.remove_dir(fs_name, path)
8686

87+
@CLIWriteCommand('fs snapshot mirror ls')
88+
def snapshot_mirror_ls(self,
89+
fs_name: str):
90+
"""List the snapshot mirrored directories"""
91+
return self.fs_snapshot_mirror.list_dirs(fs_name)
92+
8793
@CLIReadCommand('fs snapshot mirror dirmap')
8894
def snapshot_mirror_dirmap(self,
8995
fs_name: str,

0 commit comments

Comments
 (0)