From patchwork Wed Jul 20 08:45:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 105603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D96AEB6F77 for ; Wed, 20 Jul 2011 18:54:55 +1000 (EST) Received: from localhost ([::1]:36125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjSYM-0001cl-Dp for incoming@patchwork.ozlabs.org; Wed, 20 Jul 2011 04:54:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjSPY-00009h-Hz for qemu-devel@nongnu.org; Wed, 20 Jul 2011 04:45:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjSPU-0004zl-H0 for qemu-devel@nongnu.org; Wed, 20 Jul 2011 04:45:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15066) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjSPT-0004zY-TZ for qemu-devel@nongnu.org; Wed, 20 Jul 2011 04:45:40 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6K8jbIw021661 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 20 Jul 2011 04:45:37 -0400 Received: from localhost (ovpn-113-63.phx2.redhat.com [10.3.113.63]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6K8jYxR019937; Wed, 20 Jul 2011 04:45:36 -0400 From: Amit Shah To: qemu list Date: Wed, 20 Jul 2011 14:15:14 +0530 Message-Id: <3bf0dcc40e47ffb078cd576c002fc577a146112a.1311149456.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 Subject: [Qemu-devel] [PATCH 4/7] virtio-balloon: Separate status handling into separate function 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 Separate out the code to retrieve balloon info from the code that sets balloon values. This will be used to separate the two callbacks from balloon.c and help cope with 'balloon 0' on the monitor. Currently, 'balloon 0' causes a segfault in monitor_resume(). Signed-off-by: Amit Shah --- hw/virtio-balloon.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 31 insertions(+), 20 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 70a8710..2f371f2 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -199,36 +199,47 @@ static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f) return f; } +static void virtio_balloon_stat(void *opaque, MonitorCompletion cb, + void *cb_data) +{ + VirtIOBalloon *dev = opaque; + + /* For now, only allow one request at a time. This restriction can be + * removed later by queueing callback and data pairs. + */ + if (dev->stats_callback != NULL) { + return; + } + dev->stats_callback = cb; + dev->stats_opaque_callback_data = cb_data; + + if (ENABLE_GUEST_STATS + && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) { + virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset); + virtio_notify(&dev->vdev, dev->svq); + return; + } + + /* Stats are not supported. Clear out any stale values that might + * have been set by a more featureful guest kernel. + */ + reset_stats(dev); + complete_stats_request(dev); +} + static void virtio_balloon_to_target(void *opaque, ram_addr_t target, MonitorCompletion cb, void *cb_data) { VirtIOBalloon *dev = opaque; - if (target > ram_size) + if (target > ram_size) { target = ram_size; - + } if (target) { dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT; virtio_notify_config(&dev->vdev); } else { - /* For now, only allow one request at a time. This restriction can be - * removed later by queueing callback and data pairs. - */ - if (dev->stats_callback != NULL) { - return; - } - dev->stats_callback = cb; - dev->stats_opaque_callback_data = cb_data; - if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) { - virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset); - virtio_notify(&dev->vdev, dev->svq); - } else { - /* Stats are not supported. Clear out any stale values that might - * have been set by a more featureful guest kernel. - */ - reset_stats(dev); - complete_stats_request(dev); - } + virtio_balloon_stat(opaque, cb, cb_data); } }