From nobody Mon Feb 9 09:43:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15375394636771.2012247302247943; Fri, 21 Sep 2018 07:17:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D87036A5DA; Fri, 21 Sep 2018 14:17:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EB767EE38; Fri, 21 Sep 2018 14:17:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EA8774BB7F; Fri, 21 Sep 2018 14:17:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LEHcVs028305 for ; Fri, 21 Sep 2018 10:17:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2323E17CCB; Fri, 21 Sep 2018 14:17:38 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7201117964; Fri, 21 Sep 2018 14:17:37 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:21 +0200 Message-Id: <20180921141724.18879-11-skobyda@redhat.com> In-Reply-To: <20180921141724.18879-1-skobyda@redhat.com> References: <20180921141724.18879-1-skobyda@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [PATCH v2 10/13] virsh: Implement vshTable API to vcpupin, iothreadinfo, domfsinfo X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Sep 2018 14:17:42 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Kobyda --- 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" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -6905,6 +6906,7 @@ virshVcpuPinQuery(vshControl *ctl, size_t i; int ncpus; bool ret =3D false; + vshTablePtr table =3D NULL; =20 if ((ncpus =3D virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) { if (ncpus =3D=3D -1) { @@ -6913,7 +6915,7 @@ virshVcpuPinQuery(vshControl *ctl, else vshError(ctl, "%s", _("cannot get vcpupin for transient do= main")); } - return false; + goto cleanup; } =20 if (got_vcpu && vcpu >=3D 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; } =20 cpumaplen =3D VIR_CPU_MAPLEN(maxcpu); cpumap =3D vshMalloc(ctl, ncpus * cpumaplen); if ((ncpus =3D virDomainGetVcpuPinInfo(dom, ncpus, cpumap, cpumaplen, flags)) >=3D 0) { - vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity")); - vshPrintExtra(ctl, "----------------------------------\n"); + table =3D vshTableNew(_("VCPU"), _("CPU Affinity"), NULL); + if (!table) + goto cleanup; + for (i =3D 0; i < ncpus; i++) { + VIR_AUTOFREE(char *) pinInfo =3D NULL; + VIR_AUTOFREE(char *) vcpuStr =3D NULL; if (got_vcpu && i !=3D vcpu) continue; =20 - vshPrint(ctl, "%4zu: ", i); - ret =3D virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaple= n, i), - cpumaplen); - vshPrint(ctl, "\n"); - if (!ret) - break; + if (!(pinInfo =3D 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); } =20 + ret =3D true; + cleanup: + vshTableFree(table); VIR_FREE(cpumap); return ret; } @@ -7520,6 +7533,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) int maxcpu; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; virshControlPtr priv =3D ctl->privData; + vshTablePtr table =3D NULL; =20 VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -7545,19 +7559,30 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - vshPrintExtra(ctl, " %-15s %-15s\n", - _("IOThread ID"), _("CPU Affinity")); - vshPrintExtra(ctl, "--------------------------------------------------= -\n"); + table =3D vshTableNew(_("IOThread ID"), _("CPU Affinity"), NULL); + if (!table) + goto cleanup; + for (i =3D 0; i < niothreads; i++) { + VIR_AUTOFREE(char *) pinInfo =3D NULL; + VIR_AUTOFREE(char *) iothreadIdStr =3D NULL; =20 - vshPrint(ctl, " %-15u ", info[i]->iothread_id); - ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpum= aplen)); - vshPrint(ctl, "\n"); - virDomainIOThreadInfoFree(info[i]); + if (virAsprintf(&iothreadIdStr, "%u", info[i]->iothread_id) < 0) + goto cleanup; + + ignore_value(pinInfo =3D virBitmapDataFormat(info[i]->cpumap, info= [i]->cpumaplen)); + + if (vshTableRowAppend(table, iothreadIdStr, pinInfo ? pinInfo : ""= , NULL) < 0) + goto cleanup; } - VIR_FREE(info); + + vshTablePrintToStdout(table, ctl); =20 cleanup: + for (i =3D 0; i < niothreads; i++) + virDomainIOThreadInfoFree(info[i]); + VIR_FREE(info); + vshTableFree(table); virshDomainFree(dom); return niothreads >=3D 0; } @@ -13778,6 +13803,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) int ret =3D -1; size_t i, j; virDomainFSInfoPtr *info; + vshTablePtr table =3D NULL; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -13793,25 +13819,41 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) } =20 if (info) { - vshPrintExtra(ctl, "%-36s %-8s %-8s %s\n", - _("Mountpoint"), _("Name"), _("Type"), _("Target")); - vshPrintExtra(ctl, "----------------------------------------------= ---------------------\n"); + table =3D vshTableNew(_("Mountpoint"), _("Name"), _("Type"), _("Ta= rget"), NULL); + if (!table) + goto cleanup; + for (i =3D 0; i < ret; i++) { - vshPrint(ctl, "%-36s %-8s %-8s ", - info[i]->mountpoint, info[i]->name, info[i]->fstype); + virBuffer targetsBuff =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOFREE(char *) targets =3D NULL; + for (j =3D 0; j < info[i]->ndevAlias; j++) { - vshPrint(ctl, "%s", info[i]->devAlias[j]); + virBufferAdd(&targetsBuff, info[i]->devAlias[j], -1); if (j !=3D info[i]->ndevAlias - 1) - vshPrint(ctl, ","); + virBufferAddChar(&targetsBuff, ','); } - vshPrint(ctl, "\n"); =20 - virDomainFSInfoFree(info[i]); + targets =3D 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); } =20 cleanup: + if (info) { + for (i =3D 0; i < ret; i++) + virDomainFSInfoFree(info[i]); + VIR_FREE(info); + } + vshTableFree(table); virshDomainFree(dom); return ret >=3D 0; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list