From nobody Mon Feb 9 00:20:16 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 1537280541281202.7103456091944; Tue, 18 Sep 2018 07:22:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 030473002C65; Tue, 18 Sep 2018 14:22:19 +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 C1DB6309137F; Tue, 18 Sep 2018 14:22:18 +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 6B3F24A46F; Tue, 18 Sep 2018 14:22:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8IEM5SY000394 for ; Tue, 18 Sep 2018 10:22:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CC4E7A420; Tue, 18 Sep 2018 14:22:05 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6988E176A0; Tue, 18 Sep 2018 14:22:04 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 16:21:34 +0200 Message-Id: <20180918142137.16258-11-skobyda@redhat.com> In-Reply-To: <20180918142137.16258-1-skobyda@redhat.com> References: <20180918142137.16258-1-skobyda@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [PATCH 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 18 Sep 2018 14:22:20 +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 | 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" =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,42 @@ 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++) { + char *pinInfo =3D NULL; + char *vcpuStr; 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; + + VIR_FREE(vcpuStr); + VIR_FREE(pinInfo); } + + vshTablePrintToStdout(table, ctl); } =20 + ret =3D true; + cleanup: + vshTableFree(table); VIR_FREE(cpumap); return ret; } @@ -7520,6 +7536,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 +7562,32 @@ 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++) { + char *pinInfo =3D NULL; + char *iothreadIdStr; =20 - vshPrint(ctl, " %-15u ", info[i]->iothread_id); - ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpum= aplen)); - vshPrint(ctl, "\n"); + 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(pinInfo); + VIR_FREE(iothreadIdStr); virDomainIOThreadInfoFree(info[i]); } VIR_FREE(info); =20 + vshTablePrintToStdout(table, ctl); + cleanup: + vshTableFree(table); virshDomainFree(dom); return niothreads >=3D 0; } @@ -13778,6 +13808,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 +13824,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", "Target", 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; + char *targets; + 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 + targets =3D 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); } =20 cleanup: + 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