mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
libxl: Domain event handler improvements
Since libxl provides the domain ID in the event handler callback, find the domain object based on the ID. This approach prevents processing the callback on a domain that has already been reaped. Also, similar to the xl implementation, ignore the SUSPEND shutdown reason. By calling libxl_domain_suspend(), we know a shutdown event with SUSPEND reason will be generated, but it can be safely ignored since any subsequent cleanup will be done by the callers.
This commit is contained in:
parent
02ed255e22
commit
702911496f
@ -666,26 +666,34 @@ libxlVmReap(libxlDriverPrivatePtr driver,
|
|||||||
* Handle previously registered event notification from libxenlight
|
* Handle previously registered event notification from libxenlight
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
libxlEventHandler(void *data, const libxl_event *event)
|
libxlEventHandler(void *data ATTRIBUTE_UNUSED, const libxl_event *event)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = libxl_driver;
|
libxlDriverPrivatePtr driver = libxl_driver;
|
||||||
virDomainObjPtr vm = data;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainEventPtr dom_event = NULL;
|
virDomainEventPtr dom_event = NULL;
|
||||||
|
libxl_shutdown_reason xl_reason = event->u.domain_shutdown.shutdown_reason;
|
||||||
libxlDriverLock(driver);
|
|
||||||
virObjectLock(vm);
|
|
||||||
libxlDriverUnlock(driver);
|
|
||||||
|
|
||||||
if (event->type == LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) {
|
if (event->type == LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) {
|
||||||
virDomainShutoffReason reason;
|
virDomainShutoffReason reason;
|
||||||
|
|
||||||
if (event->domid != vm->def->id)
|
/*
|
||||||
|
* Similar to the xl implementation, ignore SUSPEND. Any actions needed
|
||||||
|
* after calling libxl_domain_suspend() are handled by it's callers.
|
||||||
|
*/
|
||||||
|
if (xl_reason == LIBXL_SHUTDOWN_REASON_SUSPEND)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
switch (event->u.domain_shutdown.shutdown_reason) {
|
libxlDriverLock(driver);
|
||||||
|
vm = virDomainFindByID(&driver->domains, event->domid);
|
||||||
|
libxlDriverUnlock(driver);
|
||||||
|
|
||||||
|
if (!vm)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
switch (xl_reason) {
|
||||||
case LIBXL_SHUTDOWN_REASON_POWEROFF:
|
case LIBXL_SHUTDOWN_REASON_POWEROFF:
|
||||||
case LIBXL_SHUTDOWN_REASON_CRASH:
|
case LIBXL_SHUTDOWN_REASON_CRASH:
|
||||||
if (event->u.domain_shutdown.shutdown_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
|
if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
|
||||||
dom_event = virDomainEventNewFromObj(vm,
|
dom_event = virDomainEventNewFromObj(vm,
|
||||||
VIR_DOMAIN_EVENT_STOPPED,
|
VIR_DOMAIN_EVENT_STOPPED,
|
||||||
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
|
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
|
||||||
@ -704,7 +712,7 @@ libxlEventHandler(void *data, const libxl_event *event)
|
|||||||
libxlVmStart(driver, vm, 0, -1);
|
libxlVmStart(driver, vm, 0, -1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
VIR_INFO("Unhandled shutdown_reason %d", event->u.domain_shutdown.shutdown_reason);
|
VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user