render / rpms / libvirt

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