When adding <migrationSource> I've used a slightly unusual approach. To allow using the disk source XML parser and formatter convert <migrationSource> to look like <disk>. This means that <source> will be added as a subelement of <migrationSource> 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 <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 23 ++++++------ .../migration-out-nbd-tls-in.xml | 18 +++++----- .../migration-out-nbd-tls-out.xml | 36 ++++++++++--------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a1b39220d1..3b0887a194 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) @@ -2724,6 +2719,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, char *type = NULL; int ret = -1; VIR_AUTOUNREF(virStorageSourcePtr) migrSource = NULL; + xmlNodePtr sourceNode; ctxt->node = node; @@ -2759,6 +2755,9 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, goto cleanup; } + 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 @@ </qemuCaps> <job type='none' async='migration out' phase='perform3' flags='0x0'> <disk dev='vdb' migrating='yes'> - <migrationSource type='network' format='raw' protocol='nbd' name='drive-virtio-disk1' tlsFromConfig='0'> - <host name='andariel.usersys.redhat.com' port='49152'/> - <privateData> - <nodenames> - <nodename type='storage' name='migration-vdb-storage'/> - <nodename type='format' name='migration-vdb-format'/> - </nodenames> - </privateData> + <migrationSource type='network' format='raw'> + <source protocol='nbd' name='drive-virtio-disk1' tlsFromConfig='0'> + <host name='andariel.usersys.redhat.com' port='49152'/> + <privateData> + <nodenames> + <nodename type='storage' name='migration-vdb-storage'/> + <nodename type='format' name='migration-vdb-format'/> + </nodenames> + </privateData> + </source> </migrationSource> </disk> <disk dev='vdc' migrating='yes'> 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 @@ </qemuCaps> <job type='none' async='migration out' phase='perform3' flags='0x0'> <disk dev='vdb' migrating='yes'> - <migrationSource type='network' format='raw' protocol='nbd' name='drive-virtio-disk1' tlsFromConfig='0'> - <host name='andariel.usersys.redhat.com' port='49152'/> - <privateData> - <nodenames> - <nodename type='storage' name='migration-vdb-storage'/> - <nodename type='format' name='migration-vdb-format'/> - </nodenames> - </privateData> + <migrationSource type='network' format='raw'> + <source protocol='nbd' name='drive-virtio-disk1' tlsFromConfig='0'> + <host name='andariel.usersys.redhat.com' port='49152'/> + <privateData> + <nodenames> + <nodename type='storage' name='migration-vdb-storage'/> + <nodename type='format' name='migration-vdb-format'/> + </nodenames> + </privateData> + </source> </migrationSource> </disk> <disk dev='vdc' migrating='yes'> - <migrationSource type='network' format='raw' protocol='nbd' name='drive-virtio-disk2' tlsFromConfig='0'> - <host name='andariel.usersys.redhat.com' port='49152'/> - <privateData> - <nodenames> - <nodename type='storage' name='migration-vdc-storage'/> - <nodename type='format' name='migration-vdc-format'/> - </nodenames> - </privateData> + <migrationSource type='network' format='raw'> + <source protocol='nbd' name='drive-virtio-disk2' tlsFromConfig='0'> + <host name='andariel.usersys.redhat.com' port='49152'/> + <privateData> + <nodenames> + <nodename type='storage' name='migration-vdc-storage'/> + <nodename type='format' name='migration-vdc-format'/> + </nodenames> + </privateData> + </source> </migrationSource> </disk> <disk dev='hda' migrating='no'/> -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list