Use virXMLProp* helpers to simplify the code.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/numa_conf.c | 60 +++++++++++---------------------------------
1 file changed, 14 insertions(+), 46 deletions(-)
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index b21671f587..c2e3045280 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -815,68 +815,36 @@ virDomainNumaDefNodeCacheParseXML(virDomainNuma *def,
for (i = 0; i < n; i++) {
VIR_XPATH_NODE_AUTORESTORE(ctxt)
virNumaCache *cache = &def->mem_nodes[cur_cell].caches[i];
- g_autofree char *tmp = NULL;
- unsigned int level;
- int associativity;
- int policy;
- unsigned long long size;
unsigned long long line;
- if (!(tmp = virXMLPropString(nodes[i], "level"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Missing 'level' attribute in cache element for
NUMA node %1$d"),
- cur_cell);
- return -1;
- }
-
- if (virStrToLong_uip(tmp, NULL, 10, &level) < 0 ||
- level == 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid 'level' attribute in cache element for
NUMA node %1$d"),
- cur_cell);
- return -1;
- }
- VIR_FREE(tmp);
-
- if (!(tmp = virXMLPropString(nodes[i], "associativity"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Missing 'associativity' attribute in cache
element for NUMA node %1$d"),
- cur_cell);
+ if (virXMLPropUInt(nodes[i], "level", 10,
+ VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+ &cache->level) < 0)
return -1;
- }
- if ((associativity = virNumaCacheAssociativityTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid cache associativity '%1$s'"),
- tmp);
+ if (virXMLPropEnum(nodes[i], "associativity",
+ virNumaCacheAssociativityTypeFromString,
+ VIR_XML_PROP_REQUIRED,
+ &cache->associativity) < 0)
return -1;
- }
- VIR_FREE(tmp);
-
- if (!(tmp = virXMLPropString(nodes[i], "policy"))) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Missing 'policy' attribute in cache element
for NUMA node %1$d"),
- cur_cell);
- }
- if ((policy = virNumaCachePolicyTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid cache policy '%1$s'"),
- tmp);
+ if (virXMLPropEnum(nodes[i], "policy",
+ virNumaCachePolicyTypeFromString,
+ VIR_XML_PROP_REQUIRED,
+ &cache->policy) < 0)
return -1;
- }
- VIR_FREE(tmp);
ctxt->node = nodes[i];
if (virDomainParseMemory("./size/@value", "./size/unit",
- ctxt, &size, true, false) < 0)
+ ctxt, &cache->size, true, false) < 0)
return -1;
if (virParseScaledValue("./line/@value", "./line/unit",
ctxt, &line, 1, ULLONG_MAX, true) < 0)
return -1;
- *cache = (virNumaCache){level, size, line, associativity, policy};
+ cache->line = line;
+
def->mem_nodes[cur_cell].ncaches++;
}
--
2.40.1