mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-04 16:03:49 +00:00
virsh: freecell --all getting wrong NUMA nodes count
Virsh freecell --all was not only getting wrong NUMA nodes count, but even the NUMA nodes IDs. They doesn't have to be continuous, as I've found out during testing this. Therefore a modification of nodeGetCellsFreeMemory() error message.
This commit is contained in:
parent
1c07233436
commit
595174aeb7
@ -468,7 +468,8 @@ nodeGetCellsFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
long long mem;
|
long long mem;
|
||||||
if (numa_node_size64(n, &mem) < 0) {
|
if (numa_node_size64(n, &mem) < 0) {
|
||||||
nodeReportError(VIR_ERR_INTERNAL_ERROR,
|
nodeReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Failed to query NUMA free memory"));
|
_("Failed to query NUMA free memory for node: %d"),
|
||||||
|
n);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
freeMems[numCells++] = mem;
|
freeMems[numCells++] = mem;
|
||||||
|
@ -2283,9 +2283,15 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int ret;
|
int ret;
|
||||||
int cell, cell_given;
|
int cell, cell_given;
|
||||||
unsigned long long memory;
|
unsigned long long memory;
|
||||||
unsigned long long *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
|
unsigned long nodes_cnt;
|
||||||
|
unsigned long *nodes_id = NULL;
|
||||||
|
unsigned long long *nodes_free = NULL;
|
||||||
int all_given;
|
int all_given;
|
||||||
virNodeInfo info;
|
int i;
|
||||||
|
char *cap_xml = NULL;
|
||||||
|
xmlDocPtr xml = NULL;
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
@ -2301,32 +2307,57 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (all_given) {
|
if (all_given) {
|
||||||
if (virNodeGetInfo(ctl->conn, &info) < 0) {
|
cap_xml = virConnectGetCapabilities(ctl->conn);
|
||||||
vshError(ctl, "%s", _("failed to get NUMA nodes count"));
|
if (!cap_xml) {
|
||||||
|
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info.nodes) {
|
xml = xmlReadDoc((const xmlChar *) cap_xml, "node.xml", NULL,
|
||||||
vshError(ctl, "%s", _("no NUMA nodes present"));
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
|
||||||
|
if (!xml) {
|
||||||
|
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(nodes, info.nodes) < 0) {
|
ctxt = xmlXPathNewContext(xml);
|
||||||
vshError(ctl, "%s", _("could not allocate memory"));
|
nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell",
|
||||||
goto cleanup;
|
ctxt, &nodes);
|
||||||
}
|
|
||||||
|
|
||||||
ret = virNodeGetCellsFreeMemory(ctl->conn, nodes, 0, info.nodes);
|
if (nodes_cnt == -1) {
|
||||||
if (ret != info.nodes) {
|
|
||||||
vshError(ctl, "%s", _("could not get information about "
|
vshError(ctl, "%s", _("could not get information about "
|
||||||
"all NUMA nodes"));
|
"NUMA topology"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodes_free = vshCalloc(ctl, nodes_cnt, sizeof(*nodes_free));
|
||||||
|
nodes_id = vshCalloc(ctl, nodes_cnt, sizeof(*nodes_id));
|
||||||
|
|
||||||
|
for (i = 0; i < nodes_cnt; i++) {
|
||||||
|
unsigned long id;
|
||||||
|
char *val = virXMLPropString(nodes[i], "id");
|
||||||
|
if (virStrToLong_ul(val, NULL, 10, &id)) {
|
||||||
|
vshError(ctl, "%s", _("conversion from string failed"));
|
||||||
|
VIR_FREE(val);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
VIR_FREE(val);
|
||||||
|
nodes_id[i]=id;
|
||||||
|
ret = virNodeGetCellsFreeMemory(ctl->conn, &(nodes_free[i]), id, 1);
|
||||||
|
if (ret != 1) {
|
||||||
|
vshError(ctl, _("failed to get free memory for NUMA node "
|
||||||
|
"number: %lu"), id);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memory = 0;
|
memory = 0;
|
||||||
for (cell = 0; cell < info.nodes; cell++) {
|
for (cell = 0; cell < nodes_cnt; cell++) {
|
||||||
vshPrint(ctl, "%5d: %10llu kB\n", cell, (nodes[cell]/1024));
|
vshPrint(ctl, "%5lu: %10llu kB\n", nodes_id[cell],
|
||||||
memory += nodes[cell];
|
(nodes_free[cell]/1024));
|
||||||
|
memory += nodes_free[cell];
|
||||||
}
|
}
|
||||||
|
|
||||||
vshPrintExtra(ctl, "--------------------\n");
|
vshPrintExtra(ctl, "--------------------\n");
|
||||||
@ -2351,7 +2382,13 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
func_ret = TRUE;
|
func_ret = TRUE;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
if (xml)
|
||||||
|
xmlFreeDoc(xml);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
|
VIR_FREE(nodes_free);
|
||||||
|
VIR_FREE(nodes_id);
|
||||||
|
VIR_FREE(cap_xml);
|
||||||
return func_ret;
|
return func_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user