[PATCH v2 5/9] qemu: Add attempt to call qemuMonitorDriveDel for USB failure path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Partial fix for:
    https://bugzilla.redhat.com/show_bug.cgi?id=1336225

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@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1b6e21e..47ca38c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -706,7 +706,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;
     bool driveAdded = false;
@@ -725,8 +727,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;
 
@@ -752,16 +759,20 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
 
  cleanup:
     VIR_FREE(devstr);
+    VIR_FREE(drivealias);
     VIR_FREE(drivestr);
     virObjectUnref(cfg);
     return ret;
 
  exit_monitor:
-    if (driveAdded) {
-        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 (driveAdded && 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);
     }
 
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]