c401cc
From f034be09a0d28c9aa6392048b6c725a748e860ff Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <f034be09a0d28c9aa6392048b6c725a748e860ff@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:09 +0100
c401cc
Subject: [PATCH] virsh-volume: Unify strigification of volume type
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
There were two separate places with that were stringifying type of a
c401cc
volume. One of the places was out of sync with types implemented
c401cc
upstream.
c401cc
c401cc
To avoid such problems in the future, this patch adds a common function
c401cc
to convert the type to string and reuses it across the two said places.
c401cc
c401cc
(cherry picked from commit 48072521b66668ded683f778cb686d3955d14019)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 tools/virsh-volume.c | 61 +++++++++++++++++++++++++---------------------------
c401cc
 1 file changed, 29 insertions(+), 32 deletions(-)
c401cc
c401cc
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
c401cc
index 7dab532..f5303ba 100644
c401cc
--- a/tools/virsh-volume.c
c401cc
+++ b/tools/virsh-volume.c
c401cc
@@ -934,6 +934,31 @@ out:
c401cc
     return ret;
c401cc
 }
c401cc
 
c401cc
+
c401cc
+static const char *
c401cc
+vshVolumeTypeToString(int type)
c401cc
+{
c401cc
+    switch (type) {
c401cc
+    case VIR_STORAGE_VOL_FILE:
c401cc
+        return N_("file");
c401cc
+
c401cc
+    case VIR_STORAGE_VOL_BLOCK:
c401cc
+        return N_("block");
c401cc
+
c401cc
+    case VIR_STORAGE_VOL_DIR:
c401cc
+        return N_("dir");
c401cc
+
c401cc
+    case VIR_STORAGE_VOL_NETWORK:
c401cc
+        return N_("network");
c401cc
+
c401cc
+    case VIR_STORAGE_VOL_LAST:
c401cc
+        break;
c401cc
+    }
c401cc
+
c401cc
+    return N_("unknown");
c401cc
+}
c401cc
+
c401cc
+
c401cc
 /*
c401cc
  * "vol-info" command
c401cc
  */
c401cc
@@ -975,26 +1000,9 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
c401cc
     if (virStorageVolGetInfo(vol, &info) == 0) {
c401cc
         double val;
c401cc
         const char *unit;
c401cc
-        switch (info.type) {
c401cc
-        case VIR_STORAGE_VOL_FILE:
c401cc
-            vshPrint(ctl, "%-15s %s\n", _("Type:"), _("file"));
c401cc
-            break;
c401cc
-
c401cc
-        case VIR_STORAGE_VOL_BLOCK:
c401cc
-            vshPrint(ctl, "%-15s %s\n", _("Type:"), _("block"));
c401cc
-            break;
c401cc
 
c401cc
-        case VIR_STORAGE_VOL_DIR:
c401cc
-            vshPrint(ctl, "%-15s %s\n", _("Type:"), _("dir"));
c401cc
-            break;
c401cc
-
c401cc
-        case VIR_STORAGE_VOL_NETWORK:
c401cc
-            vshPrint(ctl, "%-15s %s\n", _("Type:"), _("network"));
c401cc
-            break;
c401cc
-
c401cc
-        default:
c401cc
-            vshPrint(ctl, "%-15s %s\n", _("Type:"), _("unknown"));
c401cc
-        }
c401cc
+        vshPrint(ctl, "%-15s %s\n", _("Type:"),
c401cc
+                 _(vshVolumeTypeToString(info.type)));
c401cc
 
c401cc
         val = vshPrettyCapacity(info.capacity, &unit);
c401cc
         vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
c401cc
@@ -1369,19 +1377,8 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
c401cc
                 /* Convert the returned volume info into output strings */
c401cc
 
c401cc
                 /* Volume type */
c401cc
-                switch (volumeInfo.type) {
c401cc
-                        case VIR_STORAGE_VOL_FILE:
c401cc
-                            volInfoTexts[i].type = vshStrdup(ctl, _("file"));
c401cc
-                            break;
c401cc
-                        case VIR_STORAGE_VOL_BLOCK:
c401cc
-                            volInfoTexts[i].type = vshStrdup(ctl, _("block"));
c401cc
-                            break;
c401cc
-                        case VIR_STORAGE_VOL_DIR:
c401cc
-                            volInfoTexts[i].type = vshStrdup(ctl, _("dir"));
c401cc
-                            break;
c401cc
-                        default:
c401cc
-                            volInfoTexts[i].type = vshStrdup(ctl, _("unknown"));
c401cc
-                }
c401cc
+                volInfoTexts[i].type = vshStrdup(ctl,
c401cc
+                                                 _(vshVolumeTypeToString(volumeInfo.type)));
c401cc
 
c401cc
                 /* Create the capacity output string */
c401cc
                 val = vshPrettyCapacity(volumeInfo.capacity, &unit);
c401cc
-- 
c401cc
1.9.0
c401cc