]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: extend preallocation flags support for qemu-img
authorWim ten Have <wim.ten.have@oracle.com>
Mon, 9 Apr 2018 18:14:35 +0000 (20:14 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 11 Apr 2018 08:15:58 +0000 (10:15 +0200)
This patch adds support to qcow2 formatted filesystem object storage by
instructing qemu-img to build them with preallocation=falloc whenever the
XML described storage <allocation> matches its <capacity>.  For all other
cases the filesystem stored objects are built with preallocation=metadata.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_util.c
tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv

index b4aed0f7009b8d7e81a64e4f4a5c920a422fbba4..897dfdaaee4da967fb5dacc4327484f40b8aa717 100644 (file)
@@ -851,6 +851,7 @@ struct _virStorageBackendQemuImgInfo {
     int format;
     const char *path;
     unsigned long long size_arg;
+    unsigned long long allocation;
     bool encryption;
     bool preallocate;
     const char *compat;
@@ -884,8 +885,12 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr enc,
                               virStorageFileFormatTypeToString(info.backingFormat));
         if (info.encryption)
             virBufferAddLit(&buf, "encryption=on,");
-        if (info.preallocate)
-            virBufferAddLit(&buf, "preallocation=metadata,");
+        if (info.preallocate) {
+            if (info.size_arg > info.allocation)
+                virBufferAddLit(&buf, "preallocation=metadata,");
+            else
+                virBufferAddLit(&buf, "preallocation=falloc,");
+        }
     }
 
     if (info.nocow)
@@ -1182,6 +1187,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
     struct _virStorageBackendQemuImgInfo info = {
         .format = vol->target.format,
         .path = vol->target.path,
+        .allocation = vol->target.allocation,
         .encryption = vol->target.encryption != NULL,
         .preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA),
         .compat = vol->target.compat,
index 9073b1b1638e912e36fa136f3d98fdac9a15a319..b151b9401c99d37ae22960ec7e14ec8cb5b1e56d 100644 (file)
@@ -1,4 +1,4 @@
 qemu-img convert -f raw -O qcow2 \
--o encryption=on,preallocation=metadata \
+-o encryption=on,preallocation=falloc \
 /var/lib/libvirt/images/sparse.img \
 /var/lib/libvirt/images/OtherDemo.img