[libvirt] [PATCH 6/6] virsh: Add build flags to pool-create[-as] and pool-start

John Ferlan jferlan at redhat.com
Wed Nov 25 19:11:08 UTC 2015


https://bugzilla.redhat.com/show_bug.cgi?id=830056

Utilize recently added VIR_STORAGE_POOL_CREATE_WITH_BUILD* flags in
order to pass the flags along to the virStoragePoolCreateXML and
virStoragePoolCreate API's.

This affects the 'virsh pool-create', 'virsh pool-create-as', and
'virsh pool-start' commands.  While it could be argued that pool-start
doesn't need the flags, they could prove useful for someone trying to
do one command build --overwrite and start command processing or
essentially starting with a clean slate.

NB:
This patch is loosely based upon code originally authored by Osier
Yang that were not reviewed and pushed, see:

https://www.redhat.com/archives/libvir-list/2012-July/msg00497.html
Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 tools/virsh-pool.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 tools/virsh.pod    | 25 ++++++++++++++++++-
 2 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index cb91cd3..1bb987d 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -47,6 +47,13 @@
      .help = N_("file containing an XML pool description")    \
     },                                                        \
 
+#define OPT_BUILD_COMMON                                      \
+    {.name = "build",                                         \
+     .type = VSH_OT_BOOL,                                     \
+     .flags = 0,                                              \
+     .help = N_("build the pool as normal")                   \
+    },                                                        \
+
 #define OPT_NO_OVERWRITE_COMMON                                   \
     {.name = "no-overwrite",                                      \
      .type = VSH_OT_BOOL,                                         \
@@ -235,6 +242,9 @@ static const vshCmdInfo info_pool_create[] = {
 
 static const vshCmdOptDef opts_pool_create[] = {
     OPT_FILE_COMMON
+    OPT_BUILD_COMMON
+    OPT_NO_OVERWRITE_COMMON
+    OPT_OVERWRITE_COMMON
 
     {.name = NULL}
 };
@@ -246,15 +256,32 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = true;
     char *buffer;
+    bool build;
+    bool overwrite;
+    bool no_overwrite;
+    unsigned int flags = 0;
     virshControlPtr priv = ctl->privData;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;
 
+    build = vshCommandOptBool(cmd, "build");
+    overwrite = vshCommandOptBool(cmd, "overwrite");
+    no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(overwrite, no_overwrite);
+
+    if (build)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
+    if (overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
+    if (no_overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    pool = virStoragePoolCreateXML(priv->conn, buffer, 0);
+    pool = virStoragePoolCreateXML(priv->conn, buffer, flags);
     VIR_FREE(buffer);
 
     if (pool != NULL) {
@@ -386,6 +413,9 @@ static const vshCmdInfo info_pool_create_as[] = {
 
 static const vshCmdOptDef opts_pool_create_as[] = {
     OPTS_POOL_COMMON_X_AS
+    OPT_BUILD_COMMON
+    OPT_NO_OVERWRITE_COMMON
+    OPT_OVERWRITE_COMMON
 
     {.name = NULL}
 };
@@ -397,8 +427,25 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     char *xml;
     bool printXML = vshCommandOptBool(cmd, "print-xml");
+    bool build;
+    bool overwrite;
+    bool no_overwrite;
+    unsigned int flags = 0;
     virshControlPtr priv = ctl->privData;
 
+    build = vshCommandOptBool(cmd, "build");
+    overwrite = vshCommandOptBool(cmd, "overwrite");
+    no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(overwrite, no_overwrite);
+
+    if (build)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
+    if (overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
+    if (no_overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
+
     if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
         return false;
 
@@ -406,7 +453,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", xml);
         VIR_FREE(xml);
     } else {
-        pool = virStoragePoolCreateXML(priv->conn, xml, 0);
+        pool = virStoragePoolCreateXML(priv->conn, xml, flags);
         VIR_FREE(xml);
 
         if (pool != NULL) {
@@ -1657,6 +1704,9 @@ static const vshCmdInfo info_pool_start[] = {
 
 static const vshCmdOptDef opts_pool_start[] = {
     OPT_POOL_COMMON
+    OPT_BUILD_COMMON
+    OPT_NO_OVERWRITE_COMMON
+    OPT_OVERWRITE_COMMON
 
     {.name = NULL}
 };
@@ -1667,11 +1717,28 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
     virStoragePoolPtr pool;
     bool ret = true;
     const char *name = NULL;
+    bool build;
+    bool overwrite;
+    bool no_overwrite;
+    unsigned int flags = 0;
 
     if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
          return false;
 
-    if (virStoragePoolCreate(pool, 0) == 0) {
+    build = vshCommandOptBool(cmd, "build");
+    overwrite = vshCommandOptBool(cmd, "overwrite");
+    no_overwrite = vshCommandOptBool(cmd, "no-overwrite");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(overwrite, no_overwrite);
+
+    if (build)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
+    if (overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
+    if (no_overwrite)
+        flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
+
+    if (virStoragePoolCreate(pool, flags) == 0) {
         vshPrint(ctl, _("Pool %s started\n"), name);
     } else {
         vshError(ctl, _("Failed to start pool %s"), name);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 21ae4a3..107fc32 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3181,15 +3181,23 @@ specified or it's been determined that the disk doesn't already have one,
 by the pool source format type or "dos" if not specified for the pool.
 
 =item B<pool-create> I<file>
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]]
 
 Create and start a pool object from the XML I<file>.
 
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] perform a
+B<pool-build> after creation in order to remove the need for a
+follow-up command to build the pool. The I<--overwrite> and
+I<--no-overwrite> flags follow the same rules as B<pool-build>. If
+just I<--build> is provided, then B<pool-build> is called with no flags.
+
 =item B<pool-create-as> I<name> I<type> [I<--print-xml>]
 [I<--source-host hostname>] [I<--source-path path>] [I<--source-dev path>]
 [I<--source-name name>] [I<--target path>] [I<--source-format format>]
 [I<--auth-type authtype> I<--auth-username username> I<--secret-usage usage>]
 [[I<--adapter-name name>] | [I<--adapter-wwnn> I<--adapter-wwpn>]
 [I<--adapter-parent parent>]]
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]]
 
 
 Create and start a pool object I<name> from the raw parameters.  If
@@ -3233,6 +3241,12 @@ the wwnn and wwpn to be used for the fc_host adapter type pool. The parent
 optionally provides the name of the scsi_hostN node device to be used for
 the vHBA.
 
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] perform a
+B<pool-build> after creation in order to remove the need for a
+follow-up command to build the pool. The I<--overwrite> and
+I<--no-overwrite> flags follow the same rules as B<pool-build>. If
+just I<--build> is provided, then B<pool-build> is called with no flags.
+
 =item B<pool-define> I<file>
 
 Define an inactive persistent storage pool or modify an existing persistent one
@@ -3250,7 +3264,8 @@ I<--print-xml> is specified, then print the XML of the pool object
 without defining the pool.  Otherwise, the pool has the specified
 I<type>.
 
-Use the same arguments as B<pool-create-as>.
+Use the same arguments as B<pool-create-as>, except for the I<--build>,
+I<--overwrite>, and I<--no-overwrite> options.
 
 =item B<pool-destroy> I<pool-or-uuid>
 
@@ -3326,9 +3341,17 @@ Convert the I<uuid> to a pool name.
 Refresh the list of volumes contained in I<pool>.
 
 =item B<pool-start> I<pool-or-uuid>
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]]
 
 Start the storage I<pool>, which is previously defined but inactive.
 
+[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] perform a
+B<pool-build> prior to B<pool-start> to ensure the pool environment is
+in an expected state rather than needing to run the build command prior
+to startup. The I<--overwrite> and I<--no-overwrite> flags follow the
+same rules as B<pool-build>. If just I<--build> is provided, then
+B<pool-build> is called with no flags.
+
 B<Note>: A storage pool that relies on remote resources such as an
 "iscsi" or a (v)HBA backed "scsi" pool may need to be refreshed multiple
 times in order to have all the volumes detected (see B<pool-refresh>).
-- 
2.5.0




More information about the libvir-list mailing list