mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-14 12:58:33 +03:00
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: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
13e2c22099
commit
f86ae40324
@ -878,7 +878,7 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
|
|||||||
/*
|
/*
|
||||||
* Start a domain through libxenlight.
|
* Start a domain through libxenlight.
|
||||||
*
|
*
|
||||||
* virDomainObjPtr must be locked on invocation
|
* virDomainObjPtr must be locked and a job acquired on invocation
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
@ -903,16 +903,13 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
|
|
||||||
libxl_domain_config_init(&d_config);
|
libxl_domain_config_init(&d_config);
|
||||||
|
|
||||||
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
cfg = libxlDriverConfigGet(driver);
|
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 endjob;
|
goto cleanup;
|
||||||
|
|
||||||
if (virFileExists(managed_save_path)) {
|
if (virFileExists(managed_save_path)) {
|
||||||
|
|
||||||
@ -920,7 +917,7 @@ libxlDomainStart(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 endjob;
|
goto cleanup;
|
||||||
|
|
||||||
restore_fd = managed_save_fd;
|
restore_fd = managed_save_fd;
|
||||||
|
|
||||||
@ -934,7 +931,7 @@ libxlDomainStart(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 endjob;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainObjAssignDef(vm, def, true, NULL);
|
virDomainObjAssignDef(vm, def, true, NULL);
|
||||||
@ -951,14 +948,14 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
|
|
||||||
if (libxlBuildDomainConfig(driver->reservedVNCPorts, vm->def,
|
if (libxlBuildDomainConfig(driver->reservedVNCPorts, vm->def,
|
||||||
cfg->ctx, &d_config) < 0)
|
cfg->ctx, &d_config) < 0)
|
||||||
goto endjob;
|
goto cleanup;
|
||||||
|
|
||||||
if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
|
if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
|
||||||
goto endjob;
|
goto cleanup;
|
||||||
|
|
||||||
if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
|
if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
|
||||||
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
|
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
|
||||||
goto endjob;
|
goto cleanup;
|
||||||
|
|
||||||
/* Unlock virDomainObj while creating the domain */
|
/* Unlock virDomainObj while creating the domain */
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
@ -990,7 +987,7 @@ libxlDomainStart(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 endjob;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1037,7 +1034,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
libxlDomainEventQueue(driver, event);
|
libxlDomainEventQueue(driver, event);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto endjob;
|
goto cleanup;
|
||||||
|
|
||||||
cleanup_dom:
|
cleanup_dom:
|
||||||
if (priv->deathW) {
|
if (priv->deathW) {
|
||||||
@ -1048,10 +1045,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
vm->def->id = -1;
|
vm->def->id = -1;
|
||||||
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
|
||||||
|
|
||||||
endjob:
|
cleanup:
|
||||||
if (!libxlDomainObjEndJob(driver, vm))
|
|
||||||
vm = NULL;
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -303,18 +303,26 @@ libxlAutostartDomain(virDomainObjPtr vm,
|
|||||||
virObjectLock(vm);
|
virObjectLock(vm);
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
|
||||||
|
virObjectUnlock(vm);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (vm->autostart && !virDomainObjIsActive(vm) &&
|
if (vm->autostart && !virDomainObjIsActive(vm) &&
|
||||||
libxlDomainStart(driver, vm, false, -1) < 0) {
|
libxlDomainStart(driver, vm, false, -1) < 0) {
|
||||||
err = virGetLastError();
|
err = virGetLastError();
|
||||||
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
|
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
|
||||||
vm->def->name,
|
vm->def->name,
|
||||||
err ? err->message : _("unknown error"));
|
err ? err->message : _("unknown error"));
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(vm);
|
endjob:
|
||||||
|
if (libxlDomainObjEndJob(driver, vm))
|
||||||
|
virObjectUnlock(vm);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -885,17 +893,28 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
|
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,
|
if (libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0,
|
||||||
-1) < 0) {
|
-1) < 0) {
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
vm = NULL;
|
goto endjob;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
||||||
if (dom)
|
if (dom)
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
|
endjob:
|
||||||
|
if (!libxlDomainObjEndJob(driver, vm))
|
||||||
|
vm = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
if (vm)
|
if (vm)
|
||||||
@ -1681,7 +1700,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
|
|||||||
|
|
||||||
fd = libxlDomainSaveImageOpen(driver, cfg, from, &def, &hdr);
|
fd = libxlDomainSaveImageOpen(driver, cfg, from, &def, &hdr);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
|
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1695,12 +1714,21 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
|
|||||||
|
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) != 0, fd);
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) {
|
||||||
if (ret < 0 && !vm->persistent) {
|
if (!vm->persistent) {
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
vm = NULL;
|
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:
|
cleanup:
|
||||||
if (VIR_CLOSE(fd) < 0)
|
if (VIR_CLOSE(fd) < 0)
|
||||||
virReportSystemError(errno, "%s", _("cannot close file"));
|
virReportSystemError(errno, "%s", _("cannot close file"));
|
||||||
@ -2567,17 +2595,24 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
|
|||||||
if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjIsActive(vm)) {
|
if (virDomainObjIsActive(vm)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
"%s", _("Domain is already running"));
|
"%s", _("Domain is already running"));
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0, -1);
|
ret = libxlDomainStart(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0, -1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
dom->id = vm->def->id;
|
dom->id = vm->def->id;
|
||||||
|
|
||||||
|
endjob:
|
||||||
|
if (!libxlDomainObjEndJob(driver, vm))
|
||||||
|
vm = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user