]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Rewrite allocation tracking when cloning volumes
authorJán Tomko <jtomko@redhat.com>
Fri, 3 Jul 2015 10:47:02 +0000 (12:47 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 10 Jul 2015 06:53:26 +0000 (08:53 +0200)
Instead of storing the remaining bytes, store the position of the first
unallocated byte. This will allow changing the amount of bytes copied
by virStorageBackendCopyToFD without changing the safezero call.

No functional impact.

src/storage/storage_backend.c

index ce59f63acf6477c1d7ef0d9f87d6e6a30807db34..c71545cf63fe1b13aeab8d82a63a818a6d06a723 100644 (file)
@@ -399,7 +399,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
 {
     bool need_alloc = true;
     int ret = 0;
-    unsigned long long remain;
+    unsigned long long pos = 0;
 
     /* Seek to the final size, so the capacity is available upfront
      * for progress reporting */
@@ -433,9 +433,9 @@ createRawFile(int fd, virStorageVolDefPtr vol,
     }
 #endif
 
-    remain = vol->target.allocation;
 
     if (inputvol) {
+        unsigned long long remain = vol->target.allocation;
         /* allow zero blocks to be skipped if we've requested sparse
          * allocation (allocation < capacity) or we have already
          * been able to allocate the required space. */
@@ -446,10 +446,12 @@ createRawFile(int fd, virStorageVolDefPtr vol,
                                         want_sparse, reflink_copy);
         if (ret < 0)
             goto cleanup;
+
+        pos = vol->target.allocation - remain;
     }
 
-    if (remain && need_alloc) {
-        if (safezero(fd, vol->target.allocation - remain, remain) < 0) {
+    if (need_alloc) {
+        if (safezero(fd, pos, vol->target.allocation - pos) < 0) {
             ret = -errno;
             virReportSystemError(errno, _("cannot fill file '%s'"),
                                  vol->target.path);