From patchwork Wed Mar 9 16:15:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 86126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9A65BB6EE8 for ; Thu, 10 Mar 2011 03:14:23 +1100 (EST) Received: from localhost ([127.0.0.1]:52388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxM1j-0000oq-Ra for incoming@patchwork.ozlabs.org; Wed, 09 Mar 2011 11:14:19 -0500 Received: from [140.186.70.92] (port=39870 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxM1J-0000oQ-O6 for qemu-devel@nongnu.org; Wed, 09 Mar 2011 11:13:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxM1I-00078w-8T for qemu-devel@nongnu.org; Wed, 09 Mar 2011 11:13:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:2706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxM1H-00078l-Uy for qemu-devel@nongnu.org; Wed, 09 Mar 2011 11:13:52 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p29GDoql022359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Mar 2011 11:13:51 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p29GDnVw027302; Wed, 9 Mar 2011 11:13:50 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 9 Mar 2011 17:15:53 +0100 Message-Id: <1299687353-20424-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] block: Flush image after open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Quoting the bug report: qemu ensures that guest writes and qemu metadata writes hit the disk when necessary to prevent data corruption. However, if an image was in host pagecache prior to starting qemu, for example after running qemu-img convert, then nothing prevents writes from reaching the disk out of order, potentially causing corruption. I'm not entirely sure if there is a realistic case where we would get corruption, but it's probably a case of better safe than sorry. Reported-by: Avi Kivity Signed-off-by: Kevin Wolf --- block.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 8dea0b5..bf6892f 100644 --- a/block.c +++ b/block.c @@ -648,6 +648,14 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, bs->change_cb(bs->change_opaque, CHANGE_MEDIA); } + /* Make sure that the image is consistent on disk */ + if (!bdrv_is_read_only(bs)) { + ret = bdrv_flush(bs); + if (ret < 0) { + goto unlink_and_fail; + } + } + return 0; unlink_and_fail: