qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>,
	jforbes@redhat.com, Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH 4/7] virtio-balloon: Separate status handling into separate function
Date: Tue, 26 Jul 2011 14:38:14 +0530	[thread overview]
Message-ID: <4a97e18b878afb95d2bc6a027f0d9b38e358d142.1311671109.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1311671108.git.amit.shah@redhat.com>
In-Reply-To: <cover.1311671108.git.amit.shah@redhat.com>

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 <amit.shah@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 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);
     }
 }
 
-- 
1.7.6

  parent reply	other threads:[~2011-07-26  9:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26  9:08 [Qemu-devel] [PULL 0/7] virtio-balloon: cleanups, fix segfault from use-after-free Amit Shah
2011-07-26  9:08 ` [Qemu-devel] [PATCH 1/7] balloon: Make functions, local vars static Amit Shah
2011-07-26  9:08 ` [Qemu-devel] [PATCH 2/7] balloon: Add braces around if statements Amit Shah
2011-07-26  9:08 ` [Qemu-devel] [PATCH 3/7] balloon: Simplify code flow Amit Shah
2011-07-26  9:08 ` Amit Shah [this message]
2011-07-26  9:08 ` [Qemu-devel] [PATCH 5/7] balloon: Separate out stat and balloon handling Amit Shah
2011-07-26  9:08 ` [Qemu-devel] [PATCH 6/7] balloon: Fix header comment; add Copyright Amit Shah
2011-07-26  9:08 ` [Qemu-devel] [PATCH 7/7] virtio-balloon: " Amit Shah
  -- strict thread matches above, loose matches on Subject: below --
2011-07-20  8:35 [Qemu-devel] [PATCH 0/7] balloon: cleanups, fix segfault Amit Shah
2011-07-20  8:45 ` [Qemu-devel] [PATCH 4/7] virtio-balloon: Separate status handling into separate function Amit Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a97e18b878afb95d2bc6a027f0d9b38e358d142.1311671109.git.amit.shah@redhat.com \
    --to=amit.shah@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jforbes@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).