qemu: domain: Modify <migrationSource> to look like <disk>

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-03-22 16:48:54 +01:00
parent 1af846dd27
commit 0c10edadde
3 changed files with 43 additions and 36 deletions

View File

@ -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 <source> subelement instead of formatting the
* source directly into <migrationSource> */
if ((sourceNode = virXPathNode("./source", ctxt)))
ctxt->node = sourceNode;
if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource,
VIR_DOMAIN_DEF_PARSE_STATUS, NULL) < 0)
goto cleanup;

View File

@ -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'>

View File

@ -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'/>