]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: periodically check if copy operations should be canceled
authorVenky Shankar <vshankar@redhat.com>
Wed, 8 Jan 2020 06:00:20 +0000 (01:00 -0500)
committerRamana Raja <rraja@redhat.com>
Wed, 18 Mar 2020 05:32:46 +0000 (11:02 +0530)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/pybind/mgr/volumes/fs/async_cloner.py
src/pybind/mgr/volumes/fs/fs_util.py

index 048e06dd0d08287826c12c707c3c676cea642250..961faa583030b9e2b9d76849cd02fce3dc74ef7b 100644 (file)
@@ -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))
index 5f9995d4390b32a2d1890dd5be10cc7e0c897586..44e8d279a8a659272b506a17cad5f58674de3eec 100644 (file)
@@ -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