public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 6/8] xfs: refactor xfs_bmapi_allocate
Date: Mon, 28 Oct 2019 09:29:23 -0700	[thread overview]
Message-ID: <20191028162923.GF15222@magnolia> (raw)
In-Reply-To: <20191025150336.19411-7-hch@lst.de>

On Fri, Oct 25, 2019 at 05:03:34PM +0200, Christoph Hellwig wrote:
> Avoid duplicate userdata and data fork checks by restructuring the code
> so we only have a helper for userdata allocations that combines these
> checks in a straight foward way.  That also helps to obsoletes the
> comments explaining what the code does as it is now clearly obvious.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

LGTM,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/xfs/libxfs/xfs_bmap.c | 93 +++++++++++++++++++---------------------
>  1 file changed, 45 insertions(+), 48 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index ef75e223cb70..c278eff29e82 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -3641,20 +3641,6 @@ xfs_bmap_btalloc(
>  	return 0;
>  }
>  
> -/*
> - * xfs_bmap_alloc is called by xfs_bmapi to allocate an extent for a file.
> - * It figures out where to ask the underlying allocator to put the new extent.
> - */
> -STATIC int
> -xfs_bmap_alloc(
> -	struct xfs_bmalloca	*ap)	/* bmap alloc argument struct */
> -{
> -	if (XFS_IS_REALTIME_INODE(ap->ip) &&
> -	    xfs_alloc_is_userdata(ap->datatype))
> -		return xfs_bmap_rtalloc(ap);
> -	return xfs_bmap_btalloc(ap);
> -}
> -
>  /* Trim extent to fit a logical block range. */
>  void
>  xfs_trim_extent(
> @@ -4010,6 +3996,42 @@ xfs_bmapi_reserve_delalloc(
>  	return error;
>  }
>  
> +static int
> +xfs_bmap_alloc_userdata(
> +	struct xfs_bmalloca	*bma)
> +{
> +	struct xfs_mount	*mp = bma->ip->i_mount;
> +	int			whichfork = xfs_bmapi_whichfork(bma->flags);
> +	int			error;
> +
> +	/*
> +	 * Set the data type being allocated. For the data fork, the first data
> +	 * in the file is treated differently to all other allocations. For the
> +	 * attribute fork, we only need to ensure the allocated range is not on
> +	 * the busy list.
> +	 */
> +	bma->datatype = XFS_ALLOC_NOBUSY;
> +	if (bma->flags & XFS_BMAPI_ZERO)
> +		bma->datatype |= XFS_ALLOC_USERDATA_ZERO;
> +	if (whichfork == XFS_DATA_FORK) {
> +		if (bma->offset == 0)
> +			bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
> +		else
> +			bma->datatype |= XFS_ALLOC_USERDATA;
> +
> +		if (mp->m_dalign && bma->length >= mp->m_dalign) {
> +			error = xfs_bmap_isaeof(bma, whichfork);
> +			if (error)
> +				return error;
> +		}
> +
> +		if (XFS_IS_REALTIME_INODE(bma->ip))
> +			return xfs_bmap_rtalloc(bma);
> +	}
> +
> +	return xfs_bmap_btalloc(bma);
> +}
> +
>  static int
>  xfs_bmapi_allocate(
>  	struct xfs_bmalloca	*bma)
> @@ -4037,43 +4059,18 @@ xfs_bmapi_allocate(
>  					bma->got.br_startoff - bma->offset);
>  	}
>  
> -	/*
> -	 * Set the data type being allocated. For the data fork, the first data
> -	 * in the file is treated differently to all other allocations. For the
> -	 * attribute fork, we only need to ensure the allocated range is not on
> -	 * the busy list.
> -	 */
> -	if (!(bma->flags & XFS_BMAPI_METADATA)) {
> -		bma->datatype = XFS_ALLOC_NOBUSY;
> -		if (whichfork == XFS_DATA_FORK) {
> -			if (bma->offset == 0)
> -				bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
> -			else
> -				bma->datatype |= XFS_ALLOC_USERDATA;
> -		}
> -		if (bma->flags & XFS_BMAPI_ZERO)
> -			bma->datatype |= XFS_ALLOC_USERDATA_ZERO;
> -	}
> -
> -	bma->minlen = (bma->flags & XFS_BMAPI_CONTIG) ? bma->length : 1;
> -
> -	/*
> -	 * Only want to do the alignment at the eof if it is userdata and
> -	 * allocation length is larger than a stripe unit.
> -	 */
> -	if (mp->m_dalign && bma->length >= mp->m_dalign &&
> -	    !(bma->flags & XFS_BMAPI_METADATA) && whichfork == XFS_DATA_FORK) {
> -		error = xfs_bmap_isaeof(bma, whichfork);
> -		if (error)
> -			return error;
> -	}
> +	if (bma->flags & XFS_BMAPI_CONTIG)
> +		bma->minlen = bma->length;
> +	else
> +		bma->minlen = 1;
>  
> -	error = xfs_bmap_alloc(bma);
> -	if (error)
> +	if (bma->flags & XFS_BMAPI_METADATA)
> +		error = xfs_bmap_btalloc(bma);
> +	else
> +		error = xfs_bmap_alloc_userdata(bma);
> +	if (error || bma->blkno == NULLFSBLOCK)
>  		return error;
>  
> -	if (bma->blkno == NULLFSBLOCK)
> -		return 0;
>  	if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur)
>  		bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
>  	/*
> -- 
> 2.20.1
> 

  reply	other threads:[~2019-10-28 16:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25 15:03 a few iomap / bmap cleanups Christoph Hellwig
2019-10-25 15:03 ` [PATCH 1/8] xfs: simplify xfs_iomap_eof_align_last_fsb Christoph Hellwig
2019-10-28 15:55   ` Darrick J. Wong
2019-10-25 15:03 ` [PATCH 2/8] xfs: mark xfs_eof_alignment static Christoph Hellwig
2019-10-28 15:55   ` Darrick J. Wong
2019-10-25 15:03 ` [PATCH 3/8] xfs: remove the extsize argument to xfs_eof_alignment Christoph Hellwig
2019-10-28 16:06   ` Darrick J. Wong
2019-10-29  7:57     ` Christoph Hellwig
2019-10-25 15:03 ` [PATCH 4/8] xfs: don't log the inode in xfs_fs_map_blocks if it wasn't modified Christoph Hellwig
2019-10-28 16:12   ` Darrick J. Wong
2019-10-29  7:58     ` Christoph Hellwig
2019-10-30 16:12       ` Darrick J. Wong
2019-10-30 17:56         ` Christoph Hellwig
2019-10-25 15:03 ` [PATCH 5/8] xfs: simplify the xfs_iomap_write_direct calling conventions Christoph Hellwig
2019-10-28 16:25   ` Darrick J. Wong
2019-10-25 15:03 ` [PATCH 6/8] xfs: refactor xfs_bmapi_allocate Christoph Hellwig
2019-10-28 16:29   ` Darrick J. Wong [this message]
2019-10-25 15:03 ` [PATCH 7/8] xfs: move extent zeroing to xfs_bmapi_allocate Christoph Hellwig
2019-10-28 16:31   ` Darrick J. Wong
2019-10-25 15:03 ` [PATCH 8/8] xfs: cleanup use of the XFS_ALLOC_ flags Christoph Hellwig
2019-10-28 16:32   ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191028162923.GF15222@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox