[PATCH 09/12] qemu: hotplug: Adjust error path for attach hostdev scsi disk

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

 



Shortly a new object could be added making this code even more confusing,
so let's just adjust the exit path now to make it clearer.

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

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ec30ce7..b6cf196 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -602,7 +602,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
         goto failadddevice;
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
-        goto failexitmon;
+        goto failexitmonitor;
 
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
 
@@ -623,7 +623,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
  failadddrive:
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
 
- failexitmon:
+ failexitmonitor:
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
 
  error:
@@ -1929,6 +1929,7 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
 {
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr orig_err;
     virDomainControllerDefPtr cont = NULL;
     char *devstr = NULL;
     char *drvstr = NULL;
@@ -1989,32 +1990,24 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
         goto cleanup;
 
+    /* Attach the device - 2 step process */
     qemuDomainObjEnterMonitor(driver, vm);
-    if ((ret = qemuMonitorAddDrive(priv->mon, drvstr)) == 0) {
-        if ((ret = qemuMonitorAddDevice(priv->mon, devstr)) < 0) {
-            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);
-            }
-        }
-    }
-    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
-        ret = -1;
-        goto cleanup;
-    }
 
-    virDomainAuditHostdev(vm, hostdev, "attach", ret == 0);
-    if (ret < 0)
-        goto cleanup;
+    if (qemuMonitorAddDrive(priv->mon, drvstr) < 0)
+        goto failadddrive;
+
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto failadddevice;
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        goto failexitmonitor;
+
+    virDomainAuditHostdev(vm, hostdev, "attach", true);
 
     vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
 
     ret = 0;
+
  cleanup:
     qemuDomainSecretHostdevDestroy(hostdev);
     if (ret < 0) {
@@ -2029,6 +2022,25 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
     VIR_FREE(drvstr);
     VIR_FREE(devstr);
     return ret;
+
+ failadddevice:
+    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);
+    }
+
+ failadddrive:
+    ignore_value(qemuDomainObjExitMonitor(driver, vm));
+
+ failexitmonitor:
+    virDomainAuditHostdev(vm, hostdev, "attach", false);
+
+    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]