Signed-off-by: Simon Kobyda <skobyda(a)redhat.com>
---
tools/virsh-domain.c | 95 +++++++++++++++++++++++++++++++++-----------
1 file changed, 71 insertions(+), 24 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c1cff9fe2d..c580be998c 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -59,6 +59,7 @@
#include "virxml.h"
#include "virsh-nodedev.h"
#include "viruri.h"
+#include "vsh-table.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
@@ -6905,6 +6906,7 @@ virshVcpuPinQuery(vshControl *ctl,
size_t i;
int ncpus;
bool ret = false;
+ vshTablePtr table = NULL;
if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) {
if (ncpus == -1) {
@@ -6913,7 +6915,7 @@ virshVcpuPinQuery(vshControl *ctl,
else
vshError(ctl, "%s", _("cannot get vcpupin for transient
domain"));
}
- return false;
+ goto cleanup;
}
if (got_vcpu && vcpu >= ncpus) {
@@ -6927,28 +6929,42 @@ virshVcpuPinQuery(vshControl *ctl,
vshError(ctl,
_("vcpu %d is out of range of persistent cpu count %d"),
vcpu, ncpus);
- return false;
+ goto cleanup;
}
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
cpumaplen, flags)) >= 0) {
- vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU
Affinity"));
- vshPrintExtra(ctl, "----------------------------------\n");
+ table = vshTableNew("VCPU", "CPU Affinity", NULL);
+ if (!table)
+ goto cleanup;
+
for (i = 0; i < ncpus; i++) {
+ char *pinInfo = NULL;
+ char *vcpuStr;
if (got_vcpu && i != vcpu)
continue;
- vshPrint(ctl, "%4zu: ", i);
- ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i),
- cpumaplen);
- vshPrint(ctl, "\n");
- if (!ret)
- break;
+ if (!(pinInfo = virBitmapDataFormat(cpumap, cpumaplen)))
+ goto cleanup;
+
+ if (virAsprintf(&vcpuStr, "%lu", i) < 0)
+ goto cleanup;
+
+ if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0)
+ goto cleanup;
+
+ VIR_FREE(vcpuStr);
+ VIR_FREE(pinInfo);
}
+
+ vshTablePrintToStdout(table, ctl);
}
+ ret = true;
+ cleanup:
+ vshTableFree(table);
VIR_FREE(cpumap);
return ret;
}
@@ -7520,6 +7536,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
int maxcpu;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
virshControlPtr priv = ctl->privData;
+ vshTablePtr table = NULL;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
@@ -7545,19 +7562,32 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- vshPrintExtra(ctl, " %-15s %-15s\n",
- _("IOThread ID"), _("CPU Affinity"));
- vshPrintExtra(ctl,
"---------------------------------------------------\n");
+ table = vshTableNew("IOThread ID", "CPU Affinity", NULL);
+ if (!table)
+ goto cleanup;
+
for (i = 0; i < niothreads; i++) {
+ char *pinInfo = NULL;
+ char *iothreadIdStr;
- vshPrint(ctl, " %-15u ", info[i]->iothread_id);
- ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpumaplen));
- vshPrint(ctl, "\n");
+ if (virAsprintf(&iothreadIdStr, "%u", info[i]->iothread_id) <
0)
+ goto cleanup;
+
+ ignore_value(pinInfo = virBitmapDataFormat(info[i]->cpumap,
info[i]->cpumaplen));
+
+ if (vshTableRowAppend(table, iothreadIdStr, pinInfo ? pinInfo : "",
NULL) < 0)
+ goto cleanup;
+
+ VIR_FREE(pinInfo);
+ VIR_FREE(iothreadIdStr);
virDomainIOThreadInfoFree(info[i]);
}
VIR_FREE(info);
+ vshTablePrintToStdout(table, ctl);
+
cleanup:
+ vshTableFree(table);
virshDomainFree(dom);
return niothreads >= 0;
}
@@ -13778,6 +13808,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
int ret = -1;
size_t i, j;
virDomainFSInfoPtr *info;
+ vshTablePtr table = NULL;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
@@ -13793,25 +13824,41 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
}
if (info) {
- vshPrintExtra(ctl, "%-36s %-8s %-8s %s\n",
- _("Mountpoint"), _("Name"),
_("Type"), _("Target"));
- vshPrintExtra(ctl,
"-------------------------------------------------------------------\n");
+ table = vshTableNew("Mountpoint", "Name", "Type",
"Target", NULL);
+ if (!table)
+ goto cleanup;
+
for (i = 0; i < ret; i++) {
- vshPrint(ctl, "%-36s %-8s %-8s ",
- info[i]->mountpoint, info[i]->name, info[i]->fstype);
+ virBuffer targetsBuff = VIR_BUFFER_INITIALIZER;
+ char *targets;
+
for (j = 0; j < info[i]->ndevAlias; j++) {
- vshPrint(ctl, "%s", info[i]->devAlias[j]);
+ virBufferAdd(&targetsBuff, info[i]->devAlias[j], -1);
if (j != info[i]->ndevAlias - 1)
- vshPrint(ctl, ",");
+ virBufferAddChar(&targetsBuff, ',');
}
- vshPrint(ctl, "\n");
+ targets = virBufferContentAndReset(&targetsBuff);
+
+ if (vshTableRowAppend(table,
+ info[i]->mountpoint,
+ info[i]->name,
+ info[i]->fstype,
+ targets,
+ NULL) < 0)
+ goto cleanup;
+
+ VIR_FREE(targets);
virDomainFSInfoFree(info[i]);
}
+
+ vshTablePrintToStdout(table, ctl);
+
VIR_FREE(info);
}
cleanup:
+ vshTableFree(table);
virshDomainFree(dom);
return ret >= 0;
}
--
2.17.1