mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 04:55:18 +00:00
qemu: Clean up error path in qemuDomainAttachRedirdevDevice
It's about to get more complicated - let's alter the logic to handle various failures. Adds saving of the error as well.
This commit is contained in:
parent
8b82355e51
commit
7300ca2134
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user