]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cmdDomblkinfo: introduce helper cmdDomblkinfoPrint
authorChen Hanxiao <chenhanxiao@gmail.com>
Tue, 19 Jun 2018 10:01:23 +0000 (18:01 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 21 Jun 2018 21:39:19 +0000 (17:39 -0400)
Introduce helper cmdDomblkinfoPrint for printing.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
tools/virsh-domain-monitor.c

index 886f7f16b559a50dfac0aafcc44987eab033da61..4e28122dd1680492bc45df943334e195f45dba80 100644 (file)
@@ -400,6 +400,30 @@ 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 +444,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;