separate virDomainDefParseOsNodeInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 180 +++++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 80 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bf2cf7f..0f7069c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18595,6 +18595,105 @@ virDomainDefParseVirtTypeInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseOsNodeInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + virCapsPtr caps = param->caps; + xmlXPathContextPtr ctxt = param->ctxt; + unsigned int flags = param->flags; + char *tmp = NULL; + int ret = -1; + + def->os.bootloader = virXPathString("string(./bootloader)", ctxt); + def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); + + tmp = virXPathString("string(./os/type[1])", ctxt); + if (!tmp) { + if (def->os.bootloader) { + def->os.type = VIR_DOMAIN_OSTYPE_XEN; + } else { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("an os <type> must be specified")); + goto cleanup; + } + } else { + if ((def->os.type = virDomainOSTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown OS type '%s'"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + } + + /* + * HACK: For xen driver we previously used bogus 'linux' as the + * os type for paravirt, whereas capabilities declare it to + * be 'xen'. So we accept the former and convert + */ + if (def->os.type == VIR_DOMAIN_OSTYPE_LINUX && + def->virtType == VIR_DOMAIN_VIRT_XEN) { + def->os.type = VIR_DOMAIN_OSTYPE_XEN; + } + + tmp = virXPathString("string(./os/type[1]/@arch)", ctxt); + if (tmp && !(def->os.arch = virArchFromString(tmp))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown architecture %s"), + tmp); + goto cleanup; + } + VIR_FREE(tmp); + + def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt); + def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); + + if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) { + /* If the logic here seems fairly arbitrary, that's because it is :) + * This is duplicating how the code worked before + * CapabilitiesDomainDataLookup was added. We can simplify this, + * but it would take a bit of work because the test suite fails + * in numerous minor ways. */ + bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) || + !def->os.machine); + virCapsDomainDataPtr capsdata = NULL; + + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, + def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, + NULL, NULL))) + goto cleanup; + + if (!def->os.arch) + def->os.arch = capsdata->arch; + if ((!def->os.machine && + VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) { + VIR_FREE(capsdata); + goto cleanup; + } + VIR_FREE(capsdata); + } + + if ((tmp = virXPathString("string(./os/smbios/@mode)", ctxt))) { + int mode; + + if ((mode = virDomainSmbiosModeTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown smbios mode '%s'"), tmp); + goto cleanup; + } + def->os.smbios_mode = mode; + VIR_FREE(tmp); + } + + ret = 0; + + cleanup: + VIR_FREE(tmp); + return ret; + +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18637,6 +18736,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainPreaseInfoFunc parse_funs[] = { virDomainDefParseIdInfo, virDomainDefParseVirtTypeInfo, + virDomainDefParseOsNodeInfo, NULL }; @@ -18664,74 +18764,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - def->os.bootloader = virXPathString("string(./bootloader)", ctxt); - def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); - - tmp = virXPathString("string(./os/type[1])", ctxt); - if (!tmp) { - if (def->os.bootloader) { - def->os.type = VIR_DOMAIN_OSTYPE_XEN; - } else { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("an os <type> must be specified")); - goto error; - } - } else { - if ((def->os.type = virDomainOSTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown OS type '%s'"), tmp); - goto error; - } - VIR_FREE(tmp); - } - - /* - * HACK: For xen driver we previously used bogus 'linux' as the - * os type for paravirt, whereas capabilities declare it to - * be 'xen'. So we accept the former and convert - */ - if (def->os.type == VIR_DOMAIN_OSTYPE_LINUX && - def->virtType == VIR_DOMAIN_VIRT_XEN) { - def->os.type = VIR_DOMAIN_OSTYPE_XEN; - } - - tmp = virXPathString("string(./os/type[1]/@arch)", ctxt); - if (tmp && !(def->os.arch = virArchFromString(tmp))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown architecture %s"), - tmp); - goto error; - } - VIR_FREE(tmp); - - def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt); - def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); - - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) { - /* If the logic here seems fairly arbitrary, that's because it is :) - * This is duplicating how the code worked before - * CapabilitiesDomainDataLookup was added. We can simplify this, - * but it would take a bit of work because the test suite fails - * in numerous minor ways. */ - bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) || - !def->os.machine); - virCapsDomainDataPtr capsdata = NULL; - - if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, - NULL, NULL))) - goto error; - - if (!def->os.arch) - def->os.arch = capsdata->arch; - if ((!def->os.machine && - VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) { - VIR_FREE(capsdata); - goto error; - } - VIR_FREE(capsdata); - } - /* Extract domain name */ if (!(def->name = virXPathString("string(./name[1])", ctxt))) { virReportError(VIR_ERR_NO_NAME, NULL); @@ -20283,18 +20315,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } - if ((tmp = virXPathString("string(./os/smbios/@mode)", ctxt))) { - int mode; - - if ((mode = virDomainSmbiosModeTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown smbios mode '%s'"), tmp); - goto error; - } - def->os.smbios_mode = mode; - VIR_FREE(tmp); - } - if (virDomainKeyWrapDefParseXML(def, ctxt) < 0) goto error; -- 2.8.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list