New options --build, --build-overwrite, and --build-no-overwrite are added to commands pool-create/pool-create-as/pool-start. Perhaps it's not that necessary to allow pool building for pool-start, but it doesn't hurt to have them.
--- The documents of pool-build is not that correct, as the flags --overwrite and --no-overwrite are also supported by disk backend, but it will be a follow up patch, with fixing the documents for the new options together. --- tools/virsh.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++--- tools/virsh.pod | 27 +++++++++++++-- 2 files changed, 118 insertions(+), 9 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 01e7ce0..7e4fc6f 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -10295,6 +10295,10 @@ static const vshCmdInfo info_pool_create[] = { static const vshCmdOptDef opts_pool_create[] = { {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("file containing an XML pool description")}, + {"build", VSH_OT_BOOL, 0, N_("build the pool as normal")}, + {"build-overwrite", VSH_OT_BOOL, 0, N_("build the pool without overwriting the " + "existed pool data")}, + {"build-no-overwrite", VSH_OT_BOOL, 0, N_("build the pool with overwriting anything")}, {NULL, 0, 0, NULL} }; @@ -10305,6 +10309,10 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = true; char *buffer; + bool build; + bool build_overwrite; + bool build_no_overwrite; + unsigned int flags = 0; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -10312,10 +10320,27 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; + build = vshCommandOptBool(cmd, "build"); + build_overwrite = vshCommandOptBool(cmd, "build-overwrite"); + build_no_overwrite = vshCommandOptBool(cmd, "build-no-overwrite"); + + if (build + build_overwrite + build_no_overwrite > 1) { + vshError(ctl, _("build, build-overwrite, and build-no-overwrite must " + "be sepcified exclusively")); + return false; + } + + if (build) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD; + if (build_overwrite) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE; + if (build_no_overwrite) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE; + if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) return false; - pool = virStoragePoolCreateXML(ctl->conn, buffer, 0); + pool = virStoragePoolCreateXML(ctl->conn, buffer, flags); VIR_FREE(buffer); if (pool != NULL) { @@ -10428,7 +10453,7 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) /* * XML Building helper for pool-define-as and pool-create-as */ -static const vshCmdOptDef opts_pool_X_as[] = { +static const vshCmdOptDef opts_pool_define_as[] = { {"name", VSH_OT_DATA, VSH_OFLAG_REQ, N_("name of the pool")}, {"print-xml", VSH_OT_BOOL, 0, N_("print XML document, but don't define/create")}, {"type", VSH_OT_DATA, VSH_OFLAG_REQ, N_("type of the pool")}, @@ -10510,6 +10535,23 @@ static const vshCmdInfo info_pool_create_as[] = { {NULL, NULL} }; +static const vshCmdOptDef opts_pool_create_as[] = { + {"name", VSH_OT_DATA, VSH_OFLAG_REQ, N_("name of the pool")}, + {"print-xml", VSH_OT_BOOL, 0, N_("print XML document, but don't define/create")}, + {"type", VSH_OT_DATA, VSH_OFLAG_REQ, N_("type of the pool")}, + {"source-host", VSH_OT_DATA, 0, N_("source-host for underlying storage")}, + {"source-path", VSH_OT_DATA, 0, N_("source path for underlying storage")}, + {"source-dev", VSH_OT_DATA, 0, N_("source device for underlying storage")}, + {"source-name", VSH_OT_DATA, 0, N_("source name for underlying storage")}, + {"target", VSH_OT_DATA, 0, N_("target for underlying storage")}, + {"source-format", VSH_OT_STRING, 0, N_("format for underlying storage")}, + {"build", VSH_OT_BOOL, 0, N_("build the pool as normal")}, + {"build-overwrite", VSH_OT_BOOL, 0, N_("build the pool without overwriting " + "the existed pool data")}, + {"build-no-overwrite", VSH_OT_BOOL, 0, N_("build the pool with overwriting anything")}, + {NULL, 0, 0, NULL} +}; + static bool cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) { @@ -10517,6 +10559,10 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) const char *name; char *xml; bool printXML = vshCommandOptBool(cmd, "print-xml"); + bool build; + bool build_overwrite; + bool build_no_overwrite; + unsigned int flags = 0; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -10524,11 +10570,28 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) if (!buildPoolXML(cmd, &name, &xml)) return false; + build = vshCommandOptBool(cmd, "build"); + build_overwrite = vshCommandOptBool(cmd, "build-overwrite"); + build_no_overwrite = vshCommandOptBool(cmd, "build-no-overwrite"); + + if (build + build_overwrite + build_no_overwrite > 1) { + vshError(ctl, _("build, build-overwrite, and build-no-overwrite must " + "be sepcified exclusively")); + return false; + } + + if (build) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD; + if (build_overwrite) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE; + if (build_no_overwrite) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE; + if (printXML) { vshPrint(ctl, "%s", xml); VIR_FREE(xml); } else { - pool = virStoragePoolCreateXML(ctl->conn, xml, 0); + pool = virStoragePoolCreateXML(ctl->conn, xml, flags); VIR_FREE(xml); if (pool != NULL) { @@ -11522,6 +11585,10 @@ static const vshCmdInfo info_pool_start[] = { static const vshCmdOptDef opts_pool_start[] = { {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, N_("name or uuid of the inactive pool")}, + {"build", VSH_OT_BOOL, 0, N_("build the pool as normal")}, + {"build-overwrite", VSH_OT_BOOL, 0, N_("build the pool without overwriting the " + "existed pool data")}, + {"build-no-overwrite", VSH_OT_BOOL, 0, N_("build the pool with overwriting anything")}, {NULL, 0, 0, NULL} }; @@ -11531,6 +11598,10 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; bool ret = true; const char *name = NULL; + bool build; + bool build_overwrite; + bool build_no_overwrite; + unsigned int flags = 0; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -11538,7 +11609,24 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - if (virStoragePoolCreate(pool, 0) == 0) { + build = vshCommandOptBool(cmd, "build"); + build_overwrite = vshCommandOptBool(cmd, "build-overwrite"); + build_no_overwrite = vshCommandOptBool(cmd, "build-no-overwrite"); + + if (build + build_overwrite + build_no_overwrite > 1) { + vshError(ctl, _("build, build-overwrite, and build-no-overwrite must " + "be sepcified exclusively")); + return false; + } + + if (build) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD; + if (build_overwrite) + flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE; + if (build_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); @@ -18259,9 +18347,9 @@ static const vshCmdDef storagePoolCmds[] = { {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart, 0}, {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build, 0}, - {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as, 0}, + {"pool-create-as", cmdPoolCreateAs, opts_pool_create_as, info_pool_create_as, 0}, {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create, 0}, - {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as, 0}, + {"pool-define-as", cmdPoolDefineAs, opts_pool_define_as, info_pool_define_as, 0}, {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define, 0}, {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete, 0}, {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy, 0}, diff --git a/tools/virsh.pod b/tools/virsh.pod index ae00622..621a5b9 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2087,19 +2087,33 @@ if exists, or using mkfs to format the target device if not; If I<--overwrite> is specified, mkfs is always executed, any existed data on the target device is overwritten unconditionally. -=item B<pool-create> I<file> +=item B<pool-create> I<file> [[I<--build>] | [I<--build-overwrite>] | +[I<--build-no-overwrite>]] Create and start a pool object from the XML I<file>. +Options I<--build>, I<--build-overwrite>, and I<--build-no-overwrite> +can be used for a filesystem pool to build the pool before starting it. +If I<--build> is specified, it only makes the directory on the filesystem +pool. I<--build-overwrite> and I<--build-no-overwrite> has the same +meaning as I<--overwrite> and I<--no-overwrite> for B<pool-build>. + =item B<pool-create-as> I<name> I<--print-xml> I<type> [I<source-host>] [I<source-path>] [I<source-dev>] [I<source-name>] [<target>] -[I<--source-format format>] +[I<--source-format format>] [[I<--build>] | [I<--build-overwrite>] | +[I<--build-no-overwrite>]] Create and start a pool object I<name> from the raw parameters. If I<--print-xml> is specified, then print the XML of the pool object without creating the pool. Otherwise, the pool has the specified I<type>. +Options I<--build>, I<--build-overwrite>, and I<--build-no-overwrite> +can be used for a filesystem pool to build the pool before starting it. +If I<--build> is specified, it only makes the directory on the filesystem +pool. I<--build-overwrite> and I<--build-no-overwrite> has the same +meaning as I<--overwrite> and I<--no-overwrite> for B<pool-build>. + =item B<pool-define> I<file> Create, but do not start, a pool object from the XML I<file>. @@ -2167,10 +2181,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> +=item B<pool-start> I<pool-or-uuid> [[I<--build>] | [I<--build-overwrite>] | +[I<--build-no-overwrite>]] Start the storage I<pool>, which is previously defined but inactive. +Options I<--build>, I<--build-overwrite>, and I<--build-no-overwrite> +can be used for a filesystem pool to build the pool before starting it. +If I<--build> is specified, it only makes the directory on the filesystem +pool. I<--build-overwrite> and I<--build-no-overwrite> has the same +meaning as I<--overwrite> and I<--no-overwrite> for B<pool-build>. + =item B<pool-undefine> I<pool-or-uuid> Undefine the configuration for an inactive I<pool>. -- 1.7.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list