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