qemu: blockcopy: Allow copy of read-only disks with -blockdev

'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>
This commit is contained in:
Peter Krempa 2020-05-06 18:32:09 +02:00
parent fe574ea1f5
commit 65a12c467c
2 changed files with 14 additions and 0 deletions

View 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);

View 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) {