Received: from eggs.gnu.org ([2001:4830:134:3::10]:51210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VaoT5-0007RM-OD for qemu-devel@nongnu.org; Mon, 28 Oct 2013 11:11:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VaoSy-0006Aj-9I for qemu-devel@nongnu.org; Mon, 28 Oct 2013 11:10:59 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:37010 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VaoSx-0006AJ-K6 for qemu-devel@nongnu.org; Mon, 28 Oct 2013 11:10:51 -0400 Date: Mon, 28 Oct 2013 16:10:48 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20131028151048.GF2890@irqsave.net> References: <1382639706-7404-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1382639706-7404-1-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] qcow2: Flush image after creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Le Thursday 24 Oct 2013 =E0 20:35:06 (+0200), Max Reitz a =E9crit : > Opening the qcow2 image with BDRV_O_NO_FLUSH prevents any flushes durin= g > 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 nex= t > 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. >=20 > 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). >=20 > Signed-off-by: Max Reitz > Reviewed-by: Eric Blake > --- > v2: > - implemented Kevin's remarks: > - left ret =3D 0; in the code > - added goto out; in error handling of bdrv_open > - implemented Eric's remarks: > - changed indentation of bdrv_open arguments > - s/preponing/hoisting/ in the commit message > --- > block/qcow2.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) >=20 > 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, i= nt64_t total_size, > } > } > =20 > + bdrv_close(bs); > + > + /* Reopen the image without BDRV_O_NO_FLUSH to flush it before ret= urning */ > + ret =3D 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 =3D 0; > out: > bdrv_unref(bs); > --=20 > 1.8.3.1 >=20 >=20 Reviewed-by: Benoit Canet