[PATCH] storage: allow metadata preallocation when creating qcow2 images

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

 



Currently the 'allocation' element is not used when creating new images
with qemu-img. This patch interprets a non-zero value as a request to
preallocate metadata when a qcow2 image is created.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=684793
---
 src/storage/storage_backend.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 41a19a1..bf6f7cc 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -669,10 +669,15 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
     int imgformat = -1;
     virCommandPtr cmd = NULL;
     bool do_encryption = (vol->target.encryption != NULL);
+    bool preallocate = false;
     unsigned long long int size_arg;
 
     virCheckFlags(0, -1);
 
+    /* qcow2: preallocate metadata if requested allocation is non-zero */
+    if (vol->allocation > 0 && vol->target.format == VIR_STORAGE_FILE_QCOW2)
+        preallocate = true;
+
     const char *type = virStorageFileFormatTypeToString(vol->target.format);
     const char *backingType = vol->backingStore.path ?
         virStorageFileFormatTypeToString(vol->backingStore.format) : NULL;
@@ -842,12 +847,14 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
                              vol->target.path, NULL);
         virCommandAddArgFormat(cmd, "%lluK", size_arg);
 
-        if (do_encryption) {
-            if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
-                virCommandAddArgList(cmd, "-o", "encryption=on", NULL);
-            } else {
-                virCommandAddArg(cmd, "-e");
-            }
+        if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS &&
+            (do_encryption || preallocate)) {
+            virCommandAddArg(cmd, "-o");
+            virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ? "encryption=on" : "",
+                                   (do_encryption && preallocate) ? "," : "",
+                                   preallocate ? "preallocation=metadata" : "");
+        } else if (do_encryption){
+            virCommandAddArg(cmd, "-e");
         }
     }
 
-- 
1.7.8.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]