[libvirt PATCH 0/2] fix disk XML formatting for qemuDomainBlockCopy API

Pavel Hrdina (2): domain_conf: extract disk driver source bits to its own function virDomainDiskDefParseSource: parse source bits from driver element src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) -- 2.31.1

Attribute `type` and sub-element `metadata_cache` are internally stored in the `virStorageSource` structure. Sometimes we only care about the disk source bits so we need a dedicated helper for that. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 46 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6d90041bf8..f7920bce2c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8849,7 +8849,6 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, xmlNodePtr cur, xmlXPathContextPtr ctxt) { - g_autofree char *tmp = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) ctxt->node = cur; @@ -8900,19 +8899,6 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONZERO, &def->iothread) < 0) return -1; - if ((tmp = virXMLPropString(cur, "type"))) { - if (STREQ(tmp, "aio")) { - /* Xen back-compat */ - def->src->format = VIR_STORAGE_FILE_RAW; - } else { - if ((def->src->format = virStorageFileFormatTypeFromString(tmp)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown driver format value '%s'"), tmp); - return -1; - } - } - } - if (virXMLPropEnum(cur, "detect_zeroes", virDomainDiskDetectZeroesTypeFromString, VIR_XML_PROP_NONZERO, &def->detect_zeroes) < 0) @@ -8921,9 +8907,36 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, &def->queues) < 0) return -1; + return 0; +} + + +static int +virDomainDiskDefDriverSourceParseXML(virStorageSource *src, + xmlNodePtr cur, + xmlXPathContextPtr ctxt) +{ + g_autofree char *tmp = NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node = cur; + + if ((tmp = virXMLPropString(cur, "type"))) { + if (STREQ(tmp, "aio")) { + /* Xen back-compat */ + src->format = VIR_STORAGE_FILE_RAW; + } else { + if ((src->format = virStorageFileFormatTypeFromString(tmp)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown driver format value '%s'"), tmp); + return -1; + } + } + } + if (virParseScaledValue("./metadata_cache/max_size", NULL, ctxt, - &def->src->metadataCacheMaxSize, + &src->metadataCacheMaxSize, 1, ULLONG_MAX, false) < 0) return -1; @@ -9129,6 +9142,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, if (virDomainDiskDefDriverParseXML(def, driverNode, ctxt) < 0) return NULL; + + if (virDomainDiskDefDriverSourceParseXML(def->src, driverNode, ctxt) < 0) + return NULL; } if ((mirrorNode = virXPathNode("./mirror", ctxt))) { -- 2.31.1

Before the mentioned commit we always parsed the whole disk definition for qemuDomainBlockCopy API but we only used the @src part. Based on that assumption the code was changed to parse only the disk <source> element. Unfortunately that is not correct as we need to parse some parts of <driver> element as well. Fixes: 0202467c4ba8663db2304b140af609f93a9b3091 Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f7920bce2c..f424ed731f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15141,6 +15141,7 @@ virDomainDiskDefParseSource(const char *xmlStr, g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virStorageSource) src = NULL; + xmlNodePtr driverNode; if (!(xml = virXMLParseStringCtxtRoot(xmlStr, _("(disk_definition)"), "disk", &ctxt))) return NULL; @@ -15148,6 +15149,11 @@ virDomainDiskDefParseSource(const char *xmlStr, if (!(src = virDomainDiskDefParseSourceXML(xmlopt, ctxt->node, ctxt, flags))) return NULL; + if ((driverNode = virXPathNode("./driver", ctxt))) { + if (virDomainDiskDefDriverSourceParseXML(src, driverNode, ctxt) < 0) + return NULL; + } + if (virStorageSourceIsEmpty(src)) { virReportError(VIR_ERR_NO_SOURCE, NULL); return NULL; -- 2.31.1

On Thu, May 27, 2021 at 16:23:24 +0200, Pavel Hrdina wrote:
Pavel Hrdina (2): domain_conf: extract disk driver source bits to its own function virDomainDiskDefParseSource: parse source bits from driver element
src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-)
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
participants (2)
-
Pavel Hrdina
-
Peter Krempa