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(a)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);
A-HA! I knew it! These are mutually exclusive. So please do fix 1/6.
+
+ 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) {