[PATCH 07/12] qemu: hotplug: Adjust error path for attach virtio 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 | 55 ++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f308738..c3edd40 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -317,6 +317,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
 {
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr orig_err;
     char *devstr = NULL;
     char *drivestr = NULL;
     char *drivealias = NULL;
@@ -367,36 +368,24 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
         goto error;
 
+    /* Attach the device - 2 step process */
     qemuDomainObjEnterMonitor(driver, vm);
-    ret = qemuMonitorAddDrive(priv->mon, drivestr);
-    if (ret == 0) {
-        ret = qemuMonitorAddDevice(priv->mon, devstr);
-        if (ret < 0) {
-            virErrorPtr orig_err = virSaveLastError();
-            if (!drivealias ||
-                qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
-                VIR_WARN("Unable to remove drive %s (%s) after failed "
-                         "qemuMonitorAddDevice",
-                         NULLSTR(drivealias), drivestr);
-            }
-            if (orig_err) {
-                virSetError(orig_err);
-                virFreeError(orig_err);
-            }
-        }
-    }
+
+    if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
+        goto failadddrive;
+
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto failadddevice;
+
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
         releaseaddr = false;
-        ret = -1;
-        goto error;
+        goto failexitmonitor;
     }
 
-    virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
-
-    if (ret < 0)
-        goto error;
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
 
     virDomainDiskInsertPreAlloced(vm->def, disk);
+    ret = 0;
 
  cleanup:
     qemuDomainSecretDiskDestroy(disk);
@@ -406,6 +395,26 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     virObjectUnref(cfg);
     return ret;
 
+ failadddevice:
+    orig_err = virSaveLastError();
+    if (!drivealias ||
+        qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
+        VIR_WARN("Unable to remove drive %s (%s) after failed "
+                 "qemuMonitorAddDevice",
+                 NULLSTR(drivealias), drivestr);
+    }
+    if (orig_err) {
+        virSetError(orig_err);
+        virFreeError(orig_err);
+    }
+
+ failadddrive:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        releaseaddr = false;
+
+ failexitmonitor:
+    virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
+
  error:
     if (releaseaddr)
         qemuDomainReleaseDeviceAddress(vm, &disk->info, src);
-- 
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]