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