render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 4d6f00b6dc1d17761ea5bd3656d0e60e2f6cfa61 Mon Sep 17 00:00:00 2001
Message-Id: <4d6f00b6dc1d17761ea5bd3656d0e60e2f6cfa61@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 19 Feb 2020 15:10:22 +0100
Subject: [PATCH] qemu: block: Properly format storage slice into backing store
 strings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When creating overlay images e.g. for snapshots or when merging
snapshots we often specify the backing store string to use. Make the
formatter aware of backing chain entries which have a <slice>
configured so that we record it properly. Otherwise such images
would not work without the XML (when detecting the backing chain).

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

https://bugzilla.redhat.com/show_bug.cgi?id=1791788
Message-Id: <68328ece6d627b223d5c7f56c5286fc5d0d04502.1582120424.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_block.c | 84 ++++++++++++++++++++++++++-----------------
 1 file changed, 51 insertions(+), 33 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 1147f4d3af..387a2db2e6 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1930,44 +1930,48 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
 {
     int actualType = virStorageSourceGetActualType(src);
     g_autoptr(virJSONValue) backingProps = NULL;
+    g_autoptr(virJSONValue) sliceProps = NULL;
+    virJSONValuePtr props = NULL;
     g_autoptr(virURI) uri = NULL;
     g_autofree char *backingJSON = NULL;
     char *ret = NULL;
 
-    if (virStorageSourceIsLocalStorage(src)) {
-        ret = g_strdup(src->path);
-        return ret;
-    }
-
-    /* generate simplified URIs for the easy cases */
-    if (actualType == VIR_STORAGE_TYPE_NETWORK &&
-        src->nhosts == 1 &&
-        src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
-
-        switch ((virStorageNetProtocol) src->protocol) {
-        case VIR_STORAGE_NET_PROTOCOL_NBD:
-        case VIR_STORAGE_NET_PROTOCOL_HTTP:
-        case VIR_STORAGE_NET_PROTOCOL_HTTPS:
-        case VIR_STORAGE_NET_PROTOCOL_FTP:
-        case VIR_STORAGE_NET_PROTOCOL_FTPS:
-        case VIR_STORAGE_NET_PROTOCOL_TFTP:
-        case VIR_STORAGE_NET_PROTOCOL_ISCSI:
-        case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
-            if (!(uri = qemuBlockStorageSourceGetURI(src)))
-                return NULL;
-
-            if (!(ret = virURIFormat(uri)))
-                return NULL;
-
+    if (!src->sliceStorage) {
+        if (virStorageSourceIsLocalStorage(src)) {
+            ret = g_strdup(src->path);
             return ret;
+        }
 
-        case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
-        case VIR_STORAGE_NET_PROTOCOL_RBD:
-        case VIR_STORAGE_NET_PROTOCOL_VXHS:
-        case VIR_STORAGE_NET_PROTOCOL_SSH:
-        case VIR_STORAGE_NET_PROTOCOL_LAST:
-        case VIR_STORAGE_NET_PROTOCOL_NONE:
-            break;
+        /* generate simplified URIs for the easy cases */
+        if (actualType == VIR_STORAGE_TYPE_NETWORK &&
+            src->nhosts == 1 &&
+            src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
+
+            switch ((virStorageNetProtocol) src->protocol) {
+            case VIR_STORAGE_NET_PROTOCOL_NBD:
+            case VIR_STORAGE_NET_PROTOCOL_HTTP:
+            case VIR_STORAGE_NET_PROTOCOL_HTTPS:
+            case VIR_STORAGE_NET_PROTOCOL_FTP:
+            case VIR_STORAGE_NET_PROTOCOL_FTPS:
+            case VIR_STORAGE_NET_PROTOCOL_TFTP:
+            case VIR_STORAGE_NET_PROTOCOL_ISCSI:
+            case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
+                if (!(uri = qemuBlockStorageSourceGetURI(src)))
+                    return NULL;
+
+                if (!(ret = virURIFormat(uri)))
+                    return NULL;
+
+                return ret;
+
+            case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
+            case VIR_STORAGE_NET_PROTOCOL_RBD:
+            case VIR_STORAGE_NET_PROTOCOL_VXHS:
+            case VIR_STORAGE_NET_PROTOCOL_SSH:
+            case VIR_STORAGE_NET_PROTOCOL_LAST:
+            case VIR_STORAGE_NET_PROTOCOL_NONE:
+                break;
+            }
         }
     }
 
@@ -1975,7 +1979,21 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
     if (!(backingProps = qemuBlockStorageSourceGetBackendProps(src, false, true, false)))
         return NULL;
 
-    if (!(backingJSON = virJSONValueToString(backingProps, false)))
+    props = backingProps;
+
+    if (src->sliceStorage) {
+        if (virJSONValueObjectCreate(&sliceProps,
+                                     "s:driver", "raw",
+                                     "U:offset", src->sliceStorage->offset,
+                                     "U:size", src->sliceStorage->size,
+                                     "a:file", &backingProps,
+                                     NULL) < 0)
+            return NULL;
+
+        props = sliceProps;
+    }
+
+    if (!(backingJSON = virJSONValueToString(props, false)))
         return NULL;
 
     ret = g_strdup_printf("json:%s", backingJSON);
-- 
2.25.0