mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +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;
|
virDomainDefPtr def = vm->def;
|
||||||
char *charAlias = NULL;
|
char *charAlias = NULL;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
|
bool chardevAdded = false;
|
||||||
|
virErrorPtr orig_err;
|
||||||
|
|
||||||
if (qemuAssignDeviceRedirdevAlias(def, redirdev, -1) < 0)
|
if (qemuAssignDeviceRedirdevAlias(def, redirdev, -1) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1525,17 +1527,12 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
|
|||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
if (qemuMonitorAttachCharDev(priv->mon,
|
if (qemuMonitorAttachCharDev(priv->mon,
|
||||||
charAlias,
|
charAlias,
|
||||||
redirdev->source.chr) < 0) {
|
redirdev->source.chr) < 0)
|
||||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
goto exit_monitor;
|
||||||
goto audit;
|
chardevAdded = true;
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
|
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
|
||||||
/* detach associated chardev on error */
|
goto exit_monitor;
|
||||||
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;
|
||||||
@ -1548,6 +1545,18 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
|
|||||||
VIR_FREE(charAlias);
|
VIR_FREE(charAlias);
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
return ret;
|
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
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user