On 07/20/2016 09:50 AM, Jovanka Gulicoska wrote:
---
src/conf/node_device_conf.h | 4 ++++
src/node_device/node_device_driver.c | 42 ++++++++++++++++++++++++++++++++++++
src/node_device/node_device_driver.h | 10 +++++++++
3 files changed, 56 insertions(+)
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 9e3e6fe..8f23a98 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -31,6 +31,7 @@
# include "virthread.h"
# include "virpci.h"
# include "device_conf.h"
+# include "object_event.h"
# include <libxml/tree.h>
@@ -229,6 +230,9 @@ struct _virNodeDeviceDriverState {
virNodeDeviceObjList devs; /* currently-known devices */
void *privateData; /* driver-specific private data */
+
+ /* Immutable pointer, self-locking APIs */
+ virObjectEventStatePtr nodeDeviceEventState;
};
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 500caeb..91bb142 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -35,6 +35,7 @@
#include "virfile.h"
#include "virstring.h"
#include "node_device_conf.h"
+#include "node_device_event.h"
#include "node_device_driver.h"
#include "node_device_hal.h"
#include "node_device_linux_sysfs.h"
@@ -677,6 +678,47 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
return ret;
}
+int
+nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
+ virNodeDevicePtr dev,
+ int eventID,
+ virConnectNodeDeviceEventGenericCallback
callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ int callbackID = -1;
+
+ if (virConnectNodeDeviceEventRegisterAnyEnsureACL(conn) < 0)
+ goto cleanup;
+
+ if (virNodeDeviceEventStateRegisterID(conn, driver->nodeDeviceEventState,
+ dev, eventID, callback,
+ opaque, freecb, &callbackID) < 0)
+ callbackID = -1;
+ cleanup:
+ return callbackID;
+}
+
+int
+nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ int ret = -1;
+
+ if (virConnectNodeDeviceEventDeregisterAnyEnsureACL(conn) < 0)
+ goto cleanup;
+
+ if (virObjectEventStateDeregisterID(conn,
+ driver->nodeDeviceEventState,
+ callbackID) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ return ret;
+}
+
So this is just adding the generic API entrypoints. It looks a little strange
adding functions that can access driver->nodeDeviceEventState without any
associated code to initialize nodeDeviceEventState, but since we leave that up
to hal/udev backends I think this makes sense. Plus these functions aren't
callable via the public API unless the backend exports the function via
virNodeDeviceDriver, so the backends need to explicitly opt in anyways
ACK
- Cole
int nodedevRegister(void)
{
#ifdef WITH_UDEV
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 0f4ea57..56f89ab 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -63,4 +63,14 @@ virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn,
const char *xmlDesc, unsigned int flags);
int nodeDeviceDestroy(virNodeDevicePtr dev);
+int
+nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
+ virNodeDevicePtr dev,
+ int eventID,
+ virConnectNodeDeviceEventGenericCallback
callback,
+ void *opaque,
+ virFreeCallback freecb);
+int
+nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
+ int callbackID);
#endif /* __VIR_NODE_DEVICE_H__ */