[libvirt] [PATCH v2 1/3] cmdDomblkinfo: introduce helper cmdDomblkinfoPrint

Chen Hanxiao posted 3 patches 6 years, 11 months ago
There is a newer version of this series
[libvirt] [PATCH v2 1/3] cmdDomblkinfo: introduce helper cmdDomblkinfoPrint
Posted by Chen Hanxiao 6 years, 11 months ago
From: Chen Hanxiao <chenhanxiao@gmail.com>

Introduce helper cmdDomblkinfoPrint for printing.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
---
 tools/virsh-domain-monitor.c | 39 ++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 8cbb3db37c..daa86e8310 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -400,6 +400,29 @@ static const vshCmdOptDef opts_domblkinfo[] = {
     {.name = NULL}
 };
 
+static void
+cmdDomblkinfoPrint(vshControl *ctl,
+                   const virDomainBlockInfo *info,
+                   bool 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 val;
+        const char *unit;
+
+        val = vshPrettyCapacity(info->capacity, &unit);
+        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Capacity:"), val, unit);
+        val = vshPrettyCapacity(info->allocation, &unit);
+        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Allocation:"), val, unit);
+        val = vshPrettyCapacity(info->physical, &unit);
+        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Physical:"), val, unit);
+    }
+
+}
+
 static bool
 cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
 {
@@ -420,21 +443,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
 
     human = 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 val;
-        const char *unit;
-
-        val = vshPrettyCapacity(info.capacity, &unit);
-        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Capacity:"), val, unit);
-        val = vshPrettyCapacity(info.allocation, &unit);
-        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Allocation:"), val, unit);
-        val = vshPrettyCapacity(info.physical, &unit);
-        vshPrint(ctl, "%-15s %-.3lf %s\n", _("Physical:"), val, unit);
-    }
+    cmdDomblkinfoPrint(ctl, &info, human);
 
     ret = true;
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 1/3] cmdDomblkinfo: introduce helper cmdDomblkinfoPrint
Posted by John Ferlan 6 years, 11 months ago

On 06/11/2018 06:52 AM, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao@gmail.com>
> 
> Introduce helper cmdDomblkinfoPrint for printing.
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
> ---
>  tools/virsh-domain-monitor.c | 39 ++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 15 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list