render / rpms / libvirt

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