From: Peter Krempa Date: Mon, 17 Mar 2025 17:09:03 +0000 (+0100) Subject: qemuDomainChangeEjectableMedia: Separate rollback and success code paths X-Git-Tag: v11.2.0-rc1~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad94d8fb19d6cac5c5a0c2030d366c6f5f2d2956;p=thirdparty%2Flibvirt.git qemuDomainChangeEjectableMedia: Separate rollback and success code paths Do not use the rollback code path on success just to avoid extra call to qemuHotplugRemoveManagedPR. Rename the label and use it only when rolling back. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index db15a7262a..a8aed9c56e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -613,9 +613,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, qemuDomainObjPrivate *priv = vm->privateData; virStorageSource *oldsrc = disk->src; qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); - bool managedpr = virStorageSourceChainHasManagedPR(oldsrc) || - virStorageSourceChainHasManagedPR(newsrc); - int ret = -1; int rc; if (diskPriv->blockjob && qemuBlockJobIsRunning(diskPriv->blockjob)) { @@ -627,49 +624,45 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, disk->src = newsrc; if (virDomainDiskTranslateSourcePool(disk) < 0) - goto cleanup; + goto rollback; if (qemuDomainDetermineDiskChain(driver, vm, disk, NULL) < 0) - goto cleanup; + goto rollback; if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) - goto cleanup; + goto rollback; if (qemuDomainStorageSourceChainAccessAllow(driver, vm, newsrc) < 0) - goto cleanup; + goto rollback; if (qemuHotplugAttachManagedPR(vm, newsrc, VIR_ASYNC_JOB_NONE) < 0) - goto cleanup; + goto rollback; rc = qemuDomainChangeMediaBlockdev(vm, disk, oldsrc, newsrc, force); virDomainAuditDisk(vm, oldsrc, newsrc, "update", rc >= 0); if (rc < 0) - goto cleanup; + goto rollback; ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, oldsrc)); + if (virStorageSourceChainHasManagedPR(oldsrc)) + qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE); + /* media was changed, so we can remove the old media definition now */ g_clear_pointer(&oldsrc, virObjectUnref); + return 0; - ret = 0; - - cleanup: - /* undo changes to the new disk */ - if (ret < 0) { - ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, newsrc)); - } + rollback: + ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, newsrc)); - /* remove PR manager object if unneeded */ - if (managedpr) + if (virStorageSourceChainHasManagedPR(newsrc)) qemuHotplugRemoveManagedPR(vm, VIR_ASYNC_JOB_NONE); /* revert old image do the disk definition */ - if (oldsrc) - disk->src = oldsrc; - - return ret; + disk->src = oldsrc; + return -1; }