The libvirtd daemon impl will need to switch over to using the
new event APIs. To make this simpler, ensure all drivers currently
providing events support both the new APIs and old APIs.
* src/lxc/lxc_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c: Implement the new
virConnectDomainEvent(Dereg|Reg)isterAny driver entry points
---
src/lxc/lxc_driver.c | 60 +++++++++++++++++++++++----
src/qemu/qemu_driver.c | 64 ++++++++++++++++++++++++-----
src/test/test_driver.c | 58 ++++++++++++++++++++++----
src/vbox/vbox_tmpl.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++
src/xen/xen_driver.c | 71 ++++++++++++++++++++++++++++----
5 files changed, 325 insertions(+), 34 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 592663d..bf10f66 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1433,10 +1433,10 @@ cleanup:
static int
-lxcDomainEventRegister (virConnectPtr conn,
- virConnectDomainEventCallback callback,
- void *opaque,
- virFreeCallback freecb)
+lxcDomainEventRegister(virConnectPtr conn,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
{
lxc_driver_t *driver = conn->privateData;
int ret;
@@ -1449,9 +1449,10 @@ lxcDomainEventRegister (virConnectPtr conn,
return ret;
}
+
static int
-lxcDomainEventDeregister (virConnectPtr conn,
- virConnectDomainEventCallback callback)
+lxcDomainEventDeregister(virConnectPtr conn,
+ virConnectDomainEventCallback callback)
{
lxc_driver_t *driver = conn->privateData;
int ret;
@@ -1468,6 +1469,49 @@ lxcDomainEventDeregister (virConnectPtr conn,
return ret;
}
+
+static int
+lxcDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ lxc_driver_t *driver = conn->privateData;
+ int ret;
+
+ lxcDriverLock(driver);
+ ret = virDomainEventCallbackListAddID(conn,
+ driver->domainEventCallbacks,
+ dom, eventID,
+ callback, opaque, freecb);
+ lxcDriverUnlock(driver);
+
+ return ret;
+}
+
+
+static int
+lxcDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ lxc_driver_t *driver = conn->privateData;
+ int ret;
+
+ lxcDriverLock(driver);
+ if (driver->domainEventDispatching)
+ ret = virDomainEventCallbackListMarkDeleteID(conn,
driver->domainEventCallbacks,
+ callbackID);
+ else
+ ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
+ callbackID);
+ lxcDriverUnlock(driver);
+
+ return ret;
+}
+
+
static void lxcDomainEventDispatchFunc(virConnectPtr conn,
virDomainEventPtr event,
virConnectDomainEventGenericCallback cb,
@@ -2453,8 +2497,8 @@ static virDriver lxcDriver = {
NULL, /* cpuBaseline */
NULL, /* domainGetJobInfo */
NULL, /* domainAbortJob */
- NULL, /* domainEventRegisterAny */
- NULL, /* domainEventDeregisterAny */
+ lxcDomainEventRegisterAny, /* domainEventRegisterAny */
+ lxcDomainEventDeregisterAny, /* domainEventDeregisterAny */
};
static virStateDriver lxcStateDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d522c43..a8af7b4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7942,10 +7942,10 @@ cleanup:
static int
-qemudDomainEventRegister (virConnectPtr conn,
- virConnectDomainEventCallback callback,
- void *opaque,
- virFreeCallback freecb)
+qemuDomainEventRegister(virConnectPtr conn,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
{
struct qemud_driver *driver = conn->privateData;
int ret;
@@ -7958,9 +7958,10 @@ qemudDomainEventRegister (virConnectPtr conn,
return ret;
}
+
static int
-qemudDomainEventDeregister (virConnectPtr conn,
- virConnectDomainEventCallback callback)
+qemuDomainEventDeregister(virConnectPtr conn,
+ virConnectDomainEventCallback callback)
{
struct qemud_driver *driver = conn->privateData;
int ret;
@@ -7977,6 +7978,49 @@ qemudDomainEventDeregister (virConnectPtr conn,
return ret;
}
+
+static int
+qemuDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ struct qemud_driver *driver = conn->privateData;
+ int ret;
+
+ qemuDriverLock(driver);
+ ret = virDomainEventCallbackListAddID(conn,
+ driver->domainEventCallbacks,
+ dom, eventID,
+ callback, opaque, freecb);
+ qemuDriverUnlock(driver);
+
+ return ret;
+}
+
+
+static int
+qemuDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ struct qemud_driver *driver = conn->privateData;
+ int ret;
+
+ qemuDriverLock(driver);
+ if (driver->domainEventDispatching)
+ ret = virDomainEventCallbackListMarkDeleteID(conn,
driver->domainEventCallbacks,
+ callbackID);
+ else
+ ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
+ callbackID);
+ qemuDriverUnlock(driver);
+
+ return ret;
+}
+
+
static void qemuDomainEventDispatchFunc(virConnectPtr conn,
virDomainEventPtr event,
virConnectDomainEventGenericCallback cb,
@@ -9581,8 +9625,8 @@ static virDriver qemuDriver = {
qemudDomainMemoryPeek, /* domainMemoryPeek */
nodeGetCellsFreeMemory, /* nodeGetCellsFreeMemory */
nodeGetFreeMemory, /* getFreeMemory */
- qemudDomainEventRegister, /* domainEventRegister */
- qemudDomainEventDeregister, /* domainEventDeregister */
+ qemuDomainEventRegister, /* domainEventRegister */
+ qemuDomainEventDeregister, /* domainEventDeregister */
qemudDomainMigratePrepare2, /* domainMigratePrepare2 */
qemudDomainMigrateFinish2, /* domainMigrateFinish2 */
qemudNodeDeviceDettach, /* nodeDeviceDettach */
@@ -9597,8 +9641,8 @@ static virDriver qemuDriver = {
qemuCPUBaseline, /* cpuBaseline */
qemuDomainGetJobInfo, /* domainGetJobInfo */
qemuDomainAbortJob, /* domainAbortJob */
- NULL, /* domainEventRegisterAny */
- NULL, /* domainEventDeregisterAny */
+ qemuDomainEventRegisterAny, /* domainEventRegisterAny */
+ qemuDomainEventDeregisterAny, /* domainEventDeregisterAny */
};
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 9c26a03..8977d4e 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5054,10 +5054,10 @@ out:
/* Domain event implementations */
static int
-testDomainEventRegister (virConnectPtr conn,
- virConnectDomainEventCallback callback,
- void *opaque,
- virFreeCallback freecb)
+testDomainEventRegister(virConnectPtr conn,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
{
testConnPtr driver = conn->privateData;
int ret;
@@ -5070,9 +5070,10 @@ testDomainEventRegister (virConnectPtr conn,
return ret;
}
+
static int
-testDomainEventDeregister (virConnectPtr conn,
- virConnectDomainEventCallback callback)
+testDomainEventDeregister(virConnectPtr conn,
+ virConnectDomainEventCallback callback)
{
testConnPtr driver = conn->privateData;
int ret;
@@ -5089,6 +5090,47 @@ testDomainEventDeregister (virConnectPtr conn,
return ret;
}
+
+static int
+testDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ testConnPtr driver = conn->privateData;
+ int ret;
+
+ testDriverLock(driver);
+ ret = virDomainEventCallbackListAddID(conn, driver->domainEventCallbacks,
+ dom, eventID,
+ callback, opaque, freecb);
+ testDriverUnlock(driver);
+
+ return ret;
+}
+
+static int
+testDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ testConnPtr driver = conn->privateData;
+ int ret;
+
+ testDriverLock(driver);
+ if (driver->domainEventDispatching)
+ ret = virDomainEventCallbackListMarkDeleteID(conn,
driver->domainEventCallbacks,
+ callbackID);
+ else
+ ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
+ callbackID);
+ testDriverUnlock(driver);
+
+ return ret;
+}
+
+
static void testDomainEventDispatchFunc(virConnectPtr conn,
virDomainEventPtr event,
virConnectDomainEventGenericCallback cb,
@@ -5245,8 +5287,8 @@ static virDriver testDriver = {
NULL, /* cpuBaseline */
NULL, /* domainGetJobInfo */
NULL, /* domainAbortJob */
- NULL, /* domainEventRegisterAny */
- NULL, /* domainEventDeregisterAny */
+ testDomainEventRegisterAny, /* domainEventRegisterAny */
+ testDomainEventDeregisterAny, /* domainEventDeregisterAny */
};
static virNetworkDriver testNetworkDriver = {
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e4a7748..22f9071 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5425,6 +5425,107 @@ static int vboxDomainEventDeregister (virConnectPtr conn,
return ret;
}
+static int vboxDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb) {
+ VBOX_OBJECT_CHECK(conn, int, -1);
+ int vboxRet = -1;
+ nsresult rc;
+
+ /* Locking has to be there as callbacks are not
+ * really fully thread safe
+ */
+ vboxDriverLock(data);
+
+ if (data->vboxCallback == NULL) {
+ data->vboxCallback = vboxAllocCallbackObj();
+ if (data->vboxCallback != NULL) {
+ rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj,
data->vboxCallback);
+ if (NS_SUCCEEDED(rc)) {
+ vboxRet = 0;
+ }
+ }
+ } else {
+ vboxRet = 0;
+ }
+
+ /* Get the vbox file handle and add a event handle to it
+ * so that the events can be passed down to the user
+ */
+ if (vboxRet == 0) {
+ if (data->fdWatch < 0) {
+ PRInt32 vboxFileHandle;
+ vboxFileHandle =
data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue);
+
+ data->fdWatch = virEventAddHandle(vboxFileHandle,
VIR_EVENT_HANDLE_READABLE, vboxReadCallback, NULL, NULL);
+ }
+
+ if (data->fdWatch >= 0) {
+ /* Once a callback is registered with virtualbox, use a list
+ * to store the callbacks registered with libvirt so that
+ * later you can iterate over them
+ */
+
+ ret = virDomainEventCallbackListAddID(conn, data->domainEventCallbacks,
+ dom, eventID,
+ callback, opaque, freecb);
+ DEBUG("virDomainEventCallbackListAddID (ret = %d) ( conn: %p, "
+ "data->domainEventCallbacks: %p, callback: %p, opaque: %p,
"
+ "freecb: %p )", ret, conn, data->domainEventCallbacks,
callback,
+ opaque, freecb);
+ }
+ }
+
+ vboxDriverUnlock(data);
+
+ if (ret >= 0) {
+ return ret;
+ } else {
+ if (data->vboxObj && data->vboxCallback) {
+ data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
data->vboxCallback);
+ }
+ return -1;
+ }
+}
+
+static int vboxDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID) {
+ VBOX_OBJECT_CHECK(conn, int, -1);
+
+ /* Locking has to be there as callbacks are not
+ * really fully thread safe
+ */
+ vboxDriverLock(data);
+
+ if (data->domainEventDispatching)
+ ret = virDomainEventCallbackListMarkDeleteID(conn,
data->domainEventCallbacks,
+ callbackID);
+ else
+ ret = virDomainEventCallbackListRemoveID(conn, data->domainEventCallbacks,
+ callbackID);
+
+ if (data->vboxCallback) {
+ /* check count here of how many times register was called
+ * and only on the last de-register do the un-register call
+ */
+ if (data->domainEventCallbacks &&
virDomainEventCallbackListCount(data->domainEventCallbacks) == 0) {
+ data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
data->vboxCallback);
+ VBOX_RELEASE(data->vboxCallback);
+
+ /* Remove the Event file handle on which we are listening as well */
+ virEventRemoveHandle(data->fdWatch);
+ data->fdWatch = -1;
+ }
+ }
+
+ vboxDriverUnlock(data);
+
+ return ret;
+}
+
#endif /* !(VBOX_API_VERSION == 2002) */
/**
@@ -7055,8 +7156,13 @@ virDriver NAME(Driver) = {
NULL, /* cpuBaseline */
NULL, /* domainGetJobInfo */
NULL, /* domainAbortJob */
+#if VBOX_API_VERSION == 2002
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
+#else
+ vboxDomainEventRegisterAny, /* domainEventRegisterAny */
+ vboxDomainEventDeregisterAny, /* domainEventDeregisterAny */
+#endif
};
virNetworkDriver NAME(NetworkDriver) = {
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index bf28d43..984d72b 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1656,11 +1656,12 @@ xenUnifiedNodeGetFreeMemory (virConnectPtr conn)
return(0);
}
+
static int
-xenUnifiedDomainEventRegister (virConnectPtr conn,
- virConnectDomainEventCallback callback,
- void *opaque,
- void (*freefunc)(void *))
+xenUnifiedDomainEventRegister(virConnectPtr conn,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freefunc)
{
GET_PRIVATE (conn);
@@ -1680,9 +1681,10 @@ xenUnifiedDomainEventRegister (virConnectPtr conn,
return (ret);
}
+
static int
-xenUnifiedDomainEventDeregister (virConnectPtr conn,
- virConnectDomainEventCallback callback)
+xenUnifiedDomainEventDeregister(virConnectPtr conn,
+ virConnectDomainEventCallback callback)
{
int ret;
GET_PRIVATE (conn);
@@ -1707,6 +1709,59 @@ xenUnifiedDomainEventDeregister (virConnectPtr conn,
static int
+xenUnifiedDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freefunc)
+{
+ GET_PRIVATE (conn);
+
+ int ret;
+ xenUnifiedLock(priv);
+
+ if (priv->xsWatch == -1) {
+ xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ xenUnifiedUnlock(priv);
+ return -1;
+ }
+
+ ret = virDomainEventCallbackListAddID(conn, priv->domainEventCallbacks,
+ dom, eventID,
+ callback, opaque, freefunc);
+
+ xenUnifiedUnlock(priv);
+ return (ret);
+}
+
+static int
+xenUnifiedDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ int ret;
+ GET_PRIVATE (conn);
+ xenUnifiedLock(priv);
+
+ if (priv->xsWatch == -1) {
+ xenUnifiedError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ xenUnifiedUnlock(priv);
+ return -1;
+ }
+
+ if (priv->domainEventDispatching)
+ ret = virDomainEventCallbackListMarkDeleteID(conn,
priv->domainEventCallbacks,
+ callbackID);
+ else
+ ret = virDomainEventCallbackListRemoveID(conn, priv->domainEventCallbacks,
+ callbackID);
+
+ xenUnifiedUnlock(priv);
+ return ret;
+}
+
+
+static int
xenUnifiedNodeDeviceGetPciInfo (virNodeDevicePtr dev,
unsigned *domain,
unsigned *bus,
@@ -1906,8 +1961,8 @@ static virDriver xenUnifiedDriver = {
NULL, /* cpuBaseline */
NULL, /* domainGetJobInfo */
NULL, /* domainAbortJob */
- NULL, /* domainEventRegisterAny */
- NULL, /* domainEventDeregisterAny */
+ xenUnifiedDomainEventRegisterAny, /* domainEventRegisterAny */
+ xenUnifiedDomainEventDeregisterAny, /* domainEventDeregisterAny */
};
/**
--
1.6.6.1