]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Refactor qemuDomainAttachChrDevice error paths
authorJohn Ferlan <jferlan@redhat.com>
Mon, 13 Jun 2016 16:57:15 +0000 (12:57 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 14 Jun 2016 12:41:45 +0000 (08:41 -0400)
Refactor the error paths for attaching char device (it's about to be
more complicated).

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_hotplug.c

index 58156c6a432350337dfc09b1513e71f933a71b77..7d050739ad53ddde8196e74b8c62ed400cebe9dd 100644 (file)
@@ -1524,17 +1524,12 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
         goto cleanup;
 
     qemuDomainObjEnterMonitor(driver, vm);
-    if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0) {
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
-        goto audit;
-    }
+    if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0)
+        goto failchardev;
+
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto failadddev;
 
-    if (devstr && qemuMonitorAddDevice(priv->mon, devstr) < 0) {
-        /* detach associated chardev on error */
-        qemuMonitorDetachCharDev(priv->mon, charAlias);
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
-        goto audit;
-    }
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto audit;
 
@@ -1550,6 +1545,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
     return ret;
+
+ failadddev:
+    /* detach associated chardev on error */
+    qemuMonitorDetachCharDev(priv->mon, charAlias);
+ failchardev:
+    ignore_value(qemuDomainObjExitMonitor(driver, vm));
+    goto audit;
 }