Blame SOURCES/libvirt-virDomainDiskTranslateSourcePool-split-code-to-setup-one-storage-source.patch

d76c62
From c6a7e638954bbcb8679966f31ce398d97fa1aca1 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <c6a7e638954bbcb8679966f31ce398d97fa1aca1@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Wed, 19 Feb 2020 15:10:00 +0100
d76c62
Subject: [PATCH] virDomainDiskTranslateSourcePool: split code to setup one
d76c62
 storage source
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Extract all the code setting up one storage source from the rest which
d76c62
sets up the whole disk. This will allow us to prepare the whole backing
d76c62
chain.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 63469116cc83d6d83a45b741826b48562b03a65f)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1804603
d76c62
Message-Id: <ed85da5fc3820ff9d272034b74cb03a63b35d9de.1582120424.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/conf/domain_conf.c | 112 ++++++++++++++++++++---------------------
d76c62
 1 file changed, 55 insertions(+), 57 deletions(-)
d76c62
d76c62
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
d76c62
index 68dd640dc5..ecd00aa8fc 100644
d76c62
--- a/src/conf/domain_conf.c
d76c62
+++ b/src/conf/domain_conf.c
d76c62
@@ -31271,37 +31271,28 @@ virDomainDiskTranslateISCSIDirect(virStorageSourcePtr src,
d76c62
 }
d76c62
 
d76c62
 
d76c62
-int
d76c62
-virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
+static int
d76c62
+virDomainStorageSourceTranslateSourcePool(virStorageSourcePtr src,
d76c62
+                                          virConnectPtr conn)
d76c62
 {
d76c62
     virStorageVolInfo info;
d76c62
     g_autoptr(virStoragePoolDef) pooldef = NULL;
d76c62
     g_autofree char *poolxml = NULL;
d76c62
-    g_autoptr(virConnect) conn = NULL;
d76c62
     g_autoptr(virStoragePool) pool = NULL;
d76c62
     g_autoptr(virStorageVol) vol = NULL;
d76c62
 
d76c62
-    if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
d76c62
-        return 0;
d76c62
-
d76c62
-    if (!def->src->srcpool)
d76c62
-        return 0;
d76c62
-
d76c62
-    if (!(conn = virGetConnectStorage()))
d76c62
-        return -1;
d76c62
-
d76c62
-    if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool)))
d76c62
+    if (!(pool = virStoragePoolLookupByName(conn, src->srcpool->pool)))
d76c62
         return -1;
d76c62
 
d76c62
     if (virStoragePoolIsActive(pool) != 1) {
d76c62
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
d76c62
                        _("storage pool '%s' containing volume '%s' "
d76c62
                          "is not active"),
d76c62
-                       def->src->srcpool->pool, def->src->srcpool->volume);
d76c62
+                       src->srcpool->pool, src->srcpool->volume);
d76c62
         return -1;
d76c62
     }
d76c62
 
d76c62
-    if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume)))
d76c62
+    if (!(vol = virStorageVolLookupByName(pool, src->srcpool->volume)))
d76c62
         return -1;
d76c62
 
d76c62
     if (virStorageVolGetInfo(vol, &info) < 0)
d76c62
@@ -31313,22 +31304,22 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
     if (!(pooldef = virStoragePoolDefParseString(poolxml)))
d76c62
         return -1;
d76c62
 
d76c62
-    def->src->srcpool->pooltype = pooldef->type;
d76c62
-    def->src->srcpool->voltype = info.type;
d76c62
+    src->srcpool->pooltype = pooldef->type;
d76c62
+    src->srcpool->voltype = info.type;
d76c62
 
d76c62
-    if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
d76c62
+    if (src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
d76c62
         virReportError(VIR_ERR_XML_ERROR, "%s",
d76c62
                        _("disk source mode is only valid when "
d76c62
                          "storage pool is of iscsi type"));
d76c62
         return -1;
d76c62
     }
d76c62
 
d76c62
-    VIR_FREE(def->src->path);
d76c62
-    virStorageNetHostDefFree(def->src->nhosts, def->src->hosts);
d76c62
-    def->src->nhosts = 0;
d76c62
-    def->src->hosts = NULL;
d76c62
-    virStorageAuthDefFree(def->src->auth);
d76c62
-    def->src->auth = NULL;
d76c62
+    VIR_FREE(src->path);
d76c62
+    virStorageNetHostDefFree(src->nhosts, src->hosts);
d76c62
+    src->nhosts = 0;
d76c62
+    src->hosts = NULL;
d76c62
+    virStorageAuthDefFree(src->auth);
d76c62
+    src->auth = NULL;
d76c62
 
d76c62
     switch ((virStoragePoolType) pooldef->type) {
d76c62
     case VIR_STORAGE_POOL_DIR:
d76c62
@@ -31339,32 +31330,24 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
     case VIR_STORAGE_POOL_SCSI:
d76c62
     case VIR_STORAGE_POOL_ZFS:
d76c62
     case VIR_STORAGE_POOL_VSTORAGE:
d76c62
-        if (!(def->src->path = virStorageVolGetPath(vol)))
d76c62
+        if (!(src->path = virStorageVolGetPath(vol)))
d76c62
             return -1;
d76c62
 
d76c62
-        if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) {
d76c62
-            virReportError(VIR_ERR_XML_ERROR, "%s",
d76c62
-                           _("'startupPolicy' is only valid for "
d76c62
-                             "'file' type volume"));
d76c62
-            return -1;
d76c62
-        }
d76c62
-
d76c62
-
d76c62
         switch (info.type) {
d76c62
         case VIR_STORAGE_VOL_FILE:
d76c62
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
d76c62
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
d76c62
             break;
d76c62
 
d76c62
         case VIR_STORAGE_VOL_DIR:
d76c62
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
d76c62
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
d76c62
             break;
d76c62
 
d76c62
         case VIR_STORAGE_VOL_BLOCK:
d76c62
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
d76c62
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
d76c62
             break;
d76c62
 
d76c62
         case VIR_STORAGE_VOL_PLOOP:
d76c62
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
d76c62
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
d76c62
             break;
d76c62
 
d76c62
         case VIR_STORAGE_VOL_NETWORK:
d76c62
@@ -31380,39 +31363,25 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
         break;
d76c62
 
d76c62
     case VIR_STORAGE_POOL_ISCSI_DIRECT:
d76c62
-        if (def->startupPolicy) {
d76c62
-            virReportError(VIR_ERR_XML_ERROR, "%s",
d76c62
-                           _("'startupPolicy' is only valid for "
d76c62
-                             "'file' type volume"));
d76c62
-            return -1;
d76c62
-        }
d76c62
-
d76c62
-        if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
d76c62
+        if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
d76c62
             return -1;
d76c62
 
d76c62
         break;
d76c62
 
d76c62
     case VIR_STORAGE_POOL_ISCSI:
d76c62
-        if (def->startupPolicy) {
d76c62
-            virReportError(VIR_ERR_XML_ERROR, "%s",
d76c62
-                           _("'startupPolicy' is only valid for "
d76c62
-                             "'file' type volume"));
d76c62
-            return -1;
d76c62
-        }
d76c62
-
d76c62
-       switch (def->src->srcpool->mode) {
d76c62
+       switch (src->srcpool->mode) {
d76c62
        case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT:
d76c62
        case VIR_STORAGE_SOURCE_POOL_MODE_LAST:
d76c62
-           def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
d76c62
+           src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
d76c62
            G_GNUC_FALLTHROUGH;
d76c62
        case VIR_STORAGE_SOURCE_POOL_MODE_HOST:
d76c62
-           def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
d76c62
-           if (!(def->src->path = virStorageVolGetPath(vol)))
d76c62
+           src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
d76c62
+           if (!(src->path = virStorageVolGetPath(vol)))
d76c62
                return -1;
d76c62
            break;
d76c62
 
d76c62
        case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT:
d76c62
-           if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
d76c62
+           if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
d76c62
                return -1;
d76c62
            break;
d76c62
        }
d76c62
@@ -31434,6 +31403,35 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
 }
d76c62
 
d76c62
 
d76c62
+int
d76c62
+virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
d76c62
+{
d76c62
+    g_autoptr(virConnect) conn = NULL;
d76c62
+
d76c62
+    if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
d76c62
+        return 0;
d76c62
+
d76c62
+    if (!def->src->srcpool)
d76c62
+        return 0;
d76c62
+
d76c62
+    if (!(conn = virGetConnectStorage()))
d76c62
+        return -1;
d76c62
+
d76c62
+    if (virDomainStorageSourceTranslateSourcePool(def->src, conn) < 0)
d76c62
+        return -1;
d76c62
+
d76c62
+    if (def->startupPolicy != 0 &&
d76c62
+        virStorageSourceGetActualType(def->src) != VIR_STORAGE_VOL_FILE) {
d76c62
+        virReportError(VIR_ERR_XML_ERROR, "%s",
d76c62
+                       _("'startupPolicy' is only valid for "
d76c62
+                         "'file' type volume"));
d76c62
+        return -1;
d76c62
+    }
d76c62
+
d76c62
+    return 0;
d76c62
+}
d76c62
+
d76c62
+
d76c62
 /**
d76c62
  * virDomainDiskGetDetectZeroesMode:
d76c62
  * @discard: disk/image sector discard setting
d76c62
-- 
d76c62
2.25.0
d76c62