virsh-volume: Unify strigification of volume type

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.
This commit is contained in:
Peter Krempa 2013-11-12 16:13:41 +01:00
parent d6fdcb88b9
commit 48072521b6

View File

@ -942,6 +942,31 @@ out:
return ret; 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 * "vol-info" command
*/ */
@ -983,26 +1008,9 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
if (virStorageVolGetInfo(vol, &info) == 0) { if (virStorageVolGetInfo(vol, &info) == 0) {
double val; double val;
const char *unit; 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:"),
vshPrint(ctl, "%-15s %s\n", _("Type:"), _("block")); _(vshVolumeTypeToString(info.type)));
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"));
}
val = vshPrettyCapacity(info.capacity, &unit); val = vshPrettyCapacity(info.capacity, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
@ -1377,19 +1385,8 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
/* Convert the returned volume info into output strings */ /* Convert the returned volume info into output strings */
/* Volume type */ /* Volume type */
switch (volumeInfo.type) { volInfoTexts[i].type = vshStrdup(ctl,
case VIR_STORAGE_VOL_FILE: _(vshVolumeTypeToString(volumeInfo.type)));
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"));
}
/* Create the capacity output string */ /* Create the capacity output string */
val = vshPrettyCapacity(volumeInfo.capacity, &unit); val = vshPrettyCapacity(volumeInfo.capacity, &unit);