Now that we are generating the device aliases at the define time, we might as well format them into inactive XML. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- I've trimmed out all the test/ XML changes. I've generated them using: tests $ VIR_TEST_REGENERATE_OUTPUT=1 ./test With the changes in this patch would be ~1MB in size. If interested regenerate them on your own. Alternatively, you can find them at my github. src/conf/domain_conf.c | 7 +- tests/qemuxml2xmltest.c | 63 ++++++++++- 489 files changed, 7417 insertions(+), 1623 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 653357531..ae38bae47 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5770,10 +5770,9 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } - if (info->alias && - !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + + if (info->alias) virBufferAsprintf(buf, "<alias name='%s'/>\n", info->alias); - } if (info->mastertype == VIR_DOMAIN_CONTROLLER_MASTER_USB) { virBufferAsprintf(buf, "<master startport='%d'/>\n", @@ -6333,7 +6332,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (alias == NULL && - !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && + !(flags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE) && virXMLNodeNameEqual(cur, "alias")) { alias = cur; } else if (address == NULL && diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 4b2fbd990..c9afafe14 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -13,11 +13,16 @@ #ifdef WITH_QEMU # include "internal.h" +# include "qemu/qemu_alias.h" # include "qemu/qemu_domain_address.h" # include "qemu/qemu_domain.h" # include "testutilsqemu.h" # include "virstring.h" +# define __QEMU_CAPSPRIV_H_ALLOW__ +# include "qemu/qemu_capspriv.h" +# undef __QEMU_CAPSPRIV_H_ALLOW__ + # define VIR_FROM_THIS VIR_FROM_NONE static virQEMUDriver driver; @@ -38,6 +43,25 @@ struct testInfo { virQEMUCapsPtr qemuCaps; }; + +static int +testUpdateQEMUCaps(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) +{ + virQEMUCapsSetArch(qemuCaps, def->os.arch); + + virQEMUCapsInitQMPBasicArch(qemuCaps); + + /* We need to pretend QEMU 2.0.0 is in use so that pSeries guests + * will get the correct alias assigned to their buses. + * See virQEMUCapsHasPCIMultiBus() */ + virQEMUCapsSetVersion(qemuCaps, 2000000); + + return 0; +} + + + static int qemuXML2XMLActivePreFormatCallback(virDomainDefPtr def, const void *opaque) @@ -48,6 +72,19 @@ qemuXML2XMLActivePreFormatCallback(virDomainDefPtr def, if (!info->activeVcpus) info->activeVcpus = virDomainDefGetOnlineVcpumap(def); + /* Update capabilities according to domain definition, + * just like we're doing in qemuxml2argvtest. */ + testUpdateQEMUCaps(def, info->qemuCaps); + + /* Forcibly regenerate device aliases. They are generated in + * virDomainDefParseFile(), however, qemuCaps are filled out + * just partially therefore the generated aliases might be + * wrong. It's only after testUpdateQEMUCaps() call that we + * have full set of caps. However, we can't move the call any + * sooner because it needs vm->def. */ + if (qemuAssignDeviceAliases(def, info->qemuCaps, true) < 0) + return -1; + return 0; } @@ -64,6 +101,29 @@ testXML2XMLActive(const void *opaque) } +static int +qemuXML2XMLInactivePreFormatCallback(virDomainDefPtr def, + const void *opaque) +{ + struct testInfo *info = (struct testInfo *) opaque; + + /* Update capabilities according to domain definition, + * just like we're doing in qemuxml2argvtest. */ + testUpdateQEMUCaps(def, info->qemuCaps); + + /* Forcibly regenerate device aliases. They are generated in + * virDomainDefParseFile(), however, qemuCaps are filled out + * just partially therefore the generated aliases might be + * wrong. It's only after testUpdateQEMUCaps() call that we + * have full set of caps. However, we can't move the call any + * sooner because it needs vm->def. */ + if (qemuAssignDeviceAliases(def, info->qemuCaps, true) < 0) + return -1; + + return 0; +} + + static int testXML2XMLInactive(const void *opaque) { @@ -71,7 +131,8 @@ testXML2XMLInactive(const void *opaque) return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, info->outInactiveName, false, - NULL, opaque, 0, + qemuXML2XMLInactivePreFormatCallback, + opaque, 0, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); } -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list