[libvirt] [PATCHv2 1/9] storage: Add new argument for createVol backend API

Peter Krempa pkrempa at redhat.com
Thu Jan 16 13:14:30 UTC 2014


The new argument will be used when creating definitions for volumes that
already exist for the temporary storage volume APIs. The argument will
modify the expectations about the storage files and suppress some error
reports.
---

Notes:
    Version 2:
    - add commit message lost in a botched rebase
    - always initialize volume type for filesystem volumes

 src/storage/storage_backend.h          |  3 ++-
 src/storage/storage_backend_disk.c     |  3 ++-
 src/storage/storage_backend_fs.c       | 30 +++++++++++++++++++++++-------
 src/storage/storage_backend_logical.c  |  6 ++++--
 src/storage/storage_backend_rbd.c      |  3 ++-
 src/storage/storage_backend_sheepdog.c |  3 ++-
 src/storage/storage_driver.c           |  4 ++--
 7 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 378bc4d..34630fe 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -54,7 +54,8 @@ typedef int (*virStorageBackendBuildVol)(virConnectPtr conn,
                                          unsigned int flags);
 typedef int (*virStorageBackendCreateVol)(virConnectPtr conn,
                                           virStoragePoolObjPtr pool,
-                                          virStorageVolDefPtr vol);
+                                          virStorageVolDefPtr vol,
+                                          bool internal);
 typedef int (*virStorageBackendRefreshVol)(virConnectPtr conn,
                                            virStoragePoolObjPtr pool,
                                            virStorageVolDefPtr vol);
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index aa3b72f..a77c298 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -618,7 +618,8 @@ virStorageBackendDiskPartBoundries(virStoragePoolObjPtr pool,
 static int
 virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
-                               virStorageVolDefPtr vol)
+                               virStorageVolDefPtr vol,
+                               bool internal ATTRIBUTE_UNUSED)
 {
     if (vol->target.encryption != NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index fa11e2f..2594cde 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -996,8 +996,10 @@ virStorageBackendFileSystemDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
 static int
 virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
                                      virStoragePoolObjPtr pool,
-                                     virStorageVolDefPtr vol)
+                                     virStorageVolDefPtr vol,
+                                     bool internal)
 {
+    struct stat st;

     vol->type = VIR_STORAGE_VOL_FILE;

@@ -1007,15 +1009,29 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
                     vol->name) == -1)
         return -1;

-    if (virFileExists(vol->target.path)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       _("volume target path '%s' already exists"),
-                       vol->target.path);
-        return -1;
+    if (internal) {
+        vol->type = VIR_STORAGE_VOL_FILE;
+
+        if (stat(vol->target.path, &st) == 0) {
+            if (S_ISDIR(st.st_mode))
+                vol->type = VIR_STORAGE_VOL_DIR;
+            else if (S_ISBLK(st.st_mode))
+                vol->type = VIR_STORAGE_VOL_BLOCK;
+        }
+    } else {
+        if (virFileExists(vol->target.path)) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("volume target path '%s' already exists"),
+                           vol->target.path);
+            return -1;
+        }
     }

     VIR_FREE(vol->key);
-    return VIR_STRDUP(vol->key, vol->target.path);
+    if (VIR_STRDUP(vol->key, vol->target.path) < 0)
+        return -1;
+
+    return 0;
 }

 static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 039d962..2e2560f 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -784,7 +784,8 @@ error:
 static int
 virStorageBackendLogicalCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   virStoragePoolObjPtr pool,
-                                  virStorageVolDefPtr vol)
+                                  virStorageVolDefPtr vol,
+                                  bool internal)
 {
     if (vol->target.encryption != NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -800,7 +801,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                     vol->name) == -1)
         return -1;

-    if (virFileExists(vol->target.path)) {
+    if (!internal &&
+        virFileExists(vol->target.path)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("volume target path '%s' already exists"),
                        vol->target.path);
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index c5f0bc5..75425f4 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -439,7 +439,8 @@ cleanup:
 static int
 virStorageBackendRBDCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                               virStoragePoolObjPtr pool,
-                              virStorageVolDefPtr vol)
+                              virStorageVolDefPtr vol,
+                              bool internal ATTRIBUTE_UNUSED)
 {
     vol->type = VIR_STORAGE_VOL_NETWORK;

diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index a6981ce..705451b 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -152,7 +152,8 @@ virStorageBackendSheepdogDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
 static int
 virStorageBackendSheepdogCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
                                    virStoragePoolObjPtr pool,
-                                   virStorageVolDefPtr vol)
+                                   virStorageVolDefPtr vol,
+                                   bool internal ATTRIBUTE_UNUSED)
 {
     if (vol->target.encryption != NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index bb13e8e..a6bc801 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1643,7 +1643,7 @@ storageVolCreateXML(virStoragePoolPtr obj,
     /* Wipe any key the user may have suggested, as volume creation
      * will generate the canonical key.  */
     VIR_FREE(voldef->key);
-    if (backend->createVol(obj->conn, pool, voldef) < 0) {
+    if (backend->createVol(obj->conn, pool, voldef, false) < 0) {
         goto cleanup;
     }

@@ -1822,7 +1822,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
      * Wipe any key the user may have suggested, as volume creation
      * will generate the canonical key.  */
     VIR_FREE(newvol->key);
-    if (backend->createVol(obj->conn, pool, newvol) < 0) {
+    if (backend->createVol(obj->conn, pool, newvol, false) < 0) {
         goto cleanup;
     }

-- 
1.8.5.2




More information about the libvir-list mailing list