Received: from eggs.gnu.org ([2001:4830:134:3::10]:47283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgTXi-0006Hz-GZ for qemu-devel@nongnu.org; Wed, 13 Nov 2013 01:03:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgTXd-00061a-Tf for qemu-devel@nongnu.org; Wed, 13 Nov 2013 01:03:10 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:39214 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgTXd-00061R-NN for qemu-devel@nongnu.org; Wed, 13 Nov 2013 01:03:05 -0500 Message-ID: <3dacbe2b77741a4d476a88de6f17effc.squirrel@ssl.dlhnet.de> In-Reply-To: <20131113024616.GF24886@G08FNSTD100614.fnst.cn.fujitsu.com> References: <3bdffb8a85c3563a38f31846f4687b4c435730ab.1384227383.git.hutao@cn.fujitsu.com> <20131112103103.GB2627@dhcp-200-207.str.redhat.com> <20131113024616.GF24886@G08FNSTD100614.fnst.cn.fujitsu.com> Date: Wed, 13 Nov 2013 07:03:03 +0100 From: "Peter Lieven" MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH 4/4] qcow2: Add full image preallocation option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao Cc: Kevin Wolf , Paolo Bonzini , qemu-devel@nongnu.org What is your use case for this seris? QCOW2 creation or converting anything to QCOW2? For the later case you could use "qemu-img convert -S = 0 ..." starting in 1.8. Peter Hu Tao wrote: > This adds a preallocation=3Dfull mode to qcow2 image creation, which > creates a non-sparse image file. > > Signed-off-by: Hu Tao > --- > block/qcow2.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/block/qcow2.c b/block/qcow2.c > index 359030f..d3ca6cf 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1385,7 +1385,13 @@ static int > qcow2_change_backing_file(BlockDriverState *bs, > return qcow2_update_header(bs); > } > > -static int preallocate(BlockDriverState *bs) > +enum prealloc_mode { > + PREALLOC_OFF =3D 0, > + PREALLOC_METADATA, > + PREALLOC_FULL, > +}; > + > +static int preallocate(BlockDriverState *bs, enum prealloc_mode mode) > { > uint64_t nb_sectors; > uint64_t offset; > @@ -1394,9 +1400,12 @@ static int preallocate(BlockDriverState *bs) > int ret; > QCowL2Meta *meta; > > + assert(mode !=3D PREALLOC_OFF); > + > nb_sectors =3D bdrv_getlength(bs) >> 9; > offset =3D 0; > > + /* First allocate metadata in _really_ big chunks */ > while (nb_sectors) { > num =3D MIN(nb_sectors, INT_MAX >> 9); > ret =3D qcow2_alloc_cluster_offset(bs, offset, 0, num, &num, > @@ -1424,6 +1433,11 @@ static int preallocate(BlockDriverState *bs) > offset +=3D num << 9; > } > > + /* Then write zeros to the cluster data, if requested */ > + if (mode =3D=3D PREALLOC_FULL) { > + bdrv_zero_init(bs->file, offset, bdrv_getlength(bs)); > + } > + > /* > * It is expected that the image file is large enough to actually > contain > * all of the allocated clusters (otherwise we get failing reads > after > @@ -1572,11 +1586,11 @@ static int qcow2_create2(const char *filename, > int64_t total_size, > } > } > > - /* And if we're supposed to preallocate metadata, do that now */ > + /* And if we're supposed to preallocate data, do that now */ > if (prealloc) { > BDRVQcowState *