mirror of https://gitee.com/openkylin/libvirt.git
virsh: Add build flags to pool-create[-as] and pool-start
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
This commit is contained in:
parent
5372d49b11
commit
e193735450
|
@ -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);
|
||||
|
|
|
@ -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>).
|
||||
|
|
Loading…
Reference in New Issue