From patchwork Sat Nov 12 15:56:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 125349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 840CC1007D8 for ; Sun, 13 Nov 2011 02:57:41 +1100 (EST) Received: from localhost ([::1]:53575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFxa-0000Ek-St for incoming@patchwork.ozlabs.org; Sat, 12 Nov 2011 10:57:38 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFxM-0008Q4-4O for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RPFxL-00079p-3N for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:24 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:42190 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPFxK-00079e-NF for qemu-devel@nongnu.org; Sat, 12 Nov 2011 10:57:22 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id pACFvHo7003311; Sat, 12 Nov 2011 09:57:17 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id pACFvG7I003310; Sat, 12 Nov 2011 09:57:16 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sat, 12 Nov 2011 09:56:58 -0600 Message-Id: <1321113420-3252-5-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1321113420-3252-1-git-send-email-aliguori@us.ibm.com> References: <1321113420-3252-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Kevin Wolf , Lucas Meneghel Rodrigues , Anthony Liguori , Stefan Hajnoczi , Juan Quintela , Avi Kivity Subject: [Qemu-devel] [PATCH 5/7] block: allow migration to work with image files (v2) 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 Image files have two types of data: immutable data that describes things like image size, backing files, etc. and mutable data that includes offset and reference count tables. Today, image formats aggressively cache mutable data to improve performance. In some cases, this happens before a guest even starts. When dealing with live migration, since a file is open on two machines, the caching of meta data can lead to data corruption. This patch addresses this by introducing a mechanism to invalidate any cached mutable data a block driver may have which is then used by the live migration code. NB, this still requires coherent shared storage. Addressing migration without coherent shared storage (i.e. NFS) requires additional work. Signed-off-by: Anthony Liguori --- v1 -> v2 - rebase to latest master --- block.c | 16 ++++++++++++++++ block.h | 4 ++++ block_int.h | 5 +++++ cpus.c | 1 + migration.c | 3 +++ 5 files changed, 29 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 86910b0..d015887 100644 --- a/block.c +++ b/block.c @@ -2839,6 +2839,22 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) } } +void bdrv_invalidate_cache(BlockDriverState *bs) +{ + if (bs->drv && bs->drv->bdrv_invalidate_cache) { + bs->drv->bdrv_invalidate_cache(bs); + } +} + +void bdrv_invalidate_cache_all(void) +{ + BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { + bdrv_invalidate_cache(bs); + } +} + int bdrv_flush(BlockDriverState *bs) { Coroutine *co; diff --git a/block.h b/block.h index 051a25d..a826059 100644 --- a/block.h +++ b/block.h @@ -197,6 +197,10 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, unsigned long int req, void *buf, BlockDriverCompletionFunc *cb, void *opaque); +/* Invalidate any cached metadata used by image formats */ +void bdrv_invalidate_cache(BlockDriverState *bs); +void bdrv_invalidate_cache_all(void); + /* Ensure contents are flushed to disk. */ int bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); diff --git a/block_int.h b/block_int.h index 1ec4921..77c0187 100644 --- a/block_int.h +++ b/block_int.h @@ -88,6 +88,11 @@ struct BlockDriver { int64_t sector_num, int nb_sectors); /* + * Invalidate any cached meta-data. + */ + void (*bdrv_invalidate_cache)(BlockDriverState *bs); + + /* * Flushes all data that was already written to the OS all the way down to * the disk (for example raw-posix calls fsync()). */ diff --git a/cpus.c b/cpus.c index 82530c4..ae5ec99 100644 --- a/cpus.c +++ b/cpus.c @@ -398,6 +398,7 @@ static void do_vm_stop(RunState state) vm_state_notify(0, state); qemu_aio_flush(); bdrv_flush_all(); + bdrv_invalidate_cache_all(); monitor_protocol_event(QEVENT_STOP, NULL); } } diff --git a/migration.c b/migration.c index 6764d3a..8280d71 100644 --- a/migration.c +++ b/migration.c @@ -89,6 +89,9 @@ void process_incoming_migration(QEMUFile *f) qemu_announce_self(); DPRINTF("successfully loaded vm state\n"); + /* Make sure all file formats flush their mutable metadata */ + bdrv_invalidate_cache_all(); + if (autostart) { vm_start(); } else {