render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From c6a7e638954bbcb8679966f31ce398d97fa1aca1 Mon Sep 17 00:00:00 2001
Message-Id: <c6a7e638954bbcb8679966f31ce398d97fa1aca1@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 19 Feb 2020 15:10:00 +0100
Subject: [PATCH] virDomainDiskTranslateSourcePool: split code to setup one
 storage source
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Extract all the code setting up one storage source from the rest which
sets up the whole disk. This will allow us to prepare the whole backing
chain.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 63469116cc83d6d83a45b741826b48562b03a65f)

https://bugzilla.redhat.com/show_bug.cgi?id=1804603
Message-Id: <ed85da5fc3820ff9d272034b74cb03a63b35d9de.1582120424.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/domain_conf.c | 112 ++++++++++++++++++++---------------------
 1 file changed, 55 insertions(+), 57 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 68dd640dc5..ecd00aa8fc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31271,37 +31271,28 @@ virDomainDiskTranslateISCSIDirect(virStorageSourcePtr src,
 }
 
 
-int
-virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
+static int
+virDomainStorageSourceTranslateSourcePool(virStorageSourcePtr src,
+                                          virConnectPtr conn)
 {
     virStorageVolInfo info;
     g_autoptr(virStoragePoolDef) pooldef = NULL;
     g_autofree char *poolxml = NULL;
-    g_autoptr(virConnect) conn = NULL;
     g_autoptr(virStoragePool) pool = NULL;
     g_autoptr(virStorageVol) vol = NULL;
 
-    if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
-        return 0;
-
-    if (!def->src->srcpool)
-        return 0;
-
-    if (!(conn = virGetConnectStorage()))
-        return -1;
-
-    if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool)))
+    if (!(pool = virStoragePoolLookupByName(conn, src->srcpool->pool)))
         return -1;
 
     if (virStoragePoolIsActive(pool) != 1) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("storage pool '%s' containing volume '%s' "
                          "is not active"),
-                       def->src->srcpool->pool, def->src->srcpool->volume);
+                       src->srcpool->pool, src->srcpool->volume);
         return -1;
     }
 
-    if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume)))
+    if (!(vol = virStorageVolLookupByName(pool, src->srcpool->volume)))
         return -1;
 
     if (virStorageVolGetInfo(vol, &info) < 0)
@@ -31313,22 +31304,22 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
     if (!(pooldef = virStoragePoolDefParseString(poolxml)))
         return -1;
 
-    def->src->srcpool->pooltype = pooldef->type;
-    def->src->srcpool->voltype = info.type;
+    src->srcpool->pooltype = pooldef->type;
+    src->srcpool->voltype = info.type;
 
-    if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
+    if (src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("disk source mode is only valid when "
                          "storage pool is of iscsi type"));
         return -1;
     }
 
-    VIR_FREE(def->src->path);
-    virStorageNetHostDefFree(def->src->nhosts, def->src->hosts);
-    def->src->nhosts = 0;
-    def->src->hosts = NULL;
-    virStorageAuthDefFree(def->src->auth);
-    def->src->auth = NULL;
+    VIR_FREE(src->path);
+    virStorageNetHostDefFree(src->nhosts, src->hosts);
+    src->nhosts = 0;
+    src->hosts = NULL;
+    virStorageAuthDefFree(src->auth);
+    src->auth = NULL;
 
     switch ((virStoragePoolType) pooldef->type) {
     case VIR_STORAGE_POOL_DIR:
@@ -31339,32 +31330,24 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
     case VIR_STORAGE_POOL_SCSI:
     case VIR_STORAGE_POOL_ZFS:
     case VIR_STORAGE_POOL_VSTORAGE:
-        if (!(def->src->path = virStorageVolGetPath(vol)))
+        if (!(src->path = virStorageVolGetPath(vol)))
             return -1;
 
-        if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("'startupPolicy' is only valid for "
-                             "'file' type volume"));
-            return -1;
-        }
-
-
         switch (info.type) {
         case VIR_STORAGE_VOL_FILE:
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
             break;
 
         case VIR_STORAGE_VOL_DIR:
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR;
             break;
 
         case VIR_STORAGE_VOL_BLOCK:
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
             break;
 
         case VIR_STORAGE_VOL_PLOOP:
-            def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
+            src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE;
             break;
 
         case VIR_STORAGE_VOL_NETWORK:
@@ -31380,39 +31363,25 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
         break;
 
     case VIR_STORAGE_POOL_ISCSI_DIRECT:
-        if (def->startupPolicy) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("'startupPolicy' is only valid for "
-                             "'file' type volume"));
-            return -1;
-        }
-
-        if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
+        if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
             return -1;
 
         break;
 
     case VIR_STORAGE_POOL_ISCSI:
-        if (def->startupPolicy) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("'startupPolicy' is only valid for "
-                             "'file' type volume"));
-            return -1;
-        }
-
-       switch (def->src->srcpool->mode) {
+       switch (src->srcpool->mode) {
        case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT:
        case VIR_STORAGE_SOURCE_POOL_MODE_LAST:
-           def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
+           src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
            G_GNUC_FALLTHROUGH;
        case VIR_STORAGE_SOURCE_POOL_MODE_HOST:
-           def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
-           if (!(def->src->path = virStorageVolGetPath(vol)))
+           src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
+           if (!(src->path = virStorageVolGetPath(vol)))
                return -1;
            break;
 
        case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT:
-           if (virDomainDiskTranslateISCSIDirect(def->src, pooldef) < 0)
+           if (virDomainDiskTranslateISCSIDirect(src, pooldef) < 0)
                return -1;
            break;
        }
@@ -31434,6 +31403,35 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
 }
 
 
+int
+virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
+{
+    g_autoptr(virConnect) conn = NULL;
+
+    if (def->src->type != VIR_STORAGE_TYPE_VOLUME)
+        return 0;
+
+    if (!def->src->srcpool)
+        return 0;
+
+    if (!(conn = virGetConnectStorage()))
+        return -1;
+
+    if (virDomainStorageSourceTranslateSourcePool(def->src, conn) < 0)
+        return -1;
+
+    if (def->startupPolicy != 0 &&
+        virStorageSourceGetActualType(def->src) != VIR_STORAGE_VOL_FILE) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("'startupPolicy' is only valid for "
+                         "'file' type volume"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /**
  * virDomainDiskGetDetectZeroesMode:
  * @discard: disk/image sector discard setting
-- 
2.25.0