From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5x7E-0002z7-RG for qemu-devel@nongnu.org; Fri, 09 Mar 2012 05:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5x7A-0007kl-0p for qemu-devel@nongnu.org; Fri, 09 Mar 2012 05:32:04 -0500 Received: from mail-lpp01m010-f45.google.com ([209.85.215.45]:40703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5x79-0007kH-Ms for qemu-devel@nongnu.org; Fri, 09 Mar 2012 05:31:59 -0500 Received: by lahe6 with SMTP id e6so1595292lah.4 for ; Fri, 09 Mar 2012 02:31:57 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1331226917-6658-15-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> <1331226917-6658-15-git-send-email-pbonzini@redhat.com> Date: Fri, 9 Mar 2012 10:31:57 +0000 Message-ID: From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH 14/17] block: support FALLOC_FL_PUNCH_HOLE trimming List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Thu, Mar 8, 2012 at 5:15 PM, Paolo Bonzini wrote: > This will enable discard on more filesystems, including ext4. > > Signed-off-by: Paolo Bonzini > --- > =A0block/raw-posix.c | =A0 29 ++++++++++++++++++++++++----- > =A01 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 2d1bc13..f23d92b 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -52,6 +52,7 @@ > =A0#include > =A0#include > =A0#include > +#include > =A0#endif > =A0#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) > =A0#include > @@ -131,6 +132,7 @@ typedef struct BDRVRawState { > =A0#endif > =A0 =A0 uint8_t *aligned_buf; > =A0 =A0 unsigned aligned_buf_size; > + =A0 =A0bool has_discard : 1; > =A0#ifdef CONFIG_XFS > =A0 =A0 bool is_xfs : 1; > =A0#endif > @@ -257,11 +259,9 @@ static int raw_open_common(BlockDriverState *bs, con= st char *filename, > =A0 =A0 } > > =A0#ifdef CONFIG_XFS > - =A0 =A0if (platform_test_xfs_fd(s->fd)) { > - =A0 =A0 =A0 =A0s->is_xfs =3D 1; > - =A0 =A0} > + =A0 =A0s->is_xfs =3D platform_test_xfs_fd(s->fd); > =A0#endif > - > + =A0 =A0s->has_discard =3D 1; > =A0 =A0 return 0; > > =A0out_free_buf: > @@ -605,15 +605,34 @@ static int xfs_discard(BDRVRawState *s, int64_t sec= tor_num, int nb_sectors) > =A0static coroutine_fn int raw_co_discard(BlockDriverState *bs, > =A0 =A0 int64_t sector_num, int nb_sectors) > =A0{ > -#ifdef CONFIG_XFS > =A0 =A0 BDRVRawState *s =3D bs->opaque; > + =A0 =A0int retval; > > + =A0 =A0if (s->has_discard =3D=3D 0) { > + =A0 =A0 =A0 =A0return -ENOTSUP; > + =A0 =A0} > +#ifdef CONFIG_XFS > =A0 =A0 if (s->is_xfs) { > =A0 =A0 =A0 =A0 return xfs_discard(s, sector_num, nb_sectors); > =A0 =A0 } > =A0#endif > > +#ifdef FALLOC_FL_PUNCH_HOLE > + =A0 =A0retval =3D fallocate(s->fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_= SIZE, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sector_num << 9, (int64_t)n= b_sectors << 9); I'm concerned about introducing blocking syscalls in coroutine code paths. This needs to be done asynchronously. Stefan