[PATCH v2 2/3] storage: Create helper to set backing for CreateQemuImg code

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

 



Create a helper virStorageBackendCreateQemuImgSetBacking to perform the
backing store set

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend.c | 116 +++++++++++++++++++++++-------------------
 1 file changed, 64 insertions(+), 52 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index ff3f8c1..41c7bda 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1060,6 +1060,65 @@ virStorageBackendCreateQemuImgSetInput(virStorageVolDefPtr inputvol,
 }
 
 
+static int
+virStorageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
+                                         virStorageVolDefPtr vol,
+                                         virStorageVolDefPtr inputvol,
+                                         struct _virStorageBackendQemuImgInfo *info)
+{
+    int accessRetCode = -1;
+    char *absolutePath = NULL;
+
+    info->backingFormat = vol->target.backingStore->format;
+    info->backingPath = vol->target.backingStore->path;
+
+    if (info->preallocate) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("metadata preallocation conflicts with backing"
+                         " store"));
+        return -1;
+    }
+
+    /* XXX: Not strictly required: qemu-img has an option a different
+     * backing store, not really sure what use it serves though, and it
+     * may cause issues with lvm. Untested essentially.
+     */
+    if (inputvol && inputvol->target.backingStore &&
+        STRNEQ_NULLABLE(inputvol->target.backingStore->path,
+                        info->backingPath)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("a different backing store cannot be specified."));
+        return -1;
+    }
+
+    if (!virStorageFileFormatTypeToString(info->backingFormat)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unknown storage vol backing store type %d"),
+                       info->backingFormat);
+        return -1;
+    }
+
+    /* Convert relative backing store paths to absolute paths for access
+     * validation.
+     */
+    if ('/' != *(info->backingPath) &&
+        virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
+                    info->backingPath) < 0)
+        return -1;
+    accessRetCode = access(absolutePath ? absolutePath :
+                           info->backingPath, R_OK);
+    VIR_FREE(absolutePath);
+    if (accessRetCode != 0) {
+        virReportSystemError(errno,
+                             _("inaccessible backing store volume %s"),
+                             info->backingPath);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 
 /* Create a qemu-img virCommand from the supplied binary path,
  * volume definitions and imgformat
@@ -1075,7 +1134,6 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
 {
     virCommandPtr cmd = NULL;
     const char *type;
-    const char *backingType = NULL;
     char *opts = NULL;
     struct _virStorageBackendQemuImgInfo info = {
         .format = vol->target.format,
@@ -1120,54 +1178,10 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
         virStorageBackendCreateQemuImgSetInput(inputvol, &info) < 0)
         return NULL;
 
-    if (vol->target.backingStore) {
-        int accessRetCode = -1;
-        char *absolutePath = NULL;
-
-        info.backingFormat = vol->target.backingStore->format;
-        info.backingPath = vol->target.backingStore->path;
-
-        if (info.preallocate) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("metadata preallocation conflicts with backing"
-                             " store"));
-            return NULL;
-        }
-
-        /* XXX: Not strictly required: qemu-img has an option a different
-         * backing store, not really sure what use it serves though, and it
-         * may cause issues with lvm. Untested essentially.
-         */
-        if (inputvol && inputvol->target.backingStore &&
-            STRNEQ_NULLABLE(inputvol->target.backingStore->path, info.backingPath)) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("a different backing store cannot be specified."));
-            return NULL;
-        }
-
-        if (!(backingType = virStorageFileFormatTypeToString(info.backingFormat))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unknown storage vol backing store type %d"),
-                           info.backingFormat);
-            return NULL;
-        }
-
-        /* Convert relative backing store paths to absolute paths for access
-         * validation.
-         */
-        if ('/' != *(info.backingPath) &&
-            virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
-                        info.backingPath) < 0)
-            return NULL;
-        accessRetCode = access(absolutePath ? absolutePath : info.backingPath, R_OK);
-        VIR_FREE(absolutePath);
-        if (accessRetCode != 0) {
-            virReportSystemError(errno,
-                                 _("inaccessible backing store volume %s"),
-                                 info.backingPath);
-            return NULL;
-        }
-    }
+    if (vol->target.backingStore &&
+        virStorageBackendCreateQemuImgSetBacking(pool, vol, inputvol,
+                                                 &info) < 0)
+        return NULL;
 
     if (info.encryption &&
         virStorageBackendCreateQemuImgCheckEncryption(info.format, type,
@@ -1181,10 +1195,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     cmd = virCommandNew(create_tool);
 
     /* ignore the backing volume when we're converting a volume */
-    if (info.inputPath) {
+    if (info.inputPath)
         info.backingPath = NULL;
-        backingType = NULL;
-    }
 
     if (info.inputPath)
         virCommandAddArgList(cmd, "convert", "-f", info.inputFormatStr,
-- 
2.5.5

--
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]