Report CPU affinities / online CPUs in human-readable form (0-2,4)
instead of yy-y when this flag is present.
https://bugzilla.redhat.com/show_bug.cgi?id=985980
---
tools/virsh-domain.c | 21 +++++++++++++++++++--
tools/virsh-host.c | 25 ++++++++++++++++++++++---
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e85c906..d27886d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5528,6 +5528,10 @@ static const vshCmdOptDef opts_vcpuinfo[] = {
.flags = VSH_OFLAG_REQ,
.help = N_("domain name, id or uuid")
},
+ {.name = "pretty",
+ .type = VSH_OT_BOOL,
+ .help = N_("return human readable output")
+ },
{.name = NULL}
};
@@ -5541,6 +5545,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
int ncpus, maxcpu;
size_t cpumaplen;
bool ret = false;
+ bool pretty = vshCommandOptBool(cmd, "pretty");
int n, m;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -5589,8 +5594,20 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%-15s %s\n", _("CPU time"),
_("N/A"));
}
vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
- for (m = 0; m < maxcpu; m++) {
- vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ?
'y' : '-');
+ if (pretty) {
+ char *str;
+
+ str = virBitmapDataToString(VIR_GET_CPUMAP(cpumaps, cpumaplen, n),
+ cpumaplen);
+ if (!str)
+ goto cleanup;
+ vshPrint(ctl, "%s", str);
+ VIR_FREE(str);
+ } else {
+ for (m = 0; m < maxcpu; m++) {
+ vshPrint(ctl, "%c",
+ VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' :
'-');
+ }
}
vshPrint(ctl, "\n");
if (n < (ncpus - 1))
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index cac6086..8091437 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -32,6 +32,7 @@
#include <libxml/xmlsave.h>
#include "internal.h"
+#include "virbitmap.h"
#include "virbuffer.h"
#include "viralloc.h"
#include "virsh-domain.h"
@@ -278,12 +279,21 @@ static const vshCmdInfo info_node_cpumap[] = {
{.name = NULL}
};
+static const vshCmdOptDef opts_node_cpumap[] = {
+ {.name = "pretty",
+ .type = VSH_OT_BOOL,
+ .help = N_("return human readable output")
+ },
+ {.name = NULL}
+};
+
static bool
cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
int cpu, cpunum;
unsigned char *cpumap = NULL;
unsigned int online;
+ bool pretty = vshCommandOptBool(cmd, "pretty");
bool ret = false;
cpunum = virNodeGetCPUMap(ctl->conn, &cpumap, &online, 0);
@@ -296,8 +306,17 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
vshPrint(ctl, "%-15s %d\n", _("CPUs online:"), online);
vshPrint(ctl, "%-15s ", _("CPU map:"));
- for (cpu = 0; cpu < cpunum; cpu++)
- vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' :
'-');
+ if (pretty) {
+ char *str = virBitmapDataToString(cpumap, cpunum);
+
+ if (!str)
+ goto cleanup;
+ vshPrint(ctl, "%s", str);
+ VIR_FREE(str);
+ } else {
+ for (cpu = 0; cpu < cpunum; cpu++)
+ vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' :
'-');
+ }
vshPrint(ctl, "\n");
ret = true;
@@ -978,7 +997,7 @@ const vshCmdDef hostAndHypervisorCmds[] = {
},
{.name = "nodecpumap",
.handler = cmdNodeCpuMap,
- .opts = NULL,
+ .opts = opts_node_cpumap,
.info = info_node_cpumap,
.flags = 0
},
--
1.8.3.2