[libvirt] [PATCH v1 01/51] util: conf: separate virDomainDefParseXML into serial parts

beacause virDomainDefParseXML is too long, and all domain xml parse in this function, it's difficulty to maintain this function so separate virDomainDefParseXML into serial parts use virDomainPreaseInfoFunc. then it will easy to maintain --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34aae82..e36783b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18527,6 +18527,28 @@ virDomainCachetuneDefParse(virDomainDefPtr def, } +typedef struct _virDomainParseTotalParam virDomainParseTotalParam; +typedef virDomainParseTotalParam *virDomainParseTotalParamPtr; + +struct _virDomainParseTotalParam{ + //input parameters + virDomainDefPtr def; + xmlDocPtr xml; + xmlNodePtr root; + xmlXPathContextPtr ctxt; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; + void *parseOpaque; + unsigned int flags; + + //internal parameters + bool usb_none; + bool usb_other; + bool usb_master; + bool uuid_generated; +}; + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18536,11 +18558,14 @@ virDomainDefParseXML(xmlDocPtr xml, void *parseOpaque, unsigned int flags) { + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; size_t i, j; int n, virtType, gic_version; long id = -1; + size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; virHashTablePtr bootHash = NULL; @@ -18548,6 +18573,25 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_other = false; bool usb_master = false; char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + NULL + }; if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { char *schema = virFileFindResource("domain.rng", @@ -18565,6 +18609,14 @@ virDomainDefParseXML(xmlDocPtr xml, if (!(def = virDomainDefNew())) return NULL; + param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + } + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) if (virXPathLong("string(./@id)", ctxt, &id) < 0) id = -1; -- 2.8.3

separate virDomainDefParseIdInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e36783b..055404e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18549,6 +18549,22 @@ struct _virDomainParseTotalParam{ }; +static int +virDomainDefParseIdInfo(virDomainParseTotalParamPtr param) +{ + unsigned int flags = param->flags; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainDefPtr def = param->def; + long id = -1; + + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + if (virXPathLong("string(./@id)", ctxt, &id) < 0) + id = -1; + def->id = (int)id; + return 0; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18564,7 +18580,6 @@ virDomainDefParseXML(xmlDocPtr xml, char *tmp = NULL; size_t i, j; int n, virtType, gic_version; - long id = -1; size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; @@ -18590,6 +18605,7 @@ virDomainDefParseXML(xmlDocPtr xml, }; virDomainPreaseInfoFunc parse_funs[] = { + virDomainDefParseIdInfo, NULL }; @@ -18617,11 +18633,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - if (virXPathLong("string(./@id)", ctxt, &id) < 0) - id = -1; - def->id = (int)id; - /* Find out what type of virtualization to use */ if (!(tmp = virXMLPropString(ctxt->node, "type"))) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.8.3

separate virDomainDefParseVirtTypeInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 055404e..bf2cf7f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18565,6 +18565,36 @@ virDomainDefParseIdInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseVirtTypeInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + char *tmp = NULL; + int virtType; + int ret = -1; + + /* Find out what type of virtualization to use */ + if (!(tmp = virXMLPropString(ctxt->node, "type"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("missing domain type attribute")); + goto cleanup; + } + + if ((virtType = virDomainVirtTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid domain type %s"), tmp); + goto cleanup; + } + def->virtType = virtType; + ret = 0; + + cleanup: + VIR_FREE(tmp); + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18579,7 +18609,7 @@ virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; size_t i, j; - int n, virtType, gic_version; + int n, gic_version; size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; @@ -18606,6 +18636,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainPreaseInfoFunc parse_funs[] = { virDomainDefParseIdInfo, + virDomainDefParseVirtTypeInfo, NULL }; @@ -18633,21 +18664,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* Find out what type of virtualization to use */ - if (!(tmp = virXMLPropString(ctxt->node, "type"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing domain type attribute")); - goto error; - } - - if ((virtType = virDomainVirtTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid domain type %s"), tmp); - goto error; - } - def->virtType = virtType; - VIR_FREE(tmp); - def->os.bootloader = virXPathString("string(./bootloader)", ctxt); def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); -- 2.8.3

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

separate virDomainDefParseDomainInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 90 +++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0f7069c..2daa6df 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18694,6 +18694,58 @@ virDomainDefParseOsNodeInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseDomainInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + char *tmp = NULL; + int ret = -1; + + /* Extract domain name */ + if (!(def->name = virXPathString("string(./name[1])", ctxt))) { + virReportError(VIR_ERR_NO_NAME, NULL); + goto cleanup; + } + + /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid + * exist, they must match; and if only the latter exists, it can + * also serve as the uuid. */ + tmp = virXPathString("string(./uuid[1])", ctxt); + if (!tmp) { + if (virUUIDGenerate(def->uuid)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Failed to generate UUID")); + goto cleanup; + } + param->uuid_generated = true; + } else { + if (virUUIDParse(tmp, def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed uuid element")); + goto cleanup; + } + VIR_FREE(tmp); + } + + /* Extract short description of domain (title) */ + def->title = virXPathString("string(./title[1])", ctxt); + if (def->title && strchr(def->title, '\n')) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Domain title can't contain newlines")); + goto cleanup; + } + + /* Extract documentation if present */ + def->description = virXPathString("string(./description[1])", ctxt); + ret = 0; + + cleanup: + VIR_FREE(tmp); + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18737,6 +18789,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseIdInfo, virDomainDefParseVirtTypeInfo, virDomainDefParseOsNodeInfo, + virDomainDefParseDomainInfo, NULL }; @@ -18764,43 +18817,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* Extract domain name */ - if (!(def->name = virXPathString("string(./name[1])", ctxt))) { - virReportError(VIR_ERR_NO_NAME, NULL); - goto error; - } - - /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid - * exist, they must match; and if only the latter exists, it can - * also serve as the uuid. */ - tmp = virXPathString("string(./uuid[1])", ctxt); - if (!tmp) { - if (virUUIDGenerate(def->uuid)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Failed to generate UUID")); - goto error; - } - uuid_generated = true; - } else { - if (virUUIDParse(tmp, def->uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed uuid element")); - goto error; - } - VIR_FREE(tmp); - } - - /* Extract short description of domain (title) */ - def->title = virXPathString("string(./title[1])", ctxt); - if (def->title && strchr(def->title, '\n')) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Domain title can't contain newlines")); - goto error; - } - - /* Extract documentation if present */ - def->description = virXPathString("string(./description[1])", ctxt); - /* analysis of security label, done early even though we format it * late, so devices can refer to this for defaults */ if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { -- 2.8.3

separate virDomainDefParseSecurityLabelInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2daa6df..64b6c09 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18746,6 +18746,25 @@ virDomainDefParseDomainInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseSecurityLabelInfo(virDomainParseTotalParamPtr param) +{ + /* analysis of security label, done early even though we format it + * late, so devices can refer to this for defaults */ + if (!(param->flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { + if (virSecurityLabelDefsParseXML(param->def, + param->ctxt, + param->caps, + param->flags) == -1) + return -1; + } + + return 0; + +} + + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18790,6 +18809,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseVirtTypeInfo, virDomainDefParseOsNodeInfo, virDomainDefParseDomainInfo, + virDomainDefParseSecurityLabelInfo, NULL }; @@ -18817,13 +18837,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of security label, done early even though we format it - * late, so devices can refer to this for defaults */ - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { - if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1) - goto error; - } - /* Extract domain memory */ if (virDomainParseMemory("./memory[1]", NULL, ctxt, &def->mem.total_memory, false, true) < 0) -- 2.8.3

separate virDomainDefParseMemoryInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 228 +++++++++++++++++++++++++++---------------------- 1 file changed, 125 insertions(+), 103 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 64b6c09..809c06a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18764,96 +18764,34 @@ virDomainDefParseSecurityLabelInfo(virDomainParseTotalParamPtr param) } - -static virDomainDefPtr -virDomainDefParseXML(xmlDocPtr xml, - xmlNodePtr root, - xmlXPathContextPtr ctxt, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque, - unsigned int flags) +static int +virDomainDefParseMemoryInfo(virDomainParseTotalParamPtr param) { - typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); - - xmlNodePtr *nodes = NULL, node = NULL; - char *tmp = NULL; + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + int ret = -1; + int n; size_t i, j; - int n, gic_version; - size_t fun_index = 0; - virDomainDefPtr def; - bool uuid_generated = false; - virHashTablePtr bootHash = NULL; - bool usb_none = false; - bool usb_other = false; - bool usb_master = false; - char *netprefix = NULL; - virDomainParseTotalParam param = { - NULL, - xml, - root, - ctxt, - caps, - xmlopt, - parseOpaque, - flags, - false, - false, - false, - false - - }; - - virDomainPreaseInfoFunc parse_funs[] = { - virDomainDefParseIdInfo, - virDomainDefParseVirtTypeInfo, - virDomainDefParseOsNodeInfo, - virDomainDefParseDomainInfo, - virDomainDefParseSecurityLabelInfo, - NULL - }; - - if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - char *schema = virFileFindResource("domain.rng", - abs_topsrcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) { - VIR_FREE(schema); - return NULL; - } - VIR_FREE(schema); - } - - if (!(def = virDomainDefNew())) - return NULL; - - param.def = def; - - while (parse_funs[fun_index]) { - if (parse_funs[fun_index](¶m) < 0) - goto error; - fun_index++; - } + char *tmp = NULL; + xmlNodePtr *nodes = NULL, node = NULL; /* Extract domain memory */ if (virDomainParseMemory("./memory[1]", NULL, ctxt, &def->mem.total_memory, false, true) < 0) - goto error; + goto cleanup; if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt, &def->mem.cur_balloon, false, true) < 0) - goto error; + goto cleanup; if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt, &def->mem.max_memory, false, false) < 0) - goto error; + goto cleanup; if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memory_slots) == -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Failed to parse memory slot count")); - goto error; + goto cleanup; } /* and info about it */ @@ -18861,7 +18799,7 @@ virDomainDefParseXML(xmlDocPtr xml, (def->mem.dump_core = virTristateSwitchTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid memory core dump attribute value '%s'"), tmp); - goto error; + goto cleanup; } VIR_FREE(tmp); @@ -18870,7 +18808,7 @@ virDomainDefParseXML(xmlDocPtr xml, if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown memoryBacking/source/type '%s'"), tmp); - goto error; + goto cleanup; } VIR_FREE(tmp); } @@ -18880,7 +18818,7 @@ virDomainDefParseXML(xmlDocPtr xml, if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown memoryBacking/access/mode '%s'"), tmp); - goto error; + goto cleanup; } VIR_FREE(tmp); } @@ -18890,7 +18828,7 @@ virDomainDefParseXML(xmlDocPtr xml, if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown memoryBacking/allocation/mode '%s'"), tmp); - goto error; + goto cleanup; } VIR_FREE(tmp); } @@ -18901,29 +18839,29 @@ virDomainDefParseXML(xmlDocPtr xml, if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("hugepages are not allowed with memory allocation ondemand")); - goto error; + goto cleanup; } if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("hugepages are not allowed with anonymous memory source")); - goto error; + goto cleanup; } if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract hugepages nodes")); - goto error; + goto cleanup; } if (n) { if (VIR_ALLOC_N(def->mem.hugepages, n) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { if (virDomainHugepagesParseXML(nodes[i], ctxt, &def->mem.hugepages[i]) < 0) - goto error; + goto cleanup; def->mem.nhugepages++; for (j = 0; j < i; j++) { @@ -18936,7 +18874,7 @@ virDomainDefParseXML(xmlDocPtr xml, "of sizes %llu and %llu intersect"), def->mem.hugepages[i].size, def->mem.hugepages[j].size); - goto error; + goto cleanup; } else if (!def->mem.hugepages[i].nodemask && !def->mem.hugepages[j].nodemask) { virReportError(VIR_ERR_XML_DETAIL, @@ -18944,7 +18882,7 @@ virDomainDefParseXML(xmlDocPtr xml, "%llu and %llu"), def->mem.hugepages[i].size, def->mem.hugepages[j].size); - goto error; + goto cleanup; } } } @@ -18953,7 +18891,7 @@ virDomainDefParseXML(xmlDocPtr xml, } else { /* no hugepage pages */ if (VIR_ALLOC(def->mem.hugepages) < 0) - goto error; + goto cleanup; def->mem.nhugepages = 1; } @@ -18965,6 +18903,107 @@ virDomainDefParseXML(xmlDocPtr xml, if (virXPathBoolean("boolean(./memoryBacking/locked)", ctxt)) def->mem.locked = true; + /* Extract other memory tunables */ + if (virDomainParseMemoryLimit("./memtune/hard_limit[1]", NULL, ctxt, + &def->mem.hard_limit) < 0) + goto cleanup; + + if (virDomainParseMemoryLimit("./memtune/soft_limit[1]", NULL, ctxt, + &def->mem.soft_limit) < 0) + goto cleanup; + + if (virDomainParseMemory("./memtune/min_guarantee[1]", NULL, ctxt, + &def->mem.min_guarantee, false, false) < 0) + goto cleanup; + + if (virDomainParseMemoryLimit("./memtune/swap_hard_limit[1]", NULL, ctxt, + &def->mem.swap_hard_limit) < 0) + goto cleanup; + + ret = 0; + + cleanup: + VIR_FREE(nodes); + VIR_FREE(tmp); + return ret; + +} + + +static virDomainDefPtr +virDomainDefParseXML(xmlDocPtr xml, + xmlNodePtr root, + xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque, + unsigned int flags) +{ + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + + xmlNodePtr *nodes = NULL, node = NULL; + char *tmp = NULL; + size_t i, j; + int n, gic_version; + size_t fun_index = 0; + virDomainDefPtr def; + bool uuid_generated = false; + virHashTablePtr bootHash = NULL; + bool usb_none = false; + bool usb_other = false; + bool usb_master = false; + char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + virDomainDefParseIdInfo, + virDomainDefParseVirtTypeInfo, + virDomainDefParseOsNodeInfo, + virDomainDefParseDomainInfo, + virDomainDefParseSecurityLabelInfo, + virDomainDefParseMemoryInfo, + NULL + }; + + if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { + char *schema = virFileFindResource("domain.rng", + abs_topsrcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + return NULL; + if (virXMLValidateAgainstSchema(schema, xml) < 0) { + VIR_FREE(schema); + return NULL; + } + VIR_FREE(schema); + } + + if (!(def = virDomainDefNew())) + return NULL; + + param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + } + + /* Extract blkio cgroup tunables */ if (virXPathUInt("string(./blkiotune/weight)", ctxt, &def->blkio.weight) < 0) @@ -18995,23 +19034,6 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - /* Extract other memory tunables */ - if (virDomainParseMemoryLimit("./memtune/hard_limit[1]", NULL, ctxt, - &def->mem.hard_limit) < 0) - goto error; - - if (virDomainParseMemoryLimit("./memtune/soft_limit[1]", NULL, ctxt, - &def->mem.soft_limit) < 0) - goto error; - - if (virDomainParseMemory("./memtune/min_guarantee[1]", NULL, ctxt, - &def->mem.min_guarantee, false, false) < 0) - goto error; - - if (virDomainParseMemoryLimit("./memtune/swap_hard_limit[1]", NULL, ctxt, - &def->mem.swap_hard_limit) < 0) - goto error; - if (virDomainVcpuParse(def, ctxt, xmlopt) < 0) goto error; -- 2.8.3

separate virDomainDefParseVcpuInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 92 +++++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 809c06a..4453621 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18930,6 +18930,62 @@ virDomainDefParseMemoryInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseBikiotuneInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + int ret = -1; + int n; + size_t i, j; + xmlNodePtr *nodes = NULL; + + /* Extract blkio cgroup tunables */ + if (virXPathUInt("string(./blkiotune/weight)", ctxt, + &def->blkio.weight) < 0) + def->blkio.weight = 0; + + if ((n = virXPathNodeSet("./blkiotune/device", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot extract blkiotune nodes")); + goto cleanup; + } + if (n && VIR_ALLOC_N(def->blkio.devices, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + if (virDomainBlkioDeviceParseXML(nodes[i], + &def->blkio.devices[i]) < 0) + goto cleanup; + def->blkio.ndevices++; + for (j = 0; j < i; j++) { + if (STREQ(def->blkio.devices[j].path, + def->blkio.devices[i].path)) { + virReportError(VIR_ERR_XML_ERROR, + _("duplicate blkio device path '%s'"), + def->blkio.devices[i].path); + goto cleanup; + } + } + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int +virDomainDefParseVcpuInfo(virDomainParseTotalParamPtr param) +{ + if (virDomainVcpuParse(param->def, param->ctxt, param->xmlopt) < 0) + return -1; + + return 0; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18976,6 +19032,8 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseDomainInfo, virDomainDefParseSecurityLabelInfo, virDomainDefParseMemoryInfo, + virDomainDefParseBikiotuneInfo, + virDomainDefParseVcpuInfo, NULL }; @@ -19003,40 +19061,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - - /* Extract blkio cgroup tunables */ - if (virXPathUInt("string(./blkiotune/weight)", ctxt, - &def->blkio.weight) < 0) - def->blkio.weight = 0; - - if ((n = virXPathNodeSet("./blkiotune/device", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract blkiotune nodes")); - goto error; - } - if (n && VIR_ALLOC_N(def->blkio.devices, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - if (virDomainBlkioDeviceParseXML(nodes[i], - &def->blkio.devices[i]) < 0) - goto error; - def->blkio.ndevices++; - for (j = 0; j < i; j++) { - if (STREQ(def->blkio.devices[j].path, - def->blkio.devices[i].path)) { - virReportError(VIR_ERR_XML_ERROR, - _("duplicate blkio device path '%s'"), - def->blkio.devices[i].path); - goto error; - } - } - } - VIR_FREE(nodes); - - if (virDomainVcpuParse(def, ctxt, xmlopt) < 0) - goto error; - if (virDomainDefParseIOThreads(def, ctxt) < 0) goto error; -- 2.8.3

separate virDomainDefParseIoThreadInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4453621..1d74631 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18986,6 +18986,16 @@ virDomainDefParseVcpuInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseIoThreadInfo(virDomainParseTotalParamPtr param) +{ + if (virDomainDefParseIOThreads(param->def, param->ctxt) < 0) + return -1; + + return 0; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19034,6 +19044,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseMemoryInfo, virDomainDefParseBikiotuneInfo, virDomainDefParseVcpuInfo, + virDomainDefParseIoThreadInfo, NULL }; @@ -19061,9 +19072,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (virDomainDefParseIOThreads(def, ctxt) < 0) - goto error; - /* Extract cpu tunables. */ if ((n = virXPathULongLong("string(./cputune/shares[1])", ctxt, &def->cputune.shares)) < -1) { -- 2.8.3

separate virDomainDefParseCputuneInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 227 +++++++++++++++++++++++++++---------------------- 1 file changed, 124 insertions(+), 103 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1d74631..e50e56f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18996,88 +18996,24 @@ virDomainDefParseIoThreadInfo(virDomainParseTotalParamPtr param) } -static virDomainDefPtr -virDomainDefParseXML(xmlDocPtr xml, - xmlNodePtr root, - xmlXPathContextPtr ctxt, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque, - unsigned int flags) +static int +virDomainDefParseCputuneInfo(virDomainParseTotalParamPtr param) { - typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); - - xmlNodePtr *nodes = NULL, node = NULL; - char *tmp = NULL; - size_t i, j; - int n, gic_version; - size_t fun_index = 0; - virDomainDefPtr def; - bool uuid_generated = false; - virHashTablePtr bootHash = NULL; - bool usb_none = false; - bool usb_other = false; - bool usb_master = false; - char *netprefix = NULL; - virDomainParseTotalParam param = { - NULL, - xml, - root, - ctxt, - caps, - xmlopt, - parseOpaque, - flags, - false, - false, - false, - false - - }; - - virDomainPreaseInfoFunc parse_funs[] = { - virDomainDefParseIdInfo, - virDomainDefParseVirtTypeInfo, - virDomainDefParseOsNodeInfo, - virDomainDefParseDomainInfo, - virDomainDefParseSecurityLabelInfo, - virDomainDefParseMemoryInfo, - virDomainDefParseBikiotuneInfo, - virDomainDefParseVcpuInfo, - virDomainDefParseIoThreadInfo, - NULL - }; - - if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - char *schema = virFileFindResource("domain.rng", - abs_topsrcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) { - VIR_FREE(schema); - return NULL; - } - VIR_FREE(schema); - } - - if (!(def = virDomainDefNew())) - return NULL; - - param.def = def; + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + unsigned int flags = param->flags; - while (parse_funs[fun_index]) { - if (parse_funs[fun_index](¶m) < 0) - goto error; - fun_index++; - } + int ret = -1; + int n; + size_t i; + xmlNodePtr *nodes = NULL; /* Extract cpu tunables. */ if ((n = virXPathULongLong("string(./cputune/shares[1])", ctxt, &def->cputune.shares)) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune shares value")); - goto error; + goto cleanup; } else if (n == 0) { def->cputune.sharesSpecified = true; } @@ -19086,7 +19022,7 @@ virDomainDefParseXML(xmlDocPtr xml, &def->cputune.period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune period value")); - goto error; + goto cleanup; } if (def->cputune.period > 0 && @@ -19094,14 +19030,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune period must be in range " "[1000, 1000000]")); - goto error; + goto cleanup; } if (virXPathLongLong("string(./cputune/quota[1])", ctxt, &def->cputune.quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune quota value")); - goto error; + goto cleanup; } if (def->cputune.quota > 0 && @@ -19110,14 +19046,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune quota must be in range " "[1000, 18446744073709551]")); - goto error; + goto cleanup; } if (virXPathULongLong("string(./cputune/global_period[1])", ctxt, &def->cputune.global_period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune global period value")); - goto error; + goto cleanup; } if (def->cputune.global_period > 0 && @@ -19125,14 +19061,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune global period must be in range " "[1000, 1000000]")); - goto error; + goto cleanup; } if (virXPathLongLong("string(./cputune/global_quota[1])", ctxt, &def->cputune.global_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune global quota value")); - goto error; + goto cleanup; } if (def->cputune.global_quota > 0 && @@ -19141,14 +19077,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune global quota must be in range " "[1000, 18446744073709551]")); - goto error; + goto cleanup; } if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt, &def->cputune.emulator_period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune emulator period value")); - goto error; + goto cleanup; } if (def->cputune.emulator_period > 0 && @@ -19157,14 +19093,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune emulator_period must be in range " "[1000, 1000000]")); - goto error; + goto cleanup; } if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt, &def->cputune.emulator_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune emulator quota value")); - goto error; + goto cleanup; } if (def->cputune.emulator_quota > 0 && @@ -19173,14 +19109,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune emulator_quota must be in range " "[1000, 18446744073709551]")); - goto error; + goto cleanup; } if (virXPathULongLong("string(./cputune/iothread_period[1])", ctxt, &def->cputune.iothread_period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune iothread period value")); - goto error; + goto cleanup; } if (def->cputune.iothread_period > 0 && @@ -19189,14 +19125,14 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune iothread_period must be in range " "[1000, 1000000]")); - goto error; + goto cleanup; } if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt, &def->cputune.iothread_quota) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("can't parse cputune iothread quota value")); - goto error; + goto cleanup; } if (def->cputune.iothread_quota > 0 && @@ -19205,22 +19141,22 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Value of cputune iothread_quota must be in range " "[1000, 18446744073709551]")); - goto error; + goto cleanup; } if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { if (virDomainVcpuPinDefParseXML(def, nodes[i])) - goto error; + goto cleanup; } VIR_FREE(nodes); if ((n = virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract emulatorpin nodes")); - goto error; + goto cleanup; } if (n) { @@ -19228,11 +19164,11 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_XML_ERROR, "%s", _("only one emulatorpin is supported")); VIR_FREE(nodes); - goto error; + goto cleanup; } if (!(def->cputune.emulatorpin = virDomainEmulatorPinDefParseXML(nodes[0]))) - goto error; + goto cleanup; } VIR_FREE(nodes); @@ -19240,51 +19176,136 @@ virDomainDefParseXML(xmlDocPtr xml, if ((n = virXPathNodeSet("./cputune/iothreadpin", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract iothreadpin nodes")); - goto error; + goto cleanup; } for (i = 0; i < n; i++) { if (virDomainIOThreadPinDefParseXML(nodes[i], def) < 0) - goto error; + goto cleanup; } VIR_FREE(nodes); if ((n = virXPathNodeSet("./cputune/vcpusched", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract vcpusched nodes")); - goto error; + goto cleanup; } for (i = 0; i < n; i++) { if (virDomainVcpuThreadSchedParse(nodes[i], def) < 0) - goto error; + goto cleanup; } VIR_FREE(nodes); if ((n = virXPathNodeSet("./cputune/iothreadsched", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract iothreadsched nodes")); - goto error; + goto cleanup; } for (i = 0; i < n; i++) { if (virDomainIOThreadSchedParse(nodes[i], def) < 0) - goto error; + goto cleanup; } VIR_FREE(nodes); if ((n = virXPathNodeSet("./cputune/cachetune", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract cachetune nodes")); - goto error; + goto cleanup; } for (i = 0; i < n; i++) { if (virDomainCachetuneDefParse(def, ctxt, nodes[i], flags) < 0) - goto error; + goto cleanup; } VIR_FREE(nodes); + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static virDomainDefPtr +virDomainDefParseXML(xmlDocPtr xml, + xmlNodePtr root, + xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque, + unsigned int flags) +{ + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + + xmlNodePtr *nodes = NULL, node = NULL; + char *tmp = NULL; + size_t i, j; + int n, gic_version; + size_t fun_index = 0; + virDomainDefPtr def; + bool uuid_generated = false; + virHashTablePtr bootHash = NULL; + bool usb_none = false; + bool usb_other = false; + bool usb_master = false; + char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + virDomainDefParseIdInfo, + virDomainDefParseVirtTypeInfo, + virDomainDefParseOsNodeInfo, + virDomainDefParseDomainInfo, + virDomainDefParseSecurityLabelInfo, + virDomainDefParseMemoryInfo, + virDomainDefParseBikiotuneInfo, + virDomainDefParseVcpuInfo, + virDomainDefParseIoThreadInfo, + virDomainDefParseCputuneInfo, + NULL + }; + + if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { + char *schema = virFileFindResource("domain.rng", + abs_topsrcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + return NULL; + if (virXMLValidateAgainstSchema(schema, xml) < 0) { + VIR_FREE(schema); + return NULL; + } + VIR_FREE(schema); + } + + if (!(def = virDomainDefNew())) + return NULL; + + param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + } + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu) < 0) goto error; -- 2.8.3

separate virDomainDefParseCpuNumaInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 77 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e50e56f..892e871 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19229,6 +19229,51 @@ virDomainDefParseCputuneInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseCpuNumaInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + int ret = -1; + + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu) < 0) + goto cleanup; + + if (virDomainNumaDefCPUParseXML(def->numa, ctxt) < 0) + goto cleanup; + + if (virDomainNumaGetCPUCountTotal(def->numa) > virDomainDefGetVcpusMax(def)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Number of CPUs in <numa> exceeds the" + " <vcpu> count")); + goto cleanup; + } + + if (virDomainNumaGetMaxCPUID(def->numa) >= virDomainDefGetVcpusMax(def)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("CPU IDs in <numa> exceed the <vcpu> count")); + goto cleanup; + } + + if (virDomainNumatuneParseXML(def->numa, + def->placement_mode == + VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC, + ctxt) < 0) + goto cleanup; + + if (virDomainNumatuneHasPlacementAuto(def->numa) && + !def->cpumask && !virDomainDefHasVcpuPin(def) && + !def->cputune.emulatorpin && + !virDomainIOThreadIDArrayHasPin(def)) + def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO; + + ret = 0; + + cleanup: + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19279,6 +19324,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseVcpuInfo, virDomainDefParseIoThreadInfo, virDomainDefParseCputuneInfo, + virDomainDefParseCpuNumaInfo, NULL }; @@ -19306,37 +19352,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu) < 0) - goto error; - - if (virDomainNumaDefCPUParseXML(def->numa, ctxt) < 0) - goto error; - - if (virDomainNumaGetCPUCountTotal(def->numa) > virDomainDefGetVcpusMax(def)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Number of CPUs in <numa> exceeds the" - " <vcpu> count")); - goto error; - } - - if (virDomainNumaGetMaxCPUID(def->numa) >= virDomainDefGetVcpusMax(def)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("CPU IDs in <numa> exceed the <vcpu> count")); - goto error; - } - - if (virDomainNumatuneParseXML(def->numa, - def->placement_mode == - VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC, - ctxt) < 0) - goto error; - - if (virDomainNumatuneHasPlacementAuto(def->numa) && - !def->cpumask && !virDomainDefHasVcpuPin(def) && - !def->cputune.emulatorpin && - !virDomainIOThreadIDArrayHasPin(def)) - def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO; - if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract resource nodes")); -- 2.8.3

separate virDomainDefParseResourceInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 51 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 892e871..24bd240 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19274,6 +19274,39 @@ virDomainDefParseCpuNumaInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseResourceInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + + int ret = -1; + int n; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot extract resource nodes")); + goto cleanup; + } + + if (n > 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only one resource element is supported")); + goto cleanup; + } + + if (n && + !(def->resource = virDomainResourceDefParse(nodes[0], ctxt))) + goto cleanup; + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19325,6 +19358,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseIoThreadInfo, virDomainDefParseCputuneInfo, virDomainDefParseCpuNumaInfo, + virDomainDefParseResourceInfo, NULL }; @@ -19352,23 +19386,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract resource nodes")); - goto error; - } - - if (n > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only one resource element is supported")); - goto error; - } - - if (n && - !(def->resource = virDomainResourceDefParse(nodes[0], ctxt))) - goto error; - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseFeatureInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 221 +++++++++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 99 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 24bd240..b8fe24e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19307,94 +19307,27 @@ virDomainDefParseResourceInfo(virDomainParseTotalParamPtr param) } -static virDomainDefPtr -virDomainDefParseXML(xmlDocPtr xml, - xmlNodePtr root, - xmlXPathContextPtr ctxt, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque, - unsigned int flags) +static int +virDomainDefParseFeatureInfo(virDomainParseTotalParamPtr param) { - typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; - xmlNodePtr *nodes = NULL, node = NULL; - char *tmp = NULL; - size_t i, j; + int ret = -1; int n, gic_version; - size_t fun_index = 0; - virDomainDefPtr def; - bool uuid_generated = false; - virHashTablePtr bootHash = NULL; - bool usb_none = false; - bool usb_other = false; - bool usb_master = false; - char *netprefix = NULL; - virDomainParseTotalParam param = { - NULL, - xml, - root, - ctxt, - caps, - xmlopt, - parseOpaque, - flags, - false, - false, - false, - false - - }; - - virDomainPreaseInfoFunc parse_funs[] = { - virDomainDefParseIdInfo, - virDomainDefParseVirtTypeInfo, - virDomainDefParseOsNodeInfo, - virDomainDefParseDomainInfo, - virDomainDefParseSecurityLabelInfo, - virDomainDefParseMemoryInfo, - virDomainDefParseBikiotuneInfo, - virDomainDefParseVcpuInfo, - virDomainDefParseIoThreadInfo, - virDomainDefParseCputuneInfo, - virDomainDefParseCpuNumaInfo, - virDomainDefParseResourceInfo, - NULL - }; - - if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - char *schema = virFileFindResource("domain.rng", - abs_topsrcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) { - VIR_FREE(schema); - return NULL; - } - VIR_FREE(schema); - } - - if (!(def = virDomainDefNew())) - return NULL; - - param.def = def; - - while (parse_funs[fun_index]) { - if (parse_funs[fun_index](¶m) < 0) - goto error; - fun_index++; - } + char *tmp = NULL; + size_t i; + xmlNodePtr *nodes = NULL, node = NULL; if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unexpected feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } switch ((virDomainFeature) val) { @@ -19405,7 +19338,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown value for attribute eoi: '%s'"), tmp); - goto error; + goto cleanup; } def->apic_eoi = eoi; VIR_FREE(tmp); @@ -19427,7 +19360,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown policy attribute '%s' of feature '%s'"), tmp, virDomainFeatureTypeToString(val)); - goto error; + goto cleanup; } VIR_FREE(tmp); } else { @@ -19445,7 +19378,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown state attribute '%s' of feature '%s'"), tmp, virDomainFeatureTypeToString(val)); - goto error; + goto cleanup; } VIR_FREE(tmp); } else { @@ -19459,7 +19392,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (gic_version < 0 || gic_version == VIR_GIC_VERSION_NONE) { virReportError(VIR_ERR_XML_ERROR, _("malformed gic version: %s"), tmp); - goto error; + goto cleanup; } def->gic_version = gic_version; VIR_FREE(tmp); @@ -19475,7 +19408,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown driver mode: %s"), tmp); - goto error; + goto cleanup; } def->ioapic = value; def->features[val] = VIR_TRISTATE_SWITCH_ON; @@ -19491,7 +19424,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown HPT resizing setting: %s"), tmp); - goto error; + goto cleanup; } def->hpt_resizing = value; def->features[val] = VIR_TRISTATE_SWITCH_ON; @@ -19511,7 +19444,7 @@ virDomainDefParseXML(xmlDocPtr xml, int value; node = ctxt->node; if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { feature = virDomainHypervTypeFromString((const char *)nodes[i]->name); @@ -19519,7 +19452,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported HyperV Enlightenment feature: %s"), nodes[i]->name); - goto error; + goto cleanup; } ctxt->node = nodes[i]; @@ -19529,7 +19462,7 @@ virDomainDefParseXML(xmlDocPtr xml, _("missing 'state' attribute for " "HyperV Enlightenment feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } if ((value = virTristateSwitchTypeFromString(tmp)) < 0) { @@ -19537,7 +19470,7 @@ virDomainDefParseXML(xmlDocPtr xml, _("invalid value of state argument " "for HyperV Enlightenment feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } VIR_FREE(tmp); @@ -19561,14 +19494,14 @@ virDomainDefParseXML(xmlDocPtr xml, &def->hyperv_spinlocks) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid HyperV spinlock retry count")); - goto error; + goto cleanup; } if (def->hyperv_spinlocks < 0xFFF) { virReportError(VIR_ERR_XML_ERROR, "%s", _("HyperV spinlock retry count must be " "at least 4095")); - goto error; + goto cleanup; } break; @@ -19581,7 +19514,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_XML_ERROR, "%s", _("missing 'value' attribute for " "HyperV feature 'vendor_id'")); - goto error; + goto cleanup; } if (strlen(def->hyperv_vendor_id) > VIR_DOMAIN_HYPERV_VENDOR_ID_MAX) { @@ -19589,14 +19522,14 @@ virDomainDefParseXML(xmlDocPtr xml, _("HyperV vendor_id value must not be more " "than %d characters."), VIR_DOMAIN_HYPERV_VENDOR_ID_MAX); - goto error; + goto cleanup; } /* ensure that the string can be passed to qemu */ if (strchr(def->hyperv_vendor_id, ',')) { virReportError(VIR_ERR_XML_ERROR, "%s", _("HyperV vendor_id value is invalid")); - goto error; + goto cleanup; } /* coverity[dead_error_begin] */ @@ -19612,7 +19545,7 @@ virDomainDefParseXML(xmlDocPtr xml, int feature; int value; if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { feature = virDomainKVMTypeFromString((const char *)nodes[i]->name); @@ -19620,7 +19553,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported KVM feature: %s"), nodes[i]->name); - goto error; + goto cleanup; } switch ((virDomainKVM) feature) { @@ -19630,7 +19563,7 @@ virDomainDefParseXML(xmlDocPtr xml, _("missing 'state' attribute for " "KVM feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } if ((value = virTristateSwitchTypeFromString(tmp)) < 0) { @@ -19638,7 +19571,7 @@ virDomainDefParseXML(xmlDocPtr xml, _("invalid value of state argument " "for KVM feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } VIR_FREE(tmp); @@ -19654,14 +19587,14 @@ virDomainDefParseXML(xmlDocPtr xml, } if ((n = virXPathNodeSet("./features/capabilities/*", ctxt, &nodes)) < 0) - goto error; + goto cleanup; for (i = 0; i < n; i++) { int val = virDomainCapsFeatureTypeFromString((const char *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unexpected capability feature '%s'"), nodes[i]->name); - goto error; + goto cleanup; } if (val >= 0 && val < VIR_DOMAIN_CAPS_FEATURE_LAST) { @@ -19670,7 +19603,7 @@ virDomainDefParseXML(xmlDocPtr xml, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown state attribute '%s' of feature capability '%s'"), tmp, virDomainFeatureTypeToString(val)); - goto error; + goto cleanup; } VIR_FREE(tmp); } else { @@ -19680,6 +19613,96 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); + ret = 0; + + cleanup: + VIR_FREE(tmp); + VIR_FREE(nodes); + return ret; +} + + +static virDomainDefPtr +virDomainDefParseXML(xmlDocPtr xml, + xmlNodePtr root, + xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque, + unsigned int flags) +{ + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + + xmlNodePtr *nodes = NULL, node = NULL; + char *tmp = NULL; + size_t i, j; + int n; + size_t fun_index = 0; + virDomainDefPtr def; + bool uuid_generated = false; + virHashTablePtr bootHash = NULL; + bool usb_none = false; + bool usb_other = false; + bool usb_master = false; + char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + virDomainDefParseIdInfo, + virDomainDefParseVirtTypeInfo, + virDomainDefParseOsNodeInfo, + virDomainDefParseDomainInfo, + virDomainDefParseSecurityLabelInfo, + virDomainDefParseMemoryInfo, + virDomainDefParseBikiotuneInfo, + virDomainDefParseVcpuInfo, + virDomainDefParseIoThreadInfo, + virDomainDefParseCputuneInfo, + virDomainDefParseCpuNumaInfo, + virDomainDefParseResourceInfo, + virDomainDefParseFeatureInfo, + NULL + }; + + if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { + char *schema = virFileFindResource("domain.rng", + abs_topsrcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + return NULL; + if (virXMLValidateAgainstSchema(schema, xml) < 0) { + VIR_FREE(schema); + return NULL; + } + VIR_FREE(schema); + } + + if (!(def = virDomainDefNew())) + return NULL; + + param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + } + + if (virDomainEventActionParseXML(ctxt, "on_reboot", "string(./on_reboot[1])", &def->onReboot, -- 2.8.3

separate virDomainDefParseEventActionInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 68 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b8fe24e..8374b9d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19622,6 +19622,44 @@ virDomainDefParseFeatureInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseEventActionInfo(virDomainParseTotalParamPtr param) +{ + int ret = -1; + if (virDomainEventActionParseXML(param->ctxt, "on_reboot", + "string(./on_reboot[1])", + ¶m->def->onReboot, + VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, + virDomainLifecycleActionTypeFromString) < 0) + goto cleanup; + + if (virDomainEventActionParseXML(param->ctxt, "on_poweroff", + "string(./on_poweroff[1])", + ¶m->def->onPoweroff, + VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, + virDomainLifecycleActionTypeFromString) < 0) + goto cleanup; + + if (virDomainEventActionParseXML(param->ctxt, "on_crash", + "string(./on_crash[1])", + ¶m->def->onCrash, + VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, + virDomainLifecycleActionTypeFromString) < 0) + goto cleanup; + + if (virDomainEventActionParseXML(param->ctxt, "on_lockfailure", + "string(./on_lockfailure[1])", + ¶m->def->onLockFailure, + VIR_DOMAIN_LOCK_FAILURE_DEFAULT, + virDomainLockFailureTypeFromString) < 0) + goto cleanup; + + ret = 0; + cleanup: + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19675,6 +19713,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseCpuNumaInfo, virDomainDefParseResourceInfo, virDomainDefParseFeatureInfo, + virDomainDefParseEventActionInfo, NULL }; @@ -19702,35 +19741,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - - if (virDomainEventActionParseXML(ctxt, "on_reboot", - "string(./on_reboot[1])", - &def->onReboot, - VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, - virDomainLifecycleActionTypeFromString) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_poweroff", - "string(./on_poweroff[1])", - &def->onPoweroff, - VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, - virDomainLifecycleActionTypeFromString) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_crash", - "string(./on_crash[1])", - &def->onCrash, - VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, - virDomainLifecycleActionTypeFromString) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_lockfailure", - "string(./on_lockfailure[1])", - &def->onLockFailure, - VIR_DOMAIN_LOCK_FAILURE_DEFAULT, - virDomainLockFailureTypeFromString) < 0) - goto error; - if (virDomainPMStateParseXML(ctxt, "string(./pm/suspend-to-mem/@enabled)", &def->pm.s3) < 0) -- 2.8.3

separate virDomainDefParsePMStateInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 83 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8374b9d..248472b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15329,29 +15329,6 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, return ret; } -static int -virDomainPerfDefParseXML(virDomainDefPtr def, - xmlXPathContextPtr ctxt) -{ - size_t i; - int ret = -1; - xmlNodePtr *nodes = NULL; - int n; - - if ((n = virXPathNodeSet("./perf/event", ctxt, &nodes)) < 0) - return n; - - for (i = 0; i < n; i++) { - if (virDomainPerfEventDefParseXML(&def->perf, nodes[i]) < 0) - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(nodes); - return ret; -} static int virDomainMemorySourceDefParseXML(xmlNodePtr node, @@ -19660,6 +19637,51 @@ virDomainDefParseEventActionInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParsePMStateInfo(virDomainParseTotalParamPtr param) +{ + int ret = -1; + if (virDomainPMStateParseXML(param->ctxt, + "string(./pm/suspend-to-mem/@enabled)", + ¶m->def->pm.s3) < 0) + goto cleanup; + + if (virDomainPMStateParseXML(param->ctxt, + "string(./pm/suspend-to-disk/@enabled)", + ¶m->def->pm.s4) < 0) + goto cleanup; + + ret = 0; + cleanup: + return ret; +} + + +static int +virDomainDefParsePerfEventInfo(virDomainParseTotalParamPtr param) +{ + size_t i; + int ret = -1; + xmlNodePtr *nodes = NULL; + int n; + + if ((n = virXPathNodeSet("./perf/event", param->ctxt, &nodes)) < 0) + return n; + + for (i = 0; i < n; i++) { + if (virDomainPerfEventDefParseXML(¶m->def->perf, nodes[i]) < 0) + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; + +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19714,6 +19736,8 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseResourceInfo, virDomainDefParseFeatureInfo, virDomainDefParseEventActionInfo, + virDomainDefParsePMStateInfo, + virDomainDefParsePerfEventInfo, NULL }; @@ -19741,19 +19765,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-mem/@enabled)", - &def->pm.s3) < 0) - goto error; - - if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-disk/@enabled)", - &def->pm.s4) < 0) - goto error; - - if (virDomainPerfDefParseXML(def, ctxt) < 0) - goto error; - if ((tmp = virXPathString("string(./clock/@offset)", ctxt)) && (def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, -- 2.8.3

separate virDomainDefParseClockInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 189 +++++++++++++++++++++++++++---------------------- 1 file changed, 104 insertions(+), 85 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 248472b..1e949ea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19682,6 +19682,109 @@ virDomainDefParsePerfEventInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseClockInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + size_t i; + char *tmp = NULL; + int ret = -1; + xmlNodePtr *nodes = NULL; + int n; + + if ((tmp = virXPathString("string(./clock/@offset)", ctxt)) && + (def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown clock offset '%s'"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + tmp = virXPathString("string(./clock/@adjustment)", ctxt); + if (tmp) { + if (STREQ(tmp, "reset")) { + def->clock.data.utc_reset = true; + } else { + if (virStrToLong_ll(tmp, NULL, 10, + &def->clock.data.variable.adjustment) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown clock adjustment '%s'"), + tmp); + goto cleanup; + } + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_LOCALTIME; + break; + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_UTC; + break; + } + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; + } + VIR_FREE(tmp); + } else { + def->clock.data.utc_reset = false; + } + break; + + case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: + if (virXPathLongLong("number(./clock/@adjustment)", ctxt, + &def->clock.data.variable.adjustment) < 0) + def->clock.data.variable.adjustment = 0; + if (virXPathLongLong("number(./clock/@adjustment0)", ctxt, + &def->clock.data.variable.adjustment0) < 0) + def->clock.data.variable.adjustment0 = 0; + tmp = virXPathString("string(./clock/@basis)", ctxt); + if (tmp) { + if ((def->clock.data.variable.basis = virDomainClockBasisTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown clock basis '%s'"), tmp); + goto cleanup; + } + VIR_FREE(tmp); + } else { + def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_UTC; + } + break; + + case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE: + def->clock.data.timezone = virXPathString("string(./clock/@timezone)", ctxt); + if (!def->clock.data.timezone) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing 'timezone' attribute for clock with offset='timezone'")); + goto cleanup; + } + break; + } + + if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) + goto cleanup; + + if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i], + ctxt); + if (!timer) + goto cleanup; + + def->clock.timers[def->clock.ntimers++] = timer; + } + VIR_FREE(nodes); + + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19738,6 +19841,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseEventActionInfo, virDomainDefParsePMStateInfo, virDomainDefParsePerfEventInfo, + virDomainDefParseClockInfo, NULL }; @@ -19765,91 +19869,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((tmp = virXPathString("string(./clock/@offset)", ctxt)) && - (def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown clock offset '%s'"), tmp); - goto error; - } - VIR_FREE(tmp); - - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - tmp = virXPathString("string(./clock/@adjustment)", ctxt); - if (tmp) { - if (STREQ(tmp, "reset")) { - def->clock.data.utc_reset = true; - } else { - if (virStrToLong_ll(tmp, NULL, 10, - &def->clock.data.variable.adjustment) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown clock adjustment '%s'"), - tmp); - goto error; - } - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_LOCALTIME; - break; - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_UTC; - break; - } - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; - } - VIR_FREE(tmp); - } else { - def->clock.data.utc_reset = false; - } - break; - - case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: - if (virXPathLongLong("number(./clock/@adjustment)", ctxt, - &def->clock.data.variable.adjustment) < 0) - def->clock.data.variable.adjustment = 0; - if (virXPathLongLong("number(./clock/@adjustment0)", ctxt, - &def->clock.data.variable.adjustment0) < 0) - def->clock.data.variable.adjustment0 = 0; - tmp = virXPathString("string(./clock/@basis)", ctxt); - if (tmp) { - if ((def->clock.data.variable.basis = virDomainClockBasisTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown clock basis '%s'"), tmp); - goto error; - } - VIR_FREE(tmp); - } else { - def->clock.data.variable.basis = VIR_DOMAIN_CLOCK_BASIS_UTC; - } - break; - - case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE: - def->clock.data.timezone = virXPathString("string(./clock/@timezone)", ctxt); - if (!def->clock.data.timezone) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing 'timezone' attribute for clock with offset='timezone'")); - goto error; - } - break; - } - - if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) - goto error; - - if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i], - ctxt); - if (!timer) - goto error; - - def->clock.timers[def->clock.ntimers++] = timer; - } - VIR_FREE(nodes); - if (virDomainDefParseBootOptions(def, ctxt, &bootHash) < 0) goto error; -- 2.8.3

add bootHash to virDomainParseTotalParam --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1e949ea..1a8248d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18516,6 +18516,7 @@ struct _virDomainParseTotalParam{ virCapsPtr caps; virDomainXMLOptionPtr xmlopt; void *parseOpaque; + virHashTablePtr bootHash; unsigned int flags; //internal parameters @@ -19816,6 +19817,7 @@ virDomainDefParseXML(xmlDocPtr xml, caps, xmlopt, parseOpaque, + NULL, flags, false, false, @@ -19861,7 +19863,11 @@ virDomainDefParseXML(xmlDocPtr xml, if (!(def = virDomainDefNew())) return NULL; + if (!(bootHash = virHashCreate(5, NULL))) + goto error; + param.def = def; + param.bootHash = bootHash; while (parse_funs[fun_index]) { if (parse_funs[fun_index](¶m) < 0) -- 2.8.3

separate virDomainDefParseBootOptionsInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1a8248d..92a6522 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18169,8 +18169,7 @@ virDomainVcpuParse(virDomainDefPtr def, static int virDomainDefParseBootOptions(virDomainDefPtr def, - xmlXPathContextPtr ctxt, - virHashTablePtr *bootHash) + xmlXPathContextPtr ctxt) { xmlNodePtr *nodes = NULL; char *tmp = NULL; @@ -18302,8 +18301,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, if (virDomainDefParseBootXML(ctxt, def) < 0) goto error; - if (!(*bootHash = virHashCreate(5, NULL))) - goto error; } ret = 0; @@ -19786,6 +19783,16 @@ virDomainDefParseClockInfo(virDomainParseTotalParamPtr param) return ret; } + +static int +virDomainDefParseBootOptionsInfo(virDomainParseTotalParamPtr param) +{ + if (virDomainDefParseBootOptions(param->def, param->ctxt) < 0) + return -1; + + return 0; +} + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19844,6 +19851,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParsePMStateInfo, virDomainDefParsePerfEventInfo, virDomainDefParseClockInfo, + virDomainDefParseBootOptionsInfo, NULL }; @@ -19875,9 +19883,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (virDomainDefParseBootOptions(def, ctxt, &bootHash) < 0) - goto error; - /* analysis of the disk devices */ if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseDeviceInfo from virDomainDefParseXML, separate virDomainDefParseControllerInfo from virDomainDefParseXML, move virDomainDefParseControllerInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 153 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 52 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 92a6522..22db391 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19793,6 +19793,106 @@ virDomainDefParseBootOptionsInfo(virDomainParseTotalParamPtr param) return 0; } + +static int +virDomainDefParseControllerInfo(virDomainParseTotalParamPtr param) + +{ + virDomainDefPtr def = param->def; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + xmlXPathContextPtr ctxt = param->ctxt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the controller devices */ + if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) + goto cleanup; + + if (n && VIR_ALLOC_N(def->controllers, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt, + nodes[i], + ctxt, + flags); + + if (!controller) + goto cleanup; + + /* sanitize handling of "none" usb controller */ + if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) { + if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { + if (param->usb_other || param->usb_none) { + virDomainControllerDefFree(controller); + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto cleanup; + } + param->usb_none = true; + } else { + if (param->usb_none) { + virDomainControllerDefFree(controller); + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto cleanup; + } + param->usb_other = true; + } + + if (controller->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_NONE) + param->usb_master = true; + } + + virDomainControllerInsertPreAlloced(def, controller); + } + VIR_FREE(nodes); + + if (param->usb_other && !param->usb_master) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("No master USB controller specified")); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int +virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) +{ + typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); + int ret = -1; + size_t i = 0; + + virDomainPreaseDeviceFuc parseFuc[] = { + virDomainDefParseControllerInfo, + NULL + }; + + while (parseFuc[i]) { + if (parseFuc[i](param) < 0) + goto out; + i++; + } + ret = 0; + + out: + return ret; + + +} + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19813,8 +19913,6 @@ virDomainDefParseXML(xmlDocPtr xml, bool uuid_generated = false; virHashTablePtr bootHash = NULL; bool usb_none = false; - bool usb_other = false; - bool usb_master = false; char *netprefix = NULL; virDomainParseTotalParam param = { NULL, @@ -19852,6 +19950,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParsePerfEventInfo, virDomainDefParseClockInfo, virDomainDefParseBootOptionsInfo, + virDomainDefParseDeviceInfo, NULL }; @@ -19905,57 +20004,7 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - /* analysis of the controller devices */ - if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) - goto error; - - if (n && VIR_ALLOC_N(def->controllers, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); - - if (!controller) - goto error; - - /* sanitize handling of "none" usb controller */ - if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) { - if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { - if (usb_other || usb_none) { - virDomainControllerDefFree(controller); - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Can't add another USB controller: " - "USB is disabled for this domain")); - goto error; - } - usb_none = true; - } else { - if (usb_none) { - virDomainControllerDefFree(controller); - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Can't add another USB controller: " - "USB is disabled for this domain")); - goto error; - } - usb_other = true; - } - - if (controller->info.mastertype == VIR_DOMAIN_CONTROLLER_MASTER_NONE) - usb_master = true; - } - - virDomainControllerInsertPreAlloced(def, controller); - } - VIR_FREE(nodes); - if (usb_other && !usb_master) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("No master USB controller specified")); - goto error; - } /* analysis of the resource leases */ if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { -- 2.8.3

separate virDomainDefParseDisksInfo from virDomainDefParseXML, move virDomainDefParseDisksInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 78 +++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22db391..903dfec 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18506,17 +18506,17 @@ typedef virDomainParseTotalParam *virDomainParseTotalParamPtr; struct _virDomainParseTotalParam{ //input parameters - virDomainDefPtr def; xmlDocPtr xml; xmlNodePtr root; xmlXPathContextPtr ctxt; virCapsPtr caps; virDomainXMLOptionPtr xmlopt; void *parseOpaque; - virHashTablePtr bootHash; unsigned int flags; - //internal parameters + //internal parameters, must assignment before use it + virDomainDefPtr def; + virHashTablePtr bootHash; bool usb_none; bool usb_other; bool usb_master; @@ -19869,6 +19869,48 @@ virDomainDefParseControllerInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseDisksInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + xmlXPathContextPtr ctxt = param->ctxt; + unsigned int flags = param->flags; + virHashTablePtr bootHash = param->bootHash; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the disk devices */ + if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) + goto cleanup; + + if (n && VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainDiskDefPtr disk = virDomainDiskDefParseXML(xmlopt, + nodes[i], + ctxt, + bootHash, + def->seclabels, + def->nseclabels, + flags); + if (!disk) + goto cleanup; + + virDomainDiskInsertPreAlloced(def, disk); + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -19877,6 +19919,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainPreaseDeviceFuc parseFuc[] = { virDomainDefParseControllerInfo, + virDomainDefParseDisksInfo, NULL }; @@ -19893,6 +19936,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) } + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -19915,15 +19959,15 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_none = false; char *netprefix = NULL; virDomainParseTotalParam param = { - NULL, xml, root, ctxt, caps, xmlopt, parseOpaque, - NULL, flags, + NULL, + NULL, false, false, false, @@ -19982,30 +20026,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the disk devices */ - if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) - goto error; - - if (n && VIR_ALLOC_N(def->disks, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainDiskDefPtr disk = virDomainDiskDefParseXML(xmlopt, - nodes[i], - ctxt, - bootHash, - def->seclabels, - def->nseclabels, - flags); - if (!disk) - goto error; - - virDomainDiskInsertPreAlloced(def, disk); - } - VIR_FREE(nodes); - - - /* analysis of the resource leases */ if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.8.3

separate virDomainDefParseLeaseInfo from virDomainDefParseXML, move virDomainDefParseLeaseInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 54 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 903dfec..6a27294 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19911,6 +19911,40 @@ virDomainDefParseDisksInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseLeaseInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the resource leases */ + if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot extract device leases")); + goto cleanup; + } + if (n && VIR_ALLOC_N(def->leases, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]); + if (!lease) + goto cleanup; + + def->leases[def->nleases++] = lease; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -19920,6 +19954,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainPreaseDeviceFuc parseFuc[] = { virDomainDefParseControllerInfo, virDomainDefParseDisksInfo, + virDomainDefParseLeaseInfo, NULL }; @@ -19932,8 +19967,6 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) out: return ret; - - } @@ -20026,23 +20059,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the resource leases */ - if ((n = virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract device leases")); - goto error; - } - if (n && VIR_ALLOC_N(def->leases, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainLeaseDefPtr lease = virDomainLeaseDefParseXML(nodes[i]); - if (!lease) - goto error; - - def->leases[def->nleases++] = lease; - } - VIR_FREE(nodes); - /* analysis of the filesystems */ if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseFilesystemInfo from virDomainDefParseXML, move virDomainDefParseFilesystemInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 54 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6a27294..72ddbd7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19945,6 +19945,42 @@ virDomainDefParseLeaseInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseFilesystemInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the filesystems */ + if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->fss, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainFSDefPtr fs = virDomainFSDefParseXML(xmlopt, + nodes[i], + ctxt, + flags); + if (!fs) + goto cleanup; + + def->fss[def->nfss++] = fs; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -19955,6 +19991,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseControllerInfo, virDomainDefParseDisksInfo, virDomainDefParseLeaseInfo, + virDomainDefParseFilesystemInfo, NULL }; @@ -20059,23 +20096,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the filesystems */ - if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->fss, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainFSDefPtr fs = virDomainFSDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); - if (!fs) - goto error; - - def->fss[def->nfss++] = fs; - } - VIR_FREE(nodes); - /* analysis of the network devices */ if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseInterfaceInfo from virDomainDefParseXML, move virDomainDefParseInterfaceInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 82 +++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 72ddbd7..3448c42 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19981,6 +19981,56 @@ virDomainDefParseFilesystemInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseInterfaceInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + virHashTablePtr bootHash = param->bootHash; + virCapsPtr caps = param->caps; + + int ret = -1; + int n = 0; + size_t i; + char *netprefix = NULL; + xmlNodePtr *nodes = NULL; + + /* analysis of the network devices */ + if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->nets, n) < 0) + goto cleanup; + netprefix = caps->host.netprefix; + for (i = 0; i < n; i++) { + virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, + nodes[i], + ctxt, + bootHash, + netprefix, + flags); + if (!net) + goto cleanup; + + def->nets[def->nnets++] = net; + + /* <interface type='hostdev'> (and <interface type='net'> + * where the actual network type is already known to be + * hostdev) must also be in the hostdevs array. + */ + if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV && + virDomainHostdevInsert(def, virDomainNetGetActualHostdev(net)) < 0) { + goto cleanup; + } + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -19992,6 +20042,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseDisksInfo, virDomainDefParseLeaseInfo, virDomainDefParseFilesystemInfo, + virDomainDefParseInterfaceInfo, NULL }; @@ -20027,7 +20078,6 @@ virDomainDefParseXML(xmlDocPtr xml, bool uuid_generated = false; virHashTablePtr bootHash = NULL; bool usb_none = false; - char *netprefix = NULL; virDomainParseTotalParam param = { xml, root, @@ -20096,36 +20146,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the network devices */ - if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->nets, n) < 0) - goto error; - netprefix = caps->host.netprefix; - for (i = 0; i < n; i++) { - virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, - nodes[i], - ctxt, - bootHash, - netprefix, - flags); - if (!net) - goto error; - - def->nets[def->nnets++] = net; - - /* <interface type='hostdev'> (and <interface type='net'> - * where the actual network type is already known to be - * hostdev) must also be in the hostdevs array. - */ - if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV && - virDomainHostdevInsert(def, virDomainNetGetActualHostdev(net)) < 0) { - goto error; - } - } - VIR_FREE(nodes); - - /* analysis of the smartcard devices */ if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseSmartCardsInfo from virDomainDefParseXML, move virDomainDefParseSmartCardsInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 57 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3448c42..f818228 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20030,6 +20030,43 @@ virDomainDefParseInterfaceInfo(virDomainParseTotalParamPtr param) return ret; } + +static int +virDomainDefParseSmartCardsInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the smartcard devices */ + if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->smartcards, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainSmartcardDefPtr card = virDomainSmartcardDefParseXML(xmlopt, + nodes[i], + ctxt, + flags); + if (!card) + goto cleanup; + + def->smartcards[def->nsmartcards++] = card; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { @@ -20043,6 +20080,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseLeaseInfo, virDomainDefParseFilesystemInfo, virDomainDefParseInterfaceInfo, + virDomainDefParseSmartCardsInfo, NULL }; @@ -20146,25 +20184,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the smartcard devices */ - if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->smartcards, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainSmartcardDefPtr card = virDomainSmartcardDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); - if (!card) - goto error; - - def->smartcards[def->nsmartcards++] = card; - } - VIR_FREE(nodes); - - /* analysis of the character devices */ if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseParallelInfo from virDomainDefParseXML, move virDomainDefParseParallelInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 77 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f818228..137b392 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20067,6 +20067,54 @@ virDomainDefParseSmartCardsInfo(virDomainParseTotalParamPtr param) return ret; } + +static int +virDomainDefParseParallelInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i, j; + xmlNodePtr *nodes = NULL; + + /* analysis of the character devices */ + if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->parallels, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, + ctxt, + nodes[i], + def->seclabels, + def->nseclabels, + flags); + if (!chr) + goto cleanup; + + if (chr->target.port == -1) { + int maxport = -1; + for (j = 0; j < i; j++) { + if (def->parallels[j]->target.port > maxport) + maxport = def->parallels[j]->target.port; + } + chr->target.port = maxport + 1; + } + def->parallels[def->nparallels++] = chr; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { @@ -20081,6 +20129,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseFilesystemInfo, virDomainDefParseInterfaceInfo, virDomainDefParseSmartCardsInfo, + virDomainDefParseParallelInfo, NULL }; @@ -20184,34 +20233,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the character devices */ - if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->parallels, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, - ctxt, - nodes[i], - def->seclabels, - def->nseclabels, - flags); - if (!chr) - goto error; - - if (chr->target.port == -1) { - int maxport = -1; - for (j = 0; j < i; j++) { - if (def->parallels[j]->target.port > maxport) - maxport = def->parallels[j]->target.port; - } - chr->target.port = maxport + 1; - } - def->parallels[def->nparallels++] = chr; - } - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseSerialInfo from virDomainDefParseXML, move virDomainDefParseSerialInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 76 +++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 137b392..c4743cf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20116,6 +20116,53 @@ virDomainDefParseParallelInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseSerialInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i, j; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) + goto cleanup; + + if (n && VIR_ALLOC_N(def->serials, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, + ctxt, + nodes[i], + def->seclabels, + def->nseclabels, + flags); + if (!chr) + goto cleanup; + + if (chr->target.port == -1) { + int maxport = -1; + for (j = 0; j < i; j++) { + if (def->serials[j]->target.port > maxport) + maxport = def->serials[j]->target.port; + } + chr->target.port = maxport + 1; + } + def->serials[def->nserials++] = chr; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20130,6 +20177,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseInterfaceInfo, virDomainDefParseSmartCardsInfo, virDomainDefParseParallelInfo, + virDomainDefParseSerialInfo, NULL }; @@ -20233,34 +20281,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./devices/serial", ctxt, &nodes)) < 0) - goto error; - - if (n && VIR_ALLOC_N(def->serials, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, - ctxt, - nodes[i], - def->seclabels, - def->nseclabels, - flags); - if (!chr) - goto error; - - if (chr->target.port == -1) { - int maxport = -1; - for (j = 0; j < i; j++) { - if (def->serials[j]->target.port > maxport) - maxport = def->serials[j]->target.port; - } - chr->target.port = maxport + 1; - } - def->serials[def->nserials++] = chr; - } - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot extract console devices")); -- 2.8.3

separate virDomainDefParseConsoleInfo from virDomainDefParseXML, move virDomainDefParseConsoleInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 68 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c4743cf..b74e332 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20163,6 +20163,48 @@ virDomainDefParseSerialInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseConsoleInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot extract console devices")); + goto cleanup; + } + if (n && VIR_ALLOC_N(def->consoles, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, + ctxt, + nodes[i], + def->seclabels, + def->nseclabels, + flags); + if (!chr) + goto cleanup; + + chr->target.port = i; + def->consoles[def->nconsoles++] = chr; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20178,6 +20220,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseSmartCardsInfo, virDomainDefParseParallelInfo, virDomainDefParseSerialInfo, + virDomainDefParseConsoleInfo, NULL }; @@ -20206,7 +20249,7 @@ virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; - size_t i, j; + size_t i; int n; size_t fun_index = 0; virDomainDefPtr def; @@ -20281,29 +20324,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract console devices")); - goto error; - } - if (n && VIR_ALLOC_N(def->consoles, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, - ctxt, - nodes[i], - def->seclabels, - def->nseclabels, - flags); - if (!chr) - goto error; - - chr->target.port = i; - def->consoles[def->nconsoles++] = chr; - } - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) goto error; if (n && VIR_ALLOC_N(def->channels, n) < 0) -- 2.8.3

separate virDomainDefParseChannelInfo from virDomainDefParseXML, move virDomainDefParseChannelInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 59 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b74e332..7c8fd45 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20205,6 +20205,44 @@ virDomainDefParseConsoleInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseChannelInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->channels, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, + ctxt, + nodes[i], + def->seclabels, + def->nseclabels, + flags); + if (!chr) + goto cleanup; + + def->channels[def->nchannels++] = chr; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20221,6 +20259,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseParallelInfo, virDomainDefParseSerialInfo, virDomainDefParseConsoleInfo, + virDomainDefParseChannelInfo, NULL }; @@ -20324,26 +20363,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->channels, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt, - ctxt, - nodes[i], - def->seclabels, - def->nseclabels, - flags); - if (!chr) - goto error; - - def->channels[def->nchannels++] = chr; - } - VIR_FREE(nodes); - - /* analysis of the input devices */ if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseInputInfo from virDomainDefParseXML, move virDomainDefParseInputInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 76 +++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7c8fd45..eb610ed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20243,6 +20243,53 @@ virDomainDefParseChannelInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseInputInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the input devices */ + if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->inputs, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainInputDefPtr input = virDomainInputDefParseXML(xmlopt, + def, + nodes[i], + ctxt, + flags); + if (!input) + goto cleanup; + + /* Check if USB bus is required */ + if (input->bus == VIR_DOMAIN_INPUT_BUS_USB && param->usb_none) { + virDomainInputDefFree(input); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB input device. " + "USB bus is disabled")); + goto cleanup; + } + + def->inputs[def->ninputs++] = input; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20260,6 +20307,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseSerialInfo, virDomainDefParseConsoleInfo, virDomainDefParseChannelInfo, + virDomainDefParseInputInfo, NULL }; @@ -20363,34 +20411,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the input devices */ - if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->inputs, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainInputDefPtr input = virDomainInputDefParseXML(xmlopt, - def, - nodes[i], - ctxt, - flags); - if (!input) - goto error; - - /* Check if USB bus is required */ - if (input->bus == VIR_DOMAIN_INPUT_BUS_USB && usb_none) { - virDomainInputDefFree(input); - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Can't add USB input device. " - "USB bus is disabled")); - goto error; - } - - def->inputs[def->ninputs++] = input; - } - VIR_FREE(nodes); - /* analysis of the graphics devices */ if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseGraphicsInfo from virDomainDefParseXML, move virDomainDefParseGraphicsInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 51 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index eb610ed..71b5147 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20290,6 +20290,40 @@ virDomainDefParseInputInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseGraphicsInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the graphics devices */ + if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->graphics, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(nodes[i], + ctxt, + flags); + if (!graphics) + goto cleanup; + + def->graphics[def->ngraphics++] = graphics; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20308,6 +20342,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseConsoleInfo, virDomainDefParseChannelInfo, virDomainDefParseInputInfo, + virDomainDefParseGraphicsInfo, NULL }; @@ -20411,22 +20446,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the graphics devices */ - if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->graphics, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(nodes[i], - ctxt, - flags); - if (!graphics) - goto error; - - def->graphics[def->ngraphics++] = graphics; - } - VIR_FREE(nodes); - /* analysis of the sound devices */ if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseSoundInfo from virDomainDefParseXML, move virDomainDefParseSoundInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 54 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 71b5147..6ffde63 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20324,6 +20324,42 @@ virDomainDefParseGraphicsInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseSoundInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the sound devices */ + if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->sounds, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainSoundDefPtr sound = virDomainSoundDefParseXML(xmlopt, + nodes[i], + ctxt, + flags); + if (!sound) + goto cleanup; + + def->sounds[def->nsounds++] = sound; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20343,6 +20379,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseChannelInfo, virDomainDefParseInputInfo, virDomainDefParseGraphicsInfo, + virDomainDefParseSoundInfo, NULL }; @@ -20446,23 +20483,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the sound devices */ - if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->sounds, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainSoundDefPtr sound = virDomainSoundDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); - if (!sound) - goto error; - - def->sounds[def->nsounds++] = sound; - } - VIR_FREE(nodes); - /* analysis of the video devices */ if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseVideoInfo from virDomainDefParseXML, move virDomainDefParseVideoInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 87 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6ffde63..e2a4ce2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20360,6 +20360,58 @@ virDomainDefParseSoundInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseVideoInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the video devices */ + if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->videos, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainVideoDefPtr video; + ssize_t insertAt = -1; + + if (!(video = virDomainVideoDefParseXML(xmlopt, nodes[i], + ctxt, def, flags))) + goto cleanup; + + if (video->primary) { + if (def->nvideos != 0 && def->videos[0]->primary) { + virDomainVideoDefFree(video); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only one primary video device is supported")); + goto cleanup; + } + + insertAt = 0; + } + if (VIR_INSERT_ELEMENT_INPLACE(def->videos, + insertAt, + def->nvideos, + video) < 0) { + virDomainVideoDefFree(video); + goto cleanup; + } + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20380,6 +20432,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseInputInfo, virDomainDefParseGraphicsInfo, virDomainDefParseSoundInfo, + virDomainDefParseVideoInfo, NULL }; @@ -20483,40 +20536,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the video devices */ - if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->videos, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainVideoDefPtr video; - ssize_t insertAt = -1; - - if (!(video = virDomainVideoDefParseXML(xmlopt, nodes[i], - ctxt, def, flags))) - goto error; - - if (video->primary) { - if (def->nvideos != 0 && def->videos[0]->primary) { - virDomainVideoDefFree(video); - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only one primary video device is supported")); - goto error; - } - - insertAt = 0; - } - if (VIR_INSERT_ELEMENT_INPLACE(def->videos, - insertAt, - def->nvideos, - video) < 0) { - virDomainVideoDefFree(video); - goto error; - } - } - - VIR_FREE(nodes); - /* analysis of the host devices */ if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseHostdevInfo from virDomainDefParseXML, move virDomainDefParseHostdevInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 91 +++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e2a4ce2..1e44e76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20412,6 +20412,61 @@ virDomainDefParseVideoInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseHostdevInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + virHashTablePtr bootHash = param->bootHash; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the host devices */ + if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainHostdevDefPtr hostdev; + + hostdev = virDomainHostdevDefParseXML(xmlopt, nodes[i], ctxt, + bootHash, flags); + if (!hostdev) + goto cleanup; + + if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + param->usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add host USB device: " + "USB is disabled in this host")); + virDomainHostdevDefFree(hostdev); + goto cleanup; + } + + def->hostdevs[def->nhostdevs++] = hostdev; + + /* For a domain definition, we need to check if the controller + * for this hostdev exists yet and if not add it. This cannot be + * done during virDomainHostdevAssignAddress (as part of device + * post processing) because that will result in the failure to + * load the controller during hostdev hotplug. + */ + if (virDomainDefMaybeAddHostdevSCSIcontroller(def) < 0) + goto cleanup; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20433,6 +20488,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseGraphicsInfo, virDomainDefParseSoundInfo, virDomainDefParseVideoInfo, + virDomainDefParseHostdevInfo, NULL }; @@ -20536,41 +20592,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the host devices */ - if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainHostdevDefPtr hostdev; - - hostdev = virDomainHostdevDefParseXML(xmlopt, nodes[i], ctxt, - bootHash, flags); - if (!hostdev) - goto error; - - if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && - usb_none) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Can't add host USB device: " - "USB is disabled in this host")); - virDomainHostdevDefFree(hostdev); - goto error; - } - - def->hostdevs[def->nhostdevs++] = hostdev; - - /* For a domain definition, we need to check if the controller - * for this hostdev exists yet and if not add it. This cannot be - * done during virDomainHostdevAssignAddress (as part of device - * post processing) because that will result in the failure to - * load the controller during hostdev hotplug. - */ - if (virDomainDefMaybeAddHostdevSCSIcontroller(def) < 0) - goto error; - } - VIR_FREE(nodes); - /* analysis of the watchdog devices */ def->watchdog = NULL; if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) -- 2.8.3

separate virDomainDefParseWatchdogInfo from virDomainDefParseXML, move virDomainDefParseWatchdogInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 59 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1e44e76..b2a1b34 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20467,6 +20467,44 @@ virDomainDefParseHostdevInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseWatchdogInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + /* analysis of the watchdog devices */ + def->watchdog = NULL; + if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) + goto cleanup; + if (n > 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only a single watchdog device is supported")); + goto cleanup; + } + if (n > 0) { + virDomainWatchdogDefPtr watchdog; + + watchdog = virDomainWatchdogDefParseXML(xmlopt, nodes[0], flags); + if (!watchdog) + goto cleanup; + + def->watchdog = watchdog; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20489,6 +20527,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseSoundInfo, virDomainDefParseVideoInfo, virDomainDefParseHostdevInfo, + virDomainDefParseWatchdogInfo, NULL }; @@ -20592,26 +20631,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the watchdog devices */ - def->watchdog = NULL; - if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) - goto error; - if (n > 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("only a single watchdog device is supported")); - goto error; - } - if (n > 0) { - virDomainWatchdogDefPtr watchdog; - - watchdog = virDomainWatchdogDefParseXML(xmlopt, nodes[0], flags); - if (!watchdog) - goto error; - - def->watchdog = watchdog; - VIR_FREE(nodes); - } - /* analysis of the memballoon devices */ def->memballoon = NULL; if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) -- 2.8.3

separate virDomainDefParseMemballoonInfo from virDomainDefParseXML, move virDomainDefParseMemballoonInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b2a1b34..42736e3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20505,6 +20505,43 @@ virDomainDefParseWatchdogInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseMemballoonInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + /* analysis of the memballoon devices */ + def->memballoon = NULL; + if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) + goto cleanup; + if (n > 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only a single memory balloon device is supported")); + goto cleanup; + } + if (n > 0) { + virDomainMemballoonDefPtr memballoon; + + memballoon = virDomainMemballoonDefParseXML(xmlopt, nodes[0], ctxt, flags); + if (!memballoon) + goto cleanup; + + def->memballoon = memballoon; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20528,6 +20565,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseVideoInfo, virDomainDefParseHostdevInfo, virDomainDefParseWatchdogInfo, + virDomainDefParseMemballoonInfo, NULL }; @@ -20631,26 +20669,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the memballoon devices */ - def->memballoon = NULL; - if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) - goto error; - if (n > 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("only a single memory balloon device is supported")); - goto error; - } - if (n > 0) { - virDomainMemballoonDefPtr memballoon; - - memballoon = virDomainMemballoonDefParseXML(xmlopt, nodes[0], ctxt, flags); - if (!memballoon) - goto error; - - def->memballoon = memballoon; - VIR_FREE(nodes); - } - /* Parse the RNG devices */ if ((n = virXPathNodeSet("./devices/rng", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseRngInfo from virDomainDefParseXML, move virDomainDefParseRngInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 42736e3..a98841f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20541,6 +20541,40 @@ virDomainDefParseMemballoonInfo(virDomainParseTotalParamPtr param) return ret; } + +static int +virDomainDefParseRngInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* Parse the RNG devices */ + if ((n = virXPathNodeSet("./devices/rng", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->rngs, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainRNGDefPtr rng = virDomainRNGDefParseXML(xmlopt, nodes[i], + ctxt, flags); + if (!rng) + goto cleanup; + + def->rngs[def->nrngs++] = rng; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { @@ -20566,6 +20600,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseHostdevInfo, virDomainDefParseWatchdogInfo, virDomainDefParseMemballoonInfo, + virDomainDefParseRngInfo, NULL }; @@ -20669,21 +20704,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* Parse the RNG devices */ - if ((n = virXPathNodeSet("./devices/rng", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->rngs, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainRNGDefPtr rng = virDomainRNGDefParseXML(xmlopt, nodes[i], - ctxt, flags); - if (!rng) - goto error; - - def->rngs[def->nrngs++] = rng; - } - VIR_FREE(nodes); - /* Parse the TPM devices */ if ((n = virXPathNodeSet("./devices/tpm", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseTpmInfo from virDomainDefParseXML, move virDomainDefParseTpmInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a98841f..8f86c76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20575,6 +20575,41 @@ virDomainDefParseRngInfo(virDomainParseTotalParamPtr param) return ret; } + +static int +virDomainDefParseTpmInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + /* Parse the TPM devices */ + if ((n = virXPathNodeSet("./devices/tpm", ctxt, &nodes)) < 0) + goto cleanup; + + if (n > 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only a single TPM device is supported")); + goto cleanup; + } + + if (n > 0) { + if (!(def->tpm = virDomainTPMDefParseXML(xmlopt, nodes[0], ctxt, flags))) + goto cleanup; + } + VIR_FREE(nodes); + + cleanup: + VIR_FREE(nodes); + return ret; +} + + static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { @@ -20601,6 +20636,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseWatchdogInfo, virDomainDefParseMemballoonInfo, virDomainDefParseRngInfo, + virDomainDefParseTpmInfo, NULL }; @@ -20704,22 +20740,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* Parse the TPM devices */ - if ((n = virXPathNodeSet("./devices/tpm", ctxt, &nodes)) < 0) - goto error; - - if (n > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only a single TPM device is supported")); - goto error; - } - - if (n > 0) { - if (!(def->tpm = virDomainTPMDefParseXML(xmlopt, nodes[0], ctxt, flags))) - goto error; - } - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseNvramInfo from virDomainDefParseXML, move virDomainDefParseNvramInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 51 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8f86c76..72b3f56 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20611,6 +20611,40 @@ virDomainDefParseTpmInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseNvramInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) + goto cleanup; + + if (n > 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only a single nvram device is supported")); + goto cleanup; + } else if (n == 1) { + virDomainNVRAMDefPtr nvram = + virDomainNVRAMDefParseXML(xmlopt, nodes[0], flags); + if (!nvram) + goto cleanup; + def->nvram = nvram; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20637,6 +20671,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseMemballoonInfo, virDomainDefParseRngInfo, virDomainDefParseTpmInfo, + virDomainDefParseNvramInfo, NULL }; @@ -20740,22 +20775,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) - goto error; - - if (n > 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("only a single nvram device is supported")); - goto error; - } else if (n == 1) { - virDomainNVRAMDefPtr nvram = - virDomainNVRAMDefParseXML(xmlopt, nodes[0], flags); - if (!nvram) - goto error; - def->nvram = nvram; - VIR_FREE(nodes); - } - /* analysis of the hub devices */ if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseHubInfo from virDomainDefParseXML, move virDomainDefParseHubInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 69 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 72b3f56..37fa996 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20645,6 +20645,49 @@ virDomainDefParseNvramInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseHubInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the hub devices */ + if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->hubs, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainHubDefPtr hub; + + hub = virDomainHubDefParseXML(xmlopt, nodes[i], flags); + if (!hub) + goto cleanup; + + if (hub->type == VIR_DOMAIN_HUB_TYPE_USB && param->usb_none) { + virDomainHubDefFree(hub); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB hub: " + "USB is disabled for this domain")); + goto cleanup; + } + + def->hubs[def->nhubs++] = hub; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20672,6 +20715,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseRngInfo, virDomainDefParseTpmInfo, virDomainDefParseNvramInfo, + virDomainDefParseHubInfo, NULL }; @@ -20706,7 +20750,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefPtr def; bool uuid_generated = false; virHashTablePtr bootHash = NULL; - bool usb_none = false; virDomainParseTotalParam param = { xml, root, @@ -20775,30 +20818,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the hub devices */ - if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->hubs, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainHubDefPtr hub; - - hub = virDomainHubDefParseXML(xmlopt, nodes[i], flags); - if (!hub) - goto error; - - if (hub->type == VIR_DOMAIN_HUB_TYPE_USB && usb_none) { - virDomainHubDefFree(hub); - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Can't add USB hub: " - "USB is disabled for this domain")); - goto error; - } - - def->hubs[def->nhubs++] = hub; - } - VIR_FREE(nodes); - /* analysis of the redirected devices */ if ((n = virXPathNodeSet("./devices/redirdev", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseRedirdevInfo from virDomainDefParseXML, move virDomainDefParseRedirdevInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 51 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 37fa996..b90c83a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20688,6 +20688,41 @@ virDomainDefParseHubInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseRedirdevInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + virHashTablePtr bootHash = param->bootHash; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the redirected devices */ + if ((n = virXPathNodeSet("./devices/redirdev", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->redirdevs, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainRedirdevDefPtr redirdev = + virDomainRedirdevDefParseXML(xmlopt, nodes[i], ctxt, bootHash, flags); + if (!redirdev) + goto cleanup; + + def->redirdevs[def->nredirdevs++] = redirdev; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20716,6 +20751,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseTpmInfo, virDomainDefParseNvramInfo, virDomainDefParseHubInfo, + virDomainDefParseRedirdevInfo, NULL }; @@ -20818,21 +20854,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the redirected devices */ - if ((n = virXPathNodeSet("./devices/redirdev", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->redirdevs, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainRedirdevDefPtr redirdev = - virDomainRedirdevDefParseXML(xmlopt, nodes[i], ctxt, bootHash, flags); - if (!redirdev) - goto error; - - def->redirdevs[def->nredirdevs++] = redirdev; - } - VIR_FREE(nodes); - /* analysis of the redirection filter rules */ if ((n = virXPathNodeSet("./devices/redirfilter", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseRedirFilterInfo from virDomainDefParseXML, move virDomainDefParseRedirFilterInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 55 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b90c83a..d19d4de 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20723,6 +20723,41 @@ virDomainDefParseRedirdevInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseRedirFilterInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + /* analysis of the redirection filter rules */ + if ((n = virXPathNodeSet("./devices/redirfilter", ctxt, &nodes)) < 0) + goto cleanup; + if (n > 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only one set of redirection filter rule is supported")); + goto cleanup; + } + + if (n) { + virDomainRedirFilterDefPtr redirfilter = + virDomainRedirFilterDefParseXML(nodes[0], ctxt); + if (!redirfilter) + goto cleanup; + + def->redirfilter = redirfilter; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20752,6 +20787,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseNvramInfo, virDomainDefParseHubInfo, virDomainDefParseRedirdevInfo, + virDomainDefParseRedirFilterInfo, NULL }; @@ -20854,25 +20890,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the redirection filter rules */ - if ((n = virXPathNodeSet("./devices/redirfilter", ctxt, &nodes)) < 0) - goto error; - if (n > 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("only one set of redirection filter rule is supported")); - goto error; - } - - if (n) { - virDomainRedirFilterDefPtr redirfilter = - virDomainRedirFilterDefParseXML(nodes[0], ctxt); - if (!redirfilter) - goto error; - - def->redirfilter = redirfilter; - } - VIR_FREE(nodes); - /* analysis of the panic devices */ if ((n = virXPathNodeSet("./devices/panic", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParsePanicInfo from virDomainDefParseXML, move virDomainDefParsePanicInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d19d4de..412e59c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20758,6 +20758,41 @@ virDomainDefParseRedirFilterInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParsePanicInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of the panic devices */ + if ((n = virXPathNodeSet("./devices/panic", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->panics, n) < 0) + goto cleanup; + for (i = 0; i < n; i++) { + virDomainPanicDefPtr panic; + + panic = virDomainPanicDefParseXML(xmlopt, nodes[i], flags); + if (!panic) + goto cleanup; + + def->panics[def->npanics++] = panic; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20788,6 +20823,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseHubInfo, virDomainDefParseRedirdevInfo, virDomainDefParseRedirFilterInfo, + virDomainDefParsePanicInfo, NULL }; @@ -20890,22 +20926,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the panic devices */ - if ((n = virXPathNodeSet("./devices/panic", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->panics, n) < 0) - goto error; - for (i = 0; i < n; i++) { - virDomainPanicDefPtr panic; - - panic = virDomainPanicDefParseXML(xmlopt, nodes[i], flags); - if (!panic) - goto error; - - def->panics[def->npanics++] = panic; - } - VIR_FREE(nodes); - /* analysis of the shmem devices */ if ((n = virXPathNodeSet("./devices/shmem", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseShmemInfo from virDomainDefParseXML, move virDomainDefParseShmemInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 412e59c..281042f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20793,6 +20793,44 @@ virDomainDefParsePanicInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseShmemInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL, node=NULL; + + /* analysis of the shmem devices */ + if ((n = virXPathNodeSet("./devices/shmem", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->shmems, n) < 0) + goto cleanup; + + node = ctxt->node; + for (i = 0; i < n; i++) { + virDomainShmemDefPtr shmem; + ctxt->node = nodes[i]; + shmem = virDomainShmemDefParseXML(xmlopt, nodes[i], ctxt, flags); + if (!shmem) + goto cleanup; + + def->shmems[def->nshmems++] = shmem; + } + ctxt->node = node; + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20824,6 +20862,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseRedirdevInfo, virDomainDefParseRedirFilterInfo, virDomainDefParsePanicInfo, + virDomainDefParseShmemInfo, NULL }; @@ -20926,25 +20965,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the shmem devices */ - if ((n = virXPathNodeSet("./devices/shmem", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->shmems, n) < 0) - goto error; - - node = ctxt->node; - for (i = 0; i < n; i++) { - virDomainShmemDefPtr shmem; - ctxt->node = nodes[i]; - shmem = virDomainShmemDefParseXML(xmlopt, nodes[i], ctxt, flags); - if (!shmem) - goto error; - - def->shmems[def->nshmems++] = shmem; - } - ctxt->node = node; - VIR_FREE(nodes); - /* analysis of memory devices */ if ((n = virXPathNodeSet("./devices/memory", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseDeviceMemInfo from virDomainDefParseXML, move virDomainDefParseDeviceMemInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 57 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 281042f..7d8b875 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20831,6 +20831,43 @@ virDomainDefParseShmemInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseDeviceMemInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + virDomainXMLOptionPtr xmlopt = param->xmlopt; + unsigned int flags = param->flags; + + int ret = -1; + int n = 0; + size_t i; + xmlNodePtr *nodes = NULL; + + /* analysis of memory devices */ + if ((n = virXPathNodeSet("./devices/memory", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->mems, n) < 0) + goto cleanup; + + for (i = 0; i < n; i++) { + virDomainMemoryDefPtr mem = virDomainMemoryDefParseXML(xmlopt, + nodes[i], + ctxt, + flags); + if (!mem) + goto cleanup; + + def->mems[def->nmems++] = mem; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20863,6 +20900,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParseRedirFilterInfo, virDomainDefParsePanicInfo, virDomainDefParseShmemInfo, + virDomainDefParseDeviceMemInfo, NULL }; @@ -20891,7 +20929,6 @@ virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; - size_t i; int n; size_t fun_index = 0; virDomainDefPtr def; @@ -20965,24 +21002,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of memory devices */ - if ((n = virXPathNodeSet("./devices/memory", ctxt, &nodes)) < 0) - goto error; - if (n && VIR_ALLOC_N(def->mems, n) < 0) - goto error; - - for (i = 0; i < n; i++) { - virDomainMemoryDefPtr mem = virDomainMemoryDefParseXML(xmlopt, - nodes[i], - ctxt, - flags); - if (!mem) - goto error; - - def->mems[def->nmems++] = mem; - } - VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/iommu", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseIommuInfo from virDomainDefParseXML, move virDomainDefParseIommuInfo into virDomainDefParseDeviceInfo --- src/conf/domain_conf.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7d8b875..e6498c3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20868,6 +20868,37 @@ virDomainDefParseDeviceMemInfo(virDomainParseTotalParamPtr param) static int +virDomainDefParseIommuInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + if ((n = virXPathNodeSet("./devices/iommu", ctxt, &nodes)) < 0) + goto cleanup; + + if (n > 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only a single IOMMU device is supported")); + goto cleanup; + } + + if (n > 0) { + if (!(def->iommu = virDomainIOMMUDefParseXML(nodes[0], ctxt))) + goto cleanup; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + +static int virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) { typedef int (*virDomainPreaseDeviceFuc)(virDomainParseTotalParamPtr param); @@ -20901,6 +20932,7 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) virDomainDefParsePanicInfo, virDomainDefParseShmemInfo, virDomainDefParseDeviceMemInfo, + virDomainDefParseIommuInfo, NULL }; @@ -21002,21 +21034,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((n = virXPathNodeSet("./devices/iommu", ctxt, &nodes)) < 0) - goto error; - - if (n > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only a single IOMMU device is supported")); - goto error; - } - - if (n > 0) { - if (!(def->iommu = virDomainIOMMUDefParseXML(nodes[0], ctxt))) - goto error; - } - VIR_FREE(nodes); - /* analysis of the user namespace mapping */ if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0) goto error; -- 2.8.3

separate virDomainDefParseIdmapInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 83 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e6498c3..de8a9fc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20948,6 +20948,55 @@ virDomainDefParseDeviceInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseIdmapInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + + int ret = -1; + int n = 0; + xmlNodePtr *nodes = NULL; + + /* analysis of the user namespace mapping */ + if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0) + goto cleanup; + + if (n) { + def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, nodes, n); + if (!def->idmap.uidmap) + goto cleanup; + + def->idmap.nuidmap = n; + } + VIR_FREE(nodes); + + if ((n = virXPathNodeSet("./idmap/gid", ctxt, &nodes)) < 0) + goto cleanup; + + if (n) { + def->idmap.gidmap = virDomainIdmapDefParseXML(ctxt, nodes, n); + if (!def->idmap.gidmap) + goto cleanup; + + def->idmap.ngidmap = n; + } + VIR_FREE(nodes); + + if ((def->idmap.uidmap && !def->idmap.gidmap) || + (!def->idmap.uidmap && def->idmap.gidmap)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("uid and gid should be mapped both")); + goto cleanup; + } + ret = 0; + + cleanup: + VIR_FREE(nodes); + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -20961,7 +21010,6 @@ virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; - int n; size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; @@ -21003,6 +21051,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseClockInfo, virDomainDefParseBootOptionsInfo, virDomainDefParseDeviceInfo, + virDomainDefParseIdmapInfo, NULL }; @@ -21034,38 +21083,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* analysis of the user namespace mapping */ - if ((n = virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0) - goto error; - - if (n) { - def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, nodes, n); - if (!def->idmap.uidmap) - goto error; - - def->idmap.nuidmap = n; - } - VIR_FREE(nodes); - - if ((n = virXPathNodeSet("./idmap/gid", ctxt, &nodes)) < 0) - goto error; - - if (n) { - def->idmap.gidmap = virDomainIdmapDefParseXML(ctxt, nodes, n); - if (!def->idmap.gidmap) - goto error; - - def->idmap.ngidmap = n; - } - VIR_FREE(nodes); - - if ((def->idmap.uidmap && !def->idmap.gidmap) || - (!def->idmap.uidmap && def->idmap.gidmap)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("uid and gid should be mapped both")); - goto error; - } - if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) { xmlNodePtr oldnode = ctxt->node; ctxt->node = node; -- 2.8.3

separate virDomainDefParseSysinfoInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index de8a9fc..a8fc27c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20997,6 +20997,33 @@ virDomainDefParseIdmapInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseSysinfoInfo(virDomainParseTotalParamPtr param) +{ + virDomainDefPtr def = param->def; + xmlXPathContextPtr ctxt = param->ctxt; + bool uuid_generated = param->uuid_generated; + + int ret = -1; + xmlNodePtr node = NULL; + + if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) { + xmlNodePtr oldnode = ctxt->node; + ctxt->node = node; + def->sysinfo = virSysinfoParseXML(node, ctxt, + def->uuid, uuid_generated); + ctxt->node = oldnode; + + if (def->sysinfo == NULL) + goto cleanup; + } + ret = 0; + + cleanup: + return ret; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -21012,7 +21039,6 @@ virDomainDefParseXML(xmlDocPtr xml, char *tmp = NULL; size_t fun_index = 0; virDomainDefPtr def; - bool uuid_generated = false; virHashTablePtr bootHash = NULL; virDomainParseTotalParam param = { xml, @@ -21052,6 +21078,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseBootOptionsInfo, virDomainDefParseDeviceInfo, virDomainDefParseIdmapInfo, + virDomainDefParseSysinfoInfo, NULL }; @@ -21083,17 +21110,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) { - xmlNodePtr oldnode = ctxt->node; - ctxt->node = node; - def->sysinfo = virSysinfoParseXML(node, ctxt, - def->uuid, uuid_generated); - ctxt->node = oldnode; - - if (def->sysinfo == NULL) - goto error; - } - if (virDomainKeyWrapDefParseXML(def, ctxt) < 0) goto error; -- 2.8.3

separate virDomainDefParseKeyWrapInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a8fc27c..03bf5ad 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21024,6 +21024,16 @@ virDomainDefParseSysinfoInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseKeyWrapInfo(virDomainParseTotalParamPtr param) +{ + if (virDomainKeyWrapDefParseXML(param->def, param->ctxt) < 0) + return -1; + + return 0; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -21079,6 +21089,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseDeviceInfo, virDomainDefParseIdmapInfo, virDomainDefParseSysinfoInfo, + virDomainDefParseKeyWrapInfo, NULL }; @@ -21110,9 +21121,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - if (virDomainKeyWrapDefParseXML(def, ctxt) < 0) - goto error; - /* Extract custom metadata */ if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL) def->metadata = xmlCopyNode(node, 1); -- 2.8.3

separate virDomainDefParseMetadataInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 03bf5ad..7006e7f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21034,6 +21034,17 @@ virDomainDefParseKeyWrapInfo(virDomainParseTotalParamPtr param) } +static int +virDomainDefParseMetadataInfo(virDomainParseTotalParamPtr param) +{ + xmlNodePtr node = NULL; + /* Extract custom metadata */ + if ((node = virXPathNode("./metadata[1]", param->ctxt)) != NULL) + param->def->metadata = xmlCopyNode(node, 1); + + return 0; +} + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -21045,8 +21056,6 @@ virDomainDefParseXML(xmlDocPtr xml, { typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); - xmlNodePtr *nodes = NULL, node = NULL; - char *tmp = NULL; size_t fun_index = 0; virDomainDefPtr def; virHashTablePtr bootHash = NULL; @@ -21090,6 +21099,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseIdmapInfo, virDomainDefParseSysinfoInfo, virDomainDefParseKeyWrapInfo, + virDomainDefParseMetadataInfo, NULL }; @@ -21121,10 +21131,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* Extract custom metadata */ - if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL) - def->metadata = xmlCopyNode(node, 1); - /* we have to make a copy of all of the callback pointers here since * we won't have the virCaps structure available during free */ @@ -21148,8 +21154,6 @@ virDomainDefParseXML(xmlDocPtr xml, return def; error: - VIR_FREE(tmp); - VIR_FREE(nodes); virHashFree(bootHash); virDomainDefFree(def); return NULL; -- 2.8.3

separate virDomainDefParseNameSpaceInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7006e7f..7caff3a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21045,6 +21045,25 @@ virDomainDefParseMetadataInfo(virDomainParseTotalParamPtr param) return 0; } + +static int +virDomainDefParseNameSpaceInfo(virDomainParseTotalParamPtr param) +{ + /* we have to make a copy of all of the callback pointers here since + * we won't have the virCaps structure available during free + */ + param->def->ns = param->xmlopt->ns; + + if (param->def->ns.parse && + (param->def->ns.parse)(param->xml, + param->root, + param->ctxt, + ¶m->def->namespaceData) < 0) + return -1; + + return 0; +} + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -21100,6 +21119,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseSysinfoInfo, virDomainDefParseKeyWrapInfo, virDomainDefParseMetadataInfo, + virDomainDefParseNameSpaceInfo, NULL }; @@ -21131,15 +21151,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* we have to make a copy of all of the callback pointers here since - * we won't have the virCaps structure available during free - */ - def->ns = xmlopt->ns; - - if (def->ns.parse && - (def->ns.parse)(xml, root, ctxt, &def->namespaceData) < 0) - goto error; - /* callback to fill driver specific domain aspects */ if (virDomainDefPostParseInternal(def, caps, flags, xmlopt, parseOpaque, bootHash) < 0) -- 2.8.3

separate virDomainDefPostParseInternalInfo from virDomainDefParseXML --- src/conf/domain_conf.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7caff3a..0f2450a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21064,6 +21064,23 @@ virDomainDefParseNameSpaceInfo(virDomainParseTotalParamPtr param) return 0; } + +static int +virDomainDefPostParseInternalInfo(virDomainParseTotalParamPtr param) +{ + /* callback to fill driver specific domain aspects */ + if (virDomainDefPostParseInternal(param->def, + param->caps, + param->flags, + param->xmlopt, + param->parseOpaque, + param->bootHash) < 0) + return -1; + + return 0; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -21120,6 +21137,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseKeyWrapInfo, virDomainDefParseMetadataInfo, virDomainDefParseNameSpaceInfo, + virDomainDefPostParseInternalInfo, NULL }; @@ -21151,11 +21169,6 @@ virDomainDefParseXML(xmlDocPtr xml, fun_index++; } - /* callback to fill driver specific domain aspects */ - if (virDomainDefPostParseInternal(def, caps, flags, xmlopt, parseOpaque, - bootHash) < 0) - goto error; - /* valdiate configuration */ if (virDomainDefValidate(def, caps, flags, xmlopt) < 0) goto error; -- 2.8.3

On Thu, Feb 08, 2018 at 02:45:59PM +0800, xinhua.Cao wrote:
beacause virDomainDefParseXML is too long, and all domain xml parse in this function, it's difficulty to maintain this function so separate virDomainDefParseXML into serial parts use virDomainPreaseInfoFunc. then it will easy to maintain --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34aae82..e36783b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18527,6 +18527,28 @@ virDomainCachetuneDefParse(virDomainDefPtr def, }
+typedef struct _virDomainParseTotalParam virDomainParseTotalParam; +typedef virDomainParseTotalParam *virDomainParseTotalParamPtr; + +struct _virDomainParseTotalParam{ + //input parameters + virDomainDefPtr def; + xmlDocPtr xml; + xmlNodePtr root; + xmlXPathContextPtr ctxt; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; + void *parseOpaque; + unsigned int flags; + + //internal parameters + bool usb_none; + bool usb_other; + bool usb_master; + bool uuid_generated; +}; + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18536,11 +18558,14 @@ virDomainDefParseXML(xmlDocPtr xml, void *parseOpaque, unsigned int flags) { + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params); + xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; size_t i, j; int n, virtType, gic_version; long id = -1; + size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; virHashTablePtr bootHash = NULL; @@ -18548,6 +18573,25 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_other = false; bool usb_master = false; char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + NULL + };
if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { char *schema = virFileFindResource("domain.rng", @@ -18565,6 +18609,14 @@ virDomainDefParseXML(xmlDocPtr xml, if (!(def = virDomainDefNew())) return NULL;
+ param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + }
I don't really like this approach. I prefer to see the separate functions called explicitly by name, and just passing in the particular parameters that each function actually needs. IOW, just drop this patch entirely and update following patches so that their split function is called. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

[...] So your series went through rather messed up. I see at least two different copies of patch 2/something. On Thu, Feb 08, 2018 at 14:45:59 +0800, xinhua.Cao wrote:
beacause virDomainDefParseXML is too long, and all domain xml parse in this function, it's difficulty to maintain this function so separate virDomainDefParseXML into serial parts use virDomainPreaseInfoFunc. then it will easy to maintain
So this commit message should describe what this patch is using, but it's not.
--- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34aae82..e36783b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18527,6 +18527,28 @@ virDomainCachetuneDefParse(virDomainDefPtr def, }
+typedef struct _virDomainParseTotalParam virDomainParseTotalParam; +typedef virDomainParseTotalParam *virDomainParseTotalParamPtr; + +struct _virDomainParseTotalParam{ + //input parameters
We use only old-style comments.
+ virDomainDefPtr def; + xmlDocPtr xml; + xmlNodePtr root; + xmlXPathContextPtr ctxt; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; + void *parseOpaque; + unsigned int flags; + + //internal parameters + bool usb_none; + bool usb_other; + bool usb_master; + bool uuid_generated; +}; + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -18536,11 +18558,14 @@ virDomainDefParseXML(xmlDocPtr xml, void *parseOpaque, unsigned int flags) { + typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params);
Typo in the name and also you should not typedef in the functions.
+ xmlNodePtr *nodes = NULL, node = NULL; char *tmp = NULL; size_t i, j; int n, virtType, gic_version; long id = -1; + size_t fun_index = 0; virDomainDefPtr def; bool uuid_generated = false; virHashTablePtr bootHash = NULL; @@ -18548,6 +18573,25 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_other = false; bool usb_master = false; char *netprefix = NULL; + virDomainParseTotalParam param = { + NULL, + xml, + root, + ctxt, + caps, + xmlopt, + parseOpaque, + flags, + false, + false, + false, + false + + }; + + virDomainPreaseInfoFunc parse_funs[] = { + NULL + };
if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { char *schema = virFileFindResource("domain.rng", @@ -18565,6 +18609,14 @@ virDomainDefParseXML(xmlDocPtr xml, if (!(def = virDomainDefNew())) return NULL;
+ param.def = def; + + while (parse_funs[fun_index]) { + if (parse_funs[fun_index](¶m) < 0) + goto error; + fun_index++; + }
NACK to this. I prefer if the functions are visible in the code in the correct order, so please don't try to load them from an array of callbacks. I don't see any benefit of this.
participants (3)
-
Daniel P. Berrangé
-
Peter Krempa
-
xinhua.Cao