提交 f86ae403 编写于 作者: J Jim Fehlig

libxl: Move job acquisition in libxlDomainStart to callers

Let callers of libxlDomainStart decide when it is appropriate to
acquire a job on the associated virDomainObj.
Signed-off-by: NJim Fehlig <jfehlig@suse.com>
上级 13e2c220
......@@ -878,7 +878,7 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
/*
* Start a domain through libxenlight.
*
* virDomainObjPtr must be locked on invocation
* virDomainObjPtr must be locked and a job acquired on invocation
*/
int
libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
......@@ -903,16 +903,13 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
libxl_domain_config_init(&d_config);
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
return ret;
cfg = libxlDriverConfigGet(driver);
/* If there is a managed saved state restore it instead of starting
* from scratch. The old state is removed once the restoring succeeded. */
if (restore_fd < 0) {
managed_save_path = libxlDomainManagedSavePath(driver, vm);
if (managed_save_path == NULL)
goto endjob;
goto cleanup;
if (virFileExists(managed_save_path)) {
......@@ -920,7 +917,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
managed_save_path,
&def, &hdr);
if (managed_save_fd < 0)
goto endjob;
goto cleanup;
restore_fd = managed_save_fd;
......@@ -934,7 +931,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
_("cannot restore domain '%s' uuid %s from a file"
" which belongs to domain '%s' uuid %s"),
vm->def->name, vm_uuidstr, def->name, def_uuidstr);
goto endjob;
goto cleanup;
}
virDomainObjAssignDef(vm, def, true, NULL);
......@@ -951,14 +948,14 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
if (libxlBuildDomainConfig(driver->reservedVNCPorts, vm->def,
cfg->ctx, &d_config) < 0)
goto endjob;
goto cleanup;
if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
goto endjob;
goto cleanup;
if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
goto endjob;
goto cleanup;
/* Unlock virDomainObj while creating the domain */
virObjectUnlock(vm);
......@@ -990,7 +987,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to restore domain '%s'"),
d_config.c_info.name);
goto endjob;
goto cleanup;
}
/*
......@@ -1037,7 +1034,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
libxlDomainEventQueue(driver, event);
ret = 0;
goto endjob;
goto cleanup;
cleanup_dom:
if (priv->deathW) {
......@@ -1048,10 +1045,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
endjob:
if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml);
VIR_FREE(managed_save_path);
......
......@@ -303,18 +303,26 @@ libxlAutostartDomain(virDomainObjPtr vm,
virObjectLock(vm);
virResetLastError();
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
virObjectUnlock(vm);
return ret;
}
if (vm->autostart && !virDomainObjIsActive(vm) &&
libxlDomainStart(driver, vm, false, -1) < 0) {
err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
vm->def->name,
err ? err->message : _("unknown error"));
goto cleanup;
goto endjob;
}
ret = 0;
cleanup:
endjob:
if (libxlDomainObjEndJob(driver, vm))
virObjectUnlock(vm);
return ret;
}
......@@ -885,17 +893,28 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
goto cleanup;
def = NULL;
if (libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0,
-1) < 0) {
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
if (!vm->persistent) {
virDomainObjListRemove(driver->domains, vm);
vm = NULL;
}
goto cleanup;
}
if (libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0,
-1) < 0) {
virDomainObjListRemove(driver->domains, vm);
goto endjob;
}
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
if (dom)
dom->id = vm->def->id;
endjob:
if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
virDomainDefFree(def);
if (vm)
......@@ -1681,7 +1700,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
fd = libxlDomainSaveImageOpen(driver, cfg, from, &def, &hdr);
if (fd < 0)
return -1;
goto cleanup;
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
goto cleanup;
......@@ -1695,11 +1714,20 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
def = NULL;
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) != 0, fd);
if (ret < 0 && !vm->persistent) {
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
if (!vm->persistent) {
virDomainObjListRemove(driver->domains, vm);
vm = NULL;
}
goto cleanup;
}
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) != 0, fd);
if (ret < 0 && !vm->persistent)
virDomainObjListRemove(driver->domains, vm);
if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
if (VIR_CLOSE(fd) < 0)
......@@ -2567,17 +2595,24 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
goto cleanup;
if (virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("Domain is already running"));
goto cleanup;
goto endjob;
}
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0, -1);
if (ret < 0)
goto cleanup;
goto endjob;
dom->id = vm->def->id;
endjob:
if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
if (vm)
virObjectUnlock(vm);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册