[PATCH 6/7] 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 | 118 ++++++++++++++++++++++++------------------
 1 file changed, 67 insertions(+), 51 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 4a3c41d..624790f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -940,6 +940,7 @@ struct _virStorageBackendQemuImgInfo {
     bool nocow;
 
     const char *backingPath;
+    const char *backingType;
     int backingFormat;
 
     const char *inputPath;
@@ -1065,6 +1066,66 @@ 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 (!(info->backingType =
+          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
@@ -1080,7 +1141,6 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
 {
     virCommandPtr cmd = NULL;
     const char *type;
-    const char *backingType = NULL;
     char *opts = NULL;
     struct _virStorageBackendQemuImgInfo info = {
         .format = vol->target.format,
@@ -1125,54 +1185,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,
@@ -1188,7 +1204,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     /* ignore the backing volume when we're converting a volume */
     if (info.inputPath) {
         info.backingPath = NULL;
-        backingType = NULL;
+        info.backingType = NULL;
     }
 
     if (info.inputPath)
@@ -1214,7 +1230,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
     } else {
         if (info.backingPath) {
             if (imgformat == X_QEMU_IMG_BACKING_FORMAT_FLAG)
-                virCommandAddArgList(cmd, "-F", backingType, NULL);
+                virCommandAddArgList(cmd, "-F", info.backingType, NULL);
             else
                 VIR_DEBUG("Unable to set backing store format for %s with %s",
                           info.path, create_tool);
-- 
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]