[libvirt] [PATCH 1/5] qemu: Reorder qemuDomainAttachUSBMassStorageDevice failure path

John Ferlan jferlan at redhat.com
Wed Jun 29 21:38:00 UTC 2016


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 at redhat.com>
---
 src/qemu/qemu_hotplug.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e0b8230..ae5203e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -649,27 +649,20 @@ 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;
 
-    if (ret < 0)
-        goto error;
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto failadddevice;
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        goto failexitmonitor;
+
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
 
     virDomainDiskInsertPreAlloced(vm->def, disk);
+    ret = 0;
 
  cleanup:
     VIR_FREE(devstr);
@@ -677,6 +670,18 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
     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 */
+
+ exit_monitor:
+    ignore_value(qemuDomainObjExitMonitor(driver, vm));
+
+ failexitmonitor:
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
+
  error:
     ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
     goto cleanup;
-- 
2.5.5




More information about the libvir-list mailing list