[PATCH v3 09/14] virsh: Create macros for common "pool" options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than continually cut-n-paste the strings into each command,
create common macros to be used generically.  For virsh-volume, there
are 3 different types of "pool" options - 2 for create, 2 required
for the command, and 10 for string type options. Create 2 new macros
for the create and string type options, but use the virsh.h common
macro for the required for command option.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 tools/virsh-volume.c | 87 ++++++++++++++++------------------------------------
 1 file changed, 27 insertions(+), 60 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 7932ef2..5d9cade 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -42,6 +42,19 @@
 #include "virxml.h"
 #include "virstring.h"
 
+#define VIRSH_COMMON_OPT_VOLUME_POOL_CREATE                \
+    {.name = "pool",                                       \
+     .type = VSH_OT_DATA,                                  \
+     .flags = VSH_OFLAG_REQ,                               \
+     .help = N_("pool name")                               \
+    }                                                      \
+
+#define VIRSH_COMMON_OPT_VOLUME_POOL_STRING                \
+    {.name = "pool",                                       \
+     .type = VSH_OT_STRING,                                \
+     .help = N_("pool name or uuid")                       \
+    }                                                      \
+
 virStorageVolPtr
 virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
                      const char *optname,
@@ -145,11 +158,7 @@ static const vshCmdInfo info_vol_create_as[] = {
 };
 
 static const vshCmdOptDef opts_vol_create_as[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_CREATE,
     {.name = "name",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -353,11 +362,7 @@ static const vshCmdInfo info_vol_create[] = {
 };
 
 static const vshCmdOptDef opts_vol_create[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_CREATE,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -423,11 +428,7 @@ static const vshCmdInfo info_vol_create_from[] = {
 };
 
 static const vshCmdOptDef opts_vol_create_from[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_POOL,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -558,10 +559,7 @@ static const vshCmdOptDef opts_vol_clone[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("clone name")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "prealloc-metadata",
      .type = VSH_OT_BOOL,
      .help = N_("preallocate metadata (for qcow2 instead of full allocation)")
@@ -661,10 +659,7 @@ static const vshCmdOptDef opts_vol_upload[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("file")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "offset",
      .type = VSH_OT_INT,
      .help = N_("volume offset to upload to")
@@ -775,10 +770,7 @@ static const vshCmdOptDef opts_vol_download[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("file")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "offset",
      .type = VSH_OT_INT,
      .help = N_("volume offset to download from")
@@ -883,10 +875,7 @@ static const vshCmdOptDef opts_vol_delete[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "delete-snapshots",
      .type = VSH_OT_BOOL,
      .help = N_("delete snapshots associated with volume (must be "
@@ -940,10 +929,7 @@ static const vshCmdOptDef opts_vol_wipe[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "algorithm",
      .type = VSH_OT_STRING,
      .help = N_("perform selected wiping algorithm")
@@ -1033,10 +1019,7 @@ static const vshCmdOptDef opts_vol_info[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = NULL}
 };
 
@@ -1096,10 +1079,7 @@ static const vshCmdOptDef opts_vol_resize[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("new capacity for the vol, as scaled integer (default bytes)")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = "allocate",
      .type = VSH_OT_BOOL,
      .help = N_("allocate the new capacity, rather than leaving it sparse")
@@ -1195,10 +1175,7 @@ static const vshCmdOptDef opts_vol_dumpxml[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = NULL}
 };
 
@@ -1364,11 +1341,7 @@ static const vshCmdInfo info_vol_list[] = {
 };
 
 static const vshCmdOptDef opts_vol_list[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_POOL,
     {.name = "details",
      .type = VSH_OT_BOOL,
      .help = N_("display extended details for volumes")
@@ -1710,10 +1683,7 @@ static const vshCmdOptDef opts_vol_key[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("volume name or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = NULL}
 };
 
@@ -1749,10 +1719,7 @@ static const vshCmdOptDef opts_vol_path[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("volume name or key")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VIRSH_COMMON_OPT_VOLUME_POOL_STRING,
     {.name = NULL}
 };
 
-- 
2.5.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]