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 <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>
This commit is contained in:
Wim ten Have 2018-04-09 20:14:35 +02:00 committed by Michal Privoznik
parent c1bc9c662b
commit c9ec7088c7
2 changed files with 9 additions and 3 deletions

View 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,

View 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