Blame SOURCES/libvirt-qemu-block-Properly-format-storage-slice-into-backing-store-strings.patch

fbe740
From 4d6f00b6dc1d17761ea5bd3656d0e60e2f6cfa61 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <4d6f00b6dc1d17761ea5bd3656d0e60e2f6cfa61@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Wed, 19 Feb 2020 15:10:22 +0100
fbe740
Subject: [PATCH] qemu: block: Properly format storage slice into backing store
fbe740
 strings
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
When creating overlay images e.g. for snapshots or when merging
fbe740
snapshots we often specify the backing store string to use. Make the
fbe740
formatter aware of backing chain entries which have a <slice>
fbe740
configured so that we record it properly. Otherwise such images
fbe740
would not work without the XML (when detecting the backing 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 73ca20146700c82e257b02ff8296e42a92629c58)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
fbe740
Message-Id: <68328ece6d627b223d5c7f56c5286fc5d0d04502.1582120424.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_block.c | 84 ++++++++++++++++++++++++++-----------------
fbe740
 1 file changed, 51 insertions(+), 33 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
fbe740
index 1147f4d3af..387a2db2e6 100644
fbe740
--- a/src/qemu/qemu_block.c
fbe740
+++ b/src/qemu/qemu_block.c
fbe740
@@ -1930,44 +1930,48 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
fbe740
 {
fbe740
     int actualType = virStorageSourceGetActualType(src);
fbe740
     g_autoptr(virJSONValue) backingProps = NULL;
fbe740
+    g_autoptr(virJSONValue) sliceProps = NULL;
fbe740
+    virJSONValuePtr props = NULL;
fbe740
     g_autoptr(virURI) uri = NULL;
fbe740
     g_autofree char *backingJSON = NULL;
fbe740
     char *ret = NULL;
fbe740
 
fbe740
-    if (virStorageSourceIsLocalStorage(src)) {
fbe740
-        ret = g_strdup(src->path);
fbe740
-        return ret;
fbe740
-    }
fbe740
-
fbe740
-    /* generate simplified URIs for the easy cases */
fbe740
-    if (actualType == VIR_STORAGE_TYPE_NETWORK &&
fbe740
-        src->nhosts == 1 &&
fbe740
-        src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
fbe740
-
fbe740
-        switch ((virStorageNetProtocol) src->protocol) {
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_NBD:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_HTTP:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_HTTPS:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_FTP:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_FTPS:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_TFTP:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_ISCSI:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
fbe740
-            if (!(uri = qemuBlockStorageSourceGetURI(src)))
fbe740
-                return NULL;
fbe740
-
fbe740
-            if (!(ret = virURIFormat(uri)))
fbe740
-                return NULL;
fbe740
-
fbe740
+    if (!src->sliceStorage) {
fbe740
+        if (virStorageSourceIsLocalStorage(src)) {
fbe740
+            ret = g_strdup(src->path);
fbe740
             return ret;
fbe740
+        }
fbe740
 
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_RBD:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_VXHS:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_SSH:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_LAST:
fbe740
-        case VIR_STORAGE_NET_PROTOCOL_NONE:
fbe740
-            break;
fbe740
+        /* generate simplified URIs for the easy cases */
fbe740
+        if (actualType == VIR_STORAGE_TYPE_NETWORK &&
fbe740
+            src->nhosts == 1 &&
fbe740
+            src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
fbe740
+
fbe740
+            switch ((virStorageNetProtocol) src->protocol) {
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_NBD:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_HTTP:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_HTTPS:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_FTP:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_FTPS:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_TFTP:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_ISCSI:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
fbe740
+                if (!(uri = qemuBlockStorageSourceGetURI(src)))
fbe740
+                    return NULL;
fbe740
+
fbe740
+                if (!(ret = virURIFormat(uri)))
fbe740
+                    return NULL;
fbe740
+
fbe740
+                return ret;
fbe740
+
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_RBD:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_VXHS:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_SSH:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_LAST:
fbe740
+            case VIR_STORAGE_NET_PROTOCOL_NONE:
fbe740
+                break;
fbe740
+            }
fbe740
         }
fbe740
     }
fbe740
 
fbe740
@@ -1975,7 +1979,21 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
fbe740
     if (!(backingProps = qemuBlockStorageSourceGetBackendProps(src, false, true, false)))
fbe740
         return NULL;
fbe740
 
fbe740
-    if (!(backingJSON = virJSONValueToString(backingProps, false)))
fbe740
+    props = backingProps;
fbe740
+
fbe740
+    if (src->sliceStorage) {
fbe740
+        if (virJSONValueObjectCreate(&sliceProps,
fbe740
+                                     "s:driver", "raw",
fbe740
+                                     "U:offset", src->sliceStorage->offset,
fbe740
+                                     "U:size", src->sliceStorage->size,
fbe740
+                                     "a:file", &backingProps,
fbe740
+                                     NULL) < 0)
fbe740
+            return NULL;
fbe740
+
fbe740
+        props = sliceProps;
fbe740
+    }
fbe740
+
fbe740
+    if (!(backingJSON = virJSONValueToString(props, false)))
fbe740
         return NULL;
fbe740
 
fbe740
     ret = g_strdup_printf("json:%s", backingJSON);
fbe740
-- 
fbe740
2.25.0
fbe740