From 0c10edadde598f18b14459b54de1e6855aa632b8 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 22 Mar 2019 16:48:54 +0100 Subject: [PATCH] qemu: domain: Modify to look like MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When adding I've used a slightly unusual approach. To allow using the disk source XML parser and formatter convert to look like . This means that will be added as a subelement of rather than being formatted inline. Conversion from the old format in the parser is very simple as it involves only moving the XPath context current node slightly if the new format is found. The status XML to XML test shows that the upgrade is done correctly. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_domain.c | 25 ++++++------- .../migration-out-nbd-tls-in.xml | 18 +++++----- .../migration-out-nbd-tls-out.xml | 36 ++++++++++--------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f38ca1409f..f185613eea 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2343,28 +2343,21 @@ qemuDomainObjPrivateXMLFormatPR(virBufferPtr buf, static int qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf, - virStorageSourcePtr src) + virStorageSourcePtr src, + virDomainXMLOptionPtr xmlopt) { VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - VIR_AUTOCLEAN(virBuffer) privateDataBuf = VIR_BUFFER_INITIALIZER; int ret = -1; virBufferSetChildIndent(&childBuf, buf); - virBufferSetChildIndent(&privateDataBuf, &childBuf); virBufferAsprintf(&attrBuf, " type='%s' format='%s'", virStorageTypeToString(src->type), virStorageFileFormatTypeToString(src->format)); - if (virDomainStorageSourceFormat(&attrBuf, &childBuf, src, - VIR_DOMAIN_DEF_FORMAT_STATUS) < 0) - goto cleanup; - - if (qemuStorageSourcePrivateDataFormat(src, &privateDataBuf) < 0) - goto cleanup; - - if (virXMLFormatElement(&childBuf, "privateData", NULL, &privateDataBuf) < 0) + if (virDomainDiskSourceFormat(&childBuf, src, 0, false, + VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < 0) goto cleanup; if (virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf) < 0) @@ -2381,6 +2374,7 @@ static int qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf, virDomainObjPtr vm) { + qemuDomainObjPrivatePtr priv = vm->privateData; VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; size_t i; @@ -2399,7 +2393,8 @@ qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf, if (diskPriv->migrSource && qemuDomainObjPrivateXMLFormatNBDMigrationSource(&childBuf, - diskPriv->migrSource) < 0) + diskPriv->migrSource, + priv->driver->xmlopt) < 0) goto cleanup; if (virXMLFormatElement(buf, "disk", &attrBuf, &childBuf) < 0) @@ -2723,6 +2718,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, char *type = NULL; int ret = -1; VIR_AUTOUNREF(virStorageSourcePtr) migrSource = NULL; + xmlNodePtr sourceNode; ctxt->node = node; @@ -2758,6 +2754,11 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, goto cleanup; } + /* newer libvirt uses the subelement instead of formatting the + * source directly into */ + if ((sourceNode = virXPathNode("./source", ctxt))) + ctxt->node = sourceNode; + if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource, VIR_DOMAIN_DEF_PARSE_STATUS, NULL) < 0) goto cleanup; diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml index f3bbc752b6..2cd6c9a5e9 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml @@ -237,14 +237,16 @@ - - - - - - - - + + + + + + + + + + diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml index f3bbc752b6..869f37d488 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml @@ -237,25 +237,29 @@ - - - - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + + + +