From nobody Sat Nov 23 14:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1724078351063934.4974029526276; Mon, 19 Aug 2024 07:39:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E87C2167B; Mon, 19 Aug 2024 10:39:09 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 040471607; Mon, 19 Aug 2024 10:38:39 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 471F3BFA; Mon, 19 Aug 2024 10:38:36 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C60D5B24 for ; Mon, 19 Aug 2024 10:38:35 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-mIZoB5o8MvO4w_buWMPJCA-1; Mon, 19 Aug 2024 10:38:33 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BBAD01955BEE for ; Mon, 19 Aug 2024 14:38:32 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EEED31955BF8 for ; Mon, 19 Aug 2024 14:38:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724078315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cWRFt41lGCNMVZHDiWBPOAvNIMVV8zJ2K0JKf3mZmoE=; b=CjC6rmZjZcIBkspRi4gDJFx+fYh7y1b8tRkYWNF0FQKn6y13DCIUZAc9GhJ3SU3qx1HoH9 lGF2V003PHvIb6EyhWs69Xg+ZxQ7p4fA3jMusiQi+ceoWrEGZSoWaj8z2FxS1ZNmA9zd5U 9jAnFDGNbUxwFzj04Wl8qp5YSKQwm4w= X-MC-Unique: mIZoB5o8MvO4w_buWMPJCA-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 1/2] virsh: Simplify vshTableRowAppend() calling in cmdList(), part one Date: Mon, 19 Aug 2024 16:38:27 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OUTL7MT77B4PITJJG367UJUGB4GWRJGL X-Message-ID-Hash: OUTL7MT77B4PITJJG367UJUGB4GWRJGL X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724078352785116600 Content-Type: text/plain; charset="utf-8"; x-default="true" All calls to vshTableRowAppend() inside of cmdList() share couple of same arguments: domain ID, domain name and domain state. While the first one is stored in a variable and then passed to all vshTableRowAppend() calls, the others are passed as a function call. Switch the latter to variables too. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tools/virsh-domain-monitor.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 37184baa69..80b6857fad 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1889,6 +1889,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd) ignore_value(virStrcpyStatic(id_buf, "-")); =20 if (optTable) { + const char *domName =3D virDomainGetName(dom); + const char *stateStr =3D NULL; + state =3D virshDomainState(ctl, dom, NULL); =20 /* Domain could've been removed in the meantime */ @@ -1896,8 +1899,11 @@ cmdList(vshControl *ctl, const vshCmd *cmd) continue; =20 if (managed && state =3D=3D VIR_DOMAIN_SHUTOFF && - virDomainHasManagedSaveImage(dom, 0) > 0) - state =3D -2; + virDomainHasManagedSaveImage(dom, 0) > 0) { + stateStr =3D _("saved"); + } else { + stateStr =3D virshDomainStateToString(state); + } =20 if (optTitle && !optUUID) { g_autofree char *title =3D NULL; @@ -1905,9 +1911,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) if (!(title =3D virshGetDomainDescription(ctl, dom, true, = 0))) goto cleanup; if (vshTableRowAppend(table, id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state), + domName, stateStr, title, NULL) < 0) goto cleanup; } else if (optUUID && !optTitle) { @@ -1916,9 +1920,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) goto cleanup; } if (vshTableRowAppend(table, id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state), + domName, stateStr, uuid, NULL) < 0) goto cleanup; } else if (optUUID && optTitle) { @@ -1931,16 +1933,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd) goto cleanup; } if (vshTableRowAppend(table, id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state), + domName, stateStr, title, uuid, NULL) < 0) goto cleanup; } else { if (vshTableRowAppend(table, id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state), + domName, stateStr, NULL) < 0) goto cleanup; } --=20 2.44.2 From nobody Sat Nov 23 14:58:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1724078367610439.8771517383442; Mon, 19 Aug 2024 07:39:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87D0715D7; Mon, 19 Aug 2024 10:39:26 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7CCC51525; Mon, 19 Aug 2024 10:38:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 921E8B26; Mon, 19 Aug 2024 10:38:36 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 23628930 for ; Mon, 19 Aug 2024 10:38:36 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-47cGM51NMM-TUTC88BwOwA-1; Mon, 19 Aug 2024 10:38:34 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B60891955BF7 for ; Mon, 19 Aug 2024 14:38:33 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F4611955BFA for ; Mon, 19 Aug 2024 14:38:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724078315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cDJIqM7EvcPK+YgNV42zUZRe1/6zfrcWUJtRHMPJ3Og=; b=ckmiyQIMNUjVZ+/TzI0egXC51D8QqcKq7hyaBmEdYwyM9vNdGTBf7VGXublW0ahum7Aay/ 7ajt1JjJ8K8JkkZGGmPKvgQjUUzGB/vpofqb2PR1Sh4WVcFPxG7sCaWoES5MB05R9vCDbk AG/bdwqcWREInlnOJyvo67n+ZOvdgaI= X-MC-Unique: 47cGM51NMM-TUTC88BwOwA-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 2/2] virsh: Simplify vshTableRowAppend() calling in cmdList(), part two Date: Mon, 19 Aug 2024 16:38:28 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ILZNSDGQV33ZPRXTD2X5V2JESHZM3DZV X-Message-ID-Hash: ILZNSDGQV33ZPRXTD2X5V2JESHZM3DZV X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724078368898116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Instead of having many if-else statements, each with its own vshTableRowAppend() call, we can use a simple trick - have an array of string pointers, set array members in the if bodies and then call vshTableRowAppend() once. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tools/virsh-domain-monitor.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 80b6857fad..87efd86a69 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1891,6 +1891,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) if (optTable) { const char *domName =3D virDomainGetName(dom); const char *stateStr =3D NULL; + g_autofree char *title =3D NULL; + const char *arg[2] =3D {}; =20 state =3D virshDomainState(ctl, dom, NULL); =20 @@ -1906,43 +1908,33 @@ cmdList(vshControl *ctl, const vshCmd *cmd) } =20 if (optTitle && !optUUID) { - g_autofree char *title =3D NULL; - if (!(title =3D virshGetDomainDescription(ctl, dom, true, = 0))) goto cleanup; - if (vshTableRowAppend(table, id_buf, - domName, stateStr, - title, NULL) < 0) - goto cleanup; + + arg[0] =3D title; } else if (optUUID && !optTitle) { if (virDomainGetUUIDString(dom, uuid) < 0) { vshError(ctl, "%s", _("Failed to get domain's UUID")); goto cleanup; } - if (vshTableRowAppend(table, id_buf, - domName, stateStr, - uuid, NULL) < 0) - goto cleanup; + + arg[0] =3D uuid; } else if (optUUID && optTitle) { - g_autofree char *title =3D NULL; - if (!(title =3D virshGetDomainDescription(ctl, dom, true, = 0))) goto cleanup; if (virDomainGetUUIDString(dom, uuid) < 0) { vshError(ctl, "%s", _("Failed to get domain's UUID")); goto cleanup; } - if (vshTableRowAppend(table, id_buf, - domName, stateStr, - title, uuid, NULL) < 0) - goto cleanup; - } else { - if (vshTableRowAppend(table, id_buf, - domName, stateStr, - NULL) < 0) - goto cleanup; + + arg[0] =3D title; + arg[1] =3D uuid; } =20 + if (vshTableRowAppend(table, id_buf, + domName, stateStr, + arg[0], arg[1], NULL) < 0) + goto cleanup; } else { if (optUUID) { if (virDomainGetUUIDString(dom, uuid) < 0) { --=20 2.44.2