summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2023-05-16 10:19:42 +0200
committerPeter Krempa <pkrempa@redhat.com>2023-05-17 10:07:18 +0200
commit0d5fc7219ae605959e14d877865793f48c729f5e (patch)
tree5ad6e78b2f3dfc0a0a5b676e601a81167db9dc9a
parenta8a63587fff5ccfffee424259246ee8821bd7102 (diff)
downloadlibvirt-0d5fc7219ae605959e14d877865793f48c729f5e.tar.gz
virDomainNumaDefNodeCacheParseXML: Refactor parsing of cache XML
Use virXMLProp* helpers to simplify the code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
-rw-r--r--src/conf/numa_conf.c60
1 files 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++;
}