提交 491593e8 编写于 作者: J Jim Fehlig

libxl: use job functions in libxlVmStart

Creating a large domain could potentially be time consuming.  Use the
recently added job functions and unlock the virDomainObj while
the create operation is in progress.
Signed-off-by: NJim Fehlig <jfehlig@suse.com>
上级 4b4b61c3
...@@ -573,26 +573,30 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -573,26 +573,30 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
libxlSavefileHeader hdr; libxlSavefileHeader hdr;
int ret; int ret = -1;
uint32_t domid = 0; uint32_t domid = 0;
char *dom_xml = NULL; char *dom_xml = NULL;
char *managed_save_path = NULL; char *managed_save_path = NULL;
int managed_save_fd = -1; int managed_save_fd = -1;
libxlDomainObjPrivatePtr priv = vm->privateData; libxlDomainObjPrivatePtr priv = vm->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg;
#ifdef LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS #ifdef LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS
libxl_domain_restore_params params; libxl_domain_restore_params params;
#endif #endif
if (libxlDomainObjPrivateInitCtx(vm) < 0) if (libxlDomainObjPrivateInitCtx(vm) < 0)
goto error; return ret;
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 /* If there is a managed saved state restore it instead of starting
* from scratch. The old state is removed once the restoring succeeded. */ * from scratch. The old state is removed once the restoring succeeded. */
if (restore_fd < 0) { if (restore_fd < 0) {
managed_save_path = libxlDomainManagedSavePath(driver, vm); managed_save_path = libxlDomainManagedSavePath(driver, vm);
if (managed_save_path == NULL) if (managed_save_path == NULL)
goto error; goto endjob;
if (virFileExists(managed_save_path)) { if (virFileExists(managed_save_path)) {
...@@ -600,7 +604,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -600,7 +604,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
managed_save_path, managed_save_path,
&def, &hdr); &def, &hdr);
if (managed_save_fd < 0) if (managed_save_fd < 0)
goto error; goto endjob;
restore_fd = managed_save_fd; restore_fd = managed_save_fd;
...@@ -614,7 +618,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -614,7 +618,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
_("cannot restore domain '%s' uuid %s from a file" _("cannot restore domain '%s' uuid %s from a file"
" which belongs to domain '%s' uuid %s"), " which belongs to domain '%s' uuid %s"),
vm->def->name, vm_uuidstr, def->name, def_uuidstr); vm->def->name, vm_uuidstr, def->name, def_uuidstr);
goto error; goto endjob;
} }
virDomainObjAssignDef(vm, def, true, NULL); virDomainObjAssignDef(vm, def, true, NULL);
...@@ -632,17 +636,17 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -632,17 +636,17 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
libxl_domain_config_init(&d_config); libxl_domain_config_init(&d_config);
if (libxlBuildDomainConfig(driver, vm, &d_config) < 0) if (libxlBuildDomainConfig(driver, vm, &d_config) < 0)
goto error; goto endjob;
if (cfg->autoballoon && libxlFreeMem(priv, &d_config) < 0) { if (cfg->autoballoon && libxlFreeMem(priv, &d_config) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to get free memory for domain '%s'"), _("libxenlight failed to get free memory for domain '%s'"),
d_config.c_info.name); d_config.c_info.name);
goto error; goto endjob;
} }
/* use as synchronous operations => ao_how = NULL and no intermediate reports => ao_progress = NULL */ /* Unlock virDomainObj while creating the domain */
virObjectUnlock(vm);
if (restore_fd < 0) { if (restore_fd < 0) {
ret = libxl_domain_create_new(priv->ctx, &d_config, ret = libxl_domain_create_new(priv->ctx, &d_config,
&domid, NULL, NULL); &domid, NULL, NULL);
...@@ -656,6 +660,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -656,6 +660,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
restore_fd, NULL, NULL); restore_fd, NULL, NULL);
#endif #endif
} }
virObjectLock(vm);
if (ret) { if (ret) {
if (restore_fd < 0) if (restore_fd < 0)
...@@ -666,25 +671,29 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -666,25 +671,29 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to restore domain '%s'"), _("libxenlight failed to restore domain '%s'"),
d_config.c_info.name); d_config.c_info.name);
goto error; goto endjob;
} }
/*
* The domain has been successfully created with libxl, so it should
* be cleaned up if there are any subsequent failures.
*/
vm->def->id = domid; vm->def->id = domid;
if (libxlDomEventsRegister(vm) < 0) if (libxlDomEventsRegister(vm) < 0)
goto error; goto cleanup_dom;
if ((dom_xml = virDomainDefFormat(vm->def, 0)) == NULL) if ((dom_xml = virDomainDefFormat(vm->def, 0)) == NULL)
goto error; goto cleanup_dom;
if (libxl_userdata_store(priv->ctx, domid, "libvirt-xml", if (libxl_userdata_store(priv->ctx, domid, "libvirt-xml",
(uint8_t *)dom_xml, strlen(dom_xml) + 1)) { (uint8_t *)dom_xml, strlen(dom_xml) + 1)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("libxenlight failed to store userdata")); _("libxenlight failed to store userdata"));
goto error; goto cleanup_dom;
} }
if (libxlDomainSetVcpuAffinities(driver, vm) < 0) if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
goto error; goto cleanup_dom;
if (!start_paused) { if (!start_paused) {
libxl_domain_unpause(priv->ctx, domid); libxl_domain_unpause(priv->ctx, domid);
...@@ -693,9 +702,8 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -693,9 +702,8 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
} }
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto error; goto cleanup_dom;
if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);
...@@ -707,25 +715,25 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -707,25 +715,25 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
if (event) if (event)
libxlDomainEventQueue(driver, event); libxlDomainEventQueue(driver, event);
libxl_domain_config_dispose(&d_config); ret = 0;
VIR_FREE(dom_xml); goto endjob;
VIR_FORCE_CLOSE(managed_save_fd);
virObjectUnref(cfg); cleanup_dom:
return 0; libxl_domain_destroy(priv->ctx, domid, NULL);
vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
endjob:
if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
error:
if (domid > 0) {
libxl_domain_destroy(priv->ctx, domid, NULL);
vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
}
libxl_domain_config_dispose(&d_config); libxl_domain_config_dispose(&d_config);
VIR_FREE(dom_xml); VIR_FREE(dom_xml);
VIR_FREE(managed_save_path); VIR_FREE(managed_save_path);
virDomainDefFree(def); virDomainDefFree(def);
VIR_FORCE_CLOSE(managed_save_fd); VIR_FORCE_CLOSE(managed_save_fd);
virObjectUnref(cfg); virObjectUnref(cfg);
return -1; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册