From nobody Wed May 14 07:22:51 2025 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=126.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1529402533143121.42285022394265; Tue, 19 Jun 2018 03:02:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA2B8C049D5B; Tue, 19 Jun 2018 10:02:11 +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 7EF9C600C6; Tue, 19 Jun 2018 10:02:11 +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 237E81800537; Tue, 19 Jun 2018 10:02:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5JA1w8o016665 for ; Tue, 19 Jun 2018 06:01:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9F8660E37; Tue, 19 Jun 2018 10:01:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A652A60BEC for ; Tue, 19 Jun 2018 10:01:49 +0000 (UTC) Received: from m15-113.126.com (m15-113.126.com [220.181.15.113]) by mx1.redhat.com (Postfix) with ESMTP id 768AA3084029 for ; Tue, 19 Jun 2018 10:01:45 +0000 (UTC) Received: from localhost.localdomain (unknown [58.213.111.46]) by smtp3 (Coremail) with SMTP id DcmowACX_OV41Chb9lyYAw--.65231S5; Tue, 19 Jun 2018 18:01:43 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=i/R4G/sxo0C+YoPaPi Lm2lySoQhnVVqZSZ6SWqw/SZE=; b=bwyOk3l/O8rKgRI/5rJuQ6M2Hyc1F0VjvQ qeLDAxPFFxubREiVtJDmmjbf/a49eVqbn9BxVfXe2QbcHHpDmnI+39Ni27mqtQWU 1IqCzANlDfeON1dsnDw3GIALBgQH9sF5J+ed0HscDOUT5/DF8i627N4qhdOxluG/ 0YBWLdh4c= From: Chen Hanxiao To: libvir-list@redhat.com Date: Tue, 19 Jun 2018 18:01:25 +0800 Message-Id: <20180619100126.28086-4-chen_han_xiao@126.com> In-Reply-To: <20180619100126.28086-1-chen_han_xiao@126.com> References: <20180619100126.28086-1-chen_han_xiao@126.com> X-CM-TRANSID: DcmowACX_OV41Chb9lyYAw--.65231S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxJF17Cr47Jw4xWr13Kr4rXwb_yoWrGFWDpa n8Xryvvwn3GFnxZrsI934DKFn8K34Ivr1FqFs2g34rArsrurs7WrnIvFyY9Fy5Ar4YyF1U CrnxJ3WxWw10y37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UXTmgUUUUU= X-Originating-IP: [58.213.111.46] X-CM-SenderInfo: xfkh0spkdqs5xldrqiyswou0bp/1tbitQhqrlpD58-i1AAAs+ X-Greylist: Sender passed SPF test, ACL 227 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 19 Jun 2018 10:01:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 19 Jun 2018 10:01:47 +0000 (UTC) for IP:'220.181.15.113' DOMAIN:'m15-113.126.com' HELO:'m15-113.126.com' FROM:'chen_han_xiao@126.com' RCPT:'' X-RedHat-Spam-Score: 0.7 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_ANBREP_L2, SPF_PASS) 220.181.15.113 m15-113.126.com 220.181.15.113 m15-113.126.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Chen Hanxiao Subject: [libvirt] [PATCH v3 3/4] cmdDomblkinfoPrint: support printing "-" for invalid virDomainBlockInfo 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 19 Jun 2018 10:02:12 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Chen Hanxiao For inactive domain, we'll set virDomainBlockInfo to 0 if specific error code got. Print "-" to show the value should be ignored in this scenario. Signed-off-by: Chen Hanxiao --- tools/virsh-domain-monitor.c | 73 ++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 43e39f79c1..3acf5450b3 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -410,6 +410,15 @@ cmdDomblkinfoPrint(vshControl *ctl, bool human, bool title) { char *cap =3D NULL, *alloc =3D NULL, *phy =3D NULL; + bool invalid =3D false; + + struct blockInfoText { + char *capacity; + char *allocation; + char *physical; + }; + + struct blockInfoText *blkInfoText =3D NULL; =20 if (title) { vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"), @@ -419,15 +428,23 @@ cmdDomblkinfoPrint(vshControl *ctl, return; } =20 - if (!human) { - if (device) { - vshPrint(ctl, "%-10s %-15llu %-15llu %-15llu\n", device, - info->capacity, info->allocation, info->physical); - } else { - vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info->capacity); - vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info->allocati= on); - vshPrint(ctl, "%-15s %llu\n", _("Physical:"), info->physical); - } + invalid =3D info->capacity =3D=3D 0 && + info->allocation =3D=3D 0 && + info->physical =3D=3D 0; + blkInfoText =3D vshCalloc(ctl, 1, sizeof(*blkInfoText)); + + if (invalid) { + blkInfoText->capacity =3D vshStrdup(ctl, "-"); + blkInfoText->allocation =3D vshStrdup(ctl, "-"); + blkInfoText->physical =3D vshStrdup(ctl, "-"); + } else if (!human) { + if (virAsprintf(&blkInfoText->capacity, "%llu", + info->capacity) < 0 || + virAsprintf(&blkInfoText->allocation, "%llu", + info->allocation) < 0 || + virAsprintf(&blkInfoText->physical, "%llu", + info->physical) < 0) + goto cleanup; } else { double val_cap, val_alloc, val_phy; const char *unit_cap, *unit_alloc, *unit_phy; @@ -435,28 +452,36 @@ cmdDomblkinfoPrint(vshControl *ctl, val_cap =3D vshPrettyCapacity(info->capacity, &unit_cap); val_alloc =3D vshPrettyCapacity(info->allocation, &unit_alloc); val_phy =3D vshPrettyCapacity(info->physical, &unit_phy); - if (device) { - 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; =20 - vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", - device, cap, alloc, phy); - } else { - vshPrint(ctl, "%-15s %-.3lf %s\n", _("Capacity:"), - val_cap, unit_cap); - vshPrint(ctl, "%-15s %-.3lf %s\n", _("Allocation:"), - val_alloc, unit_alloc); - vshPrint(ctl, "%-15s %-.3lf %s\n", _("Physical:"), - val_phy, unit_phy); - } + if (virAsprintf(&blkInfoText->capacity, "%.3lf %s", + val_cap, unit_cap) < 0 || + virAsprintf(&blkInfoText->allocation, "%.3lf %s", + val_alloc, unit_alloc) < 0 || + virAsprintf(&blkInfoText->physical, "%.3lf %s", + val_phy, unit_phy) < 0) + goto cleanup; + } + + if (device) { + vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", device, + blkInfoText->capacity, blkInfoText->allocation, + blkInfoText->physical); + } else { + vshPrint(ctl, "%-15s %s\n", _("Capacity:"), blkInfoText->capacity); + vshPrint(ctl, "%-15s %s\n", _("Allocation:"), blkInfoText->allocat= ion); + vshPrint(ctl, "%-15s %s\n", _("Physical:"), blkInfoText->physical); } =20 cleanup: VIR_FREE(cap); VIR_FREE(alloc); VIR_FREE(phy); + if (blkInfoText) { + VIR_FREE(blkInfoText->capacity); + VIR_FREE(blkInfoText->allocation); + VIR_FREE(blkInfoText->physical); + } + VIR_FREE(blkInfoText); } =20 static bool --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list