We are overwriting @ret a lot. It makes hard to see what is actually going on. Use more gotos. Two functions are fixed here: qemuDomainDetachShmemDevice() and qemuDomainDetachWatchdog(). Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_hotplug.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0062e27a3b..e84dc909b9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5283,19 +5283,20 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver, } qemuDomainMarkDeviceForRemoval(vm, &shmem->info); + qemuDomainObjEnterMonitor(driver, vm); - - ret = qemuMonitorDelDevice(priv->mon, shmem->info.alias); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret = -1; - - if (ret == 0) { - if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) - ret = qemuDomainRemoveShmemDevice(driver, vm, shmem); + if (qemuMonitorDelDevice(priv->mon, shmem->info.alias) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + goto cleanup; } + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto cleanup; + + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) + ret = qemuDomainRemoveShmemDevice(driver, vm, shmem); + + cleanup: qemuDomainResetDeviceRemoval(vm); - return ret; } @@ -5336,19 +5337,20 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver, } qemuDomainMarkDeviceForRemoval(vm, &watchdog->info); + qemuDomainObjEnterMonitor(driver, vm); - - ret = qemuMonitorDelDevice(priv->mon, watchdog->info.alias); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret = -1; - - if (ret == 0) { - if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) - ret = qemuDomainRemoveWatchdog(driver, vm, watchdog); + if (qemuMonitorDelDevice(priv->mon, watchdog->info.alias) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + goto cleanup; } + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto cleanup; + + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) + ret = qemuDomainRemoveWatchdog(driver, vm, watchdog); + + cleanup: qemuDomainResetDeviceRemoval(vm); - return ret; } -- 2.16.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list