[PATCH 2/2] virsh: New options for the 3 pool commands to allow pool building

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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-pool.c |  100 ++++++++++++++++++++++++++++++++++++++++++++++++---
 tools/virsh.pod    |   27 ++++++++++++--
 2 files changed, 118 insertions(+), 9 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index af80427..ad6aef6 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -124,6 +124,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}
 };
 
@@ -134,6 +138,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;
@@ -141,10 +149,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) {
@@ -161,7 +186,7 @@ cmdPoolCreate(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")},
@@ -237,6 +262,23 @@ cleanup:
 /*
  * "pool-create-as" command
  */
+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 const vshCmdInfo info_pool_create_as[] = {
     {"help", N_("create a pool from a set of args")},
     {"desc", N_("Create a pool.")},
@@ -250,6 +292,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;
@@ -257,11 +303,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) {
@@ -1244,6 +1307,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}
 };
 
@@ -1253,6 +1320,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;
@@ -1260,7 +1331,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);
@@ -1421,9 +1509,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 35613c4..bcc944a 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2097,19 +2097,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>.
@@ -2177,10 +2191,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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]