From patchwork Tue Feb 12 09:37:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 219753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4B9AC2C031E for ; Tue, 12 Feb 2013 20:37:52 +1100 (EST) Received: from localhost ([::1]:38711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CJC-0005sT-AI for incoming@patchwork.ozlabs.org; Tue, 12 Feb 2013 04:37:50 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CIs-0005co-9z for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5CIn-0003aV-IM for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CIn-0003aO-8h for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:25 -0500 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 r1C9bOti026768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Feb 2013 04:37:24 -0500 Received: from localhost (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1C9bNUT001798; Tue, 12 Feb 2013 04:37:24 -0500 From: Stefan Hajnoczi To: Date: Tue, 12 Feb 2013 10:37:15 +0100 Message-Id: <1360661835-28663-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1360661835-28663-1-git-send-email-stefanha@redhat.com> References: <1360661835-28663-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi , Juan Quintela Subject: [Qemu-devel] [PATCH for-1.4 2/2] block-migration: fix pending() and iterate() return values 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 The return value of .save_live_pending() is the number of bytes remaining. This is just an estimate because we do not know how many blocks will be dirtied by the running guest. Currently our return value for .save_live_pending() is wrong because it includes dirty blocks but not in-flight bdrv_aio_readv() requests or unsent blocks. Crucially, it also doesn't include the bulk phase where the entire device is transferred - therefore we risk completing block migration before all blocks have been transferred! The return value of .save_live_iterate() is the number of bytes transferred this iteration. Currently we return whether there are bytes remaining, which is incorrect. Move the bytes remaining calculation into .save_live_pending() and really return the number of bytes transferred this iteration in .save_live_iterate(). Also fix the %ld format specifier which was used for a uint64_t argument. PRIu64 must be use to avoid warnings on 32-bit hosts. Signed-off-by: Stefan Hajnoczi --- block-migration.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/block-migration.c b/block-migration.c index bcd0039..43ab202 100644 --- a/block-migration.c +++ b/block-migration.c @@ -539,6 +539,7 @@ static int block_save_setup(QEMUFile *f, void *opaque) static int block_save_iterate(QEMUFile *f, void *opaque) { int ret; + int64_t last_ftell = qemu_ftell(f); DPRINTF("Enter save live iterate submitted %d transferred %d\n", block_mig_state.submitted, block_mig_state.transferred); @@ -582,12 +583,7 @@ static int block_save_iterate(QEMUFile *f, void *opaque) qemu_put_be64(f, BLK_MIG_FLAG_EOS); - /* Complete when bulk transfer is done and all dirty blocks have been - * transferred. - */ - return block_mig_state.bulk_completed && - block_mig_state.submitted == 0 && - block_mig_state.read_done == 0; + return qemu_ftell(f) - last_ftell; } static int block_save_complete(QEMUFile *f, void *opaque) @@ -629,10 +625,18 @@ static int block_save_complete(QEMUFile *f, void *opaque) static uint64_t block_save_pending(QEMUFile *f, void *opaque, uint64_t max_size) { + /* Estimate pending number of bytes to send */ + uint64_t pending = get_remaining_dirty() + + block_mig_state.submitted * BLOCK_SIZE + + block_mig_state.read_done * BLOCK_SIZE; + + /* Report at least one block pending during bulk phase */ + if (pending == 0 && !block_mig_state.bulk_completed) { + pending = BLOCK_SIZE; + } - DPRINTF("Enter save live pending %ld\n", get_remaining_dirty()); - - return get_remaining_dirty(); + DPRINTF("Enter save live pending %" PRIu64 "\n", pending); + return pending; } static int block_load(QEMUFile *f, void *opaque, int version_id)