From nobody Sun Apr 28 17:30:52 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.zoho.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1493678175561810.1543716627953; Mon, 1 May 2017 15:36:15 -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 C58A019F0FA; Mon, 1 May 2017 22:36:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CBD4176B2; Mon, 1 May 2017 22:36:13 +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 29BE65EC63; Mon, 1 May 2017 22:36:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v41MaBwk006402 for ; Mon, 1 May 2017 18:36:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B21671C8E; Mon, 1 May 2017 22:36:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5411071C82 for ; Mon, 1 May 2017 22:36:08 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 490F766CEE for ; Mon, 1 May 2017 22:36:07 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id c45so18040193qtb.0 for ; Mon, 01 May 2017 15:36:07 -0700 (PDT) Received: from localhost.localdomain ([186.223.99.170]) by smtp.googlemail.com with ESMTPSA id t23sm11913050qka.37.2017.05.01.15.36.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 May 2017 15:36:05 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C58A019F0FA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C58A019F0FA Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QTLUSXDV" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 490F766CEE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 490F766CEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=xxq9H4xsEusSLy438REe0KmwIzQ9OCbnQolxOtALTh4=; b=QTLUSXDV5AV5kSirPmwWUUCRMGUep9BzemQbr+p2kKjR5P/wkV5vFs1KrGE5BzV8pJ sRKk1wshFWOjtS6Ai0ybBQ/QVRQTTy/t4Y54YjOqBDTe4ZUXWYVN3jLgLGE6ryIF9HEW w0F0O8V6IuCj5EfvcBrdnLD44FwWiilVvSCjOKOmpgO4w/YLPb+Ft8kiNgUwsQwRSRRI uFImuwxcZyTXfy3dvMuOhZAITo2+orALcCMNkJrKoHkCMHdg0+0+AHAPUVMqV7/fFE7v ZaPwoE+x29cmA2cvecNF1Iplm8b4zNA5yFrQxXEutsBoAmNs2eT+nSSyD/24YaGMyhEP 8SBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=xxq9H4xsEusSLy438REe0KmwIzQ9OCbnQolxOtALTh4=; b=MA66yXf6jhKvc961dVdDDjTistJvB/IJtOb67VqqHdjHUUpTHlBPK6qy9NQq+q518i BlywelvCzWiiVtprO+Qd2zUuJ2NG31GFyJ/I+/0BKc+GQod5pv7M1bE9MgeY59CAWz/f PTN33hMgzMYg7pZEx1iHrOfAILXIlApkLWLyW1GdJw3zkHsDwSkiXfUUli5QdLFbAEG0 dTQ0SfI9Czu1rW4acivJjrftmUe01ZfmXdQHgRgdR2x9ggTqWlgXNbBhDZSUsgevh+s9 KESaO2KjEo4AD/FWI3zvD053AiJpcyotTjUnfswVIfAJkfFlD5ARP++6tNxoTKMHY29w Ah5Q== X-Gm-Message-State: AN3rC/7W15lEgtZVr7qObRaoCwaP/AKQlCs49RfzB69acBSCp3agrWHd tsLyrQVISQLJJST1 X-Received: by 10.200.34.162 with SMTP id f31mr25479836qta.65.1493678166315; Mon, 01 May 2017 15:36:06 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Mon, 1 May 2017 19:35:55 -0300 Message-Id: <1493678155-10011-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 01 May 2017 22:36:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 01 May 2017 22:36:07 +0000 (UTC) for IP:'209.85.216.195' DOMAIN:'mail-qt0-f195.google.com' HELO:'mail-qt0-f195.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.17 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.195 mail-qt0-f195.google.com 209.85.216.195 mail-qt0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh-domain-monitor: add human readable output for '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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 01 May 2017 22:36:14 +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" The virsh command 'domblkinfo' returns the capacity, allocation and phisycal size of the devices attached in a domain. Usually, this sizes are very big and hard to understand and calculate. This commits introduce a human readab= le support to check the size of each field easilly. For example, the command today: virsh # domblkinfo my_domain hda Capacity: 21474836480 Allocation: 14875545600 Physical: 21474836480 After this patch: virsh # domblkinfo my_domain hda --human Capacity: 20.0G Allocation: 13.9G Physical: 20.0G This commit supports Bytes, KiB and MiB too. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1330940 Signed-off-by: Julio Faracco --- tools/virsh-domain-monitor.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/virsh.pod | 5 +++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 3db4795..755d740 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -396,6 +396,10 @@ static const vshCmdOptDef opts_domblkinfo[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("block device") }, + {.name =3D "human", + .type =3D VSH_OT_BOOL, + .help =3D N_("Human readable output") + }, {.name =3D NULL} }; =20 @@ -405,6 +409,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) virDomainBlockInfo info; virDomainPtr dom; bool ret =3D false; + bool human =3D false; const char *device =3D NULL; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) @@ -416,9 +421,39 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) goto cleanup; =20 - vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity); - vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation); - vshPrint(ctl, "%-15s %llu\n", _("Physical:"), info.physical); + human =3D vshCommandOptBool(cmd, "human"); + + if (!human) { + vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity); + vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation); + vshPrint(ctl, "%-15s %llu\n", _("Physical:"), info.physical); + } else { + double sizeCapacity =3D 1; + const char *sizeStr =3D "B"; + + /* Check if capacity can be in K. */ + if (info.capacity >=3D 1024) { + sizeCapacity =3D 1024.0; + sizeStr =3D "K"; + } + /* Check if capacity can be in M. */ + if (info.capacity >=3D 1048576) { + sizeCapacity =3D 1048576.0; + sizeStr =3D "M"; + } + /* Check if capacity can be in G. */ + if (info.capacity >=3D 1073741824) { + sizeCapacity =3D 1073741824.0; + sizeStr =3D "G"; + } + + vshPrint(ctl, "%-15s %.1f%s\n", _("Capacity:"), + info.capacity/sizeCapacity, sizeStr); + vshPrint(ctl, "%-15s %.1f%s\n", _("Allocation:"), + info.allocation/sizeCapacity, sizeStr); + vshPrint(ctl, "%-15s %.1f%s\n", _("Physical:"), + info.physical/sizeCapacity, sizeStr); + } =20 ret =3D true; =20 diff --git a/tools/virsh.pod b/tools/virsh.pod index e16f62f..9f67de2 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -841,12 +841,13 @@ B command says that a domain was paused due= to I/O error. The B command lists all block devices in error state and the error seen on each of them. =20 -=3Ditem B I I +=3Ditem B I I [I<--human>] =20 Get block device size info for a domain. A I corresponds to a unique target name () or source file () for one of the disk devices attached to I (see -also B for listing these names). +also B for listing these names). If I<--human> is set, the +output will have a human readable design. =20 =3Ditem B I [I<--inactive>] [I<--details>] =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list