]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add a virFreeCallback to event loop APIs
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 19 Nov 2008 16:24:01 +0000 (16:24 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 19 Nov 2008 16:24:01 +0000 (16:24 +0000)
16 files changed:
ChangeLog
examples/domain-events/events-c/event-test.c
include/libvirt/libvirt.h
include/libvirt/libvirt.h.in
python/libvir.c
python/libvirt_wrap.h
python/types.c
qemud/event.c
qemud/event.h
qemud/mdns.c
qemud/qemud.c
src/event.c
src/event.h
src/lxc_driver.c
src/qemu_driver.c
src/remote_internal.c

index c589c38fcbbab1267707adc137f4d399353b2c07..364fa0febbed0327823ea17118d01408fe1da801 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Wed Nov 19 16:22:00 GMT 2008 Daniel Berrange <berrange@redhat.com>
+
+       Add virFreeCallback to event loop APIs.
+       * include/libvirt/libvirt.h.in: Add a virFreeCallback arg
+       to the virEventAddHandle and virEventAddTimeout methods.
+       * qemud/event.c: Invoke the virFreeCallback when releasing
+       a handle/timer event
+       * qemud/event.h, qemud/qemud.c, qemud/mdns.c,
+       src/event.h, src/event.c, src/lxc_driver.c,
+       src/qemu_driver.c, src/remote_internal.c: Update to pass
+       around the virFreeCallback where needed
+
 Wed Nov 19 16:15:00 GMT 2008 Daniel Berrange <berrange@redhat.com>
 
        * include/libvirt/libvirt.h.in: Change semantics of AddHandle
index df463cf2cd16cda6df8ac59558b9de33aa411d07..f56980887cd292a85b9c128023d966596d9540b8 100644 (file)
@@ -24,6 +24,7 @@
 int h_fd = 0;
 virEventHandleType h_event = 0;
 virEventHandleCallback h_cb = NULL;
+virFreeCallback h_ff = NULL;
 void *h_opaque = NULL;
 
 /* timeout globals */
@@ -31,6 +32,7 @@ void *h_opaque = NULL;
 int t_active = 0;
 int t_timeout = -1;
 virEventTimeoutCallback t_cb = NULL;
+virFreeCallback t_ff = NULL;
 void *t_opaque = NULL;
 
 
@@ -41,12 +43,16 @@ int myDomainEventCallback1 (virConnectPtr conn, virDomainPtr dom,
 int myDomainEventCallback2 (virConnectPtr conn, virDomainPtr dom,
                             int event, int detail, void *opaque);
 int myEventAddHandleFunc  (int fd, int event,
-                           virEventHandleCallback cb, void *opaque);
+                           virEventHandleCallback cb,
+                           void *opaque,
+                           virFreeCallback ff);
 void myEventUpdateHandleFunc(int watch, int event);
 int  myEventRemoveHandleFunc(int watch);
 
-int myEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
-                          void *opaque);
+int myEventAddTimeoutFunc(int timeout,
+                          virEventTimeoutCallback cb,
+                          void *opaque,
+                          virFreeCallback ff);
 void myEventUpdateTimeoutFunc(int timer, int timout);
 int myEventRemoveTimeoutFunc(int timer);
 
@@ -208,12 +214,15 @@ virEventHandleType myPollEventToEventHandleType(int events)
 }
 
 int  myEventAddHandleFunc(int fd, int event,
-                          virEventHandleCallback cb, void *opaque)
+                          virEventHandleCallback cb,
+                          void *opaque,
+                          virFreeCallback ff)
 {
     DEBUG("Add handle %d %d %p %p", fd, event, cb, opaque);
     h_fd = fd;
     h_event = myEventHandleTypeToPollEvent(event);
     h_cb = cb;
+    h_ff = ff;
     h_opaque = opaque;
     return 0;
 }
@@ -229,16 +238,21 @@ int  myEventRemoveHandleFunc(int fd)
 {
     DEBUG("Removed Handle %d", fd);
     h_fd = 0;
+    if (h_ff)
+       (h_ff)(h_opaque);
     return 0;
 }
 
-int myEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
-                          void *opaque)
+int myEventAddTimeoutFunc(int timeout,
+                          virEventTimeoutCallback cb,
+                          void *opaque,
+                          virFreeCallback ff)
 {
     DEBUG("Adding Timeout %d %p %p", timeout, cb, opaque);
     t_active = 1;
     t_timeout = timeout;
     t_cb = cb;
+    t_ff = ff;
     t_opaque = opaque;
     return 0;
 }
@@ -253,6 +267,8 @@ int myEventRemoveTimeoutFunc(int timer)
 {
    DEBUG("Timeout removed %d", timer);
    t_active = 0;
+   if (t_ff)
+       (t_ff)(t_opaque);
    return 0;
 }
 
index af2ee2cfd5d9899d68a453c5b1d598b457661e1f..469c870c113d929f0b578406ba6a888cc341be4b 100644 (file)
@@ -1138,18 +1138,25 @@ typedef void (*virEventHandleCallback)(int watch, int fd, int events, void *opaq
  * virEventAddHandleFunc:
  * @fd: file descriptor to listen on
  * @event: bitset of events on which to fire the callback
- * @cb: the callback to be called
+ * @cb: the callback to be called when an event occurrs
  * @opaque: user data to pass to the callback
+ * @ff: the callback invoked to free opaque data blob
  *
  * Part of the EventImpl, this callback Adds a file handle callback to
  * listen for specific events. The same file handle can be registered
  * multiple times provided the requested event sets are non-overlapping
  *
+ * If the opaque user data requires free'ing when the handle
+ * is unregistered, then a 2nd callback can be supplied for
+ * this purpose.
+ *
  * Returns a handle watch number to be used for updating
  * and unregistering for events
  */
 typedef int (*virEventAddHandleFunc)(int fd, int event,
-                                     virEventHandleCallback cb, void *opaque);
+                                     virEventHandleCallback cb,
+                                     void *opaque,
+                                     virFreeCallback ff);
 
 /**
  * virEventUpdateHandleFunc:
@@ -1166,7 +1173,11 @@ typedef void (*virEventUpdateHandleFunc)(int watch, int event);
  * @watch: file descriptor watch to stop listening on
  *
  * Part of the EventImpl, this user-provided callback is notified when
- * an fd is no longer being listened on
+ * an fd is no longer being listened on.
+ *
+ * If a virEventHandleFreeFunc was supplied when the handle was
+ * registered, it will be invoked some time during, or after this
+ * function call, when it is safe to release the user data.
  */
 typedef int (*virEventRemoveHandleFunc)(int watch);
 
@@ -1185,14 +1196,21 @@ typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
  * @timeout: The timeout to monitor
  * @cb: the callback to call when timeout has expired
  * @opaque: user data to pass to the callback
+ * @ff: the callback invoked to free opaque data blob
  *
  * Part of the EventImpl, this user-defined callback handles adding an
  * event timeout.
  *
+ * If the opaque user data requires free'ing when the handle
+ * is unregistered, then a 2nd callback can be supplied for
+ * this purpose.
+ *
  * Returns a timer value
  */
-typedef int (*virEventAddTimeoutFunc)(int timeout, virEventTimeoutCallback cb,
-                                      void *opaque);
+typedef int (*virEventAddTimeoutFunc)(int timeout,
+                                      virEventTimeoutCallback cb,
+                                      void *opaque,
+                                      virFreeCallback ff);
 
 /**
  * virEventUpdateTimeoutFunc:
@@ -1210,6 +1228,10 @@ typedef void (*virEventUpdateTimeoutFunc)(int timer, int timeout);
  *
  * Part of the EventImpl, this user-defined callback removes a timer
  *
+ * If a virEventTimeoutFreeFunc was supplied when the handle was
+ * registered, it will be invoked some time during, or after this
+ * function call, when it is safe to release the user data.
+ *
  * Returns 0 on success, -1 on failure
  */
 typedef int (*virEventRemoveTimeoutFunc)(int timer);
index 08712d03b70364261cad87c71381499a57a4f0b8..5bdc67710c53ebeefd1cf38d5b79a41a7dd600c9 100644 (file)
@@ -1138,18 +1138,25 @@ typedef void (*virEventHandleCallback)(int watch, int fd, int events, void *opaq
  * virEventAddHandleFunc:
  * @fd: file descriptor to listen on
  * @event: bitset of events on which to fire the callback
- * @cb: the callback to be called
+ * @cb: the callback to be called when an event occurrs
  * @opaque: user data to pass to the callback
+ * @ff: the callback invoked to free opaque data blob
  *
  * Part of the EventImpl, this callback Adds a file handle callback to
  * listen for specific events. The same file handle can be registered
  * multiple times provided the requested event sets are non-overlapping
  *
+ * If the opaque user data requires free'ing when the handle
+ * is unregistered, then a 2nd callback can be supplied for
+ * this purpose.
+ *
  * Returns a handle watch number to be used for updating
  * and unregistering for events
  */
 typedef int (*virEventAddHandleFunc)(int fd, int event,
-                                     virEventHandleCallback cb, void *opaque);
+                                     virEventHandleCallback cb,
+                                     void *opaque,
+                                     virFreeCallback ff);
 
 /**
  * virEventUpdateHandleFunc:
@@ -1166,7 +1173,11 @@ typedef void (*virEventUpdateHandleFunc)(int watch, int event);
  * @watch: file descriptor watch to stop listening on
  *
  * Part of the EventImpl, this user-provided callback is notified when
- * an fd is no longer being listened on
+ * an fd is no longer being listened on.
+ *
+ * If a virEventHandleFreeFunc was supplied when the handle was
+ * registered, it will be invoked some time during, or after this
+ * function call, when it is safe to release the user data.
  */
 typedef int (*virEventRemoveHandleFunc)(int watch);
 
@@ -1185,14 +1196,21 @@ typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
  * @timeout: The timeout to monitor
  * @cb: the callback to call when timeout has expired
  * @opaque: user data to pass to the callback
+ * @ff: the callback invoked to free opaque data blob
  *
  * Part of the EventImpl, this user-defined callback handles adding an
  * event timeout.
  *
+ * If the opaque user data requires free'ing when the handle
+ * is unregistered, then a 2nd callback can be supplied for
+ * this purpose.
+ *
  * Returns a timer value
  */
-typedef int (*virEventAddTimeoutFunc)(int timeout, virEventTimeoutCallback cb,
-                                      void *opaque);
+typedef int (*virEventAddTimeoutFunc)(int timeout,
+                                      virEventTimeoutCallback cb,
+                                      void *opaque,
+                                      virFreeCallback ff);
 
 /**
  * virEventUpdateTimeoutFunc:
@@ -1210,6 +1228,10 @@ typedef void (*virEventUpdateTimeoutFunc)(int timer, int timeout);
  *
  * Part of the EventImpl, this user-defined callback removes a timer
  *
+ * If a virEventTimeoutFreeFunc was supplied when the handle was
+ * registered, it will be invoked some time during, or after this
+ * function call, when it is safe to release the user data.
+ *
  * Returns 0 on success, -1 on failure
  */
 typedef int (*virEventRemoveTimeoutFunc)(int timer);
index 8fb9d60d931d3f8ad6898949c1190c7e742fde76..07ed09ede30d85f17c2debb3ec0bb19c156e712c 100644 (file)
@@ -1704,12 +1704,16 @@ static PyObject *removeTimeoutObj = NULL;
 
 
 static int
-libvirt_virEventAddHandleFunc  (int fd ATTRIBUTE_UNUSED, int event ATTRIBUTE_UNUSED,
-                                virEventHandleCallback cb, void *opaque)
+libvirt_virEventAddHandleFunc  (int fd,
+                                int event,
+                                virEventHandleCallback cb,
+                                void *opaque,
+                                virFreeCallback ff)
 {
     PyObject *result = NULL;
     PyObject *python_cb;
     PyObject *cb_obj;
+    PyObject *ff_obj;
     PyObject *opaque_obj;
     PyObject *cb_args;
     PyObject *pyobj_args;
@@ -1730,11 +1734,13 @@ libvirt_virEventAddHandleFunc  (int fd ATTRIBUTE_UNUSED, int event ATTRIBUTE_UNU
 
     /* create tuple for cb */
     cb_obj = libvirt_virEventHandleCallbackWrap(cb);
+    ff_obj = libvirt_virFreeCallbackWrap(ff);
     opaque_obj = libvirt_virVoidPtrWrap(opaque);
 
-    cb_args = PyTuple_New(2);
+    cb_args = PyTuple_New(3);
     PyTuple_SetItem(cb_args, 0, cb_obj);
     PyTuple_SetItem(cb_args, 1, opaque_obj);
+    PyTuple_SetItem(cb_args, 2, ff_obj);
 
     pyobj_args = PyTuple_New(4);
     PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd));
@@ -1799,14 +1805,17 @@ libvirt_virEventRemoveHandleFunc(int fd)
 }
 
 static int
-libvirt_virEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
-                               void *opaque)
+libvirt_virEventAddTimeoutFunc(int timeout,
+                               virEventTimeoutCallback cb,
+                               void *opaque,
+                               virFreeCallback ff)
 {
     PyObject *result = NULL;
 
     PyObject *python_cb;
 
     PyObject *cb_obj;
+    PyObject *ff_obj;
     PyObject *opaque_obj;
     PyObject *cb_args;
     PyObject *pyobj_args;
@@ -1827,11 +1836,13 @@ libvirt_virEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
 
     /* create tuple for cb */
     cb_obj = libvirt_virEventTimeoutCallbackWrap(cb);
+    ff_obj = libvirt_virFreeCallbackWrap(ff);
     opaque_obj = libvirt_virVoidPtrWrap(opaque);
 
-    cb_args = PyTuple_New(2);
+    cb_args = PyTuple_New(3);
     PyTuple_SetItem(cb_args, 0, cb_obj);
     PyTuple_SetItem(cb_args, 1, opaque_obj);
+    PyTuple_SetItem(cb_args, 2, ff_obj);
 
     pyobj_args = PyTuple_New(3);
 
index b46deafae2106c2546225a36641bd959e1690ebe..b3cbcb8788277544fe89be61497ef81a8f363303 100644 (file)
@@ -103,6 +103,7 @@ PyObject * libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node);
 PyObject * libvirt_virStorageVolPtrWrap(virStorageVolPtr node);
 PyObject * libvirt_virEventHandleCallbackWrap(virEventHandleCallback node);
 PyObject * libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node);
+PyObject * libvirt_virFreeCallbackWrap(virFreeCallback node);
 PyObject * libvirt_virVoidPtrWrap(void* node);
 
 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
index 1c1db89a047eb2509ccb97de7218636224f87bf2..4285134f4dd154924aeda60cdff22f7f278eeba5 100644 (file)
@@ -195,6 +195,22 @@ libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
     return (ret);
 }
 
+PyObject *
+libvirt_virFreeCallbackWrap(virFreeCallback node)
+{
+    PyObject *ret;
+
+    if (node == NULL) {
+        printf("%s: WARNING - Wrapping None\n", __FUNCTION__);
+        Py_INCREF(Py_None);
+        return (Py_None);
+    }
+    ret =
+        PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
+                                     NULL);
+    return (ret);
+}
+
 PyObject *
 libvirt_virVoidPtrWrap(void* node)
 {
index 3054064a943f8e58200235296368d4453b401bdf..e8eed0c42de8f83a7e959a55a2dceb3d52b91792 100644 (file)
@@ -41,6 +41,7 @@ struct virEventHandle {
     int fd;
     int events;
     virEventHandleCallback cb;
+    virFreeCallback ff;
     void *opaque;
     int deleted;
 };
@@ -51,6 +52,7 @@ struct virEventTimeout {
     int frequency;
     unsigned long long expiresAt;
     virEventTimeoutCallback cb;
+    virFreeCallback ff;
     void *opaque;
     int deleted;
 };
@@ -83,8 +85,10 @@ static int nextTimer = 0;
  * NB, it *must* be safe to call this from within a callback
  * For this reason we only ever append to existing list.
  */
-int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb,
-                          void *opaque) {
+int virEventAddHandleImpl(int fd, int events,
+                          virEventHandleCallback cb,
+                          void *opaque,
+                          virFreeCallback ff) {
     EVENT_DEBUG("Add handle %d %d %p %p", fd, events, cb, opaque);
     if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
         EVENT_DEBUG("Used %d handle slots, adding %d more",
@@ -100,6 +104,7 @@ int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb,
     eventLoop.handles[eventLoop.handlesCount].events =
                                          virEventHandleTypeToPollEvent(events);
     eventLoop.handles[eventLoop.handlesCount].cb = cb;
+    eventLoop.handles[eventLoop.handlesCount].ff = ff;
     eventLoop.handles[eventLoop.handlesCount].opaque = opaque;
     eventLoop.handles[eventLoop.handlesCount].deleted = 0;
 
@@ -147,7 +152,10 @@ int virEventRemoveHandleImpl(int watch) {
  * NB, it *must* be safe to call this from within a callback
  * For this reason we only ever append to existing list.
  */
-int virEventAddTimeoutImpl(int frequency, virEventTimeoutCallback cb, void *opaque) {
+int virEventAddTimeoutImpl(int frequency,
+                           virEventTimeoutCallback cb,
+                           void *opaque,
+                           virFreeCallback ff) {
     struct timeval now;
     EVENT_DEBUG("Adding timer %d with %d ms freq", nextTimer, frequency);
     if (gettimeofday(&now, NULL) < 0) {
@@ -166,6 +174,7 @@ int virEventAddTimeoutImpl(int frequency, virEventTimeoutCallback cb, void *opaq
     eventLoop.timeouts[eventLoop.timeoutsCount].timer = nextTimer++;
     eventLoop.timeouts[eventLoop.timeoutsCount].frequency = frequency;
     eventLoop.timeouts[eventLoop.timeoutsCount].cb = cb;
+    eventLoop.timeouts[eventLoop.timeoutsCount].ff = ff;
     eventLoop.timeouts[eventLoop.timeoutsCount].opaque = opaque;
     eventLoop.timeouts[eventLoop.timeoutsCount].deleted = 0;
     eventLoop.timeouts[eventLoop.timeoutsCount].expiresAt =
@@ -393,6 +402,9 @@ static int virEventCleanupTimeouts(void) {
         }
 
         EVENT_DEBUG("Purging timeout %d with id %d", i, eventLoop.timeouts[i].timer);
+        if (eventLoop.timeouts[i].ff)
+            (eventLoop.timeouts[i].ff)(eventLoop.timeouts[i].opaque);
+
         if ((i+1) < eventLoop.timeoutsCount) {
             memmove(eventLoop.timeouts+i,
                     eventLoop.timeouts+i+1,
@@ -429,6 +441,9 @@ static int virEventCleanupHandles(void) {
             continue;
         }
 
+        if (eventLoop.handles[i].ff)
+            (eventLoop.handles[i].ff)(eventLoop.handles[i].opaque);
+
         if ((i+1) < eventLoop.handlesCount) {
             memmove(eventLoop.handles+i,
                     eventLoop.handles+i+1,
index 3bad23238098494b5ffc8ae99fe04dd1d8a69715..615dd69a6733188641842e6ff5fb7db419d5121b 100644 (file)
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb,
-                          void *opaque);
+int virEventAddHandleImpl(int fd, int events,
+                          virEventHandleCallback cb,
+                          void *opaque,
+                          virFreeCallback ff);
 
 /**
  * virEventUpdateHandleImpl: change event set for a monitored file handle
@@ -71,7 +73,10 @@ int virEventRemoveHandleImpl(int watch);
  * returns -1 if the file handle cannot be registered, a positive
  * integer timer id upon success
  */
-int virEventAddTimeoutImpl(int frequency, virEventTimeoutCallback cb, void *opaque);
+int virEventAddTimeoutImpl(int frequency,
+                           virEventTimeoutCallback cb,
+                           void *opaque,
+                           virFreeCallback ff);
 
 /**
  * virEventUpdateTimeoutImpl: change frequency for a timer
index 2e7480897195fba639310b3b6456e16f4002a977..bf9bb3d02cb7abef2dd1da162e9b78a5919111dc 100644 (file)
@@ -238,6 +238,12 @@ static void libvirtd_mdns_watch_dispatch(int watch, int fd, int events, void *op
     w->callback(w, fd, fd_events, w->userdata);
 }
 
+static void libvirtd_mdns_watch_dofree(void *w)
+{
+    VIR_FREE(w);
+}
+
+
 static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
                                            int fd, AvahiWatchEvent event,
                                            AvahiWatchCallback cb, void *userdata) {
@@ -254,7 +260,9 @@ static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED
     AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
     hEvents = virPollEventToEventHandleType(event);
     if ((w->watch = virEventAddHandleImpl(fd, hEvents,
-                                          libvirtd_mdns_watch_dispatch, w)) < 0) {
+                                          libvirtd_mdns_watch_dispatch,
+                                          w,
+                                          libvirtd_mdns_watch_dofree)) < 0) {
         VIR_FREE(w);
         return NULL;
     }
@@ -278,7 +286,6 @@ static void libvirtd_mdns_watch_free(AvahiWatch *w)
 {
     AVAHI_DEBUG("Free handle %p %d", w, w->fd);
     virEventRemoveHandleImpl(w->watch);
-    VIR_FREE(w);
 }
 
 static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
@@ -289,6 +296,11 @@ static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opa
     t->callback(t, t->userdata);
 }
 
+static void libvirtd_mdns_timeout_dofree(void *t)
+{
+    VIR_FREE(t);
+}
+
 static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
                                                 const struct timeval *tv,
                                                 AvahiTimeoutCallback cb,
@@ -319,7 +331,10 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UN
         timeout = -1;
     }
 
-    t->timer = virEventAddTimeoutImpl(timeout, libvirtd_mdns_timeout_dispatch, t);
+    t->timer = virEventAddTimeoutImpl(timeout,
+                                      libvirtd_mdns_timeout_dispatch,
+                                      t,
+                                      libvirtd_mdns_timeout_dofree);
     t->callback = cb;
     t->userdata = userdata;
 
@@ -358,7 +373,6 @@ static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
 {
     AVAHI_DEBUG("Free timeout %p", t);
     virEventRemoveTimeoutImpl(t->timer);
-    VIR_FREE(t);
 }
 
 
index c3ef35cdbc21f3622c5901159646fe4c974061d1..fd4f3c0625e619dad8ef0cf89a5cb37c979289f0 100644 (file)
@@ -540,7 +540,7 @@ static int qemudListenUnix(struct qemud_server *server,
                                              VIR_EVENT_HANDLE_ERROR |
                                              VIR_EVENT_HANDLE_HANGUP,
                                              qemudDispatchServerEvent,
-                                             server)) < 0) {
+                                             server, NULL)) < 0) {
         qemudLog(QEMUD_ERR, "%s",
                  _("Failed to add server event callback"));
         goto cleanup;
@@ -672,7 +672,7 @@ remoteListenTCP (struct qemud_server *server,
                                                  VIR_EVENT_HANDLE_ERROR |
                                                  VIR_EVENT_HANDLE_HANGUP,
                                                  qemudDispatchServerEvent,
-                                                 server)) < 0) {
+                                                 server, NULL)) < 0) {
             qemudLog(QEMUD_ERR, "%s", _("Failed to add server event callback"));
             goto cleanup;
         }
@@ -1655,7 +1655,7 @@ static int qemudRegisterClientEvent(struct qemud_server *server,
                                                mode | VIR_EVENT_HANDLE_ERROR |
                                                VIR_EVENT_HANDLE_HANGUP,
                                                qemudDispatchClientEvent,
-                                               server)) < 0)
+                                               server, NULL)) < 0)
             return -1;
 
     return 0;
@@ -1721,7 +1721,9 @@ static int qemudRunLoop(struct qemud_server *server) {
          * shutdown after timeout seconds
          */
         if (timeout > 0 && !virStateActive() && !server->clients) {
-            timerid = virEventAddTimeoutImpl(timeout*1000, qemudInactiveTimer, server);
+            timerid = virEventAddTimeoutImpl(timeout*1000,
+                                             qemudInactiveTimer,
+                                             server, NULL);
             qemudDebug("Scheduling shutdown timer %d", timerid);
         }
 
@@ -2270,7 +2272,7 @@ int main(int argc, char **argv) {
     if (virEventAddHandleImpl(sigpipe[0],
                               VIR_EVENT_HANDLE_READABLE,
                               qemudDispatchSignalEvent,
-                              server) < 0) {
+                              server, NULL) < 0) {
         qemudLog(QEMUD_ERR,
                  "%s", _("Failed to register callback for signal pipe"));
         ret = 3;
index b0ee8b669defce5ec33616d74a6a11564664c676..59b9ac6212bff8e31525b291a554a82d760d3b92 100644 (file)
@@ -34,12 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
 static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
 static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
 
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb,
-                      void *opaque) {
+int virEventAddHandle(int fd,
+                      int events,
+                      virEventHandleCallback cb,
+                      void *opaque,
+                      virFreeCallback ff) {
     if (!addHandleImpl)
         return -1;
 
-    return addHandleImpl(fd, events, cb, opaque);
+    return addHandleImpl(fd, events, cb, opaque, ff);
 }
 
 void virEventUpdateHandle(int watch, int events) {
@@ -53,11 +56,14 @@ int virEventRemoveHandle(int watch) {
     return removeHandleImpl(watch);
 }
 
-int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) {
+int virEventAddTimeout(int timeout,
+                       virEventTimeoutCallback cb,
+                       void *opaque,
+                       virFreeCallback ff) {
     if (!addTimeoutImpl)
         return -1;
 
-    return addTimeoutImpl(timeout, cb, opaque);
+    return addTimeoutImpl(timeout, cb, opaque, ff);
 }
 
 void virEventUpdateTimeout(int timer, int timeout) {
index fc804c2a79073c5eedce26eaf5c763bd7f633ab2..dc20622c7e47788d9bdc9bc5f739f86b62e8a6c6 100644 (file)
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb,
-                      void *opaque);
+int virEventAddHandle(int fd, int events,
+                      virEventHandleCallback cb,
+                      void *opaque,
+                      virFreeCallback ff);
 
 /**
  * virEventUpdateHandle: change event set for a monitored file handle
@@ -69,7 +71,10 @@ int virEventRemoveHandle(int watch);
  * returns -1 if the file handle cannot be registered, a positive
  * integer timer id upon success
  */
-int virEventAddTimeout(int frequency, virEventTimeoutCallback cb, void *opaque);
+int virEventAddTimeout(int frequency,
+                       virEventTimeoutCallback cb,
+                       void *opaque,
+                       virFreeCallback ff);
 
 /**
  * virEventUpdateTimeoutImpl: change frequency for a timer
index ec206b715c448f37d946d2e4167f79a909839819..c4ba24ac70e647975f5bd1461912404dfbd17a5d 100644 (file)
@@ -820,7 +820,7 @@ static int lxcVmStart(virConnectPtr conn,
              vm->monitor,
              VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
              lxcMonitorEvent,
-             driver)) < 0) {
+             driver, NULL)) < 0) {
         lxcVmTerminate(conn, driver, vm, 0);
         goto cleanup;
     }
index d43119040b11a73eda80ad4a42d43e696e6014e8..5ad60f1dd2ed293412528145c739461e8df11a50 100644 (file)
@@ -948,17 +948,17 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 
     if (ret == 0) {
         if (((vm->stdout_watch = virEventAddHandle(vm->stdout_fd,
-                                                  VIR_EVENT_HANDLE_READABLE |
-                                                  VIR_EVENT_HANDLE_ERROR |
-                                                  VIR_EVENT_HANDLE_HANGUP,
-                                                  qemudDispatchVMEvent,
-                                                  driver)) < 0) ||
+                                                   VIR_EVENT_HANDLE_READABLE |
+                                                   VIR_EVENT_HANDLE_ERROR |
+                                                   VIR_EVENT_HANDLE_HANGUP,
+                                                   qemudDispatchVMEvent,
+                                                   driver, NULL)) < 0) ||
             ((vm->stderr_watch = virEventAddHandle(vm->stderr_fd,
                                                    VIR_EVENT_HANDLE_READABLE |
                                                    VIR_EVENT_HANDLE_ERROR |
                                                    VIR_EVENT_HANDLE_HANGUP,
                                                    qemudDispatchVMEvent,
-                                                   driver)) < 0) ||
+                                                   driver, NULL)) < 0) ||
             (qemudWaitForMonitor(conn, driver, vm) < 0) ||
             (qemudDetectVcpuPIDs(conn, driver, vm) < 0) ||
             (qemudInitCpus(conn, driver, vm, migrateFrom) < 0)) {
index 08f6aeca0e37ee93ba514151e782d291362277d9..7ca6ec10c98d8882c072405fabb51f3e890a4b75 100644 (file)
@@ -762,15 +762,15 @@ doRemoteOpen (virConnectPtr conn,
                                          VIR_EVENT_HANDLE_ERROR |
                                          VIR_EVENT_HANDLE_HANGUP,
                                          remoteDomainEventFired,
-                                         conn)) < 0) {
+                                         conn, NULL)) < 0) {
         DEBUG0("virEventAddHandle failed: No addHandleImpl defined."
                " continuing without events.");
     } else {
 
         DEBUG0("Adding Timeout for remote event queue flushing");
         if ( (priv->eventFlushTimer = virEventAddTimeout(-1,
-                                               remoteDomainEventQueueFlush,
-                                               conn)) < 0) {
+                                                         remoteDomainEventQueueFlush,
+                                                         conn, NULL)) < 0) {
             DEBUG0("virEventAddTimeout failed: No addTimeoutImpl defined. "
                     "continuing without events.");
         }