aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio-balloon.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-06-14 18:12:56 +0100
committerLuiz Capitulino <lcapitulino@redhat.com>2012-06-15 13:34:50 -0300
commit973603a813c5d60534b4fa0313f83be40e2b9c47 (patch)
treed9b07f5d7457b67b309537884c3b80de3a8022cc /hw/virtio-balloon.c
parent395c3b80bb48c0e1cbce3436e63af3650cc46d1a (diff)
Add event notification for guest balloon changes
After setting a balloon target value, applications have to continually poll 'query-balloon' to determine whether the guest has reacted to this request. The virtio-balloon backend knows exactly when the guest has reacted though, and thus it is possible to emit a JSON event to tell the mgmt application whenever the guest balloon changes. This introduces a new 'qemu_balloon_changed()' API which is to be called by balloon driver backends, whenever they have a change in balloon value. This takes the 'actual' balloon value, as would be found in the BalloonInfo struct. The qemu_balloon_change API emits a JSON monitor event which looks like: {"timestamp": {"seconds": 1337162462, "microseconds": 814521}, "event": "BALLOON_CHANGE", "data": {"actual": 944766976}} * balloon.c, balloon.h: Introduce qemu_balloon_changed() for emitting balloon change events on the monitor * hw/virtio-balloon.c: Invoke qemu_balloon_changed() whenever the guest changes the balloon actual value * monitor.c, monitor.h: Define QEVENT_BALLOON_CHANGE Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Acked-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'hw/virtio-balloon.c')
-rw-r--r--hw/virtio-balloon.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 075ed87e37..d048cef50f 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -146,8 +146,13 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
{
VirtIOBalloon *dev = to_virtio_balloon(vdev);
struct virtio_balloon_config config;
+ uint32_t oldactual = dev->actual;
memcpy(&config, config_data, 8);
dev->actual = le32_to_cpu(config.actual);
+ if (dev->actual != oldactual) {
+ qemu_balloon_changed(ram_size -
+ (dev->actual << VIRTIO_BALLOON_PFN_SHIFT));
+ }
}
static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)