[libvirt] [PATCH 2/3] storage: New flags to allow building the pool while creating it

Osier Yang jyang at redhat.com
Wed Jul 11 14:27:39 UTC 2012


We see the requirement for allowing to build the pool while pool-create
/pool-create-as/pool-start often in either upstream list or bugzilla,
so this patch introduces the flags virStoragePoolCreateFlags for
both virStoragePoolCreate and virStoragePoolCreateXML.

VIR_STORAGE_POOL_CREATE_WITH_BUILD allows to build the pool as
normal (for a filesystem pool, means only making the directory),
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE allows to build
the pool with overwriting the existed pool data. Oppositely,
VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE doesn't allow
to overwrite anything.
---
 include/libvirt/libvirt.h.in |   13 +++++++++++++
 src/libvirt.c                |    4 ++--
 src/storage/storage_driver.c |   38 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e1c9789..3646e78 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2362,6 +2362,19 @@ typedef enum {
     VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros (slow) */
 } virStoragePoolDeleteFlags;
 
+typedef enum {
+    VIR_STORAGE_POOL_CREATE_NORMAL = 0,
+
+    /* Create the pool with regular building */
+    VIR_STORAGE_POOL_CREATE_WITH_BUILD = 1 << 0,
+
+    /* Create the pool with building, overwrite the existing pool data */
+    VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE = 1 << 1,
+
+    /* Create the pool with building, don't overwrite the existing pool data */
+    VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = 1 << 2,
+} virStoragePoolCreateFlags;
+
 typedef struct _virStoragePoolInfo virStoragePoolInfo;
 
 struct _virStoragePoolInfo {
diff --git a/src/libvirt.c b/src/libvirt.c
index db6ba15..0cd6110 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -11595,7 +11595,7 @@ error:
  * virStoragePoolCreateXML:
  * @conn: pointer to hypervisor connection
  * @xmlDesc: XML description for new pool
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virStoragePoolCreateFlags
  *
  * Create a new storage based on its XML description. The
  * pool is not persistent, so its definition will disappear
@@ -11779,7 +11779,7 @@ error:
 /**
  * virStoragePoolCreate:
  * @pool: pointer to storage pool
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virStoragePoolCreateFlags
  *
  * Starts an inactive storage pool
  *
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index fbc630d..0835850 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -518,8 +518,11 @@ storagePoolCreate(virConnectPtr conn,
     virStoragePoolObjPtr pool = NULL;
     virStoragePoolPtr ret = NULL;
     virStorageBackendPtr backend;
+    unsigned int build_flags = 0;
 
-    virCheckFlags(0, NULL);
+    virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
+                  VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
+                  VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, NULL);
 
     storageDriverLock(driver);
     if (!(def = virStoragePoolDefParseString(xml)))
@@ -538,6 +541,21 @@ storagePoolCreate(virConnectPtr conn,
         goto cleanup;
     def = NULL;
 
+    if (backend->buildPool) {
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)
+            build_flags |= VIR_STORAGE_POOL_BUILD_NEW;
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
+            build_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
+            build_flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
+
+        if (backend->buildPool(conn, pool, build_flags) < 0) {
+            virStoragePoolObjRemove(&driver->pools, pool);
+            pool = NULL;
+            goto cleanup;
+        }
+    }
+
     if (backend->startPool &&
         backend->startPool(conn, pool) < 0) {
         virStoragePoolObjRemove(&driver->pools, pool);
@@ -670,8 +688,11 @@ storagePoolStart(virStoragePoolPtr obj,
     virStoragePoolObjPtr pool;
     virStorageBackendPtr backend;
     int ret = -1;
+    unsigned int start_flags = 0;
 
-    virCheckFlags(0, -1);
+    virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
+                  VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
+                  VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, -1);
 
     storageDriverLock(driver);
     pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
@@ -691,6 +712,19 @@ storagePoolStart(virStoragePoolPtr obj,
                               "%s", _("pool already active"));
         goto cleanup;
     }
+
+    if (backend->buildPool) {
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)
+            start_flags |= VIR_STORAGE_POOL_BUILD_NEW;
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
+            start_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
+        if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
+            start_flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
+
+        if (backend->buildPool(obj->conn, pool, start_flags) < 0)
+            goto cleanup;
+    }
+
     if (backend->startPool &&
         backend->startPool(obj->conn, pool) < 0)
         goto cleanup;
-- 
1.7.7.3




More information about the libvir-list mailing list