diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b6e5640..d037c9d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1240,9 +1240,15 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver, qemuDomainObjEnterMonitor(driver, vm); if ((ret = qemuMonitorAddDrive(priv->mon, drvstr)) == 0) { if ((ret = qemuMonitorAddDevice(priv->mon, devstr)) < 0) { - VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", - drvstr, devstr); - qemuMonitorDriveDel(priv->mon, drvstr); + virErrorPtr orig_err = virSaveLastError(); + if (qemuMonitorDriveDel(priv->mon, drvstr) < 0) + VIR_WARN("Unable to remove drive %s (%s) after failed " + "qemuMonitorAddDevice", + drvstr, devstr); + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } } } qemuDomainObjExitMonitor(driver, vm); @@ -2545,9 +2551,15 @@ qemuDomainDetachHostScsiDevice(virQEMUDriverPtr driver, qemuDomainObjEnterMonitor(driver, vm); if ((ret = qemuMonitorDelDevice(priv->mon, detach->info->alias)) == 0) { if ((ret = qemuMonitorDriveDel(priv->mon, drvstr)) < 0) { - VIR_WARN("qemuMonitorDriveDel failed on %s (%s)", - detach->info->alias, drvstr); - qemuMonitorAddDevice(priv->mon, devstr); + virErrorPtr orig_err = virSaveLastError(); + if (qemuMonitorAddDevice(priv->mon, devstr) < 0) + VIR_WARN("Unable to add device %s (%s) after failed " + "qemuMonitorDriveDel", + drvstr, devstr); + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } } } qemuDomainObjExitMonitor(driver, vm);