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

[libvirt] [PATCH 7/9] storage: Don't try sparse detection if writing to block device.



We don't gain any space savings, so skip the detection to speed up
the cloning operation.
---
 src/storage_backend.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/storage_backend.c b/src/storage_backend.c
index 37c227f..b5e4ac7 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -106,7 +106,8 @@ virStorageBackendCopyToFD(virConnectPtr conn,
                           virStorageVolDefPtr vol,
                           virStorageVolDefPtr inputvol,
                           int fd,
-                          unsigned long long *total)
+                          unsigned long long *total,
+                          int is_dest_file)
 {
     int inputfd = -1;
     int amtread = -1;
@@ -155,7 +156,7 @@ virStorageBackendCopyToFD(virConnectPtr conn,
             int interval = ((512 > amtleft) ? amtleft : 512);
             int offset = amtread - amtleft;
 
-            if (memcmp(buf+offset, zerobuf, interval) == 0) {
+            if (is_dest_file && memcmp(buf+offset, zerobuf, interval) == 0) {
                 if (lseek(fd, interval, SEEK_CUR) < 0) {
                     virReportSystemError(conn, errno,
                                          _("cannot extend file '%s'"),
@@ -210,7 +211,8 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn,
     remain = vol->allocation;
 
     if (inputvol) {
-        int res = virStorageBackendCopyToFD(conn, vol, inputvol, fd, &remain);
+        int res = virStorageBackendCopyToFD(conn, vol, inputvol,
+                                            fd, &remain, 0);
         if (res < 0)
             goto cleanup;
     }
@@ -262,7 +264,8 @@ virStorageBackendCreateRaw(virConnectPtr conn,
     remain = vol->allocation;
 
     if (inputvol) {
-        int res = virStorageBackendCopyToFD(conn, vol, inputvol, fd, &remain);
+        int res = virStorageBackendCopyToFD(conn, vol, inputvol,
+                                            fd, &remain, 1);
         if (res < 0)
             goto cleanup;
     }
-- 
1.6.0.6


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