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

John Ferlan jferlan at redhat.com
Tue Apr 12 14:42:42 UTC 2016


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 at redhat.com>
---
 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




More information about the libvir-list mailing list