From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCb-0006Gh-NB for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbCCV-0001pz-QZ for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32976) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCV-0001pr-IP for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:27 -0400 From: Kevin Wolf Date: Tue, 29 Oct 2013 17:30:59 +0100 Message-Id: <1383064269-27720-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1383064269-27720-1-git-send-email-kwolf@redhat.com> References: <1383064269-27720-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 07/17] qcow2: Flush image after creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Max Reitz Opening the qcow2 image with BDRV_O_NO_FLUSH prevents any flushes during the image creation. This means that the image has not yet been flushed to disk when qemu-img create exits. This flush is delayed until the next operation on the image involving opening it without BDRV_O_NO_FLUSH and closing (or directly flushing) it. For large images and/or images with a small cluster size and preallocated metadata, this flush may take a significant amount of time and may occur unexpectedly. Reopening the image without BDRV_O_NO_FLUSH right before the end of qcow2_create2() results in hoisting the potentially costly flush into the image creation, which is expected to take some time (whereas successive image operations may be not). Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Benoit Canet Signed-off-by: Kevin Wolf --- block/qcow2.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 01269f9..6e5d98d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1584,6 +1584,16 @@ static int qcow2_create2(const char *filename, int64_t total_size, } } + bdrv_close(bs); + + /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */ + ret = bdrv_open(bs, filename, NULL, + BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err); + if (error_is_set(&local_err)) { + error_propagate(errp, local_err); + goto out; + } + ret = 0; out: bdrv_unref(bs); -- 1.8.1.4