mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +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");
|
||||
size_t i;
|
||||
g_autofree char *cap_xml = NULL;
|
||||
g_autoptr(xmlDoc) xml = NULL;
|
||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||
virshControl *priv = ctl->privData;
|
||||
|
||||
@ -171,14 +170,28 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
||||
if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &cell) < 0)
|
||||
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))) {
|
||||
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||
return false;
|
||||
}
|
||||
|
||||
xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt);
|
||||
if (!xml) {
|
||||
if (!virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt)) {
|
||||
vshError(ctl, "%s", _("unable to get node capabilities"));
|
||||
return false;
|
||||
}
|
||||
@ -187,8 +200,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
||||
ctxt, &nodes);
|
||||
|
||||
if (nodes_cnt == -1) {
|
||||
vshError(ctl, "%s", _("could not get information about "
|
||||
"NUMA topology"));
|
||||
vshError(ctl, "%s", _("could not get information about NUMA topology"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -219,19 +231,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
vshPrintExtra(ctl, "--------------------\n");
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user