render / rpms / libvirt

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