From patchwork Thu Jun 14 17:12:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 164972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 76B59B6FD5 for ; Fri, 15 Jun 2012 03:13:23 +1000 (EST) Received: from localhost ([::1]:36896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfDbk-0008KP-AU for incoming@patchwork.ozlabs.org; Thu, 14 Jun 2012 13:13:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfDba-0008J4-CC for qemu-devel@nongnu.org; Thu, 14 Jun 2012 13:13:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfDbV-0005RV-A5 for qemu-devel@nongnu.org; Thu, 14 Jun 2012 13:13:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfDbV-0005RC-11 for qemu-devel@nongnu.org; Thu, 14 Jun 2012 13:13:05 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5EHD2X0004643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 14 Jun 2012 13:13:03 -0400 Received: from avocado.gsslab.fab.redhat.com (avocado.gsslab.fab.redhat.com [10.33.8.113]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5EHCxG5020911; Thu, 14 Jun 2012 13:13:01 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2012 18:12:56 +0100 Message-Id: <1339693977-7397-2-git-send-email-berrange@redhat.com> In-Reply-To: <1339693977-7397-1-git-send-email-berrange@redhat.com> References: <1339693977-7397-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Amit Shah , Markus Armbruster , Anthony Liguori , Luiz Capitulino Subject: [Qemu-devel] [PATCH v3 1/2] Add event notification for guest balloon changes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Daniel P. Berrange" 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 --- QMP/qmp-events.txt | 18 ++++++++++++++++++ balloon.c | 14 ++++++++++++++ balloon.h | 2 ++ hw/virtio-balloon.c | 5 +++++ monitor.c | 1 + monitor.h | 1 + 6 files changed, 41 insertions(+), 0 deletions(-) diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt index 9286af5..9ba7079 100644 --- a/QMP/qmp-events.txt +++ b/QMP/qmp-events.txt @@ -335,3 +335,21 @@ Example: "len": 10737418240, "offset": 134217728, "speed": 0 }, "timestamp": { "seconds": 1267061043, "microseconds": 959568 } } + + +BALLOON_CHANGE +---------- + +Emitted when the guest changes the actual BALLOON level. This +value is equivalent to the 'actual' field return by the +'query-balloon' command + +Data: + +- "actual": actual level of the guest memory balloon in bytes (json-number) + +Example: + +{ "event": "BALLOON_CHANGE", + "data": { "actual": 944766976 }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } diff --git a/balloon.c b/balloon.c index aa354f7..e02ab1c 100644 --- a/balloon.c +++ b/balloon.c @@ -30,6 +30,7 @@ #include "balloon.h" #include "trace.h" #include "qmp-commands.h" +#include "qjson.h" static QEMUBalloonEvent *balloon_event_fn; static QEMUBalloonStatus *balloon_stat_fn; @@ -80,6 +81,19 @@ static int qemu_balloon_status(BalloonInfo *info) return 1; } +void qemu_balloon_changed(int64_t actual) +{ + QObject *data; + + data = qobject_from_jsonf("{ 'actual': %" PRId64 " }", + actual); + + monitor_protocol_event(QEVENT_BALLOON_CHANGE, data); + + qobject_decref(data); +} + + BalloonInfo *qmp_query_balloon(Error **errp) { BalloonInfo *info; diff --git a/balloon.h b/balloon.h index b60fd5d..b803a00 100644 --- a/balloon.h +++ b/balloon.h @@ -24,4 +24,6 @@ int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, QEMUBalloonStatus *stat_func, void *opaque); void qemu_remove_balloon_handler(void *opaque); +void qemu_balloon_changed(int64_t actual); + #endif diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 075ed87..d048cef 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) diff --git a/monitor.c b/monitor.c index a3bc2c7..75fd4cf 100644 --- a/monitor.c +++ b/monitor.c @@ -443,6 +443,7 @@ static const char *monitor_event_names[] = { [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_WAKEUP] = "WAKEUP", + [QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE", }; QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX) diff --git a/monitor.h b/monitor.h index cd1d878..5f4de1b 100644 --- a/monitor.h +++ b/monitor.h @@ -41,6 +41,7 @@ typedef enum MonitorEvent { QEVENT_DEVICE_TRAY_MOVED, QEVENT_SUSPEND, QEVENT_WAKEUP, + QEVENT_BALLOON_CHANGE, /* Add to 'monitor_event_names' array in monitor.c when * defining new events here */