[PATCH 2/4] qemu: Clean up error path in qemuDomainAttachRedirdevDevice

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

 



It's about to get more complicated - let's alter the logic to handle
various failures. Adds saving of the error as well.

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

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8a7c7cb..cdd9222 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1509,6 +1509,8 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
     virDomainDefPtr def = vm->def;
     char *charAlias = NULL;
     char *devstr = NULL;
+    bool chardevAdded = false;
+    virErrorPtr orig_err;
 
     if (qemuAssignDeviceRedirdevAlias(def, redirdev, -1) < 0)
         goto cleanup;
@@ -1525,17 +1527,12 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
     qemuDomainObjEnterMonitor(driver, vm);
     if (qemuMonitorAttachCharDev(priv->mon,
                                  charAlias,
-                                 &(redirdev->source.chr)) < 0) {
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
-        goto audit;
-    }
+                                 &(redirdev->source.chr)) < 0)
+        goto exit_monitor;
+    chardevAdded = true;
 
-    if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
-        /* detach associated chardev on error */
-        qemuMonitorDetachCharDev(priv->mon, charAlias);
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
-        goto audit;
-    }
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto exit_monitor;
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto audit;
@@ -1548,6 +1545,18 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
     return ret;
+
+ exit_monitor:
+    orig_err = virSaveLastError();
+    /* detach associated chardev on error */
+    if (chardevAdded)
+        ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias));
+    if (orig_err) {
+        virSetError(orig_err);
+        virFreeError(orig_err);
+    }
+    ignore_value(qemuDomainObjExitMonitor(driver, vm));
+    goto audit;
 }
 
 static int
-- 
2.7.4

--
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]