mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 04:25:19 +00:00
virsh: host: refactor cmdFreecell()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
ba78db1f73
commit
21a0019392
@ -162,7 +162,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool cellno = vshCommandOptBool(cmd, "cellno");
|
bool cellno = vshCommandOptBool(cmd, "cellno");
|
||||||
size_t i;
|
size_t i;
|
||||||
g_autofree char *cap_xml = NULL;
|
g_autofree char *cap_xml = NULL;
|
||||||
g_autoptr(xmlDoc) xml = NULL;
|
|
||||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||||
virshControl *priv = ctl->privData;
|
virshControl *priv = ctl->privData;
|
||||||
|
|
||||||
@ -171,14 +170,28 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0)
|
if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (all) {
|
if (!all) {
|
||||||
|
if (cellno) {
|
||||||
|
if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((memory = virNodeGetFreeMemory(priv->conn)) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(cap_xml = virConnectGetCapabilities(priv->conn))) {
|
if (!(cap_xml = virConnectGetCapabilities(priv->conn))) {
|
||||||
vshError(ctl, "%s", _("unable to get node capabilities"));
|
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt);
|
if (!virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt)) {
|
||||||
if (!xml) {
|
|
||||||
vshError(ctl, "%s", _("unable to get node capabilities"));
|
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -187,8 +200,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ctxt, &nodes);
|
ctxt, &nodes);
|
||||||
|
|
||||||
if (nodes_cnt == -1) {
|
if (nodes_cnt == -1) {
|
||||||
vshError(ctl, "%s", _("could not get information about "
|
vshError(ctl, "%s", _("could not get information about NUMA topology"));
|
||||||
"NUMA topology"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,19 +231,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
vshPrintExtra(ctl, "--------------------\n");
|
vshPrintExtra(ctl, "--------------------\n");
|
||||||
vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024);
|
vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024);
|
||||||
} else {
|
|
||||||
if (cellno) {
|
|
||||||
if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024));
|
|
||||||
} else {
|
|
||||||
if ((memory = virNodeGetFreeMemory(priv->conn)) == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user