From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlV3m-0001t5-9M for qemu-devel@nongnu.org; Tue, 26 Nov 2013 21:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlV3h-0002KF-Mk for qemu-devel@nongnu.org; Tue, 26 Nov 2013 21:41:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlV3h-0002K7-EF for qemu-devel@nongnu.org; Tue, 26 Nov 2013 21:40:57 -0500 Message-ID: <52955BAA.5030904@redhat.com> Date: Wed, 27 Nov 2013 10:40:42 +0800 From: Fam Zheng MIME-Version: 1.0 References: <46eda2920fc6169f16957756306acca4ed3bbe95.1385518315.git.hutao@cn.fujitsu.com> In-Reply-To: <46eda2920fc6169f16957756306acca4ed3bbe95.1385518315.git.hutao@cn.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_preallocate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao , Kevin Wolf , "Daniel P. Berrange" , Peter Lieven Cc: qemu-devel@nongnu.org On 2013=E5=B9=B411=E6=9C=8827=E6=97=A5 10:15, Hu Tao wrote: > Signed-off-by: Hu Tao > --- > block/raw-posix.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index f836c8e..c563073 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -1050,6 +1050,39 @@ static int64_t raw_get_allocated_file_size(Block= DriverState *bs) > return (int64_t)st.st_blocks * 512; > } > > +#ifdef __linux__ > +static int raw_preallocate2(int fd, int64_t offset, int64_t length) > +{ > + int ret =3D -1; > + > + ret =3D fallocate(fd, 0, offset, length); > + > + /* fallback to posix_fallocate() if fallocate() is not supported *= / > + if (ret < 0 && (errno =3D=3D ENOSYS || errno =3D=3D EOPNOTSUPP)) { > + ret =3D posix_fallocate(fd, offset, length); > + } > + > + return ret; > +} > +#else > +static int raw_preallocate2(int fd, int64_t offset, int64_t length) > +{ > + return posix_fallocate(fd, offset, length); > +} > +#endif > + > +static int raw_preallocate(BlockDriverState *bs, int64_t offset, int64= _t length) > +{ > + BDRVRawState *s =3D bs->opaque; > + int64_t len =3D bdrv_getlength(bs); > + > + if (offset + length < 0 || offset + length > len) { > + return -1; -EINVAL Fam > + } > + > + return raw_preallocate2(s->fd, offset, length); > +} > + > static int raw_create(const char *filename, QEMUOptionParameter *opti= ons, > Error **errp) > { > @@ -1221,6 +1254,7 @@ static BlockDriver bdrv_file =3D { > .bdrv_close =3D raw_close, > .bdrv_create =3D raw_create, > .bdrv_has_zero_init =3D bdrv_has_zero_init_1, > + .bdrv_preallocate =3D raw_preallocate, > .bdrv_co_get_block_status =3D raw_co_get_block_status, > > .bdrv_aio_readv =3D raw_aio_readv, >