qemu: Refactor qemuDomainAttachChrDevice error paths

Refactor the error paths for attaching char device (it's about to be
more complicated).

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2016-06-13 12:57:15 -04:00
parent 323d5bdc94
commit 55931292c9

View File

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