From 4a35c97dc2e2710ce18a02ac02ff04688e87bfa3 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Wed, 8 Jan 2020 01:00:20 -0500 Subject: [PATCH] mgr/volumes: periodically check if copy operations should be canceled Signed-off-by: Venky Shankar (cherry picked from commit 9a0507acb62249e904d54c5ed11ef106f3239bd8) --- src/pybind/mgr/volumes/fs/async_cloner.py | 6 ++---- src/pybind/mgr/volumes/fs/fs_util.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/async_cloner.py b/src/pybind/mgr/volumes/fs/async_cloner.py index a0802fb928122..963fa34a6f1dd 100644 --- a/src/pybind/mgr/volumes/fs/async_cloner.py +++ b/src/pybind/mgr/volumes/fs/async_cloner.py @@ -83,9 +83,7 @@ def sync_attrs(fs_handle, target_path, source_statx): def bulk_copy(fs_handle, source_path, dst_path, should_cancel): """ bulk copy data from source to destination -- only directories, symlinks - and regular files are synced. note that @should_cancel is not used right - now but would be required when implementing cancelation for in-progress - clone operations. + and regular files are synced. """ log.info("copying data from {0} to {1}".format(source_path, dst_path)) def cptree(src_root_path, dst_root_path): @@ -125,7 +123,7 @@ def bulk_copy(fs_handle, source_path, dst_path, should_cancel): raise elif stat.S_ISREG(stx["mode"]): log.debug("cptree: (REG) {0}".format(d_full_src)) - copy_file(fs_handle, d_full_src, d_full_dst, mo) + copy_file(fs_handle, d_full_src, d_full_dst, mo, cancel_check=should_cancel) else: handled = False log.warn("cptree: (IGNORE) {0}".format(d_full_src)) diff --git a/src/pybind/mgr/volumes/fs/fs_util.py b/src/pybind/mgr/volumes/fs/fs_util.py index 79c0fa9c09238..baf6dae6243a8 100644 --- a/src/pybind/mgr/volumes/fs/fs_util.py +++ b/src/pybind/mgr/volumes/fs/fs_util.py @@ -86,7 +86,7 @@ def list_one_entry_at_a_time(fs, dirpath): except cephfs.Error as e: raise VolumeException(-e.args[0], e.args[1]) -def copy_file(fs, src, dst, mode): +def copy_file(fs, src, dst, mode, cancel_check=None): """ Copy a regular file from @src to @dst. @dst is overwritten if it exists. """ @@ -104,6 +104,8 @@ def copy_file(fs, src, dst, mode): IO_SIZE = 8 * 1024 * 1024 try: while True: + if cancel_check and cancel_check(): + raise VolumeException(-errno.EINTR, "copy operation interrupted") data = fs.read(src_fd, -1, IO_SIZE) if not len(data): break -- 2.39.5