libvirt/SOURCES/libvirt-qemu-blockcopy-Allow-copy-of-read-only-disks-with-blockdev.patch
2021-09-10 11:57:33 +00:00

72 lines
3.0 KiB
Diff

From 352140578bbab5afe3f711c88732b24c6332da1a Mon Sep 17 00:00:00 2001
Message-Id: <352140578bbab5afe3f711c88732b24c6332da1a@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 12 May 2020 17:24:11 +0200
Subject: [PATCH] qemu: blockcopy: Allow copy of read-only disks with -blockdev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
'blockdev-mirror' requires the write permission internally to do the
copy. This means that we have to force the image to be read-write for
the duration of the copy and can fix it after the copy is done.
https://bugzilla.redhat.com/show_bug.cgi?id=1832204
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 65a12c467cd683809b4d445b8cf1c3ae250209b2)
Message-Id: <296aeeaa0ab2b90e872c76c6f15eda080b749bdb.1589296861.git.pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_blockjob.c | 5 +++++
src/qemu/qemu_driver.c | 9 +++++++++
2 files changed, 14 insertions(+)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 21a043d369..c80c71295b 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -1281,6 +1281,7 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDriverPtr driver,
qemuBlockJobDataPtr job,
qemuDomainAsyncJob asyncJob)
{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
VIR_DEBUG("copy job '%s' on VM '%s' pivoted", job->name, vm->def->name);
/* mirror may be NULL for copy job corresponding to migration */
@@ -1296,6 +1297,10 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDriverPtr driver,
!virStorageSourceIsBacking(job->disk->mirror->backingStore))
job->disk->mirror->backingStore = g_steal_pointer(&job->disk->src->backingStore);
+ if (job->disk->src->readonly &&
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN))
+ ignore_value(qemuBlockReopenReadOnly(vm, job->disk->mirror, asyncJob));
+
qemuBlockJobRewriteConfigDiskSource(vm, job->disk, job->disk->mirror);
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->disk->src);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7ae8641577..9f7d96c0b6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18389,6 +18389,15 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
keepParentLabel) < 0)
goto endjob;
+ if (mirror->readonly) {
+ if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN)) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("copy of read-only disks is not supported"));
+ goto endjob;
+ }
+ mirror->readonly = false;
+ }
+
/* we must initialize XML-provided chain prior to detecting to keep semantics
* with VM startup */
if (blockdev) {
--
2.26.2