qemu: Alter error path cleanup for qemuDomainAttachChrDevice

Based on recent review comment - rather than have a spate of goto failxxxx,
change to a boolean based model. Ensures that the original error can be
preserved and cleanup is a bit more orderly if more objects are added.
This commit is contained in:
John Ferlan 2016-07-14 17:55:05 -04:00
parent c3b5f22dec
commit 05bc30d2bb

View File

@ -1508,9 +1508,11 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
{
int ret = -1, rc;
qemuDomainObjPrivatePtr priv = vm->privateData;
virErrorPtr orig_err;
virDomainDefPtr vmdef = vm->def;
char *devstr = NULL;
char *charAlias = NULL;
bool chardevAttached = false;
bool need_release = false;
if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
@ -1536,10 +1538,11 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor(driver, vm);
if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0)
goto failchardev;
goto exit_monitor;
chardevAttached = true;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
goto failadddev;
goto exit_monitor;
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto audit;
@ -1557,10 +1560,16 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
VIR_FREE(devstr);
return ret;
failadddev:
exit_monitor:
orig_err = virSaveLastError();
/* detach associated chardev on error */
if (chardevAttached)
qemuMonitorDetachCharDev(priv->mon, charAlias);
failchardev:
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
}
ignore_value(qemuDomainObjExitMonitor(driver, vm));
goto audit;
}