[Libguestfs] [PATCH libnbd 2/8] copy: Rename copy_subcommand to create_subcommand

Nir Soffer
Sun, 20 Feb 2022 12:13:57 -0000

copy_subcommand creates a new command without copying the original
command. Rename the function to make this more clear.

Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
 copy/multi-thread-copying.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/copy/multi-thread-copying.c b/copy/multi-thread-copying.c
index 632d7006..2d16d2df 100644
--- a/copy/multi-thread-copying.c
+++ b/copy/multi-thread-copying.c
@@ -332,26 +332,25 @@ poll_both_ends (uintptr_t index)
       dst->ops->asynch_notify_write (dst, index);
     else if ((fds[1].revents & (POLLERR | POLLNVAL)) != 0) {
       errno = ENOTCONN;
       perror (dst->name);
       exit (EXIT_FAILURE);
     }
   }
 }

 /* Create a sub-command of an existing command.  This creates a slice
- * referencing the buffer of the existing command in order to avoid
- * copying.
+ * referencing the buffer of the existing command without copying.
  */
 static struct command *
-copy_subcommand (struct command *command, uint64_t offset, size_t len,
-                 bool zero)
+create_subcommand (struct command *command, uint64_t offset, size_t len,
+                   bool zero)
 {
   const uint64_t end = command->offset + command->slice.len;
   struct command *newcommand;

   assert (command->offset <= offset && offset < end);
   assert (offset + len <= end);

   newcommand = calloc (1, sizeof *newcommand);
   if (newcommand == NULL) {
     perror ("calloc");
@@ -409,21 +408,21 @@ finished_read (void *vp, int *error)
          i + sparse_size <= end;
          i += sparse_size) {
       if (is_zero (slice_ptr (command->slice) + i-start, sparse_size)) {
         /* It's a zero range.  If the last was a zero too then we do
          * nothing here which coalesces.  Otherwise write the last data
          * and start a new zero range.
          */
         if (!last_is_zero) {
           /* Write the last data (if any). */
           if (i - last_offset > 0) {
-            newcommand = copy_subcommand (command,
+            newcommand = create_subcommand (command,
                                           last_offset, i - last_offset,
                                           false);
             dst->ops->asynch_write (dst, newcommand,
                                     (nbd_completion_callback) {
                                       .callback = free_command,
                                       .user_data = newcommand,
                                     });
           }
           /* Start the new zero range. */
           last_offset = i;
@@ -431,55 +430,55 @@ finished_read (void *vp, int *error)
         }
       }
       else {
         /* It's data.  If the last was data too, do nothing =>
          * coalesce.  Otherwise write the last zero range and start a
          * new data.
          */
         if (last_is_zero) {
           /* Write the last zero range (if any). */
           if (i - last_offset > 0) {
-            newcommand = copy_subcommand (command,
-                                          last_offset, i - last_offset,
-                                          true);
+            newcommand = create_subcommand (command,
+                                            last_offset, i - last_offset,
+                                            true);
             fill_dst_range_with_zeroes (newcommand);
           }
           /* Start the new data. */
           last_offset = i;
           last_is_zero = false;
         }
       }
     } /* for i */

     /* Write the last_offset up to i. */
     if (i - last_offset > 0) {
       if (!last_is_zero) {
-        newcommand = copy_subcommand (command,
-                                      last_offset, i - last_offset,
-                                      false);
+        newcommand = create_subcommand (command,
+                                        last_offset, i - last_offset,
+                                        false);
         dst->ops->asynch_write (dst, newcommand,
                                 (nbd_completion_callback) {
                                   .callback = free_command,
                                   .user_data = newcommand,
                                 });
       }
       else {
-        newcommand = copy_subcommand (command,
-                                      last_offset, i - last_offset,
-                                      true);
+        newcommand = create_subcommand (command,
+                                        last_offset, i - last_offset,
+                                        true);
         fill_dst_range_with_zeroes (newcommand);
       }
     }

     /* There may be an unaligned tail, so write that. */
     if (end - i > 0) {
-      newcommand = copy_subcommand (command, i, end - i, false);
+      newcommand = create_subcommand (command, i, end - i, false);
       dst->ops->asynch_write (dst, newcommand,
                               (nbd_completion_callback) {
                                 .callback = free_command,
                                 .user_data = newcommand,
                               });
     }

     /* Free the original command since it has been split into
      * subcommands and the original is no longer needed.
      */
--
2.35.1