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