From c9ec7088c7a3f4cd26bb471f1f243931fff6f4f9 Mon Sep 17 00:00:00 2001 From: Wim ten Have Date: Mon, 9 Apr 2018 20:14:35 +0200 Subject: [PATCH] storage: extend preallocation flags support for qemu-img 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 matches its . For all other cases the filesystem stored objects are built with preallocation=metadata. Signed-off-by: Wim ten Have Signed-off-by: Michal Privoznik --- src/storage/storage_util.c | 10 ++++++++-- .../qcow2-nocapacity-convert-prealloc.argv | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index b4aed0f700..897dfdaaee 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -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, diff --git a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv index 9073b1b163..b151b9401c 100644 --- a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv +++ b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv @@ -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