From 964650ed2a3e36a1e12d720ff5d9caa5a1552ebe Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 14 Jan 2021 13:57:52 +0100 Subject: [PATCH] conf: disk: Parse and format also for Commit 154df5840d added support for as property of a . Since the same parser is used to parse the XML used with virDomainBlockCopy it starts the copy job with the appropriate cache configured, but the doesn't show this configuration nor it's preserved if libvirtd is restarted during the mirror. Add parsing, formatting and tests for for a . Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 22 ++++++++++++++++++- tests/qemuxml2argvdata/disk-mirror.xml | 14 ++++++++++++ .../qemuxml2xmloutdata/disk-mirror-active.xml | 18 ++++++++++++++- .../disk-mirror-inactive.xml | 9 +++++++- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 349fc28c2a..01b7187637 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8784,6 +8784,12 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, return -1; } + if (virParseScaledValue("./format/metadata_cache/max_size", NULL, + ctxt, + &def->mirror->metadataCacheMaxSize, + 1, ULLONG_MAX, false) < 0) + return -1; + return 0; } @@ -24283,6 +24289,8 @@ virDomainDiskDefFormatMirror(virBufferPtr buf, { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) formatAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) formatChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); const char *formatStr = NULL; /* For now, mirroring is currently output-only: we only output it @@ -24311,7 +24319,19 @@ virDomainDiskDefFormatMirror(virBufferPtr buf, virBufferEscapeString(&attrBuf, " ready='%s'", virDomainDiskMirrorStateTypeToString(disk->mirrorState)); - virBufferEscapeString(&childBuf, "\n", formatStr); + virBufferEscapeString(&formatAttrBuf, " type='%s'", formatStr); + if (disk->mirror->metadataCacheMaxSize > 0) { + g_auto(virBuffer) metadataCacheChildBuf = VIR_BUFFER_INIT_CHILD(&formatChildBuf); + + virBufferAsprintf(&metadataCacheChildBuf, + "%llu\n", + disk->mirror->metadataCacheMaxSize); + + virXMLFormatElement(&formatChildBuf, "metadata_cache", NULL, &metadataCacheChildBuf); + } + + virXMLFormatElement(&childBuf, "format", &formatAttrBuf, &formatChildBuf); + if (virDomainDiskSourceFormat(&childBuf, disk->mirror, "source", 0, true, flags, false, false, xmlopt) < 0) return -1; diff --git a/tests/qemuxml2argvdata/disk-mirror.xml b/tests/qemuxml2argvdata/disk-mirror.xml index 2d61fe29c3..73886e99f4 100644 --- a/tests/qemuxml2argvdata/disk-mirror.xml +++ b/tests/qemuxml2argvdata/disk-mirror.xml @@ -54,6 +54,20 @@ + + + + + + + 1234 + + + + + + + diff --git a/tests/qemuxml2xmloutdata/disk-mirror-active.xml b/tests/qemuxml2xmloutdata/disk-mirror-active.xml index 17fb061d49..0e2669398c 100644 --- a/tests/qemuxml2xmloutdata/disk-mirror-active.xml +++ b/tests/qemuxml2xmloutdata/disk-mirror-active.xml @@ -61,6 +61,22 @@
+ + + + + + + + 1234 + + + + + + +
+
@@ -71,7 +87,7 @@ -
+
diff --git a/tests/qemuxml2xmloutdata/disk-mirror-inactive.xml b/tests/qemuxml2xmloutdata/disk-mirror-inactive.xml index 157ffcf6b2..6c7f92c1cc 100644 --- a/tests/qemuxml2xmloutdata/disk-mirror-inactive.xml +++ b/tests/qemuxml2xmloutdata/disk-mirror-inactive.xml @@ -43,6 +43,13 @@
+ + + + + +
+
@@ -53,7 +60,7 @@ -
+