From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:45758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROvzw-00016c-LR for qemu-devel@nongnu.org; Fri, 11 Nov 2011 13:38:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROvzt-0002VV-QN for qemu-devel@nongnu.org; Fri, 11 Nov 2011 13:38:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROvzt-0002VB-JQ for qemu-devel@nongnu.org; Fri, 11 Nov 2011 13:38:41 -0500 From: Kevin Wolf Date: Fri, 11 Nov 2011 18:39:28 +0100 Message-Id: <1321033168-8739-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1321033168-8739-1-git-send-email-kwolf@redhat.com> References: <1321033168-8739-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 16/16] block: Make cache=unsafe flush to the OS List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org cache=unsafe completely ignored bdrv_flush, because flushing the host disk costs a lot of performance. However, this means that qcow2 images (and potentially any other format) can lose data even after the guest has issued a flush if the qemu process crashes/is killed. In case of a host crash, data loss is certainly expected with cache=unsafe, but if just the qemu process dies this is a bit too unsafe. Now that we have two separate flush functions, we can choose to flush everythign to the OS, but don't enforce that it's physically written to the disk. Signed-off-by: Kevin Wolf --- block.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index b1a4629..86910b0 100644 --- a/block.c +++ b/block.c @@ -2791,12 +2791,11 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int ret; - if (bs->open_flags & BDRV_O_NO_FLUSH) { - return 0; - } else if (!bs->drv) { + if (!bs->drv) { return 0; } + /* Write back cached data to the OS even with cache=unsafe */ if (bs->drv->bdrv_co_flush_to_os) { ret = bs->drv->bdrv_co_flush_to_os(bs); if (ret < 0) { @@ -2804,6 +2803,11 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) } } + /* But don't actually force it to the disk with cache=unsafe */ + if (bs->open_flags & BDRV_O_NO_FLUSH) { + return 0; + } + if (bs->drv->bdrv_co_flush_to_disk) { return bs->drv->bdrv_co_flush_to_disk(bs); } else if (bs->drv->bdrv_aio_flush) { -- 1.7.6.4