[PATCH v2 1/9] qemu: Reorder qemuDomainAttachUSBMassStorageDevice failure path

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

 



Modify the error/exit path to match what was done for Virtio and SCSI.
If nothing else it'll have a consistent look'n'feel

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5e18d34..6364d68 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -709,6 +709,7 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
     int ret = -1;
     char *drivestr = NULL;
     char *devstr = NULL;
+    bool driveAdded = false;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     const char *src = virDomainDiskGetSource(disk);
 
@@ -733,27 +734,21 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
         goto error;
 
     qemuDomainObjEnterMonitor(driver, vm);
-    ret = qemuMonitorAddDrive(priv->mon, drivestr);
-    if (ret == 0) {
-        ret = qemuMonitorAddDevice(priv->mon, devstr);
-        if (ret < 0) {
-            VIR_WARN("qemuMonitorAddDevice failed on %s (%s)",
-                     drivestr, devstr);
-            /* XXX should call 'drive_del' on error but this does not
-               exist yet */
-        }
-    }
-    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
-        ret = -1;
-        goto error;
-    }
 
-    virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
+    if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
+        goto exit_monitor;
+    driveAdded = true;
 
-    if (ret < 0)
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto exit_monitor;
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto error;
 
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
+
     virDomainDiskInsertPreAlloced(vm->def, disk);
+    ret = 0;
 
  cleanup:
     VIR_FREE(devstr);
@@ -761,6 +756,17 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
     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 */
+    }
+
+    ignore_value(qemuDomainObjExitMonitor(driver, vm));
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
+
  error:
     ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
     goto cleanup;
-- 
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]