From patchwork Mon Dec 14 20:53:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 41136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C57CAB6F12 for ; Tue, 15 Dec 2009 08:03:32 +1100 (EST) Received: from localhost ([127.0.0.1]:59009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKI4o-0001MH-3W for incoming@patchwork.ozlabs.org; Mon, 14 Dec 2009 16:03:30 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NKHvV-0002KE-8d for qemu-devel@nongnu.org; Mon, 14 Dec 2009 15:53:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NKHvQ-0002FC-5y for qemu-devel@nongnu.org; Mon, 14 Dec 2009 15:53:52 -0500 Received: from [199.232.76.173] (port=39718 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKHvP-0002Ez-SX for qemu-devel@nongnu.org; Mon, 14 Dec 2009 15:53:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23146) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NKHvP-0002fV-BN for qemu-devel@nongnu.org; Mon, 14 Dec 2009 15:53:47 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBEKrk2p003784 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Dec 2009 15:53:46 -0500 Received: from localhost (vpn-10-150.rdu.redhat.com [10.11.10.150]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBEKrjf1007376; Mon, 14 Dec 2009 15:53:45 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 14 Dec 2009 18:53:22 -0200 Message-Id: <1260824004-2941-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1260824004-2941-1-git-send-email-lcapitulino@redhat.com> References: <1260824004-2941-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 3/5] monitor: do_balloon(): Check for errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org do_balloon() should check for ballooning availability as do_info_balloon() does. Noted by Daniel P. Berrange . Signed-off-by: Luiz Capitulino --- monitor.c | 35 ++++++++++++++++++++++++++--------- 1 files changed, 26 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index d5041dc..920ccff 100644 --- a/monitor.c +++ b/monitor.c @@ -2053,14 +2053,34 @@ static void do_info_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } +static ram_addr_t balloon_get_value(void) +{ + ram_addr_t actual; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return 0; + } + + actual = qemu_balloon_status(); + if (actual == 0) { + qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return 0; + } + + return actual; +} + /** * do_balloon(): Request VM to change its memory allocation */ static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data) { - int value = qdict_get_int(qdict, "value"); - ram_addr_t target = value; - qemu_balloon(target << 20); + if (balloon_get_value()) { + /* ballooning is active */ + ram_addr_t value = qdict_get_int(qdict, "value"); + qemu_balloon(value << 20); + } } static void monitor_print_balloon(Monitor *mon, const QObject *data) @@ -2088,14 +2108,11 @@ static void do_info_balloon(Monitor *mon, QObject **ret_data) { ram_addr_t actual; - actual = qemu_balloon_status(); - if (kvm_enabled() && !kvm_has_sync_mmu()) - qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - else if (actual == 0) - qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); - else + actual = balloon_get_value(); + if (actual != 0) { *ret_data = qobject_from_jsonf("{ 'balloon': %" PRId64 "}", (int64_t) actual); + } } static qemu_acl *find_acl(Monitor *mon, const char *name)