[libvirt] [PATCH 8/8] virsh: Create macros for common "vol" options

John Ferlan jferlan at redhat.com
Thu Dec 17 16:55:48 UTC 2015


Rather than continually cut-n-paste the strings into each command,
create common macros to be used generically.  Replace the more commonly
used "vol" option with a macro. This also adjusts 2 commands that
didn't have the correct helpstr - 'vol-create-from' and 'vol-clone'.
Both are described in the man page as taking vol, path, or key and
the code uses the virshCommandOptVol instead of virshCommandOptVolBy.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 tools/virsh-volume.c | 61 ++++++++++++++--------------------------------------
 1 file changed, 16 insertions(+), 45 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index b88d4c4..9c97c1d 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -62,6 +62,13 @@
      .help = N_("pool name or uuid")                       \
     }                                                      \
 
+#define VSH_VOLUME_VOL_OPT_COMMON                          \
+    {.name = "vol",                                        \
+     .type = VSH_OT_DATA,                                  \
+     .flags = VSH_OFLAG_REQ,                               \
+     .help = N_("vol name, key or path")                   \
+    }                                                      \
+
 virStorageVolPtr
 virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
                      const char *optname,
@@ -441,11 +448,7 @@ static const vshCmdOptDef opts_vol_create_from[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("file containing an XML vol description")
     },
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("input vol name or key")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     {.name = "inputpool",
      .type = VSH_OT_STRING,
      .help = N_("pool name or uuid of the input volume's pool")
@@ -556,11 +559,7 @@ static const vshCmdInfo info_vol_clone[] = {
 };
 
 static const vshCmdOptDef opts_vol_clone[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("orig vol name or key")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     {.name = "newname",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -656,11 +655,7 @@ static const vshCmdInfo info_vol_upload[] = {
 };
 
 static const vshCmdOptDef opts_vol_upload[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -767,11 +762,7 @@ static const vshCmdInfo info_vol_download[] = {
 };
 
 static const vshCmdOptDef opts_vol_download[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -877,11 +868,7 @@ static const vshCmdInfo info_vol_delete[] = {
 };
 
 static const vshCmdOptDef opts_vol_delete[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
@@ -921,11 +908,7 @@ static const vshCmdInfo info_vol_wipe[] = {
 };
 
 static const vshCmdOptDef opts_vol_wipe[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "algorithm",
      .type = VSH_OT_STRING,
@@ -1011,11 +994,7 @@ static const vshCmdInfo info_vol_info[] = {
 };
 
 static const vshCmdOptDef opts_vol_info[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
@@ -1066,11 +1045,7 @@ static const vshCmdInfo info_vol_resize[] = {
 };
 
 static const vshCmdOptDef opts_vol_resize[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     {.name = "capacity",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -1167,11 +1142,7 @@ static const vshCmdInfo info_vol_dumpxml[] = {
 };
 
 static const vshCmdOptDef opts_vol_dumpxml[] = {
-    {.name = "vol",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("vol name, key or path")
-    },
+    VSH_VOLUME_VOL_OPT_COMMON,
     VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
-- 
2.5.0




More information about the libvir-list mailing list