diff mbox

[v3,3/4] balloon: reset balloon bitmap ramblock size on source and target.

Message ID 1463570514-29814-1-git-send-email-jitendra.kolhe@hpe.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jitendra Kolhe May 18, 2016, 11:21 a.m. UTC
In case migration fails or gets aborted, the source guest will continue
to run on source host in which case the balloon bitmap ramblock is resized
back to maximum if it is set to zero as a part of migration setup. On target
the balloon bitmap size is always resized to maximum after migration.

Signed-off-by: Jitendra Kolhe <jitendra.kolhe@hpe.com>
---
 balloon.c                          | 15 +++++++++++++++
 hw/virtio/virtio-balloon.c         | 15 +++++++++++++++
 include/hw/virtio/virtio-balloon.h |  1 +
 include/sysemu/balloon.h           |  1 +
 4 files changed, 32 insertions(+)
diff mbox

Patch

diff --git a/balloon.c b/balloon.c
index 5b98aa7..494b8aa 100644
--- a/balloon.c
+++ b/balloon.c
@@ -259,3 +259,18 @@  void qemu_balloon_bitmap_setup(void)
         memory_region_ram_resize(bmap_mr, 0, &error_fatal);
     }
 }
+
+void qemu_balloon_bitmap_reset(bool source)
+{
+    RAMBlock *block;
+    block = qemu_ram_block_by_name(BALLOON_BMAP_NAME);
+
+    assert(block);
+    if (source && (balloon_bitmap_state == BALLOON_BITMAP_DISABLE ||
+                   balloon_bitmap_state == BALLOON_BITMAP_DISABLE_FROM_GUEST)) {
+        memory_region_ram_resize(bmap_mr, block->max_length, &error_fatal);
+    } else {
+        memory_region_ram_resize(bmap_mr, block->max_length, &error_fatal);
+    }
+    balloon_bitmap_state = BALLOON_BITMAP_INIT;
+}
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 5031fa8..a69773c 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -26,6 +26,7 @@ 
 #include "qapi/visitor.h"
 #include "qapi-event.h"
 #include "trace.h"
+#include "migration/migration.h"
 
 #if defined(__linux__)
 #include <sys/mman.h>
@@ -319,6 +320,16 @@  out:
     }
 }
 
+static void virtio_balloon_migration_state_changed(Notifier *notifier,
+                                                   void *data)
+{
+    MigrationState *mig = data;
+
+    if (migration_has_failed(mig)) {
+        qemu_balloon_bitmap_reset(true);
+    }
+}
+
 static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
     VirtIOBalloon *dev = VIRTIO_BALLOON(vdev);
@@ -451,6 +462,7 @@  static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
 
     s->num_pages = qemu_get_be32(f);
     s->actual = qemu_get_be32(f);
+    qemu_balloon_bitmap_reset(false);
 
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
@@ -481,6 +493,8 @@  static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     s->ivq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
     s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
     s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
+    s->migration_state_notifier.notify = virtio_balloon_migration_state_changed;
+    add_migration_state_change_notifier(&s->migration_state_notifier);
 
     reset_stats(s);
 
@@ -493,6 +507,7 @@  static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOBalloon *s = VIRTIO_BALLOON(dev);
 
+    remove_migration_state_change_notifier(&s->migration_state_notifier);
     balloon_stats_destroy_timer(s);
     qemu_remove_balloon_handler(s);
     unregister_savevm(dev, "virtio-balloon", s);
diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index 35f62ac..1ded5a9 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -43,6 +43,7 @@  typedef struct VirtIOBalloon {
     int64_t stats_last_update;
     int64_t stats_poll_interval;
     uint32_t host_features;
+    Notifier migration_state_notifier;
 } VirtIOBalloon;
 
 #endif
diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h
index 8cf5a2f..9a9bed9 100644
--- a/include/sysemu/balloon.h
+++ b/include/sysemu/balloon.h
@@ -33,5 +33,6 @@  void qemu_balloon_bitmap_update(ram_addr_t addr, int deflate);
 void qemu_balloon_bitmap_extend(RAMBlock *new_block,
                                 ram_addr_t old, ram_addr_t new);
 void qemu_balloon_bitmap_setup(void);
+void qemu_balloon_bitmap_reset(bool source);
 
 #endif