render / rpms / libvirt

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