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