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

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