Similar to the other disk types, add the qemuMonitorDriveDel in the failure
to add/hotplug a USB.
Added a couple of other formatting changes just to have a less cluttered look
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index be3ba4d..f73a0a8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -622,7 +622,9 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virErrorPtr orig_err;
int ret = -1;
+ char *drivealias = NULL;
char *drivestr = NULL;
char *devstr = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@@ -640,8 +642,13 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error;
+
if (!(drivestr = qemuBuildDriveStr(disk, false, priv->qemuCaps)))
goto error;
+
+ if (!(drivealias = qemuAssignDeviceDiskDriveAlias(disk->info.alias)))
+ goto error;
+
if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
goto error;
@@ -666,15 +673,21 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
cleanup:
VIR_FREE(devstr);
+ VIR_FREE(drivealias);
VIR_FREE(drivestr);
virObjectUnref(cfg);
return ret;
failadddevice:
- VIR_WARN("qemuMonitorAddDevice failed on %s (%s)",
- drivestr, devstr);
- /* XXX should call 'drive_del' on error but this does not
- exist yet */
+ orig_err = virSaveLastError();
+ if (qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
+ VIR_WARN("Unable to remove drive %s (%s) after failed "
+ "qemuMonitorAddDevice", drivealias, drivestr);
+ }
+ if (orig_err) {
+ virSetError(orig_err);
+ virFreeError(orig_err);
+ }
exit_monitor:
ignore_value(qemuDomainObjExitMonitor(driver, vm));
--
2.5.5