Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/libvirt_private.syms | 6 +++
src/qemu/qemu_conf.h | 6 +---
src/qemu/qemu_driver.c | 80 +++++++++++++++-------------------------------
3 files changed, 33 insertions(+), 59 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 19e581c..2fcecc8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -349,6 +349,12 @@ virDomainEventRTCChangeNewFromDom;
virDomainEventRTCChangeNewFromObj;
virDomainEventRebootNewFromDom;
virDomainEventRebootNewFromObj;
+virDomainEventStateDeregister;
+virDomainEventStateDeregisterAny;
+virDomainEventStateFlush;
+virDomainEventStateQueue;
+virDomainEventStateFree;
+virDomainEventStateNew;
virDomainEventWatchdogNewFromDom;
virDomainEventWatchdogNewFromObj;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 83ddedd..0733822 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -107,11 +107,7 @@ struct qemud_driver {
virCapsPtr caps;
- /* An array of callbacks */
- virDomainEventCallbackListPtr domainEventCallbacks;
- virDomainEventQueuePtr domainEventQueue;
- int domainEventTimer;
- int domainEventDispatching;
+ virDomainEventStatePtr domainEventState;
char *securityDriverName;
virSecurityDriverPtr securityDriver;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e915705..8ceae48 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1198,15 +1198,17 @@ qemudStartup(int privileged) {
if (virDomainObjListInit(&qemu_driver->domains) < 0)
goto out_of_memory;
- /* Init callback list */
- if (VIR_ALLOC(qemu_driver->domainEventCallbacks) < 0)
- goto out_of_memory;
- if (!(qemu_driver->domainEventQueue = virDomainEventQueueNew()))
- goto out_of_memory;
-
- if ((qemu_driver->domainEventTimer =
- virEventAddTimeout(-1, qemuDomainEventFlush, qemu_driver, NULL)) < 0)
+ /* Init domain events */
+ qemu_driver->domainEventState = virDomainEventStateNew(qemuDomainEventFlush,
+ qemu_driver,
+ NULL);
+ if (!qemu_driver->domainEventState)
goto error;
+ if (!qemu_driver->domainEventState->timer < 0) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("could not initialize domain event timer"));
+ goto error;
+ }
/* Allocate bitmap for vnc port reservation */
if ((qemu_driver->reservedVNCPorts =
@@ -1567,12 +1569,7 @@ qemudShutdown(void) {
VIR_FREE(qemu_driver->cgroupDeviceACL);
}
- /* Free domain callback list */
- virDomainEventCallbackListFree(qemu_driver->domainEventCallbacks);
- virDomainEventQueueFree(qemu_driver->domainEventQueue);
-
- if (qemu_driver->domainEventTimer != -1)
- virEventRemoveTimeout(qemu_driver->domainEventTimer);
+ virDomainEventStateFree(qemu_driver->domainEventState);
if (qemu_driver->brctl)
brShutdown(qemu_driver->brctl);
@@ -3206,7 +3203,8 @@ static int qemudClose(virConnectPtr conn) {
/* Get rid of callbacks registered for this conn */
qemuDriverLock(driver);
- virDomainEventCallbackListRemoveConn(conn, driver->domainEventCallbacks);
+ virDomainEventCallbackListRemoveConn(conn,
+ driver->domainEventState->callbacks);
qemuDriverUnlock(driver);
conn->privateData = NULL;
@@ -7815,7 +7813,8 @@ qemuDomainEventRegister(virConnectPtr conn,
int ret;
qemuDriverLock(driver);
- ret = virDomainEventCallbackListAdd(conn, driver->domainEventCallbacks,
+ ret = virDomainEventCallbackListAdd(conn,
+ driver->domainEventState->callbacks,
callback, opaque, freecb);
qemuDriverUnlock(driver);
@@ -7831,12 +7830,9 @@ qemuDomainEventDeregister(virConnectPtr conn,
int ret;
qemuDriverLock(driver);
- if (driver->domainEventDispatching)
- ret = virDomainEventCallbackListMarkDelete(conn,
driver->domainEventCallbacks,
- callback);
- else
- ret = virDomainEventCallbackListRemove(conn, driver->domainEventCallbacks,
- callback);
+ ret = virDomainEventStateDeregister(conn,
+ driver->domainEventState,
+ callback);
qemuDriverUnlock(driver);
return ret;
@@ -7856,7 +7852,7 @@ qemuDomainEventRegisterAny(virConnectPtr conn,
qemuDriverLock(driver);
ret = virDomainEventCallbackListAddID(conn,
- driver->domainEventCallbacks,
+ driver->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb);
qemuDriverUnlock(driver);
@@ -7873,12 +7869,9 @@ qemuDomainEventDeregisterAny(virConnectPtr conn,
int ret;
qemuDriverLock(driver);
- if (driver->domainEventDispatching)
- ret = virDomainEventCallbackListMarkDeleteID(conn,
driver->domainEventCallbacks,
- callbackID);
- else
- ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
- callbackID);
+ ret = virDomainEventStateDeregisterAny(conn,
+ driver->domainEventState,
+ callbackID);
qemuDriverUnlock(driver);
return ret;
@@ -7902,28 +7895,11 @@ static void qemuDomainEventDispatchFunc(virConnectPtr conn,
static void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
{
struct qemud_driver *driver = opaque;
- virDomainEventQueue tempQueue;
qemuDriverLock(driver);
-
- driver->domainEventDispatching = 1;
-
- /* Copy the queue, so we're reentrant safe */
- tempQueue.count = driver->domainEventQueue->count;
- tempQueue.events = driver->domainEventQueue->events;
- driver->domainEventQueue->count = 0;
- driver->domainEventQueue->events = NULL;
-
- virEventUpdateTimeout(driver->domainEventTimer, -1);
- virDomainEventQueueDispatch(&tempQueue,
- driver->domainEventCallbacks,
- qemuDomainEventDispatchFunc,
- driver);
-
- /* Purge any deleted callbacks */
- virDomainEventCallbackListPurgeMarked(driver->domainEventCallbacks);
-
- driver->domainEventDispatching = 0;
+ virDomainEventStateFlush(driver->domainEventState,
+ qemuDomainEventDispatchFunc,
+ driver);
qemuDriverUnlock(driver);
}
@@ -7932,11 +7908,7 @@ static void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void
*opaque)
static void qemuDomainEventQueue(struct qemud_driver *driver,
virDomainEventPtr event)
{
- if (virDomainEventQueuePush(driver->domainEventQueue,
- event) < 0)
- virDomainEventFree(event);
- if (qemu_driver->domainEventQueue->count == 1)
- virEventUpdateTimeout(driver->domainEventTimer, 0);
+ virDomainEventStateQueue(driver->domainEventState, event);
}
/* Migration support. */
--
1.7.3.3