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

Re: [libvirt] [PATCH 3/7] qemu: Use virDomainEventState helpers



On Thu, May 12, 2011 at 01:14:27PM -0400, Cole Robinson wrote:
> v2:
>     Drop libvirt_private.syms changes
> 
> v3:
>     Adjust for new virDomainEventStateNew argument
> 
> Signed-off-by: Cole Robinson <crobinso redhat com>
> ---
>  src/qemu/qemu_conf.h   |    6 +-----
>  src/qemu/qemu_domain.c |   29 ++++-------------------------
>  src/qemu/qemu_driver.c |   46 ++++++++++++++++++----------------------------
>  3 files changed, 23 insertions(+), 58 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
> index f2bfa1e..ceec16d 100644
> --- a/src/qemu/qemu_conf.h
> +++ b/src/qemu/qemu_conf.h
> @@ -109,11 +109,7 @@ struct qemud_driver {
>  
>      virCapsPtr caps;
>  
> -    /* An array of callbacks */
> -    virDomainEventCallbackListPtr domainEventCallbacks;
> -    virDomainEventQueuePtr domainEventQueue;
> -    int domainEventTimer;
> -    int domainEventDispatching;
> +    virDomainEventStatePtr domainEventState;
>  
>      char *securityDriverName;
>      virSecurityManagerPtr securityManager;
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 19e1938..fd465e5 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -65,28 +65,11 @@ static void qemuDomainEventDispatchFunc(virConnectPtr conn,
>  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);
>  }
>  
> @@ -95,11 +78,7 @@ void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
>  void qemuDomainEventQueue(struct qemud_driver *driver,
>                            virDomainEventPtr event)
>  {
> -    if (virDomainEventQueuePush(driver->domainEventQueue,
> -                                event) < 0)
> -        virDomainEventFree(event);
> -    if (driver->domainEventQueue->count == 1)
> -        virEventUpdateTimeout(driver->domainEventTimer, 0);
> +    virDomainEventStateQueue(driver->domainEventState, event);
>  }
>  
>  
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 732c187..f98c163 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -393,14 +393,12 @@ 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,
> +                                                           true);
> +    if (!qemu_driver->domainEventState)
>          goto error;
>  
>      /* Allocate bitmap for vnc port reservation */
> @@ -764,11 +762,7 @@ qemudShutdown(void) {
>      }
>  
>      /* 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);
> @@ -856,7 +850,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;
> @@ -5563,7 +5558,8 @@ qemuDomainEventRegister(virConnectPtr conn,
>      int ret;
>  
>      qemuDriverLock(driver);
> -    ret = virDomainEventCallbackListAdd(conn, driver->domainEventCallbacks,
> +    ret = virDomainEventCallbackListAdd(conn,
> +                                        driver->domainEventState->callbacks,
>                                          callback, opaque, freecb);
>      qemuDriverUnlock(driver);
>  
> @@ -5579,12 +5575,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;
> @@ -5604,7 +5597,7 @@ qemuDomainEventRegisterAny(virConnectPtr conn,
>  
>      qemuDriverLock(driver);
>      ret = virDomainEventCallbackListAddID(conn,
> -                                          driver->domainEventCallbacks,
> +                                          driver->domainEventState->callbacks,
>                                            dom, eventID,
>                                            callback, opaque, freecb);
>      qemuDriverUnlock(driver);
> @@ -5621,12 +5614,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;

ACK


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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