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>
This commit is contained in:
Peter Krempa 2023-05-16 10:19:42 +02:00
parent a8a63587ff
commit 0d5fc7219a

View File

@ -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);
if (virXMLPropUInt(nodes[i], "level", 10,
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
&cache->level) < 0)
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);
if (virXMLPropEnum(nodes[i], "associativity",
virNumaCacheAssociativityTypeFromString,
VIR_XML_PROP_REQUIRED,
&cache->associativity) < 0)
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 (virXMLPropEnum(nodes[i], "policy",
virNumaCachePolicyTypeFromString,
VIR_XML_PROP_REQUIRED,
&cache->policy) < 0)
return -1;
}
if ((associativity = virNumaCacheAssociativityTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid cache associativity '%1$s'"),
tmp);
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);
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++;
}