diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index b4aed0f7009b8d7e81a64e4f4a5c920a422fbba4..897dfdaaee4da967fb5dacc4327484f40b8aa717 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 9073b1b1638e912e36fa136f3d98fdac9a15a319..b151b9401c99d37ae22960ec7e14ec8cb5b1e56d 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