提交 c9ec7088 编写于 作者: W Wim ten Have 提交者: Michal Privoznik

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: NWim ten Have <wim.ten.have@oracle.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 c1bc9c66
...@@ -851,6 +851,7 @@ struct _virStorageBackendQemuImgInfo { ...@@ -851,6 +851,7 @@ struct _virStorageBackendQemuImgInfo {
int format; int format;
const char *path; const char *path;
unsigned long long size_arg; unsigned long long size_arg;
unsigned long long allocation;
bool encryption; bool encryption;
bool preallocate; bool preallocate;
const char *compat; const char *compat;
...@@ -884,8 +885,12 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr enc, ...@@ -884,8 +885,12 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr enc,
virStorageFileFormatTypeToString(info.backingFormat)); virStorageFileFormatTypeToString(info.backingFormat));
if (info.encryption) if (info.encryption)
virBufferAddLit(&buf, "encryption=on,"); virBufferAddLit(&buf, "encryption=on,");
if (info.preallocate) if (info.preallocate) {
virBufferAddLit(&buf, "preallocation=metadata,"); if (info.size_arg > info.allocation)
virBufferAddLit(&buf, "preallocation=metadata,");
else
virBufferAddLit(&buf, "preallocation=falloc,");
}
} }
if (info.nocow) if (info.nocow)
...@@ -1182,6 +1187,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool, ...@@ -1182,6 +1187,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
struct _virStorageBackendQemuImgInfo info = { struct _virStorageBackendQemuImgInfo info = {
.format = vol->target.format, .format = vol->target.format,
.path = vol->target.path, .path = vol->target.path,
.allocation = vol->target.allocation,
.encryption = vol->target.encryption != NULL, .encryption = vol->target.encryption != NULL,
.preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA), .preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA),
.compat = vol->target.compat, .compat = vol->target.compat,
......
qemu-img convert -f raw -O qcow2 \ 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/sparse.img \
/var/lib/libvirt/images/OtherDemo.img /var/lib/libvirt/images/OtherDemo.img
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册