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

Re: [libvirt] [PATCH 3/4] add a qemu-specific event register API supported in qemu driver



On 12/16/2011 09:59 AM, shaohef linux vnet ibm com wrote:
> From: ShaoHe Feng <shaohef linux vnet ibm com>
> 
> 
> Signed-off-by: ShaoHe Feng <shaohef linux vnet ibm com>
> ---
>  src/qemu/qemu_driver.c       |   42 ++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor.c      |   10 ++++++++++
>  src/qemu/qemu_monitor.h      |    8 ++++++++
>  src/qemu/qemu_monitor_json.c |   35 +++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_process.c      |   24 ++++++++++++++++++++++++
>  5 files changed, 119 insertions(+), 0 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 725b593..b9f1ec4 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -8015,6 +8015,46 @@ qemuDomainEventDeregisterAny(virConnectPtr conn,
>  }
>  
>  
> +static int
> +qemuDomainQemuEventRegister(virConnectPtr conn,
> +                            virDomainPtr dom,
> +                            const char *eventName,
> +                            virConnectDomainEventGenericCallback callback,
> +                            void *opaque,
> +                            virFreeCallback freecb)
> +{
> +    struct qemud_driver *driver = conn->privateData;
> +    int ret;
> +
> +    qemuDriverLock(driver);
> +    ret = virDomainEventCallbackListAddName(conn,
> +                                            driver->domainEventState->callbacks,
> +                                            dom, eventName,
> +                                            VIR_QEMU_DOMAIN_EVENT_ID_UNKNOWN,
> +                                            callback, opaque, freecb);
> +    qemuDriverUnlock(driver);

This implementation looks quite simple, but I guess it depends on
whether the work I mentioned in 1/4 about domain_event changes should be
moved somewhere separate.

> +++ b/src/qemu/qemu_monitor_json.c
> @@ -58,6 +58,7 @@ static void qemuMonitorJSONHandleVNCConnect(qemuMonitorPtr mon, virJSONValuePtr
>  static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValuePtr data);
>  static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data);
>  static void qemuMonitorJSONHandleBlockJob(qemuMonitorPtr mon, virJSONValuePtr data);
> +static void qemuMonitorJSONHandleUnmatchedEvent(qemuMonitorPtr mon, virJSONValuePtr obj);
>  
>  struct {
>      const char *type;
> @@ -74,6 +75,7 @@ struct {
>      { "VNC_INITIALIZED", qemuMonitorJSONHandleVNCInitialize, },
>      { "VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect, },
>      { "BLOCK_JOB_COMPLETED", qemuMonitorJSONHandleBlockJob, },
> +    { "DEFAULT_UNKNOW_EVENT", qemuMonitorJSONHandleUnmatchedEvent, },

s/UNKNOW/UNKNOWN/

but again, I think we should be checking _every_ qemu event for
registration through libvirt-qemu, even the ones known by libvirt.

>  };
>  
>  
> @@ -83,6 +85,7 @@ qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon,
>  {
>      const char *type;
>      int i;
> +    int findEventFlag = -1;
>      VIR_DEBUG("mon=%p obj=%p", mon, obj);
>  
>      type = virJSONValueObjectGetString(obj, "event");
> @@ -98,9 +101,24 @@ qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon,
>              VIR_DEBUG("handle %s handler=%p data=%p", type,
>                        eventHandlers[i].handler, data);
>              (eventHandlers[i].handler)(mon, data);
> +            findEventFlag = 0;
>              break;
>          }
>      }

Which means this code should really be doing:

check hash table, if name found, then send qemu event to libvirt-qemu
check table of known events, if found, then call registered eventHandler

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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