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

[libvirt] [PATCH 6/8] lxc: Use virDomainEventState helpers



Signed-off-by: Cole Robinson <crobinso redhat com>
---
 src/lxc/lxc_conf.h   |    6 +---
 src/lxc/lxc_driver.c |   76 ++++++++++++++++----------------------------------
 2 files changed, 25 insertions(+), 57 deletions(-)

diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index f820d6d..308a3dd 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -55,11 +55,7 @@ struct __lxc_driver {
     int log_libvirtd;
     int have_netns;
 
-    /* An array of callbacks */
-    virDomainEventCallbackListPtr domainEventCallbacks;
-    virDomainEventQueuePtr domainEventQueue;
-    int domainEventTimer;
-    int domainEventDispatching;
+    virDomainEventStatePtr domainEventState;
 };
 
 int lxcLoadDriverConfig(lxc_driver_t *driver);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index eb58086..8717d08 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -158,7 +158,8 @@ static int lxcClose(virConnectPtr conn)
     lxc_driver_t *driver = conn->privateData;
 
     lxcDriverLock(driver);
-    virDomainEventCallbackListRemoveConn(conn, driver->domainEventCallbacks);
+    virDomainEventCallbackListRemoveConn(conn,
+                                         driver->domainEventState->callbacks);
     lxcDriverUnlock(driver);
 
     conn->privateData = NULL;
@@ -1772,7 +1773,8 @@ lxcDomainEventRegister(virConnectPtr conn,
     int ret;
 
     lxcDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn, driver->domainEventCallbacks,
+    ret = virDomainEventCallbackListAdd(conn,
+                                        driver->domainEventState->callbacks,
                                         callback, opaque, freecb);
     lxcDriverUnlock(driver);
 
@@ -1788,12 +1790,9 @@ lxcDomainEventDeregister(virConnectPtr conn,
     int ret;
 
     lxcDriverLock(driver);
-    if (driver->domainEventDispatching)
-        ret = virDomainEventCallbackListMarkDelete(conn, driver->domainEventCallbacks,
-                                                   callback);
-    else
-        ret = virDomainEventCallbackListRemove(conn, driver->domainEventCallbacks,
-                                               callback);
+    ret = virDomainEventStateDeregister(conn,
+                                        driver->domainEventState,
+                                        callback);
     lxcDriverUnlock(driver);
 
     return ret;
@@ -1813,7 +1812,7 @@ lxcDomainEventRegisterAny(virConnectPtr conn,
 
     lxcDriverLock(driver);
     ret = virDomainEventCallbackListAddID(conn,
-                                          driver->domainEventCallbacks,
+                                          driver->domainEventState->callbacks,
                                           dom, eventID,
                                           callback, opaque, freecb);
     lxcDriverUnlock(driver);
@@ -1830,12 +1829,9 @@ lxcDomainEventDeregisterAny(virConnectPtr conn,
     int ret;
 
     lxcDriverLock(driver);
-    if (driver->domainEventDispatching)
-        ret = virDomainEventCallbackListMarkDeleteID(conn, driver->domainEventCallbacks,
-                                                     callbackID);
-    else
-        ret = virDomainEventCallbackListRemoveID(conn, driver->domainEventCallbacks,
-                                                 callbackID);
+    ret = virDomainEventStateDeregisterAny(conn,
+                                           driver->domainEventState,
+                                           callbackID);
     lxcDriverUnlock(driver);
 
     return ret;
@@ -1860,28 +1856,11 @@ static void lxcDomainEventDispatchFunc(virConnectPtr conn,
 static void lxcDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
 {
     lxc_driver_t *driver = opaque;
-    virDomainEventQueue tempQueue;
 
     lxcDriverLock(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,
-                                lxcDomainEventDispatchFunc,
-                                driver);
-
-    /* Purge any deleted callbacks */
-    virDomainEventCallbackListPurgeMarked(driver->domainEventCallbacks);
-
-    driver->domainEventDispatching = 0;
+    virDomainEventStateFlush(driver->domainEventState,
+                             lxcDomainEventDispatchFunc,
+                             driver);
     lxcDriverUnlock(driver);
 }
 
@@ -1890,11 +1869,7 @@ static void lxcDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
 static void lxcDomainEventQueue(lxc_driver_t *driver,
                                  virDomainEventPtr event)
 {
-    if (virDomainEventQueuePush(driver->domainEventQueue,
-                                event) < 0)
-        virDomainEventFree(event);
-    if (lxc_driver->domainEventQueue->count == 1)
-        virEventUpdateTimeout(driver->domainEventTimer, 0);
+    virDomainEventStateQueue(driver->domainEventState, event);
 }
 
 /**
@@ -2109,14 +2084,16 @@ static int lxcStartup(int privileged)
     if (virDomainObjListInit(&lxc_driver->domains) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(lxc_driver->domainEventCallbacks) < 0)
+    lxc_driver->domainEventState = virDomainEventStateNew(lxcDomainEventFlush,
+                                                          lxc_driver,
+                                                          NULL);
+    if (!lxc_driver->domainEventState)
         goto cleanup;
-    if (!(lxc_driver->domainEventQueue = virDomainEventQueueNew()))
-        goto cleanup;
-
-    if ((lxc_driver->domainEventTimer =
-         virEventAddTimeout(-1, lxcDomainEventFlush, lxc_driver, NULL)) < 0)
+    if (!lxc_driver->domainEventState->timer < 0) {
+        lxcError(VIR_ERR_INTERNAL_ERROR, "%s",
+                 _("could not initialize domain event timer"));
         goto cleanup;
+    }
 
     lxc_driver->log_libvirtd = 0; /* by default log to container logfile */
     lxc_driver->have_netns = lxcCheckNetNsSupport();
@@ -2204,12 +2181,7 @@ static int lxcShutdown(void)
 
     lxcDriverLock(lxc_driver);
     virDomainObjListDeinit(&lxc_driver->domains);
-
-    virDomainEventCallbackListFree(lxc_driver->domainEventCallbacks);
-    virDomainEventQueueFree(lxc_driver->domainEventQueue);
-
-    if (lxc_driver->domainEventTimer != -1)
-        virEventRemoveTimeout(lxc_driver->domainEventTimer);
+    virDomainEventStateFree(lxc_driver->domainEventState);
 
     virCapabilitiesFree(lxc_driver->caps);
     VIR_FREE(lxc_driver->configDir);
-- 
1.7.3.3


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