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(a)redhat.com>
---
src/qemu/qemu_block.c | 11 ++++
src/qemu/qemu_domain.c | 15 +++++
src/qemu/qemu_snapshot.c | 14 +++++
.../disk-metadata-cache.x86_64-latest.args | 57 +++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
5 files changed, 98 insertions(+)
create mode 100644 tests/qemuxml2argvdata/disk-metadata-cache.x86_64-latest.args
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 4640e339c0..857c5aa8d0 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1343,6 +1343,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;
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index bfb6e23942..38defdab4b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4626,6 +4626,21 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
return -1;
}
+ /* 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;
}
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 15494c3415..e7e7e7babc 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -717,6 +717,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;
diff --git a/tests/qemuxml2argvdata/disk-metadata-cache.x86_64-latest.args
b/tests/qemuxml2argvdata/disk-metadata-cache.x86_64-latest.args
new file mode 100644
index 0000000000..3e520664ab
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-metadata-cache.x86_64-latest.args
@@ -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
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index d2712e0dce..d6fa81078f 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1212,6 +1212,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);
--
2.29.2