[PATCH v2 10/13] virsh: Implement vshTable API to vcpupin, iothreadinfo, domfsinfo

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

 



Signed-off-by: Simon Kobyda <skobyda@xxxxxxxxxx>
---
 tools/virsh-domain.c | 98 +++++++++++++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 28 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c1cff9fe2d..2a416b919a 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,39 @@ 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++) {
+            VIR_AUTOFREE(char *) pinInfo = NULL;
+            VIR_AUTOFREE(char *) vcpuStr = NULL;
             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;
         }
+
+        vshTablePrintToStdout(table, ctl);
     }
 
+    ret = true;
+ cleanup:
+    vshTableFree(table);
     VIR_FREE(cpumap);
     return ret;
 }
@@ -7520,6 +7533,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 +7559,30 @@ 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++) {
+        VIR_AUTOFREE(char *) pinInfo = NULL;
+        VIR_AUTOFREE(char *) iothreadIdStr = NULL;
 
-        vshPrint(ctl, " %-15u ", info[i]->iothread_id);
-        ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpumaplen));
-        vshPrint(ctl, "\n");
-        virDomainIOThreadInfoFree(info[i]);
+        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(info);
+
+    vshTablePrintToStdout(table, ctl);
 
  cleanup:
+    for (i = 0; i < niothreads; i++)
+        virDomainIOThreadInfoFree(info[i]);
+    VIR_FREE(info);
+    vshTableFree(table);
     virshDomainFree(dom);
     return niothreads >= 0;
 }
@@ -13778,6 +13803,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 +13819,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;
+            VIR_AUTOFREE(char *) targets = NULL;
+
             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");
 
-            virDomainFSInfoFree(info[i]);
+            targets = virBufferContentAndReset(&targetsBuff);
+
+            if (vshTableRowAppend(table,
+                                  info[i]->mountpoint,
+                                  info[i]->name,
+                                  info[i]->fstype,
+                                  targets,
+                                  NULL) < 0)
+                goto cleanup;
         }
-        VIR_FREE(info);
+
+        vshTablePrintToStdout(table, ctl);
     }
 
  cleanup:
+    if (info) {
+        for (i = 0; i < ret; i++)
+            virDomainFSInfoFree(info[i]);
+        VIR_FREE(info);
+    }
+    vshTableFree(table);
     virshDomainFree(dom);
     return ret >= 0;
 }
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux