[libvirt] [PATCH 2/2] Wire up handling for QMP's BALLOON_EVENT

Eric Blake eblake at redhat.com
Wed May 16 17:42:35 UTC 2012


On 05/16/2012 08:35 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
> 
> If QEMU supports the BALLOON_EVENT QMP event, then we can
> avoid invoking 'query-balloon' when returning XML or the
> domain info.
> 
> * src/qemu/qemu_capabilities.c, src/qemu/qemu_capabilities.h:
>   Add QEMU_CAPS_BALLOON_EVENT
> * src/qemu/qemu_driver.c: Skip query-balloon in
>   qemudDomainGetInfo and qemuDomainGetXMLDesc if we have
>   QEMU_CAPS_BALLOON_EVENT set
> * src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Check
>   for BALLOON_EVENT at connect to monitor. Add callback
>   for balloon change notifications
> * src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h:
>   Add handling of BALLOON_EVENT and impl 'query-events'
>   check
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  src/qemu/qemu_capabilities.c |    2 +
>  src/qemu/qemu_capabilities.h |    1 +
>  src/qemu/qemu_driver.c       |    7 ++++-
>  src/qemu/qemu_monitor.c      |   18 +++++++++++-
>  src/qemu/qemu_monitor.h      |    5 +++
>  src/qemu/qemu_monitor_json.c |   65 ++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |    2 +
>  src/qemu/qemu_process.c      |   31 ++++++++++++++++++++
>  8 files changed, 129 insertions(+), 2 deletions(-)
> 

> +    QEMU_CAPS_BALLOON_EVENT      = 95, /* Async event for balloon changes */

Yet another cap bit that can only be learned when the guest is live.  We
really need to start caching qemu capabilities per binary...  But at
least your patch only matters for live guests (unlike my recent patches
for block copy, where I was giving a bad error message for offline
guests until I added commit 8e532d34 to shuffle things around).

> +static void
> +qemuMonitorJSONHandleBalloonChange(qemuMonitorPtr mon,
> +                                   virJSONValuePtr data)
> +{
> +    unsigned long long actual = 0;
> +    if (virJSONValueObjectGetNumberUlong(data, "actual", &actual) < 0) {
> +        VIR_WARN("missing actual in balloon change event");
> +        return;
> +    }
> +    actual = (actual/1024);

I think you want to use VIR_DIV_UP(actual, 1024) here, just in case qemu
ever reports a value with finer granularity than a kilobyte.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120516/d0f9c882/attachment-0001.sig>


More information about the libvir-list mailing list