From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZHib-0005BW-7R for qemu-devel@nongnu.org; Thu, 24 Oct 2013 06:00:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZHiV-00034R-7r for qemu-devel@nongnu.org; Thu, 24 Oct 2013 06:00:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZHiU-000346-RB for qemu-devel@nongnu.org; Thu, 24 Oct 2013 06:00:35 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9OA0XC7017473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 24 Oct 2013 06:00:34 -0400 Date: Thu, 24 Oct 2013 12:00:12 +0200 From: Kevin Wolf Message-ID: <20131024100012.GD7385@dhcp-200-207.str.redhat.com> References: <1382557241-23117-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1382557241-23117-1-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qcow2: Flush image after creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Am 23.10.2013 um 21:40 hat Max Reitz geschrieben: > 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 preponing 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 > --- > block/qcow2.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/block/qcow2.c b/block/qcow2.c > index c1abaff..8b98c3a 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1584,7 +1584,15 @@ static int qcow2_create2(const char *filename, int64_t total_size, > } > } > > - ret = 0; I would prefer to keep the explicit ret = 0 there (just like the unnecessary last 'goto out:', it just makes things more obvious and consistent) > + 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); So a goto here wouldn't hurt either. Note how the unnecessary goto in the block before allowed you to just add your new code without modifying existing parts. > + } > + > out: > bdrv_unref(bs); > return ret; Kevin