[PATCHv4 1/2] Rewrite allocation tracking when cloning volumes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index ce59f63..c71545c 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -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);
-- 
2.3.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]