render / rpms / libvirt

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