mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
libxl: acquire a job when destroying a domain
A job should be acquired at the beginning of a domain destroy operation, not at the end when cleaning up the domain. Fix two occurrences of this late job acquisition in the libxl driver. Doing so renders libxlDomainCleanupJob unused, so it is removed. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
f86ae40324
commit
894d2ff759
@ -371,6 +371,9 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
|
|
||||||
cfg = libxlDriverConfigGet(driver);
|
cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
|
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (xl_reason == LIBXL_SHUTDOWN_REASON_POWEROFF) {
|
if (xl_reason == LIBXL_SHUTDOWN_REASON_POWEROFF) {
|
||||||
dom_event = virDomainEventLifecycleNewFromObj(vm,
|
dom_event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
VIR_DOMAIN_EVENT_STOPPED,
|
VIR_DOMAIN_EVENT_STOPPED,
|
||||||
@ -384,7 +387,7 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
goto restart;
|
goto restart;
|
||||||
case VIR_DOMAIN_LIFECYCLE_PRESERVE:
|
case VIR_DOMAIN_LIFECYCLE_PRESERVE:
|
||||||
case VIR_DOMAIN_LIFECYCLE_LAST:
|
case VIR_DOMAIN_LIFECYCLE_LAST:
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
} else if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
|
} else if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
|
||||||
dom_event = virDomainEventLifecycleNewFromObj(vm,
|
dom_event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
@ -399,7 +402,7 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
goto restart;
|
goto restart;
|
||||||
case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
|
case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
|
||||||
case VIR_DOMAIN_LIFECYCLE_CRASH_LAST:
|
case VIR_DOMAIN_LIFECYCLE_CRASH_LAST:
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
|
case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
|
||||||
libxlDomainAutoCoreDump(driver, vm);
|
libxlDomainAutoCoreDump(driver, vm);
|
||||||
goto destroy;
|
goto destroy;
|
||||||
@ -420,11 +423,11 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
goto restart;
|
goto restart;
|
||||||
case VIR_DOMAIN_LIFECYCLE_PRESERVE:
|
case VIR_DOMAIN_LIFECYCLE_PRESERVE:
|
||||||
case VIR_DOMAIN_LIFECYCLE_LAST:
|
case VIR_DOMAIN_LIFECYCLE_LAST:
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
|
VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy:
|
destroy:
|
||||||
@ -433,13 +436,11 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
dom_event = NULL;
|
dom_event = NULL;
|
||||||
}
|
}
|
||||||
libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
|
libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
|
||||||
if (libxlDomainCleanupJob(driver, vm, reason)) {
|
libxlDomainCleanup(driver, vm, reason);
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent)
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
vm = NULL;
|
|
||||||
}
|
goto endjob;
|
||||||
}
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
if (dom_event) {
|
if (dom_event) {
|
||||||
@ -447,13 +448,17 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
dom_event = NULL;
|
dom_event = NULL;
|
||||||
}
|
}
|
||||||
libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
|
libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
|
||||||
libxlDomainCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
|
||||||
if (libxlDomainStart(driver, vm, false, -1) < 0) {
|
if (libxlDomainStart(driver, vm, false, -1) < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
VIR_ERROR(_("Failed to restart VM '%s': %s"),
|
VIR_ERROR(_("Failed to restart VM '%s': %s"),
|
||||||
vm->def->name, err ? err->message : _("unknown error"));
|
vm->def->name, err ? err->message : _("unknown error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endjob:
|
||||||
|
if (!libxlDomainObjEndJob(driver, vm))
|
||||||
|
vm = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
@ -690,26 +695,6 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
|
|||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Cleanup function for domain that has reached shutoff state.
|
|
||||||
* Executed in the context of a job.
|
|
||||||
*
|
|
||||||
* virDomainObjPtr should be locked on invocation
|
|
||||||
* Returns true if references remain on virDomainObjPtr, false otherwise.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
libxlDomainCleanupJob(libxlDriverPrivatePtr driver,
|
|
||||||
virDomainObjPtr vm,
|
|
||||||
virDomainShutoffReason reason)
|
|
||||||
{
|
|
||||||
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_DESTROY) < 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
libxlDomainCleanup(driver, vm, reason);
|
|
||||||
|
|
||||||
return libxlDomainObjEndJob(driver, vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Core dump domain to default dump path.
|
* Core dump domain to default dump path.
|
||||||
*
|
*
|
||||||
@ -735,15 +720,11 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
|
|||||||
timestr) < 0)
|
timestr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
/* Unlock virDomainObj while dumping core */
|
/* Unlock virDomainObj while dumping core */
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
|
libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
|
||||||
virObjectLock(vm);
|
virObjectLock(vm);
|
||||||
|
|
||||||
ignore_value(libxlDomainObjEndJob(driver, vm));
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -108,10 +108,6 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
|
|||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainShutoffReason reason);
|
virDomainShutoffReason reason);
|
||||||
|
|
||||||
bool
|
|
||||||
libxlDomainCleanupJob(libxlDriverPrivatePtr driver,
|
|
||||||
virDomainObjPtr vm,
|
|
||||||
virDomainShutoffReason reason);
|
|
||||||
/*
|
/*
|
||||||
* Note: Xen 4.3 removed the const from the event handler signature.
|
* Note: Xen 4.3 removed the const from the event handler signature.
|
||||||
* Detect which signature to use based on
|
* Detect which signature to use based on
|
||||||
|
@ -1240,10 +1240,13 @@ libxlDomainDestroyFlags(virDomainPtr dom,
|
|||||||
if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainDestroyFlagsEnsureACL(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 not running"));
|
"%s", _("Domain is not running"));
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
|
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
|
||||||
@ -1252,18 +1255,19 @@ libxlDomainDestroyFlags(virDomainPtr dom,
|
|||||||
if (libxl_domain_destroy(cfg->ctx, vm->def->id, NULL) < 0) {
|
if (libxl_domain_destroy(cfg->ctx, vm->def->id, NULL) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to destroy domain '%d'"), vm->def->id);
|
_("Failed to destroy domain '%d'"), vm->def->id);
|
||||||
goto cleanup;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libxlDomainCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED)) {
|
libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent)
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
vm = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
endjob:
|
||||||
|
if (!libxlDomainObjEndJob(driver, vm))
|
||||||
|
vm = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user