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

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