From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36820 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuQhX-0002Qv-13 for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OuQhR-0004xm-5g for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:06 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:55881) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OuQhR-0004xZ-3Y for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:01 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o8BE4uFd031621 for ; Sat, 11 Sep 2010 10:04:56 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8BE50Tv390258 for ; Sat, 11 Sep 2010 10:05:00 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o8BE502H017002 for ; Sat, 11 Sep 2010 10:05:00 -0400 From: Anthony Liguori Date: Sat, 11 Sep 2010 09:04:54 -0500 Message-Id: <1284213896-12705-2-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> References: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH 1/3] block: allow migration to work with image files List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Juan Quintela 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 diff --git a/block.c b/block.c index ebbc376..cd2ee31 100644 --- a/block.c +++ b/block.c @@ -1453,6 +1453,22 @@ const char *bdrv_get_device_name(BlockDriverState *bs) return bs->device_name; } +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); + } +} + void bdrv_flush(BlockDriverState *bs) { if (bs->open_flags & BDRV_O_NO_FLUSH) { diff --git a/block.h b/block.h index 5f64380..387f6d3 100644 --- a/block.h +++ b/block.h @@ -141,6 +141,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. */ void bdrv_flush(BlockDriverState *bs); void bdrv_flush_all(void); diff --git a/block_int.h b/block_int.h index e8e7156..bca99b2 100644 --- a/block_int.h +++ b/block_int.h @@ -60,6 +60,7 @@ struct BlockDriver { void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); void (*bdrv_flush)(BlockDriverState *bs); + void (*bdrv_invalidate_cache)(BlockDriverState *bs); int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); diff --git a/migration.c b/migration.c index 468d517..64d3d15 100644 --- a/migration.c +++ b/migration.c @@ -69,6 +69,9 @@ void process_incoming_migration(QEMUFile *f) incoming_expected = false; + /* Make sure all file formats flush their mutable metadata */ + bdrv_invalidate_cache_all(); + if (autostart) vm_start(); } @@ -370,6 +373,7 @@ void migrate_fd_put_ready(void *opaque) qemu_aio_flush(); bdrv_flush_all(); + bdrv_invalidate_cache_all(); if ((qemu_savevm_state_complete(s->mon, s->file)) < 0) { if (old_vm_running) { vm_start(); -- 1.7.0.4