virDomainNumatuneNodeParseXML: Use virXMLProp*

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-05-13 17:31:57 +02:00 committed by Laine Stump
parent f16305b36f
commit 960984510b

View File

@ -186,25 +186,13 @@ virDomainNumatuneNodeParseXML(virDomainNuma *numa,
} }
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int mode = 0;
unsigned int cellid = 0; unsigned int cellid = 0;
virDomainNumaNode *mem_node = NULL; virDomainNumaNode *mem_node = NULL;
xmlNodePtr cur_node = nodes[i]; xmlNodePtr cur_node = nodes[i];
tmp = virXMLPropString(cur_node, "cellid"); if (virXMLPropUInt(cur_node, "cellid", 10, VIR_XML_PROP_REQUIRED,
if (!tmp) { &cellid) < 0)
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing required cellid attribute "
"in memnode element"));
goto cleanup; goto cleanup;
}
if (virStrToLong_uip(tmp, NULL, 10, &cellid) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid cellid attribute in memnode element: %s"),
tmp);
goto cleanup;
}
VIR_FREE(tmp);
if (cellid >= numa->nmem_nodes) { if (cellid >= numa->nmem_nodes) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
@ -222,26 +210,19 @@ virDomainNumatuneNodeParseXML(virDomainNuma *numa,
goto cleanup; goto cleanup;
} }
tmp = virXMLPropString(cur_node, "mode"); if (virXMLPropEnumDefault(cur_node, "mode",
if (!tmp) { virDomainNumatuneMemModeTypeFromString,
mem_node->mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; VIR_XML_PROP_NONE, &mem_node->mode,
} else { VIR_DOMAIN_NUMATUNE_MEM_STRICT) < 0)
if ((mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Invalid mode attribute in memnode element"));
goto cleanup; goto cleanup;
}
if (numa->memory.mode == VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE && if (numa->memory.mode == VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE &&
mode != VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) { mem_node->mode != VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("'restrictive' mode is required in memnode element " _("'restrictive' mode is required in memnode element "
"when mode is 'restrictive' in memory element")); "when mode is 'restrictive' in memory element"));
goto cleanup; goto cleanup;
} }
VIR_FREE(tmp);
mem_node->mode = mode;
}
tmp = virXMLPropString(cur_node, "nodeset"); tmp = virXMLPropString(cur_node, "nodeset");
if (!tmp) { if (!tmp) {