提交 9d201a5c 编写于 作者: D Daniel P. Berrange

Don't overwrite error message during VM cleanup

If an LXC VM fails to start, quite a few cleanup paths will
result in the original error message being overwritten. Some
other cleanup paths also forgot to actually terminate the VM.

* src/lxc/lxc_driver.c: Ensure VM is terminated on startup
  failure and preserve original error
上级 26798492
...@@ -1638,6 +1638,7 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1638,6 +1638,7 @@ static int lxcVmStart(virConnectPtr conn,
char *timestamp; char *timestamp;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
lxcDomainObjPrivatePtr priv = vm->privateData; lxcDomainObjPrivatePtr priv = vm->privateData;
virErrorPtr err = NULL;
if (!lxc_driver->cgroup) { if (!lxc_driver->cgroup) {
lxcError(VIR_ERR_INTERNAL_ERROR, "%s", lxcError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -1769,8 +1770,7 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1769,8 +1770,7 @@ static int lxcVmStart(virConnectPtr conn,
_("guest failed to start: %s"), out); _("guest failed to start: %s"), out);
} }
lxcVmTerminate(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); goto error;
goto cleanup;
} }
if ((priv->monitorWatch = virEventAddHandle( if ((priv->monitorWatch = virEventAddHandle(
...@@ -1778,31 +1778,32 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1778,31 +1778,32 @@ static int lxcVmStart(virConnectPtr conn,
VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP, VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
lxcMonitorEvent, lxcMonitorEvent,
vm, NULL)) < 0) { vm, NULL)) < 0) {
lxcVmTerminate(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); goto error;
goto cleanup;
} }
if (autoDestroy && if (autoDestroy &&
lxcProcessAutoDestroyAdd(driver, vm, conn) < 0) lxcProcessAutoDestroyAdd(driver, vm, conn) < 0)
goto cleanup; goto error;
/* /*
* Again, need to save the live configuration, because the function * Again, need to save the live configuration, because the function
* requires vm->def->id != -1 to save tty info surely. * requires vm->def->id != -1 to save tty info surely.
*/ */
if (virDomainSaveConfig(driver->stateDir, vm->def) < 0) if (virDomainSaveConfig(driver->stateDir, vm->def) < 0)
goto cleanup; goto error;
if (virDomainObjSetDefTransient(driver->caps, vm, false) < 0) if (virDomainObjSetDefTransient(driver->caps, vm, false) < 0)
goto cleanup; goto error;
/* Write domain status to disk. */ /* Write domain status to disk. */
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
goto cleanup; goto error;
rc = 0; rc = 0;
cleanup: cleanup:
if (rc != 0 && !err)
err = virSaveLastError();
virCommandFree(cmd); virCommandFree(cmd);
if (VIR_CLOSE(logfd) < 0) { if (VIR_CLOSE(logfd) < 0) {
virReportSystemError(errno, "%s", _("could not close logfile")); virReportSystemError(errno, "%s", _("could not close logfile"));
...@@ -1821,7 +1822,18 @@ cleanup: ...@@ -1821,7 +1822,18 @@ cleanup:
VIR_FORCE_CLOSE(handshakefds[0]); VIR_FORCE_CLOSE(handshakefds[0]);
VIR_FORCE_CLOSE(handshakefds[1]); VIR_FORCE_CLOSE(handshakefds[1]);
VIR_FREE(logfile); VIR_FREE(logfile);
if (err) {
virSetError(err);
virResetError(err);
}
return rc; return rc;
error:
err = virSaveLastError();
lxcVmTerminate(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
goto cleanup;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册