Patchwork balloon: Don't try fetching info if machine is stopped

login
register
mail settings
Submitter Amit Shah
Date Aug. 19, 2010, 4:14 a.m.
Message ID <d93a60e33f51a95242bf0c927f15003e834727c8.1282191270.git.amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/62105/
State New
Headers show

Comments

Amit Shah - Aug. 19, 2010, 4:14 a.m.
If the machine is stopped and 'info balloon' is invoked, the monitor
process just hangs waiting for info from the guest. Return the most
recent balloon data in that case.

See https://bugzilla.redhat.com/show_bug.cgi?id=623903

Reported-by: <lihuang@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 balloon.c           |   18 +++++++++++++-----
 balloon.h           |    6 ++++--
 hw/virtio-balloon.c |    9 +++++++--
 3 files changed, 24 insertions(+), 9 deletions(-)
Paolo Bonzini - Aug. 19, 2010, 7:56 a.m.
On 08/19/2010 06:14 AM, Amit Shah wrote:
> +    get_cached_data = 0;
> +    if (!vm_running) {
> +        get_cached_data = 1;
> +    }

     get_cached_data = !vm_running;

Alternatively, see below...

> +    ret = qemu_balloon_status(cb, opaque, get_cached_data);
>       if (!ret) {

Piggybacking on the existing coding style thread, here

     ret = qemu_balloon_status(cb, opaque, !vm_running);

would be quite hard to read indeed.  Maybe we can use something like this:

     ret = qemu_balloon_status(cb, opaque,
			      /*get_cached_data=*/ !vm_running);

?

Paolo

Patch

diff --git a/balloon.c b/balloon.c
index 8e0b7f1..8826676 100644
--- a/balloon.c
+++ b/balloon.c
@@ -43,17 +43,20 @@  void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
 int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
 {
     if (qemu_balloon_event) {
-        qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque);
+        qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque,
+                           false);
         return 1;
     } else {
         return 0;
     }
 }
 
-int qemu_balloon_status(MonitorCompletion cb, void *opaque)
+int qemu_balloon_status(MonitorCompletion cb, void *opaque,
+                        bool get_cached_data)
 {
     if (qemu_balloon_event) {
-        qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);
+        qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque,
+                           get_cached_data);
         return 1;
     } else {
         return 0;
@@ -106,14 +109,19 @@  void monitor_print_balloon(Monitor *mon, const QObject *data)
  */
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque)
 {
-    int ret;
+    int ret, get_cached_data;
 
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
         qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
         return -1;
     }
 
-    ret = qemu_balloon_status(cb, opaque);
+    get_cached_data = 0;
+    if (!vm_running) {
+        get_cached_data = 1;
+    }
+
+    ret = qemu_balloon_status(cb, opaque, get_cached_data);
     if (!ret) {
         qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
         return -1;
diff --git a/balloon.h b/balloon.h
index d478e28..729631c 100644
--- a/balloon.h
+++ b/balloon.h
@@ -17,13 +17,15 @@ 
 #include "monitor.h"
 
 typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target,
-                                MonitorCompletion cb, void *cb_data);
+                                MonitorCompletion cb, void *cb_data,
+                                bool get_cached_data);
 
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque);
 
 int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque);
 
-int qemu_balloon_status(MonitorCompletion cb, void *opaque);
+int qemu_balloon_status(MonitorCompletion cb, void *opaque,
+                        bool get_cached_data);
 
 void monitor_print_balloon(Monitor *mon, const QObject *data);
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque);
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 9fe3886..68df891 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -195,7 +195,8 @@  static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)
 }
 
 static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
-                                     MonitorCompletion cb, void *cb_data)
+                                     MonitorCompletion cb, void *cb_data,
+                                     bool get_cached_data)
 {
     VirtIOBalloon *dev = opaque;
 
@@ -213,8 +214,12 @@  static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
             return;
         }
         dev->stats_callback = cb;
-        dev->stats_opaque_callback_data = cb_data; 
+        dev->stats_opaque_callback_data = cb_data;
         if (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ)) {
+            if (get_cached_data) {
+                complete_stats_request(dev);
+                return;
+            }
             virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
             virtio_notify(&dev->vdev, dev->svq);
         } else {