[PATCH 3/8] Add APIs to allow management of callbacks purely with virDomainEventState

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

While virDomainEventState has APIs for managing removal of callbacks,
while locked, adding callbacks in the first place requires direct
access to the virDomainEventCallbackList structure. This is not
threadsafe since it is bypassing the virDomainEventState locks

* src/conf/domain_event.c, src/conf/domain_event.h,
  src/libvirt_private.syms: Add APIs for managing callbacks
  via virDomainEventState.
---
 src/conf/domain_event.c  |   99 ++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_event.h  |   24 +++++++++++
 src/libvirt_private.syms |    4 ++
 3 files changed, 127 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 00c5dbf..c6adae4 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1342,6 +1342,68 @@ virDomainEventStateFlush(virDomainEventStatePtr state,
 
 
 /**
+ * virDomainEventStateRegister:
+ * @state: domain event state
+ * @conn: connection to associate with callback
+ * @callback: function to remove from event
+ * @opaque: data blob to pass to callback
+ * @freecb: callback to free @opaque
+ *
+ * Register the function @callback with connection @conn,
+ * from @state, for lifecycle events.
+ *
+ * Returns: the number of lifecycle callbacks now registered, or -1 on error
+ */
+int virDomainEventStateRegister(virConnectPtr conn,
+                                virDomainEventStatePtr state,
+                                virConnectDomainEventCallback callback,
+                                void *opaque,
+                                virFreeCallback freecb)
+{
+    int ret;
+    virDomainEventStateLock(state);
+    ret = virDomainEventCallbackListAdd(conn, state->callbacks,
+                                        callback, opaque, freecb);
+    virDomainEventStateUnlock(state);
+    return ret;
+}
+
+
+/**
+ * virDomainEventStateRegisterID:
+ * @state: domain event state
+ * @conn: connection to associate with callback
+ * @eventID: ID of the event type to register for
+ * @cb: function to remove from event
+ * @opaque: data blob to pass to callback
+ * @freecb: callback to free @opaque
+ * @callbackID: filled with callback ID
+ *
+ * Register the function @callbackID with connection @conn,
+ * from @state, for events of type @eventID.
+ *
+ * Returns: the number of callbacks now registered, or -1 on error
+ */
+int virDomainEventStateRegisterID(virConnectPtr conn,
+                                  virDomainEventStatePtr state,
+                                  virDomainPtr dom,
+                                  int eventID,
+                                  virConnectDomainEventGenericCallback cb,
+                                  void *opaque,
+                                  virFreeCallback freecb,
+                                  int *callbackID)
+{
+    int ret;
+    virDomainEventStateLock(state);
+    ret = virDomainEventCallbackListAddID(conn, state->callbacks,
+                                          dom, eventID, cb, opaque, freecb,
+                                          callbackID);
+    virDomainEventStateUnlock(state);
+    return ret;
+}
+
+
+/**
  * virDomainEventStateDeregister:
  * @state: domain event state
  * @conn: connection to associate with callback
@@ -1398,3 +1460,40 @@ virDomainEventStateDeregisterID(virConnectPtr conn,
     virDomainEventStateUnlock(state);
     return ret;
 }
+
+
+/**
+ * virDomainEventStateDeregisterConn:
+ * @state: domain event state
+ * @conn: connection to associate with callbacks
+ *
+ * Remove all callbacks from @state associated with the
+ * connection @conn
+ *
+ * Returns 0 on success, -1 on error
+ */
+int
+virDomainEventStateDeregisterConn(virConnectPtr conn,
+                                  virDomainEventStatePtr state)
+{
+    int ret;
+    virDomainEventStateLock(state);
+    ret = virDomainEventCallbackListRemoveConn(conn, state->callbacks);
+    virDomainEventStateUnlock(state);
+    return ret;
+}
+
+
+int
+virDomainEventStateEventID(virConnectPtr conn,
+                           virDomainEventStatePtr state,
+                           int callbackID)
+{
+    int ret;
+
+    virDomainEventStateLock(state);
+    ret = virDomainEventCallbackListEventID(conn,
+                                            state->callbacks, callbackID);
+    virDomainEventStateUnlock(state);
+    return ret;
+}
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 83656e6..7eefadb 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -237,6 +237,21 @@ virDomainEventStateFlush(virDomainEventStatePtr state,
                          virDomainEventDispatchFunc dispatchFunc,
                          void *opaque)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int virDomainEventStateRegister(virConnectPtr conn,
+                                virDomainEventStatePtr state,
+                                virConnectDomainEventCallback callback,
+                                void *opaque,
+                                virFreeCallback freecb)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+int virDomainEventStateRegisterID(virConnectPtr conn,
+                                  virDomainEventStatePtr state,
+                                  virDomainPtr dom,
+                                  int eventID,
+                                  virConnectDomainEventGenericCallback cb,
+                                  void *opaque,
+                                  virFreeCallback freecb,
+                                  int *callbackID)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
 int
 virDomainEventStateDeregister(virConnectPtr conn,
                               virDomainEventStatePtr state,
@@ -247,5 +262,14 @@ virDomainEventStateDeregisterID(virConnectPtr conn,
                                 virDomainEventStatePtr state,
                                 int callbackID)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int
+virDomainEventStateDeregisterConn(virConnectPtr conn,
+                                  virDomainEventStatePtr state)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int
+virDomainEventStateEventID(virConnectPtr conn,
+                           virDomainEventStatePtr state,
+                           int callbackID)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 #endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3d1d7d2..0c664ed 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -511,6 +511,10 @@ virDomainEventRebootNewFromDom;
 virDomainEventRebootNewFromObj;
 virDomainEventStateDeregister;
 virDomainEventStateDeregisterID;
+virDomainEventStateDeregisterConn;
+virDomainEventStateEventID;
+virDomainEventStateRegister;
+virDomainEventStateRegisterID;
 virDomainEventStateFlush;
 virDomainEventStateFree;
 virDomainEventStateNew;
-- 
1.7.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]