mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
virDomainNumatuneParseXML: Refactor cleanup
Use automatic memory clearing for the temporary strings and bitmap and remove the cleanup section. There are multiple temporary strings added so that we don't reuse one. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
29da6dcc9d
commit
33d6d05754
@ -224,22 +224,23 @@ virDomainNumatuneParseXML(virDomainNuma *numa,
|
|||||||
bool placement_static,
|
bool placement_static,
|
||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
char *tmp = NULL;
|
g_autofree char *modestr = NULL;
|
||||||
int mode = -1;
|
int mode = -1;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
g_autofree char *placementstr = NULL;
|
||||||
int placement = -1;
|
int placement = -1;
|
||||||
int ret = -1;
|
g_autofree char *nodesetstr = NULL;
|
||||||
virBitmap *nodeset = NULL;
|
g_autoptr(virBitmap) nodeset = NULL;
|
||||||
xmlNodePtr node = NULL;
|
xmlNodePtr node = NULL;
|
||||||
|
|
||||||
if (virXPathInt("count(./numatune)", ctxt, &n) < 0) {
|
if (virXPathInt("count(./numatune)", ctxt, &n) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("cannot extract numatune nodes"));
|
_("cannot extract numatune nodes"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
} else if (n > 1) {
|
} else if (n > 1) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("only one numatune is supported"));
|
_("only one numatune is supported"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = virXPathNode("./numatune/memory[1]", ctxt);
|
node = virXPathNode("./numatune/memory[1]", ctxt);
|
||||||
@ -248,34 +249,29 @@ virDomainNumatuneParseXML(virDomainNuma *numa,
|
|||||||
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
if ((tmp = virXMLPropString(node, "mode")) &&
|
if ((modestr = virXMLPropString(node, "mode")) &&
|
||||||
(mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
|
(mode = virDomainNumatuneMemModeTypeFromString(modestr)) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Unsupported NUMA memory tuning mode '%s'"), tmp);
|
_("Unsupported NUMA memory tuning mode '%s'"), modestr);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
if ((tmp = virXMLPropString(node, "placement")) &&
|
if ((placementstr = virXMLPropString(node, "placement")) &&
|
||||||
(placement = virDomainNumatunePlacementTypeFromString(tmp)) < 0) {
|
(placement = virDomainNumatunePlacementTypeFromString(placementstr)) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Unsupported NUMA memory placement mode '%s'"), tmp);
|
_("Unsupported NUMA memory placement mode '%s'"), placementstr);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
tmp = virXMLPropString(node, "nodeset");
|
if ((nodesetstr = virXMLPropString(node, "nodeset"))) {
|
||||||
if (tmp) {
|
if (virBitmapParse(nodesetstr, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
||||||
if (virBitmapParse(tmp, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virBitmapIsAllClear(nodeset)) {
|
if (virBitmapIsAllClear(nodeset)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Invalid value of 'nodeset': %s"), tmp);
|
_("Invalid value of 'nodeset': %s"), nodesetstr);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,16 +280,12 @@ virDomainNumatuneParseXML(virDomainNuma *numa,
|
|||||||
placement,
|
placement,
|
||||||
mode,
|
mode,
|
||||||
nodeset) < 0)
|
nodeset) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virDomainNumatuneNodeParseXML(numa, ctxt) < 0)
|
if (virDomainNumatuneNodeParseXML(numa, ctxt) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virBitmapFree(nodeset);
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user