qemu: Implement '<metadata_cache><max_size>' control for qcow2

qemu's qcow2 driver allows control of the metadata cache of qcow2 driver
by the 'cache-size' property. Wire it up to the recently introduced
elements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-01-06 18:20:29 +01:00
parent 06380cb587
commit dc837a412f
5 changed files with 98 additions and 0 deletions

View File

@ -1405,6 +1405,17 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageSourcePtr src,
if (qemuBlockStorageSourceGetFormatQcowGenericProps(src, "qcow2", props) < 0)
return -1;
/* 'cache-size' controls the maximum size of L2 and refcount caches.
* see: qemu.git/docs/qcow2-cache.txt
* https://git.qemu.org/?p=qemu.git;a=blob;f=docs/qcow2-cache.txt
*/
if (src->metadataCacheMaxSize > 0) {
if (virJSONValueObjectAdd(props,
"U:cache-size", src->metadataCacheMaxSize,
NULL) < 0)
return -1;
}
return 0;
}

View File

@ -4657,6 +4657,21 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
}
}
/* metadata cache size control is currently supported only for qcow2 */
if (src->metadataCacheMaxSize > 0) {
if (src->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metdata cache max size control is supported only with qcow2 images"));
return -1;
}
if (!blockdev) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metdata cache max size control is not supported with this QEMU binary"));
return -1;
}
}
return 0;
}

View File

@ -720,6 +720,20 @@ qemuSnapshotPrepare(virDomainObjPtr vm,
return -1;
}
if (disk->src->metadataCacheMaxSize > 0) {
if (disk->src->format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metdata cache max size control is supported only with qcow2 images"));
return -1;
}
if (!blockdev) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metdata cache max size control is not supported with this QEMU binary"));
return -1;
}
}
if (qemuSnapshotPrepareDiskExternal(vm, dom_disk, disk,
active, reuse, blockdev) < 0)
return -1;

View File

@ -0,0 +1,57 @@
LC_ALL=C \
PATH=/bin \
HOME=/tmp/lib/domain--1-QEMUGuest1 \
USER=test \
LOGNAME=test \
XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-i386 \
-name guest=QEMUGuest1,debug-threads=on \
-S \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \
-cpu qemu64 \
-m 214 \
-object memory-backend-ram,id=pc.ram,size=224395264 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,fd=1729,server,nowait \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown \
-no-acpi \
-boot strict=on \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-blockdev '{"driver":"file","filename":"/tmp/QEMUGuest1.img",\
"node-name":"libvirt-3-storage","cache":{"direct":true,"no-flush":false},\
"auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-3-format","read-only":false,\
"cache":{"direct":true,"no-flush":false},"driver":"qcow2","cache-size":12345,\
"file":"libvirt-3-storage"}' \
-device ide-hd,bus=ide.0,unit=0,drive=libvirt-3-format,id=ide0-0-0,bootindex=1,\
write-cache=on \
-blockdev '{"driver":"file","filename":"/tmp/backing-store.qcow",\
"node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},\
"auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-2-format","read-only":true,\
"cache":{"direct":true,"no-flush":false},"driver":"qcow2","cache-size":1048576,\
"file":"libvirt-2-storage","backing":null}' \
-blockdev '{"driver":"file","filename":"/tmp/QEMUGuest2.img",\
"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\
"auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,\
"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\
"file":"libvirt-1-storage","backing":"libvirt-2-format"}' \
-device ide-hd,bus=ide.0,unit=1,drive=libvirt-1-format,id=ide0-0-1,\
write-cache=on \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny \
-msg timestamp=on

View File

@ -1223,6 +1223,7 @@ mymain(void)
DO_TEST_CAPS_VER("disk-cache", "2.7.0");
DO_TEST_CAPS_VER("disk-cache", "2.12.0");
DO_TEST_CAPS_LATEST("disk-cache");
DO_TEST_CAPS_LATEST("disk-metadata-cache");
DO_TEST_CAPS_ARCH_VER_PARSE_ERROR("disk-transient", "x86_64", "4.1.0");
DO_TEST_CAPS_LATEST("disk-transient");
DO_TEST("disk-network-nbd", NONE);