mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
libxl: move event registration to driver initialization
Register a domain event handler with the driver-wide libxl_ctx during driver initialization. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
331a02a701
commit
109cf8d89c
@ -470,19 +470,9 @@ libxlDomainShutdownThread(void *opaque)
|
||||
|
||||
/*
|
||||
* Handle previously registered domain event notification from libxenlight.
|
||||
*
|
||||
* Note: Xen 4.3 removed the const from the event handler signature.
|
||||
* Detect which signature to use based on
|
||||
* LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG.
|
||||
*/
|
||||
#ifdef LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG
|
||||
# define VIR_LIBXL_EVENT_CONST /* empty */
|
||||
#else
|
||||
# define VIR_LIBXL_EVENT_CONST const
|
||||
#endif
|
||||
|
||||
static void
|
||||
libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
|
||||
void
|
||||
libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
|
||||
{
|
||||
virDomainObjPtr vm = data;
|
||||
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||
@ -530,12 +520,6 @@ libxlEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
|
||||
libxl_event_free(priv->ctx, (libxl_event *)event);
|
||||
}
|
||||
|
||||
const struct libxl_event_hooks ev_hooks = {
|
||||
.event_occurs_mask = LIBXL_EVENTMASK_ALL,
|
||||
.event_occurs = libxlEventHandler,
|
||||
.disaster = NULL,
|
||||
};
|
||||
|
||||
int
|
||||
libxlDomainObjPrivateInitCtx(virDomainObjPtr vm)
|
||||
{
|
||||
@ -769,7 +753,6 @@ libxlDomainEventsRegister(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
|
||||
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||
|
||||
priv->driver = driver;
|
||||
libxl_event_register_callbacks(priv->ctx, &ev_hooks, vm);
|
||||
|
||||
/* Always enable domain death events */
|
||||
if (libxl_evenable_domain_death(priv->ctx, vm->def->id, 0, &priv->deathW))
|
||||
|
@ -118,6 +118,21 @@ bool
|
||||
libxlDomainCleanupJob(libxlDriverPrivatePtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virDomainShutoffReason reason);
|
||||
/*
|
||||
* Note: Xen 4.3 removed the const from the event handler signature.
|
||||
* Detect which signature to use based on
|
||||
* LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG.
|
||||
*/
|
||||
# ifdef LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG
|
||||
# define VIR_LIBXL_EVENT_CONST /* empty */
|
||||
# else
|
||||
# define VIR_LIBXL_EVENT_CONST const
|
||||
# endif
|
||||
|
||||
void
|
||||
libxlDomainEventHandler(void *data,
|
||||
VIR_LIBXL_EVENT_CONST libxl_event *event);
|
||||
|
||||
int
|
||||
libxlDomainEventsRegister(libxlDriverPrivatePtr driver,
|
||||
virDomainObjPtr vm);
|
||||
|
@ -481,6 +481,12 @@ static const libxl_childproc_hooks libxl_child_hooks = {
|
||||
#endif
|
||||
};
|
||||
|
||||
const struct libxl_event_hooks ev_hooks = {
|
||||
.event_occurs_mask = LIBXL_EVENTMASK_ALL,
|
||||
.event_occurs = libxlDomainEventHandler,
|
||||
.disaster = NULL,
|
||||
};
|
||||
|
||||
static int
|
||||
libxlStateInitialize(bool privileged,
|
||||
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
||||
@ -532,6 +538,9 @@ libxlStateInitialize(bool privileged,
|
||||
/* Setup child process handling. See $xen-src/tools/libxl/libxl_event.h */
|
||||
libxl_childproc_setmode(cfg->ctx, &libxl_child_hooks, cfg->ctx);
|
||||
|
||||
/* Register callback to handle domain events */
|
||||
libxl_event_register_callbacks(cfg->ctx, &ev_hooks, libxl_driver);
|
||||
|
||||
libxl_driver->config = cfg;
|
||||
if (virFileMakePath(cfg->stateDir) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
Loading…
Reference in New Issue
Block a user