From patchwork Wed May 18 11:21:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jitendra Kolhe X-Patchwork-Id: 9117901 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 833459F1C1 for ; Wed, 18 May 2016 11:19:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA9D220166 for ; Wed, 18 May 2016 11:19:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8ADA20109 for ; Wed, 18 May 2016 11:19:42 +0000 (UTC) Received: from localhost ([::1]:44309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zVt-0007Vn-Rx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 May 2016 07:19:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zVL-0007Sr-9M for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2zVF-0006ti-QM for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:06 -0400 Received: from g2t2352.austin.hpe.com ([15.233.44.25]:38294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zVF-0006tD-KK for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:01 -0400 Received: from hpvmrhel1.in.rdlabs.hpecorp.net (unknown [15.213.178.32]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 80BDB3F; Wed, 18 May 2016 11:18:48 +0000 (UTC) From: Jitendra Kolhe To: qemu-devel@nongnu.org Date: Wed, 18 May 2016 16:51:54 +0530 Message-Id: <1463570514-29814-1-git-send-email-jitendra.kolhe@hpe.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 15.233.44.25 Subject: [Qemu-devel] [PATCH v3 3/4] balloon: reset balloon bitmap ramblock size on source and target. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: renganathan.meenakshisundaram@hpe.com, JBottomley@Odin.com, ehabkost@redhat.com, crosthwaite.peter@gmail.com, simhan@hpe.com, quintela@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, jitendra.kolhe@hpe.com, borntraeger@de.ibm.com, mst@redhat.com, mohan_parthasarathy@hpe.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 --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 @@ -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