]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: blockcopy: Allow copy of read-only disks with -blockdev
authorPeter Krempa <pkrempa@redhat.com>
Wed, 6 May 2020 16:32:09 +0000 (18:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 May 2020 04:56:09 +0000 (06:56 +0200)
'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>
src/qemu/qemu_blockjob.c
src/qemu/qemu_driver.c

index b9eecd3f982b7f3079c6741500d8acf45cf3bbf9..e51499532ff545aec2eef56c1ba11a9353daab2c 100644 (file)
@@ -1282,6 +1282,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 */
@@ -1297,6 +1298,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);
index a98a2986f56a7ab133b2660648904aa3c0f0ca44..db65862163d62cede03a6de43952936e48aedf0e 100644 (file)
@@ -18120,6 +18120,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) {