[Libguestfs] [PATCH libnbd 1/8] copy: Remove wrong references to holes

Nir Soffer nsoffer at redhat.com
Sun Feb 20 12:13:56 UTC 2022


In the past nbdcopy was looking for hole extents instead of zero
extents. When we fixed this, we forgot to update some comments and
variable names referencing hole instead of zero.

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

diff --git a/copy/multi-thread-copying.c b/copy/multi-thread-copying.c
index 7459b446..632d7006 100644
--- a/copy/multi-thread-copying.c
+++ b/copy/multi-thread-copying.c
@@ -337,36 +337,36 @@ poll_both_ends (uintptr_t index)
     }
   }
 }
 
 /* Create a sub-command of an existing command.  This creates a slice
  * referencing the buffer of the existing command in order to avoid
  * copying.
  */
 static struct command *
 copy_subcommand (struct command *command, uint64_t offset, size_t len,
-                 bool hole)
+                 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");
     exit (EXIT_FAILURE);
   }
   newcommand->offset = offset;
   newcommand->slice.len = len;
-  if (!hole) {
+  if (!zero) {
     newcommand->slice.buffer = command->slice.buffer;
     newcommand->slice.buffer->refs++;
     newcommand->slice.base = offset - command->offset;
   }
   newcommand->index = command->index;
 
   return newcommand;
 }
 
 /* Callback called when src has finished one read command.  This
@@ -390,76 +390,76 @@ finished_read (void *vp, int *error)
     dst->ops->asynch_write (dst, command,
                             (nbd_completion_callback) {
                               .callback = free_command,
                               .user_data = command,
                             });
   }
   else {                               /* Sparseness detection. */
     const uint64_t start = command->offset;
     const uint64_t end = start + command->slice.len;
     uint64_t last_offset = start;
-    bool last_is_hole = false;
+    bool last_is_zero = false;
     uint64_t i;
     struct command *newcommand;
     int dummy = 0;
 
     /* Iterate over whole blocks in the command, starting on a block
      * boundary.
      */
     for (i = MIN (ROUND_UP (start, sparse_size), end);
          i + sparse_size <= end;
          i += sparse_size) {
       if (is_zero (slice_ptr (command->slice) + i-start, sparse_size)) {
-        /* It's a hole.  If the last was a hole too then we do nothing
-         * here which coalesces.  Otherwise write the last data and
-         * start a new hole.
+        /* 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_hole) {
+        if (!last_is_zero) {
           /* Write the last data (if any). */
           if (i - last_offset > 0) {
             newcommand = copy_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 hole. */
+          /* Start the new zero range. */
           last_offset = i;
-          last_is_hole = true;
+          last_is_zero = true;
         }
       }
       else {
         /* It's data.  If the last was data too, do nothing =>
-         * coalesce.  Otherwise write the last hole and start a new
-         * data.
+         * coalesce.  Otherwise write the last zero range and start a
+         * new data.
          */
-        if (last_is_hole) {
-          /* Write the last hole (if any). */
+        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);
             fill_dst_range_with_zeroes (newcommand);
           }
           /* Start the new data. */
           last_offset = i;
-          last_is_hole = false;
+          last_is_zero = false;
         }
       }
     } /* for i */
 
     /* Write the last_offset up to i. */
     if (i - last_offset > 0) {
-      if (!last_is_hole) {
+      if (!last_is_zero) {
         newcommand = copy_subcommand (command,
                                       last_offset, i - last_offset,
                                       false);
         dst->ops->asynch_write (dst, newcommand,
                                 (nbd_completion_callback) {
                                   .callback = free_command,
                                   .user_data = newcommand,
                                 });
       }
       else {
@@ -483,22 +483,22 @@ finished_read (void *vp, int *error)
     /* Free the original command since it has been split into
      * subcommands and the original is no longer needed.
      */
     free_command (command, &dummy);
   }
 
   return 1; /* auto-retires the command */
 }
 
 /* Fill a range in dst with zeroes.  This is called from the copying
- * loop when we see a hole in the source.  Depending on the command
- * line flags this could mean:
+ * loop when we see a zero range in the source.  Depending on the
+ * command line flags this could mean:
  *
  * --destination-is-zero:
  *                 do nothing
  *
  * --allocated:    write zeroes allocating space using an efficient
  *                 zeroing command or writing a command of zeroes
  *
  * (neither flag)  write zeroes punching a hole using an efficient
  *                 zeroing command or fallback to writing a command
  *                 of zeroes.
-- 
2.35.1




More information about the Libguestfs mailing list