Blame SOURCES/libvirt-qemu-block-Support-VIR_DOMAIN_BLOCK_COMMIT-PULL-REBASE_RELATIVE-with-blockdev.patch

a41c76
From 9990d25b88bd2a03c5badb1e40da01030c4b68e4 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <9990d25b88bd2a03c5badb1e40da01030c4b68e4@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 30 Mar 2020 17:21:41 +0200
a41c76
Subject: [PATCH] qemu: block: Support
a41c76
 VIR_DOMAIN_BLOCK_COMMIT/PULL/REBASE_RELATIVE with blockdev
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Preservation of the relative relationship requires us to load the
a41c76
backing store strings from the disk images. With blockdev we stopped
a41c76
detecting the backing chain if it's specified in the XML so the relative
a41c76
links were not loaded at that point. To preserve the functionality from
a41c76
the pre-blockdev without accessing the backing chain unnecessarily
a41c76
during VM startup we must refresh the relative links when relative
a41c76
block commit or block pull is requested.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1818655
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit ffc6249c79dbf980d116af7c7ed20222538a7c1c)
a41c76
Message-Id: <05fc4389e00afd4b8bf5653fb730c4d8f6a4516d.1585581552.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_block.c  | 46 ++++++++++++++++++++++++++++++++++++++++++
a41c76
 src/qemu/qemu_block.h  |  5 +++++
a41c76
 src/qemu/qemu_driver.c |  8 ++++++++
a41c76
 3 files changed, 59 insertions(+)
a41c76
a41c76
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
a41c76
index ba7318b074..e7577c1312 100644
a41c76
--- a/src/qemu/qemu_block.c
a41c76
+++ b/src/qemu/qemu_block.c
a41c76
@@ -3341,3 +3341,49 @@ qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src)
a41c76
 
a41c76
     return virBufferContentAndReset(&buf;;
a41c76
 }
a41c76
+
a41c76
+
a41c76
+/**
a41c76
+ * qemuBlockUpdateRelativeBacking:
a41c76
+ * @vm: domain object
a41c76
+ * @src: starting point of the update
a41c76
+ * @topsrc: top level image in the backing chain (used to get security label)
a41c76
+ *
a41c76
+ * Reload data necessary for keeping backing store links starting from @src
a41c76
+ * relative.
a41c76
+ */
a41c76
+int
a41c76
+qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
a41c76
+                               virStorageSourcePtr src,
a41c76
+                               virStorageSourcePtr topsrc)
a41c76
+{
a41c76
+    qemuDomainObjPrivatePtr priv = vm->privateData;
a41c76
+    virQEMUDriverPtr driver = priv->driver;
a41c76
+    virStorageSourcePtr n;
a41c76
+
a41c76
+    for (n = src; virStorageSourceHasBacking(n); n = n->backingStore) {
a41c76
+        g_autofree char *backingStoreStr = NULL;
a41c76
+        int rc;
a41c76
+
a41c76
+        if (n->backingStore->relPath)
a41c76
+            break;
a41c76
+
a41c76
+        if (!virStorageFileSupportsBackingChainTraversal(n))
a41c76
+            continue;
a41c76
+
a41c76
+        if (qemuDomainStorageFileInit(driver, vm, n, topsrc) < 0)
a41c76
+            return -1;
a41c76
+
a41c76
+        rc = virStorageFileGetBackingStoreStr(n, &backingStoreStr);
a41c76
+
a41c76
+        virStorageFileDeinit(n);
a41c76
+
a41c76
+        if (rc < 0)
a41c76
+            return rc;
a41c76
+
a41c76
+        if (backingStoreStr && virStorageIsRelative(backingStoreStr))
a41c76
+            n->backingStore->relPath = g_steal_pointer(&backingStoreStr);
a41c76
+    }
a41c76
+
a41c76
+    return 0;
a41c76
+}
a41c76
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
a41c76
index 4e7708ce74..06afa54115 100644
a41c76
--- a/src/qemu/qemu_block.h
a41c76
+++ b/src/qemu/qemu_block.h
a41c76
@@ -258,3 +258,8 @@ qemuBlockReopenReadOnly(virDomainObjPtr vm,
a41c76
 
a41c76
 char *
a41c76
 qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src);
a41c76
+
a41c76
+int
a41c76
+qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
a41c76
+                               virStorageSourcePtr src,
a41c76
+                               virStorageSourcePtr topsrc);
a41c76
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
a41c76
index 3c3c7b6041..27a50f60ef 100644
a41c76
--- a/src/qemu/qemu_driver.c
a41c76
+++ b/src/qemu/qemu_driver.c
a41c76
@@ -17740,6 +17740,10 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm,
a41c76
                 goto endjob;
a41c76
             }
a41c76
 
a41c76
+            if (blockdev &&
a41c76
+                qemuBlockUpdateRelativeBacking(vm, disk->src, disk->src) < 0)
a41c76
+                goto endjob;
a41c76
+
a41c76
             if (virStorageFileGetRelativeBackingPath(disk->src->backingStore,
a41c76
                                                      baseSource,
a41c76
                                                      &backingPath) < 0)
a41c76
@@ -18867,6 +18871,10 @@ qemuDomainBlockCommit(virDomainPtr dom,
a41c76
             goto endjob;
a41c76
         }
a41c76
 
a41c76
+        if (blockdev && top_parent &&
a41c76
+            qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0)
a41c76
+            goto endjob;
a41c76
+
a41c76
         if (virStorageFileGetRelativeBackingPath(topSource, baseSource,
a41c76
                                                  &backingPath) < 0)
a41c76
             goto endjob;
a41c76
-- 
a41c76
2.26.0
a41c76