[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/2] virsh: fix wrong NUMA nodes count getting



as written in docs, one must parse capabilities XML to get the right
count of NUMA nodes.
---
 tools/virsh.c |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 8804fc3..1086555 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2333,8 +2333,9 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     int cell, cell_given;
     unsigned long long memory;
     unsigned long long *nodes = NULL;
+    unsigned long nodes_cnt;
     int all_given;
-    virNodeInfo info;
+    char *node_xml;
 
 
     if (!vshConnectionUsability(ctl, ctl->conn))
@@ -2350,30 +2351,33 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (all_given) {
-        if (virNodeGetInfo(ctl->conn, &info) < 0) {
-            vshError(ctl, "%s", _("failed to get NUMA nodes count"));
+        node_xml = virConnectGetCapabilities(ctl->conn);
+        if (!node_xml) {
+            vshError(ctl, "%s", _("unable to get node capabilities"));
             goto cleanup;
         }
 
-        if (!info.nodes) {
-            vshError(ctl, "%s", _("no NUMA nodes present"));
-            goto cleanup;
-        }
+        ret = xPathULong(node_xml,
+                         (char*)"string(/capabilities/host/topology/cells/@num)",
+                         &nodes_cnt);
+
+        if (ret)
+            nodes_cnt = 1;
 
-        if (VIR_ALLOC_N(nodes, info.nodes) < 0) {
+        if (VIR_ALLOC_N(nodes, nodes_cnt) < 0) {
             vshError(ctl, "%s", _("could not allocate memory"));
             goto cleanup;
         }
 
-        ret = virNodeGetCellsFreeMemory(ctl->conn, nodes, 0, info.nodes);
-        if (ret != info.nodes) {
+        ret = virNodeGetCellsFreeMemory(ctl->conn, nodes, 0, nodes_cnt);
+        if (ret != nodes_cnt) {
             vshError(ctl, "%s", _("could not get information about "
                                   "all NUMA nodes"));
             goto cleanup;
         }
 
         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));
             memory += nodes[cell];
         }
@@ -2401,6 +2405,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
 
 cleanup:
     VIR_FREE(nodes);
+    VIR_FREE(node_xml);
     return func_ret;
 }
 
-- 
1.7.3.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]