From nobody Sun May 5 01:20:36 2024 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 153753945400447.22992968654967; Fri, 21 Sep 2018 07:17:34 -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 CD0F830001DE; Fri, 21 Sep 2018 14:17:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BEE37EE23; Fri, 21 Sep 2018 14:17:31 +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 EAF94181A12E; Fri, 21 Sep 2018 14:17:30 +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 w8LEHTki028226 for ; Fri, 21 Sep 2018 10:17:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 037B517CCB; Fri, 21 Sep 2018 14:17:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51A0B17964; Fri, 21 Sep 2018 14:17:28 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:12 +0200 Message-Id: <20180921141724.18879-2-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 01/13] virsh: Implement vsh-table to iface-list 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.45]); Fri, 21 Sep 2018 14:17:32 +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-interface.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 50518c667b..1eb1a27ac7 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -48,6 +48,7 @@ #include "virutil.h" #include "virxml.h" #include "virstring.h" +#include "vsh-table.h" =20 virInterfacePtr virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, @@ -356,6 +357,8 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATT= RIBUTE_UNUSED) unsigned int flags =3D VIR_CONNECT_LIST_INTERFACES_ACTIVE; virshInterfaceListPtr list =3D NULL; size_t i; + bool ret =3D false; + vshTablePtr table =3D NULL; =20 if (inactive) flags =3D VIR_CONNECT_LIST_INTERFACES_INACTIVE; @@ -366,21 +369,29 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd A= TTRIBUTE_UNUSED) if (!(list =3D virshInterfaceListCollect(ctl, flags))) return false; =20 - vshPrintExtra(ctl, " %-20s %-10s %s\n", _("Name"), _("State"), - _("MAC Address")); - vshPrintExtra(ctl, "--------------------------------------------------= -\n"); + table =3D vshTableNew(_("Name"), _("State"), _("MAC Address"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < list->nifaces; i++) { virInterfacePtr iface =3D list->ifaces[i]; =20 - vshPrint(ctl, " %-20s %-10s %s\n", - virInterfaceGetName(iface), - virInterfaceIsActive(iface) ? _("active") : _("inactive"), - virInterfaceGetMACString(iface)); + if (vshTableRowAppend(table, + virInterfaceGetName(iface), + virInterfaceIsActive(iface) ? _("active") + : _("inactive"), + virInterfaceGetMACString(iface), + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + + ret =3D true; + cleanup: + vshTableFree(table); virshInterfaceListFree(list); - return true; + return ret; } =20 /* --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539459019973.5372247599887; Fri, 21 Sep 2018 07:17:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E86BE308A967; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4C9C171C4; Fri, 21 Sep 2018 14:17:36 +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 65DA0181A13A; Fri, 21 Sep 2018 14:17:36 +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 w8LEHU6s028237 for ; Fri, 21 Sep 2018 10:17:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 075F053C21; Fri, 21 Sep 2018 14:17:30 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55B1517964; Fri, 21 Sep 2018 14:17:29 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:13 +0200 Message-Id: <20180921141724.18879-3-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 02/13] virsh: Implement vshTable API to net-list and net-dhcp-leases 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 21 Sep 2018 14:17:37 +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-network.c | 59 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index ca07fb568f..440b23d8a8 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -33,6 +33,7 @@ #include "virstring.h" #include "virtime.h" #include "conf/network_conf.h" +#include "vsh-table.h" =20 #define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \ {.name =3D "network", \ @@ -677,6 +678,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) bool optUUID =3D vshCommandOptBool(cmd, "uuid"); char uuid[VIR_UUID_STRING_BUFLEN]; unsigned int flags =3D VIR_CONNECT_LIST_NETWORKS_ACTIVE; + vshTablePtr table =3D NULL; =20 if (vshCommandOptBool(cmd, "inactive")) flags =3D VIR_CONNECT_LIST_NETWORKS_INACTIVE; @@ -705,10 +707,10 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATT= RIBUTE_UNUSED) return false; =20 if (optTable) { - vshPrintExtra(ctl, " %-20s %-10s %-13s %s\n", _("Name"), _("State"= ), - _("Autostart"), _("Persistent")); - vshPrintExtra(ctl, - "---------------------------------------------------= -------\n"); + table =3D vshTableNew(_("Name"), _("State"), _("Autostart"), + _("Persistent"), NULL); + if (!table) + goto cleanup; } =20 for (i =3D 0; i < list->nnets; i++) { @@ -722,11 +724,15 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATT= RIBUTE_UNUSED) else autostartStr =3D is_autostart ? _("yes") : _("no"); =20 - vshPrint(ctl, " %-20s %-10s %-13s %s\n", - virNetworkGetName(network), - virNetworkIsActive(network) ? _("active") : _("inacti= ve"), - autostartStr, - virNetworkIsPersistent(network) ? _("yes") : _("no")); + if (vshTableRowAppend(table, + virNetworkGetName(network), + virNetworkIsActive(network) ? + _("active") : _("inactive"), + autostartStr, + virNetworkIsPersistent(network) ? + _("yes") : _("no"), + NULL) < 0) + goto cleanup; } else if (optUUID) { if (virNetworkGetUUIDString(network, uuid) < 0) { vshError(ctl, "%s", _("Failed to get network's UUID")); @@ -738,8 +744,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) } } =20 + if (optTable) + vshTablePrintToStdout(table, ctl); + ret =3D true; cleanup: + vshTableFree(table); virshNetworkListFree(list); return ret; } @@ -1351,6 +1361,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) size_t i; unsigned int flags =3D 0; virNetworkPtr network =3D NULL; + vshTablePtr table =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0) return false; @@ -1366,15 +1377,15 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) /* Sort the list according to MAC Address/IAID */ qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter); =20 - vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n", - _("Expiry Time"), _("MAC address"), _("Protocol"), - _("IP address"), _("Hostname"), _("Client ID or DUID"), - "-------------------------------------------------------= ---", - "-------------------------------------------------------= --"); + table =3D vshTableNew(_("Expiry Time"), _("MAC address"), _("Protocol"= ), + _("IP address"), _("Hostname"), _("Client ID or DU= ID"), + NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < nleases; i++) { const char *typestr =3D NULL; - char *cidr_format =3D NULL; + VIR_AUTOFREE(char *) cidr_format =3D NULL; virNetworkDHCPLeasePtr lease =3D leases[i]; time_t expirytime_tmp =3D lease->expirytime; struct tm ts; @@ -1390,17 +1401,23 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) ignore_value(virAsprintf(&cidr_format, "%s/%d", lease->ipaddr, lease->prefix)); =20 - vshPrint(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n", - expirytime, EMPTYSTR(lease->mac), - EMPTYSTR(typestr), cidr_format, - EMPTYSTR(lease->hostname), EMPTYSTR(lease->clientid)); - - VIR_FREE(cidr_format); + if (vshTableRowAppend(table, + expirytime, + EMPTYSTR(lease->mac), + EMPTYSTR(typestr), + EMPTYSTR(cidr_format), + EMPTYSTR(lease->hostname), + EMPTYSTR(lease->clientid), + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); if (leases) { for (i =3D 0; i < nleases; i++) virNetworkDHCPLeaseFree(leases[i]); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 153753946415061.30446622776901; Fri, 21 Sep 2018 07:17:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC722307D942; Fri, 21 Sep 2018 14:17:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BFEA1084383; 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 3B2C3181A13C; Fri, 21 Sep 2018 14:17:41 +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 w8LEHVSP028245 for ; Fri, 21 Sep 2018 10:17:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EE0F17CCB; Fri, 21 Sep 2018 14:17:31 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59F758209A; Fri, 21 Sep 2018 14:17:30 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:14 +0200 Message-Id: <20180921141724.18879-4-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 03/13] virsh: Implement vshTable API to secret-list 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); 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-secret.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 670beea706..87239ff60b 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -35,6 +35,7 @@ #include "virsecret.h" #include "virstring.h" #include "virtime.h" +#include "vsh-table.h" =20 static virSecretPtr virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **nam= e) @@ -507,6 +508,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIB= UTE_UNUSED) virshSecretListPtr list =3D NULL; bool ret =3D false; unsigned int flags =3D 0; + vshTablePtr table =3D NULL; =20 if (vshCommandOptBool(cmd, "ephemeral")) flags |=3D VIR_CONNECT_LIST_SECRETS_EPHEMERAL; @@ -523,15 +525,17 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) if (!(list =3D virshSecretListCollect(ctl, flags))) return false; =20 - vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage")); - vshPrintExtra(ctl, "----------------------------------------" - "----------------------------------------\n"); + table =3D vshTableNew(_("UUID"), _("Usage"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < list->nsecrets; i++) { virSecretPtr sec =3D list->secrets[i]; int usageType =3D virSecretGetUsageType(sec); const char *usageStr =3D virSecretUsageTypeToString(usageType); char uuid[VIR_UUID_STRING_BUFLEN]; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOFREE(char *) usage =3D NULL; =20 if (virSecretGetUUIDString(sec, uuid) < 0) { vshError(ctl, "%s", _("Failed to get uuid of secret")); @@ -539,18 +543,26 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) } =20 if (usageType) { - vshPrint(ctl, " %-36s %s %s\n", - uuid, usageStr, - virSecretGetUsageID(sec)); + virBufferStrcat(&buf, usageStr, " ", + virSecretGetUsageID(sec), NULL); + usage =3D virBufferContentAndReset(&buf); + if (!usage) + goto cleanup; + + if (vshTableRowAppend(table, uuid, usage, NULL) < 0) + goto cleanup; } else { - vshPrint(ctl, " %-36s %s\n", - uuid, _("Unused")); + if (vshTableRowAppend(table, uuid, _("Unused"), NULL) < 0) + goto cleanup; } } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); virshSecretListFree(list); return ret; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539458033470.0568331032181; Fri, 21 Sep 2018 07:17:38 -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 DC89B8CD0; Fri, 21 Sep 2018 14:17:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A05C05C3FD; Fri, 21 Sep 2018 14:17:35 +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 5628B181A12F; Fri, 21 Sep 2018 14:17:35 +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 w8LEHW0j028252 for ; Fri, 21 Sep 2018 10:17:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1362053C21; Fri, 21 Sep 2018 14:17:32 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E8D517964; Fri, 21 Sep 2018 14:17:31 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:15 +0200 Message-Id: <20180921141724.18879-5-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 04/13] virsh: Implement vshTable API to nwfilter-list and nwfilterbinding-list 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.38]); Fri, 21 Sep 2018 14:17:36 +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-nwfilter.c | 47 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 1cdbe5053a..b680ea082c 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -31,6 +31,7 @@ #include "viralloc.h" #include "virfile.h" #include "virutil.h" +#include "vsh-table.h" =20 virNWFilterPtr virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, @@ -359,26 +360,35 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd AT= TRIBUTE_UNUSED) { size_t i; char uuid[VIR_UUID_STRING_BUFLEN]; + bool ret =3D false; virshNWFilterListPtr list =3D NULL; + vshTablePtr table =3D NULL; =20 if (!(list =3D virshNWFilterListCollect(ctl, 0))) return false; =20 - vshPrintExtra(ctl, " %-36s %-20s \n", _("UUID"), _("Name")); - vshPrintExtra(ctl, "---------------------------------" - "---------------------------------\n"); + table =3D vshTableNew(_("UUID"), _("Name"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < list->nfilters; i++) { virNWFilterPtr nwfilter =3D list->filters[i]; =20 virNWFilterGetUUIDString(nwfilter, uuid); - vshPrint(ctl, " %-36s %-20s\n", - uuid, - virNWFilterGetName(nwfilter)); + if (vshTableRowAppend(table, + uuid, + virNWFilterGetName(nwfilter), + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + + ret =3D true; + cleanup: + vshTableFree(table); virshNWFilterListFree(list); - return true; + return ret; } =20 /* @@ -714,25 +724,34 @@ static bool cmdNWFilterBindingList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { size_t i; + bool ret =3D false; virshNWFilterBindingListPtr list =3D NULL; + vshTablePtr table =3D NULL; =20 if (!(list =3D virshNWFilterBindingListCollect(ctl, 0))) return false; =20 - vshPrintExtra(ctl, " %-20s %-20s \n", _("Port Dev"), _("Filter")); - vshPrintExtra(ctl, "---------------------------------" - "---------------------------------\n"); + table =3D vshTableNew(_("Port Dev"), _("Filter"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < list->nbindings; i++) { virNWFilterBindingPtr binding =3D list->bindings[i]; =20 - vshPrint(ctl, " %-20s %-20s\n", - virNWFilterBindingGetPortDev(binding), - virNWFilterBindingGetFilterName(binding)); + if (vshTableRowAppend(table, + virNWFilterBindingGetPortDev(binding), + virNWFilterBindingGetFilterName(binding), + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + + ret =3D true; + cleanup: + vshTableFree(table); virshNWFilterBindingListFree(list); - return true; + return ret; } =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 15375394666821016.3194936330411; Fri, 21 Sep 2018 07:17:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BEFF5F744; Fri, 21 Sep 2018 14:17:44 +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 4C0AB8208C; Fri, 21 Sep 2018 14:17:44 +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 E5CBA4A469; Fri, 21 Sep 2018 14:17:43 +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 w8LEHXF4028257 for ; Fri, 21 Sep 2018 10:17:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CFB117964; Fri, 21 Sep 2018 14:17:33 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6878A83BE1; Fri, 21 Sep 2018 14:17:32 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:16 +0200 Message-Id: <20180921141724.18879-6-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 05/13] virsh: Implement vshTable API to snapshot-list. 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Sep 2018 14:17:45 +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-snapshot.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index a4ea959230..73861957ba 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -41,6 +41,7 @@ #include "virstring.h" #include "virxml.h" #include "conf/snapshot_conf.h" +#include "vsh-table.h" =20 /* Helper for snapshot-create and snapshot-create-as */ static bool @@ -1487,6 +1488,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) char *parent_snap =3D NULL; virDomainSnapshotPtr start =3D NULL; virshSnapshotListPtr snaplist =3D NULL; + vshTablePtr table =3D NULL; =20 VSH_EXCLUSIVE_OPTIONS_VAR(tree, name); VSH_EXCLUSIVE_OPTIONS_VAR(parent, roots); @@ -1547,15 +1549,12 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) =20 if (!tree && !name) { if (parent) - vshPrintExtra(ctl, " %-20s %-25s %-15s %s", - _("Name"), _("Creation Time"), _("State"), - _("Parent")); + table =3D vshTableNew(_("Name"), _("Creation Time"), _("State"= ), _("Parent"), NULL); else - vshPrintExtra(ctl, " %-20s %-25s %s", - _("Name"), _("Creation Time"), _("State")); - vshPrintExtra(ctl, "\n" - "------------------------------" - "------------------------------\n"); + table =3D vshTableNew(_("Name"), _("Creation Time"), _("State"= ), NULL); + + if (!table) + goto cleanup; } =20 if (tree) { @@ -1614,13 +1613,20 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", &time_info); =20 - if (parent) - vshPrint(ctl, " %-20s %-25s %-15s %s\n", - snap_name, timestr, state, parent_snap); - else - vshPrint(ctl, " %-20s %-25s %s\n", snap_name, timestr, state); + if (parent) { + if (vshTableRowAppend(table, snap_name, timestr, state, parent= _snap, + NULL) < 0) + goto cleanup; + } else { + if (vshTableRowAppend(table, snap_name, timestr, state, + NULL) < 0) + goto cleanup; + } } =20 + if (table) + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: @@ -1633,6 +1639,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) xmlFreeDoc(xml); VIR_FREE(doc); virshDomainFree(dom); + vshTableFree(table); =20 return ret; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539471485919.670146773019; Fri, 21 Sep 2018 07:17:51 -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 8F79630001E1; Fri, 21 Sep 2018 14:17:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 545853091325; Fri, 21 Sep 2018 14:17:49 +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 EB7DE181A71F; Fri, 21 Sep 2018 14:17:48 +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 w8LEHYGj028265 for ; Fri, 21 Sep 2018 10:17:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D4ED17964; Fri, 21 Sep 2018 14:17:34 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C43A8208C; Fri, 21 Sep 2018 14:17:33 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:17 +0200 Message-Id: <20180921141724.18879-7-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 06/13] virsh: Set up cmdDomblkinfo() and cmdDomblkinfoPrint() for vshTable API implementation 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.40]); Fri, 21 Sep 2018 14:17:50 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" I've moved all the printing from cmdDomblkinfoPrint() to cmdDomblkinfo(), and renamed the cmdDomblkinfoPrint() to cmdDomblkinfoGet(), since nature of that function changed from gathering and printing informations only to gathering information. This I believe simplifies the functions and makes the implementation of vshTable API simpler. Signed-off-by: Simon Kobyda --- tools/virsh-domain-monitor.c | 78 +++++++++++++++++------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index adc5bb1a7a..cb48f9a7be 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -406,33 +406,23 @@ static const vshCmdOptDef opts_domblkinfo[] =3D { {.name =3D NULL} }; =20 -static void -cmdDomblkinfoPrint(vshControl *ctl, +static bool +cmdDomblkinfoGet(vshControl *ctl, const virDomainBlockInfo *info, - const char *device, - bool human, bool title) + char **cap, + char **alloc, + char **phy, + bool human) { - char *cap =3D NULL; - char *alloc =3D NULL; - char *phy =3D NULL; - - if (title) { - vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"), - _("Capacity"), _("Allocation"), _("Physical")); - vshPrintExtra(ctl, "-----------------------------" - "------------------------\n"); - return; - } - if (info->capacity =3D=3D 0 && info->allocation =3D=3D 0 && info->phys= ical =3D=3D 0) { - cap =3D vshStrdup(ctl, "-"); - alloc =3D vshStrdup(ctl, "-"); - phy =3D vshStrdup(ctl, "-"); + *cap =3D vshStrdup(ctl, "-"); + *alloc =3D vshStrdup(ctl, "-"); + *phy =3D vshStrdup(ctl, "-"); } else if (!human) { - if (virAsprintf(&cap, "%llu", info->capacity) < 0 || - virAsprintf(&alloc, "%llu", info->allocation) < 0 || - virAsprintf(&phy, "%llu", info->physical) < 0) - goto cleanup; + if (virAsprintf(cap, "%llu", info->capacity) < 0 || + virAsprintf(alloc, "%llu", info->allocation) < 0 || + virAsprintf(phy, "%llu", info->physical) < 0) + return false; } else { double val_cap, val_alloc, val_phy; const char *unit_cap, *unit_alloc, *unit_phy; @@ -441,24 +431,13 @@ cmdDomblkinfoPrint(vshControl *ctl, val_alloc =3D vshPrettyCapacity(info->allocation, &unit_alloc); val_phy =3D vshPrettyCapacity(info->physical, &unit_phy); =20 - if (virAsprintf(&cap, "%.3lf %s", val_cap, unit_cap) < 0 || - virAsprintf(&alloc, "%.3lf %s", val_alloc, unit_alloc) < 0 || - virAsprintf(&phy, "%.3lf %s", val_phy, unit_phy) < 0) - goto cleanup; - } - - if (device) { - vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", device, cap, alloc, phy= ); - } else { - vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap); - vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc); - vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy); + if (virAsprintf(cap, "%.3lf %s", val_cap, unit_cap) < 0 || + virAsprintf(alloc, "%.3lf %s", val_alloc, unit_alloc) < 0 || + virAsprintf(phy, "%.3lf %s", val_phy, unit_phy) < 0) + return false; } =20 - cleanup: - VIR_FREE(cap); - VIR_FREE(alloc); - VIR_FREE(phy); + return true; } =20 =20 @@ -478,6 +457,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *disks =3D NULL; char *target =3D NULL; char *protocol =3D NULL; + char *cap =3D NULL; + char *alloc =3D NULL; + char *phy =3D NULL; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -502,7 +484,10 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 /* print the title */ - cmdDomblkinfoPrint(ctl, NULL, NULL, false, true); + vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"), + _("Capacity"), _("Allocation"), _("Physical")); + vshPrintExtra(ctl, "-----------------------------" + "------------------------\n"); =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; @@ -525,7 +510,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) } } =20 - cmdDomblkinfoPrint(ctl, &info, target, human, false); + if (!cmdDomblkinfoGet(ctl, &info, &cap, &alloc, &phy, human)) + goto cleanup; + vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", target, cap, alloc,= phy); =20 VIR_FREE(target); VIR_FREE(protocol); @@ -534,12 +521,19 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) goto cleanup; =20 - cmdDomblkinfoPrint(ctl, &info, NULL, human, false); + if (!cmdDomblkinfoGet(ctl, &info, &cap, &alloc, &phy, human)) + goto cleanup; + vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap); + vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc); + vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy); } =20 ret =3D true; =20 cleanup: + VIR_FREE(cap); + VIR_FREE(alloc); + VIR_FREE(phy); virshDomainFree(dom); VIR_FREE(target); VIR_FREE(protocol); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539469320248.34532464187203; Fri, 21 Sep 2018 07:17:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 377AC5F734; Fri, 21 Sep 2018 14:17:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDEC98750A; Fri, 21 Sep 2018 14:17:46 +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 8FA49181A55B; Fri, 21 Sep 2018 14:17:46 +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 w8LEHZgm028275 for ; Fri, 21 Sep 2018 10:17:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F47C8208C; Fri, 21 Sep 2018 14:17:35 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE3517964; Fri, 21 Sep 2018 14:17:34 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:18 +0200 Message-Id: <20180921141724.18879-8-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 07/13] virsh: Implement vshTable API to domblkinfo 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Sep 2018 14:17:48 +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-monitor.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index cb48f9a7be..80c7e8a99e 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -460,6 +460,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) char *cap =3D NULL; char *alloc =3D NULL; char *phy =3D NULL; + vshTablePtr table =3D NULL; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -483,11 +484,10 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) if (ndisks < 0) goto cleanup; =20 - /* print the title */ - vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"), - _("Capacity"), _("Allocation"), _("Physical")); - vshPrintExtra(ctl, "-----------------------------" - "------------------------\n"); + /* title */ + table =3D vshTableNew(_("Target"), _("Capacity"), _("Allocation"),= _("Physical"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; @@ -512,11 +512,15 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) =20 if (!cmdDomblkinfoGet(ctl, &info, &cap, &alloc, &phy, human)) goto cleanup; - vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", target, cap, alloc,= phy); + if (vshTableRowAppend(table, target, cap, alloc, phy, NULL) < = 0) + goto cleanup; =20 VIR_FREE(target); VIR_FREE(protocol); } + + vshTablePrintToStdout(table, ctl); + } else { if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) goto cleanup; @@ -531,6 +535,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: + vshTableFree(table); VIR_FREE(cap); VIR_FREE(alloc); VIR_FREE(phy); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539476655254.39979074986718; Fri, 21 Sep 2018 07:17:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C575307D98F; Fri, 21 Sep 2018 14:17:54 +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 D25B260E3E; Fri, 21 Sep 2018 14:17:53 +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 859C84A471; Fri, 21 Sep 2018 14:17:53 +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 w8LEHaMG028285 for ; Fri, 21 Sep 2018 10:17:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2293D53C21; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F73917964; Fri, 21 Sep 2018 14:17:35 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:19 +0200 Message-Id: <20180921141724.18879-9-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 08/13] virsh: Implement vshTable API to domblklist 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Sep 2018 14:17:54 +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-monitor.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 80c7e8a99e..b887bb48d9 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -589,6 +589,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) char *device =3D NULL; char *target =3D NULL; char *source =3D NULL; + vshTablePtr table =3D NULL; =20 if (vshCommandOptBool(cmd, "inactive")) flags |=3D VIR_DOMAIN_XML_INACTIVE; @@ -603,12 +604,12 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 if (details) - vshPrintExtra(ctl, "%-10s %-10s %-10s %s\n", _("Type"), - _("Device"), _("Target"), _("Source")); + table =3D vshTableNew(_("Type"), _("Device"), _("Target"), _("Sour= ce"), NULL); else - vshPrintExtra(ctl, "%-10s %s\n", _("Target"), _("Source")); + table =3D vshTableNew(_("Target"), _("Source"), NULL); =20 - vshPrintExtra(ctl, "------------------------------------------------\n= "); + if (!table) + goto cleanup; =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; @@ -633,10 +634,13 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) "|./source/@name" "|./source/@volume)", ctxt); if (details) { - vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device, - target, source ? source : "-"); + if (vshTableRowAppend(table, type, device, target, + source ? source : "-", NULL) < 0) + goto cleanup; } else { - vshPrint(ctl, "%-10s %s\n", target, source ? source : "-"); + if (vshTableRowAppend(table, target, + source ? source : "-", NULL) < 0) + goto cleanup; } =20 VIR_FREE(source); @@ -645,9 +649,12 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) VIR_FREE(type); } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); VIR_FREE(source); VIR_FREE(target); VIR_FREE(device); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539480132515.8103332809013; Fri, 21 Sep 2018 07:18:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F89C30001D3; Fri, 21 Sep 2018 14:17:58 +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 39E017DFE6; Fri, 21 Sep 2018 14:17:58 +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 E0F5E4A46D; Fri, 21 Sep 2018 14:17:57 +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 w8LEHbuv028292 for ; Fri, 21 Sep 2018 10:17:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 269A153C21; Fri, 21 Sep 2018 14:17:37 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F61617CCB; Fri, 21 Sep 2018 14:17:36 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:20 +0200 Message-Id: <20180921141724.18879-10-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 09/13] virsh: Implement vshTable API to domiflist 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 21 Sep 2018 14:17:59 +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-monitor.c | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index b887bb48d9..4bba8438af 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -693,6 +693,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) int ninterfaces; xmlNodePtr *interfaces =3D NULL; size_t i; + vshTablePtr table =3D NULL; =20 if (vshCommandOptBool(cmd, "inactive")) flags |=3D VIR_DOMAIN_XML_INACTIVE; @@ -704,16 +705,17 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) if (ninterfaces < 0) goto cleanup; =20 - vshPrintExtra(ctl, "%-10s %-10s %-10s %-11s %s\n", _("Interface"), - _("Type"), _("Source"), _("Model"), _("MAC")); - vshPrintExtra(ctl, "--------------------------------------------------= -----\n"); + table =3D vshTableNew(_("Interface"), _("Type"), + _("Source"), _("Model"), _("MAC"), NULL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < ninterfaces; i++) { - char *type =3D NULL; - char *source =3D NULL; - char *target =3D NULL; - char *model =3D NULL; - char *mac =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) source =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) mac =3D NULL; =20 ctxt->node =3D interfaces[i]; type =3D virXPathString("string(./@type)", ctxt); @@ -727,23 +729,22 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) model =3D virXPathString("string(./model/@type)", ctxt); mac =3D virXPathString("string(./mac/@address)", ctxt); =20 - vshPrint(ctl, "%-10s %-10s %-10s %-11s %-10s\n", - target ? target : "-", - type, - source ? source : "-", - model ? model : "-", - mac ? mac : "-"); - - VIR_FREE(type); - VIR_FREE(source); - VIR_FREE(target); - VIR_FREE(model); - VIR_FREE(mac); + if (vshTableRowAppend(table, + target ? target : "-", + type, + source ? source : "-", + model ? model : "-", + mac ? mac : "-", + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); VIR_FREE(interfaces); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 From nobody Sun May 5 01:20:36 2024 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 1537539473451464.07784412858666; Fri, 21 Sep 2018 07:17:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A603B4DD62; Fri, 21 Sep 2018 14:17:51 +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 64513308BDB2; Fri, 21 Sep 2018 14:17:51 +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 13DC54A46E; Fri, 21 Sep 2018 14:17:51 +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 w8LEHd3o028315 for ; Fri, 21 Sep 2018 10:17:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2858917964; Fri, 21 Sep 2018 14:17:39 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75B6A8208E; Fri, 21 Sep 2018 14:17:38 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:22 +0200 Message-Id: <20180921141724.18879-12-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 11/13] virsh: Implement vshTable API to pool-list 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Sep 2018 14:17:52 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Local lengthy unicode-unreliable table formatting was replaced by new API. Great example of how new API saves space and time. Removed a lot of string lenght canculation used by the local table. Signed-off-by: Simon Kobyda --- tools/virsh-pool.c | 162 +++++++++------------------------------------ 1 file changed, 31 insertions(+), 131 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 89206a48f5..75ec572af2 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -33,6 +33,7 @@ #include "conf/storage_conf.h" #include "virstring.h" #include "virtime.h" +#include "vsh-table.h" =20 #define VIRSH_COMMON_OPT_POOL_FULL(cflags) \ VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags) @@ -1113,10 +1114,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) virStoragePoolInfo info; size_t i; bool ret =3D false; - size_t stringLength =3D 0, nameStrLength =3D 0; - size_t autostartStrLength =3D 0, persistStrLength =3D 0; - size_t stateStrLength =3D 0, capStrLength =3D 0; - size_t allocStrLength =3D 0, availStrLength =3D 0; struct poolInfoText { char *state; char *autostart; @@ -1133,7 +1130,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIB= UTE_UNUSED) bool inactive, all; bool uuid =3D false; bool name =3D false; - char *outputStr =3D NULL; + vshTablePtr table =3D NULL; =20 inactive =3D vshCommandOptBool(cmd, "inactive"); all =3D vshCommandOptBool(cmd, "all"); @@ -1260,11 +1257,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) else poolInfoTexts[i].persistent =3D vshStrdup(ctl, persistent ? _("yes") : _("no"= )); - - /* Keep the length of persistent string if longest so far */ - stringLength =3D strlen(poolInfoTexts[i].persistent); - if (stringLength > persistStrLength) - persistStrLength =3D stringLength; } =20 /* Collect further extended information about the pool */ @@ -1310,21 +1302,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) poolInfoTexts[i].allocation =3D vshStrdup(ctl, _("-")); poolInfoTexts[i].available =3D vshStrdup(ctl, _("-")); } - - /* Keep the length of capacity string if longest so far */ - stringLength =3D strlen(poolInfoTexts[i].capacity); - if (stringLength > capStrLength) - capStrLength =3D stringLength; - - /* Keep the length of allocation string if longest so far = */ - stringLength =3D strlen(poolInfoTexts[i].allocation); - if (stringLength > allocStrLength) - allocStrLength =3D stringLength; - - /* Keep the length of available string if longest so far */ - stringLength =3D strlen(poolInfoTexts[i].available); - if (stringLength > availStrLength) - availStrLength =3D stringLength; } else { /* --details option was not specified, only active/inactive * state strings are used */ @@ -1334,21 +1311,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) poolInfoTexts[i].state =3D vshStrdup(ctl, _("inactive"= )); } } - - /* Keep the length of name string if longest so far */ - stringLength =3D strlen(virStoragePoolGetName(list->pools[i])); - if (stringLength > nameStrLength) - nameStrLength =3D stringLength; - - /* Keep the length of state string if longest so far */ - stringLength =3D strlen(poolInfoTexts[i].state); - if (stringLength > stateStrLength) - stateStrLength =3D stringLength; - - /* Keep the length of autostart string if longest so far */ - stringLength =3D strlen(poolInfoTexts[i].autostart); - if (stringLength > autostartStrLength) - autostartStrLength =3D stringLength; } =20 /* If the --details option wasn't selected, we output the pool @@ -1376,19 +1338,23 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) } =20 /* Output old style header */ - vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), - _("Autostart")); - vshPrintExtra(ctl, "-------------------------------------------\n"= ); + table =3D vshTableNew(_("Name"), _("State"), _("Autostart"), NULL); + if (!table) + goto cleanup; =20 /* Output old style pool info */ for (i =3D 0; i < list->npools; i++) { const char *name_str =3D virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, " %-20s %-10s %-10s\n", - name_str, - poolInfoTexts[i].state, - poolInfoTexts[i].autostart); + if (vshTableRowAppend(table, + name_str, + poolInfoTexts[i].state, + poolInfoTexts[i].autostart, + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + /* Cleanup and return */ ret =3D true; goto cleanup; @@ -1396,99 +1362,33 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTR= IBUTE_UNUSED) =20 /* We only get here if the --details option was selected. */ =20 - /* Use the length of name header string if it's longest */ - stringLength =3D strlen(_("Name")); - if (stringLength > nameStrLength) - nameStrLength =3D stringLength; - - /* Use the length of state header string if it's longest */ - stringLength =3D strlen(_("State")); - if (stringLength > stateStrLength) - stateStrLength =3D stringLength; - - /* Use the length of autostart header string if it's longest */ - stringLength =3D strlen(_("Autostart")); - if (stringLength > autostartStrLength) - autostartStrLength =3D stringLength; - - /* Use the length of persistent header string if it's longest */ - stringLength =3D strlen(_("Persistent")); - if (stringLength > persistStrLength) - persistStrLength =3D stringLength; - - /* Use the length of capacity header string if it's longest */ - stringLength =3D strlen(_("Capacity")); - if (stringLength > capStrLength) - capStrLength =3D stringLength; - - /* Use the length of allocation header string if it's longest */ - stringLength =3D strlen(_("Allocation")); - if (stringLength > allocStrLength) - allocStrLength =3D stringLength; - - /* Use the length of available header string if it's longest */ - stringLength =3D strlen(_("Available")); - if (stringLength > availStrLength) - availStrLength =3D stringLength; - - /* Display the string lengths for debugging. */ - vshDebug(ctl, VSH_ERR_DEBUG, "Longest name string =3D %lu chars\n", - (unsigned long) nameStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest state string =3D %lu chars\n", - (unsigned long) stateStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest autostart string =3D %lu chars\n= ", - (unsigned long) autostartStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest persistent string =3D %lu chars\= n", - (unsigned long) persistStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest capacity string =3D %lu chars\n", - (unsigned long) capStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest allocation string =3D %lu chars\= n", - (unsigned long) allocStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, "Longest available string =3D %lu chars\n= ", - (unsigned long) availStrLength); - - /* Create the output template. Each column is sized according to - * the longest string. - */ - if (virAsprintf(&outputStr, - " %%-%lus %%-%lus %%-%lus %%-%lus %%%lus %%%lus = %%%lus\n", - (unsigned long) nameStrLength, - (unsigned long) stateStrLength, - (unsigned long) autostartStrLength, - (unsigned long) persistStrLength, - (unsigned long) capStrLength, - (unsigned long) allocStrLength, - (unsigned long) availStrLength) < 0) + /* Insert the header into table */ + table =3D vshTableNew(_("Name"), _("State"), _("Autostart"), _("Persis= tent"), + _("Capacity"), _("Allocation"), _("Available"), NU= LL); + if (!table) goto cleanup; =20 - /* Display the header */ - vshPrintExtra(ctl, outputStr, _("Name"), _("State"), _("Autostart"), - _("Persistent"), _("Capacity"), _("Allocation"), - _("Available")); - for (i =3D nameStrLength + stateStrLength + autostartStrLength - + persistStrLength + capStrLength - + allocStrLength + availStrLength - + 14; i > 0; i--) - vshPrintExtra(ctl, "-"); - vshPrintExtra(ctl, "\n"); - - /* Display the pool info rows */ + /* Insert the pool info rows into table*/ for (i =3D 0; i < list->npools; i++) { - vshPrint(ctl, outputStr, - virStoragePoolGetName(list->pools[i]), - poolInfoTexts[i].state, - poolInfoTexts[i].autostart, - poolInfoTexts[i].persistent, - poolInfoTexts[i].capacity, - poolInfoTexts[i].allocation, - poolInfoTexts[i].available); + if (vshTableRowAppend(table, + virStoragePoolGetName(list->pools[i]), + poolInfoTexts[i].state, + poolInfoTexts[i].autostart, + poolInfoTexts[i].persistent, + poolInfoTexts[i].capacity, + poolInfoTexts[i].allocation, + poolInfoTexts[i].available, + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + /* Cleanup and return */ ret =3D true; =20 cleanup: - VIR_FREE(outputStr); + vshTableFree(table); if (list && list->npools) { for (i =3D 0; i < list->npools; i++) { VIR_FREE(poolInfoTexts[i].state); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539478032387.53652034131585; Fri, 21 Sep 2018 07:17:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DC27C03D47F; Fri, 21 Sep 2018 14:17:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED79280F75; Fri, 21 Sep 2018 14:17:55 +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 9BF41181A530; Fri, 21 Sep 2018 14:17:55 +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 w8LEHeaZ028326 for ; Fri, 21 Sep 2018 10:17:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 28C938209A; Fri, 21 Sep 2018 14:17:40 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76F5053C21; Fri, 21 Sep 2018 14:17:39 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:23 +0200 Message-Id: <20180921141724.18879-13-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 12/13] virsh: Implement vshTable API to vol-list 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Sep 2018 14:17:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Local lengthy unicode-unreliable table formatting was replaced by new API. Great example of how new API saves space and time. Removed a lot of string lenght calculation used by the local table. Signed-off-by: Simon Kobyda --- tools/virsh-volume.c | 129 ++++++++++--------------------------------- 1 file changed, 28 insertions(+), 101 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 42d11701ec..6cd989446e 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -42,6 +42,7 @@ #include "virsh-pool.h" #include "virxml.h" #include "virstring.h" +#include "vsh-table.h" =20 #define VIRSH_COMMON_OPT_POOL_FULL \ VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \ @@ -1382,16 +1383,11 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) { virStorageVolInfo volumeInfo; virStoragePoolPtr pool; - char *outputStr =3D NULL; const char *unit; double val; bool details =3D vshCommandOptBool(cmd, "details"); size_t i; bool ret =3D false; - int stringLength =3D 0; - size_t allocStrLength =3D 0, capStrLength =3D 0; - size_t nameStrLength =3D 0, pathStrLength =3D 0; - size_t typeStrLength =3D 0; struct volInfoText { char *allocation; char *capacity; @@ -1400,6 +1396,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBU= TE_UNUSED) }; struct volInfoText *volInfoTexts =3D NULL; virshStorageVolListPtr list =3D NULL; + vshTablePtr table =3D NULL; =20 /* Look up the pool information given to us by the user */ if (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -1446,36 +1443,6 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIB= UTE_UNUSED) "%.2lf %s", val, unit) < 0) goto cleanup; } - - /* Remember the largest length for each output string. - * This lets us displaying header and volume information rows - * using a single, properly sized, printf style output string. - */ - - /* Keep the length of name string if longest so far */ - stringLength =3D strlen(virStorageVolGetName(list->vols[i])); - if (stringLength > nameStrLength) - nameStrLength =3D stringLength; - - /* Keep the length of path string if longest so far */ - stringLength =3D strlen(volInfoTexts[i].path); - if (stringLength > pathStrLength) - pathStrLength =3D stringLength; - - /* Keep the length of type string if longest so far */ - stringLength =3D strlen(volInfoTexts[i].type); - if (stringLength > typeStrLength) - typeStrLength =3D stringLength; - - /* Keep the length of capacity string if longest so far */ - stringLength =3D strlen(volInfoTexts[i].capacity); - if (stringLength > capStrLength) - capStrLength =3D stringLength; - - /* Keep the length of allocation string if longest so far */ - stringLength =3D strlen(volInfoTexts[i].allocation); - if (stringLength > allocStrLength) - allocStrLength =3D stringLength; } } =20 @@ -1487,14 +1454,20 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) /* Output basic info then return if --details option not selected */ if (!details) { /* The old output format */ - vshPrintExtra(ctl, " %-20s %-40s\n", _("Name"), _("Path")); - vshPrintExtra(ctl, "---------------------------------------" - "---------------------------------------\n"); + table =3D vshTableNew(_("Name"), _("Path"), NULL); + if (!table) + goto cleanup; + for (i =3D 0; i < list->nvols; i++) { - vshPrint(ctl, " %-20s %-40s\n", virStorageVolGetName(list->vol= s[i]), - volInfoTexts[i].path); + if (vshTableRowAppend(table, + virStorageVolGetName(list->vols[i]), + volInfoTexts[i].path, + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + /* Cleanup and return */ ret =3D true; goto cleanup; @@ -1502,75 +1475,30 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRI= BUTE_UNUSED) =20 /* We only get here if the --details option was selected. */ =20 - /* Use the length of name header string if it's longest */ - stringLength =3D strlen(_("Name")); - if (stringLength > nameStrLength) - nameStrLength =3D stringLength; - - /* Use the length of path header string if it's longest */ - stringLength =3D strlen(_("Path")); - if (stringLength > pathStrLength) - pathStrLength =3D stringLength; - - /* Use the length of type header string if it's longest */ - stringLength =3D strlen(_("Type")); - if (stringLength > typeStrLength) - typeStrLength =3D stringLength; - - /* Use the length of capacity header string if it's longest */ - stringLength =3D strlen(_("Capacity")); - if (stringLength > capStrLength) - capStrLength =3D stringLength; - - /* Use the length of allocation header string if it's longest */ - stringLength =3D strlen(_("Allocation")); - if (stringLength > allocStrLength) - allocStrLength =3D stringLength; - - /* Display the string lengths for debugging */ - vshDebug(ctl, VSH_ERR_DEBUG, - "Longest name string =3D %zu chars\n", nameStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, - "Longest path string =3D %zu chars\n", pathStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, - "Longest type string =3D %zu chars\n", typeStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, - "Longest capacity string =3D %zu chars\n", capStrLength); - vshDebug(ctl, VSH_ERR_DEBUG, - "Longest allocation string =3D %zu chars\n", allocStrLength); - - if (virAsprintf(&outputStr, - " %%-%lus %%-%lus %%-%lus %%%lus %%%lus\n", - (unsigned long) nameStrLength, - (unsigned long) pathStrLength, - (unsigned long) typeStrLength, - (unsigned long) capStrLength, - (unsigned long) allocStrLength) < 0) + /* Insert the header into table */ + table =3D vshTableNew(_("Name"), _("Path"), _("Type"), _("Capacity"), = _("Allocation"), NULL); + if (!table) goto cleanup; =20 - /* Display the header */ - vshPrintExtra(ctl, outputStr, _("Name"), _("Path"), _("Type"), - _("Capacity"), _("Allocation")); - for (i =3D nameStrLength + pathStrLength + typeStrLength - + capStrLength + allocStrLength - + 10; i > 0; i--) - vshPrintExtra(ctl, "-"); - vshPrintExtra(ctl, "\n"); - - /* Display the volume info rows */ + /* Insert the volume info rows into table */ for (i =3D 0; i < list->nvols; i++) { - vshPrint(ctl, outputStr, - virStorageVolGetName(list->vols[i]), - volInfoTexts[i].path, - volInfoTexts[i].type, - volInfoTexts[i].capacity, - volInfoTexts[i].allocation); + if (vshTableRowAppend(table, + virStorageVolGetName(list->vols[i]), + volInfoTexts[i].path, + volInfoTexts[i].type, + volInfoTexts[i].capacity, + volInfoTexts[i].allocation, + NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + /* Cleanup and return */ ret =3D true; =20 cleanup: + vshTableFree(table); =20 /* Safely free the memory allocated in this function */ if (list && list->nvols) { @@ -1584,7 +1512,6 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBU= TE_UNUSED) } =20 /* Cleanup remaining memory */ - VIR_FREE(outputStr); VIR_FREE(volInfoTexts); virStoragePoolFree(pool); virshStorageVolListFree(list); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 01:20:36 2024 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 1537539468377231.88616581094539; Fri, 21 Sep 2018 07:17:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85D9D30022E8; Fri, 21 Sep 2018 14:17:46 +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 459127DFE0; Fri, 21 Sep 2018 14:17:46 +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 C7B724A46C; Fri, 21 Sep 2018 14:17:45 +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 w8LEHf0h028333 for ; Fri, 21 Sep 2018 10:17:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A7BC8208E; Fri, 21 Sep 2018 14:17:41 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 786138209A; Fri, 21 Sep 2018 14:17:40 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Fri, 21 Sep 2018 16:17:24 +0200 Message-Id: <20180921141724.18879-14-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 13/13] virt-admin: Implement vshTable API to server-list and client-list 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 21 Sep 2018 14:17:47 +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/virt-admin.c | 47 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 63822bc13e..d119e4d960 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -40,6 +40,7 @@ #include "virgettext.h" #include "virtime.h" #include "virt-admin-completer.h" +#include "vsh-table.h" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -382,6 +383,7 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE= _UNUSED) char *uri =3D NULL; virAdmServerPtr *srvs =3D NULL; vshAdmControlPtr priv =3D ctl->privData; + vshTablePtr table =3D NULL; =20 /* Obtain a list of available servers on the daemon */ if ((nsrvs =3D virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) { @@ -391,13 +393,27 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBU= TE_UNUSED) goto cleanup; } =20 - vshPrintExtra(ctl, " %-5s %-15s\n", "Id", "Name"); - vshPrintExtra(ctl, "---------------\n"); - for (i =3D 0; i < nsrvs; i++) - vshPrint(ctl, " %-5zu %-15s\n", i, virAdmServerGetName(srvs[i])); + table =3D vshTableNew(_("Id"), _("Name"), NULL); + if (!table) + goto cleanup; + + for (i =3D 0; i < nsrvs; i++) { + VIR_AUTOFREE(char *) idStr =3D NULL; + if (virAsprintf(&idStr, "%lu", i) < 0) + goto cleanup; + + if (vshTableRowAppend(table, + idStr, + virAdmServerGetName(srvs[i]), + NULL) < 0) + goto cleanup; + } + + vshTablePrintToStdout(table, ctl); =20 ret =3D true; cleanup: + vshTableFree(table); if (srvs) { for (i =3D 0; i < nsrvs; i++) virAdmServerFree(srvs[i]); @@ -613,10 +629,10 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) const char *srvname =3D NULL; unsigned long long id; virClientTransport transport; - char *timestr =3D NULL; virAdmServerPtr srv =3D NULL; virAdmClientPtr *clts =3D NULL; vshAdmControlPtr priv =3D ctl->privData; + vshTablePtr table =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0) return false; @@ -631,12 +647,13 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - vshPrintExtra(ctl, " %-5s %-15s %-15s\n%s\n", _("Id"), _("Transport"), - _("Connected since"), - "-------------------------" - "-------------------------"); + table =3D vshTableNew(_("Id"), _("Transport"), _("Connected sice"), NU= LL); + if (!table) + goto cleanup; =20 for (i =3D 0; i < nclts; i++) { + VIR_AUTOFREE(char *) timestr =3D NULL; + VIR_AUTOFREE(char *) idStr =3D NULL; virAdmClientPtr client =3D clts[i]; id =3D virAdmClientGetID(client); transport =3D virAdmClientGetTransport(client); @@ -644,14 +661,20 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) ×tr) < 0) goto cleanup; =20 - vshPrint(ctl, " %-5llu %-15s %-15s\n", - id, vshAdmClientTransportToString(transport), timestr); - VIR_FREE(timestr); + if (virAsprintf(&idStr, "%llu", id) < 0) + goto cleanup; + if (vshTableRowAppend(table, idStr, + vshAdmClientTransportToString(transport), + timestr, NULL) < 0) + goto cleanup; } =20 + vshTablePrintToStdout(table, ctl); + ret =3D true; =20 cleanup: + vshTableFree(table); if (clts) { for (i =3D 0; i < nclts; i++) virAdmClientFree(clts[i]); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list