mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
parent
a8a63587ff
commit
0d5fc7219a
@ -815,68 +815,36 @@ virDomainNumaDefNodeCacheParseXML(virDomainNuma *def,
|
|||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||||
virNumaCache *cache = &def->mem_nodes[cur_cell].caches[i];
|
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;
|
unsigned long long line;
|
||||||
|
|
||||||
if (!(tmp = virXMLPropString(nodes[i], "level"))) {
|
if (virXMLPropUInt(nodes[i], "level", 10,
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
||||||
_("Missing 'level' attribute in cache element for NUMA node %1$d"),
|
&cache->level) < 0)
|
||||||
cur_cell);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (virStrToLong_uip(tmp, NULL, 10, &level) < 0 ||
|
if (virXMLPropEnum(nodes[i], "associativity",
|
||||||
level == 0) {
|
virNumaCacheAssociativityTypeFromString,
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
VIR_XML_PROP_REQUIRED,
|
||||||
_("Invalid 'level' attribute in cache element for NUMA node %1$d"),
|
&cache->associativity) < 0)
|
||||||
cur_cell);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
if (!(tmp = virXMLPropString(nodes[i], "associativity"))) {
|
if (virXMLPropEnum(nodes[i], "policy",
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virNumaCachePolicyTypeFromString,
|
||||||
_("Missing 'associativity' attribute in cache element for NUMA node %1$d"),
|
VIR_XML_PROP_REQUIRED,
|
||||||
cur_cell);
|
&cache->policy) < 0)
|
||||||
return -1;
|
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];
|
ctxt->node = nodes[i];
|
||||||
if (virDomainParseMemory("./size/@value", "./size/unit",
|
if (virDomainParseMemory("./size/@value", "./size/unit",
|
||||||
ctxt, &size, true, false) < 0)
|
ctxt, &cache->size, true, false) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virParseScaledValue("./line/@value", "./line/unit",
|
if (virParseScaledValue("./line/@value", "./line/unit",
|
||||||
ctxt, &line, 1, ULLONG_MAX, true) < 0)
|
ctxt, &line, 1, ULLONG_MAX, true) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*cache = (virNumaCache){level, size, line, associativity, policy};
|
cache->line = line;
|
||||||
|
|
||||||
def->mem_nodes[cur_cell].ncaches++;
|
def->mem_nodes[cur_cell].ncaches++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user