[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 05/10] 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@xxxxxxxx>
---
 src/libxl/libxl_domain.c | 21 ++-------------------
 src/libxl/libxl_domain.h | 15 +++++++++++++++
 src/libxl/libxl_driver.c |  9 +++++++++
 3 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 0fc03f7..73bd5d0 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -463,19 +463,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;
@@ -523,12 +513,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)
 {
@@ -762,7 +746,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))
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index f459fdf..96e238e 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -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);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5503c07..8e88645 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -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,
-- 
1.8.4.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.