diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index b94c1dcbda..f2f25da19c 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -47,6 +47,13 @@ .help = N_("file containing an XML pool description") \ } \ +#define VSH_POOL_BUILD_OPT_COMMON \ + {.name = "build", \ + .type = VSH_OT_BOOL, \ + .flags = 0, \ + .help = N_("build the pool as normal") \ + } \ + #define VSH_POOL_NO_OVERWRITE_OPT_COMMON \ {.name = "no-overwrite", \ .type = VSH_OT_BOOL, \ @@ -235,6 +242,9 @@ static const vshCmdInfo info_pool_create[] = { static const vshCmdOptDef opts_pool_create[] = { VSH_POOL_FILE_OPT_COMMON, + VSH_POOL_BUILD_OPT_COMMON, + VSH_POOL_NO_OVERWRITE_OPT_COMMON, + VSH_POOL_OVERWRITE_OPT_COMMON, {.name = NULL} }; @@ -246,15 +256,33 @@ 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_EXPR("overwrite", overwrite, + "no-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 +414,9 @@ static const vshCmdInfo info_pool_create_as[] = { static const vshCmdOptDef opts_pool_create_as[] = { VSH_POOL_X_AS_OPT_COMMON, + VSH_POOL_BUILD_OPT_COMMON, + VSH_POOL_NO_OVERWRITE_OPT_COMMON, + VSH_POOL_OVERWRITE_OPT_COMMON, {.name = NULL} }; @@ -397,8 +428,26 @@ 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_EXPR("overwrite", overwrite, + "no-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 +455,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 +1706,9 @@ static const vshCmdInfo info_pool_start[] = { static const vshCmdOptDef opts_pool_start[] = { VSH_POOL_OPT_COMMON, + VSH_POOL_BUILD_OPT_COMMON, + VSH_POOL_NO_OVERWRITE_OPT_COMMON, + VSH_POOL_OVERWRITE_OPT_COMMON, {.name = NULL} }; @@ -1667,11 +1719,29 @@ 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_EXPR("overwrite", overwrite, + "no-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 21ae4a3e5b..107fc324e5 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 I +[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] Create and start a pool object from the XML I. +[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] perform a +B 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. If +just I<--build> is provided, then B is called with no flags. + =item B I I [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 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 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. If +just I<--build> is provided, then B is called with no flags. + =item B I 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. -Use the same arguments as B. +Use the same arguments as B, except for the I<--build>, +I<--overwrite>, and I<--no-overwrite> options. =item B I @@ -3326,9 +3341,17 @@ Convert the I to a pool name. Refresh the list of volumes contained in I. =item B I +[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] Start the storage I, which is previously defined but inactive. +[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] perform a +B prior to B 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. If just I<--build> is provided, then +B is called with no flags. + B: 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).