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

[libvirt] [PATCHv2 6/9] virNodeGetCPUMapFlags: Implement virsh support.



- Added a new host command nodecpumap
- Added documentation

Example:
$ virsh nodecpumap
CPUs present:  8
CPUs online:   3
CPU map:       10101000

Signed-off-by: Viktor Mihajlovski <mihajlov linux vnet ibm com>
---
 tools/virsh-host.c |   41 +++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod    |    5 +++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 5cf192d..e4f9327 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -271,6 +271,46 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "nodecpumap" command
+ */
+static const vshCmdInfo info_node_cpumap[] = {
+    {"help", N_("node cpu map")},
+    {"desc", N_("Displays the node's total number of CPUs, the number of"
+                " online CPUs and the list of online CPUs.")},
+    {NULL, NULL}
+};
+
+static bool
+cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    int cpu, cpunum;
+    unsigned char *cpumap = NULL;
+    unsigned int online;
+    bool ret = false;
+
+    cpunum = virNodeGetCPUMapFlags(ctl->conn, &cpumap, &online, 0);
+    if (cpunum < 0) {
+        vshError(ctl, "%s", _("Unable to get cpu map"));
+        goto cleanup;
+    }
+
+    vshPrint(ctl, "%-15s %d\n", _("CPUs present:"), cpunum);
+    vshPrint(ctl, "%-15s %d\n", _("CPUs online:"), online);
+
+    vshPrint(ctl, "%-15s ", _("CPU map:"));
+    for (cpu = 0; cpu < cpunum; cpu++) {
+        vshPrint(ctl, "%d", VIR_CPU_USED(cpumap, cpu) ? 1 : 0);
+    }
+    vshPrint(ctl, "\n");
+
+    ret = true;
+
+  cleanup:
+    VIR_FREE(cpumap);
+    return ret;
+}
+
+/*
  * "nodecpustats" command
  */
 static const vshCmdInfo info_nodecpustats[] = {
@@ -1026,6 +1066,7 @@ const vshCmdDef hostAndHypervisorCmds[] = {
     {"hostname", cmdHostname, NULL, info_hostname, 0},
     {"node-memory-tune", cmdNodeMemoryTune,
      opts_node_memory_tune, info_node_memory_tune, 0},
+    {"nodecpumap", cmdNodeCpuMap, NULL, info_node_cpumap, 0},
     {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
     {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
     {"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 2d90b7b..9a2c0e1 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -277,6 +277,11 @@ and size of the physical memory. The output corresponds to virNodeInfo
 structure. Specifically, the "CPU socket(s)" field means number of CPU
 sockets per NUMA cell.
 
+=item B<nodecpumap>
+
+Displays the node's total number of CPUs, the number of online CPUs
+and the list of online CPUs.
+
 =item B<nodecpustats> [I<cpu>] [I<--percent>]
 
 Returns cpu stats of the node.
-- 
1.7.0.4


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