/*
* 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,
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)) {
managed_save_path,
&def, &hdr);
if (managed_save_fd < 0)
- goto endjob;
+ goto cleanup;
restore_fd = managed_save_fd;
_("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);
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);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to restore domain '%s'"),
d_config.c_info.name);
- goto endjob;
+ goto cleanup;
}
/*
libxlDomainEventQueue(driver, event);
ret = 0;
- goto endjob;
+ goto cleanup;
cleanup_dom:
if (priv->deathW) {
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);
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:
- virObjectUnlock(vm);
+
+ endjob:
+ if (libxlDomainObjEndJob(driver, vm))
+ virObjectUnlock(vm);
+
return ret;
}
goto cleanup;
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,
-1) < 0) {
virDomainObjListRemove(driver->domains, vm);
- vm = NULL;
- goto cleanup;
+ 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)
fd = libxlDomainSaveImageOpen(driver, cfg, from, &def, &hdr);
if (fd < 0)
- return -1;
+ goto cleanup;
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
goto cleanup;
def = NULL;
+ 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) {
+ if (ret < 0 && !vm->persistent)
virDomainObjListRemove(driver->domains, vm);
+
+ if (!libxlDomainObjEndJob(driver, vm))
vm = NULL;
- }
cleanup:
if (VIR_CLOSE(fd) < 0)
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);