The disk storage source needs to be prepared if we want to use -blockdev or secrets for the new media image. It does not hurt to do the same for the legacy hotplug code as well.
Unfortunately helpers like qemuDomainPrepareDiskSource take virDomainDiskDef as an argument and it would be hard to fix them to take an explicit source, so the function also temporarily replaces disk->src for the new source in this function. Signed-off-by: Peter Krempa <pkre...@redhat.com> --- src/qemu/qemu_hotplug.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7ee8201ce0..d201266805 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -730,10 +730,17 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, virStorageSourcePtr newsrc, bool force) { + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); qemuDomainObjPrivatePtr priv = vm->privateData; + virStorageSourcePtr oldsrc = disk->src; int ret = -1; int rc; + disk->src = newsrc; + + if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) + goto cleanup; + if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0) goto cleanup; @@ -741,11 +748,11 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, goto cleanup; if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) - rc = qemuDomainChangeMediaBlockdev(driver, vm, disk, disk->src, newsrc, force); + rc = qemuDomainChangeMediaBlockdev(driver, vm, disk, oldsrc, newsrc, force); else rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force); - virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >= 0); + virDomainAuditDisk(vm, oldsrc, newsrc, "update", rc >= 0); if (rc < 0) { ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, true)); @@ -753,17 +760,24 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, } /* remove the old source from shared device list */ + disk->src = oldsrc; ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); - ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true)); + ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, oldsrc, true)); - virStorageSourceFree(disk->src); - VIR_STEAL_PTR(disk->src, newsrc); + /* media was changed, so we can remove the old media definition now */ + virStorageSourceFree(oldsrc); + oldsrc = NULL; + disk->src = newsrc; ignore_value(qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE)); ret = 0; cleanup: + if (oldsrc) + disk->src = oldsrc; + + virObjectUnref(cfg); return ret; } -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list