libvirt/SOURCES/libvirt-qemu-block-Support-VIR_DOMAIN_BLOCK_COMMIT-PULL-REBASE_RELATIVE-with-blockdev.patch
2021-09-10 11:57:33 +00:00

128 lines
4.4 KiB
Diff

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