From: Venky Shankar Date: Wed, 8 Jan 2020 06:00:20 +0000 (-0500) Subject: mgr/volumes: periodically check if copy operations should be canceled X-Git-Tag: v15.2.0~26^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9a0507acb62249e904d54c5ed11ef106f3239bd8;p=ceph.git mgr/volumes: periodically check if copy operations should be canceled Signed-off-by: Venky Shankar --- diff --git a/src/pybind/mgr/volumes/fs/async_cloner.py b/src/pybind/mgr/volumes/fs/async_cloner.py index 048e06dd0d08..961faa583030 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 5f9995d4390b..44e8d279a8a6 100644 --- a/src/pybind/mgr/volumes/fs/fs_util.py +++ b/src/pybind/mgr/volumes/fs/fs_util.py @@ -89,7 +89,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. """ @@ -107,6 +107,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