Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Pankaj Raghav <p.raghav@samsung.com>
Cc: linux-xfs@vger.kernel.org, bfoster@redhat.com, lukas@herbolt.com,
	dgc@kernel.org, gost.dev@samsung.com, pankaj.raghav@linux.dev,
	andres@anarazel.de, kundan.kumar@samsung.com, hch@lst.de,
	cem@kernel.org, hch@infradead.org
Subject: Re: [PATCH v7 1/2] xfs: add an allocation mode to xfs_alloc_file_space()
Date: Wed, 24 Jun 2026 10:47:20 -0700	[thread overview]
Message-ID: <20260624174720.GT6078@frogsfrogsfrogs> (raw)
In-Reply-To: <20260622083106.2914092-2-p.raghav@samsung.com>

On Mon, Jun 22, 2026 at 10:31:05AM +0200, Pankaj Raghav wrote:
> xfs_alloc_file_space() hardcodes XFS_BMAPI_PREALLOC to preallocate
> unwritten extents across a range.
> 
> In preparation for FALLOC_FL_WRITE_ZEROES, add an explicit allocation
> mode argument, enum xfs_alloc_file_space_mode, and derive the xfs_bmapi
> flags from it. The only mode for now is XFS_ALLOC_FILE_SPACE_PREALLOC,
> which preallocates unwritten extents and marks the inode as preallocated
> exactly as before, so there is no functional change.
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
> ---
>  fs/xfs/xfs_bmap_util.c | 25 +++++++++++++++++++++----
>  fs/xfs/xfs_bmap_util.h |  6 +++++-
>  fs/xfs/xfs_file.c      |  9 ++++++---
>  3 files changed, 32 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index 3b9f262f8e91..8dfb3c1e3759 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -642,11 +642,19 @@ xfs_free_eofblocks(
>  	return error;
>  }
>  
> +/*
> + * Allocate space for a file according to @mode:
> + *
> + * XFS_ALLOC_FILE_SPACE_PREALLOC:
> + * Preallocate unwritten extents across the range and mark the inode as
> + * preallocated.

"Preallocate unwritten extents over holes across the range..."?

Other than that, this looks good to me.

--D

> + */
>  int
>  xfs_alloc_file_space(
>  	struct xfs_inode	*ip,
>  	xfs_off_t		offset,
> -	xfs_off_t		len)
> +	xfs_off_t		len,
> +	enum xfs_alloc_file_space_mode mode)
>  {
>  	xfs_mount_t		*mp = ip->i_mount;
>  	xfs_off_t		count;
> @@ -657,6 +665,7 @@ xfs_alloc_file_space(
>  	int			rt;
>  	xfs_trans_t		*tp;
>  	xfs_bmbt_irec_t		imaps[1], *imapp;
> +	uint32_t		bmapi_flags, nr_exts;
>  	int			error;
>  
>  	if (xfs_is_always_cow_inode(ip))
> @@ -674,6 +683,15 @@ xfs_alloc_file_space(
>  	if (len <= 0)
>  		return -EINVAL;
>  
> +	switch (mode) {
> +	case XFS_ALLOC_FILE_SPACE_PREALLOC:
> +		bmapi_flags = XFS_BMAPI_PREALLOC;
> +		nr_exts = XFS_IEXT_ADD_NOSPLIT_CNT;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
>  	rt = XFS_IS_REALTIME_INODE(ip);
>  	extsz = xfs_get_extsz_hint(ip);
>  
> @@ -733,8 +751,7 @@ xfs_alloc_file_space(
>  		if (error)
>  			break;
>  
> -		error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
> -				XFS_IEXT_ADD_NOSPLIT_CNT);
> +		error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, nr_exts);
>  		if (error)
>  			goto error;
>  
> @@ -748,7 +765,7 @@ xfs_alloc_file_space(
>  		 * will eventually reach the requested range.
>  		 */
>  		error = xfs_bmapi_write(tp, ip, startoffset_fsb,
> -				allocatesize_fsb, XFS_BMAPI_PREALLOC, 0, imapp,
> +				allocatesize_fsb, bmapi_flags, 0, imapp,
>  				&nimaps);
>  		if (error) {
>  			if (error != -ENOSR)
> diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
> index c477b3361630..232b4c48247e 100644
> --- a/fs/xfs/xfs_bmap_util.h
> +++ b/fs/xfs/xfs_bmap_util.h
> @@ -55,8 +55,12 @@ int	xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
>  			     int *is_empty);
>  
>  /* preallocation and hole punch interface */
> +enum xfs_alloc_file_space_mode {
> +	XFS_ALLOC_FILE_SPACE_PREALLOC,
> +};
> +
>  int	xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
> -		xfs_off_t len);
> +		xfs_off_t len, enum xfs_alloc_file_space_mode mode);
>  int	xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
>  		xfs_off_t len, struct xfs_zone_alloc_ctx *ac);
>  int	xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index 845a97c9b063..e90ea6ebdc8e 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -1406,7 +1406,8 @@ xfs_falloc_zero_range(
>  		len = round_up(offset + len, blksize) -
>  			round_down(offset, blksize);
>  		offset = round_down(offset, blksize);
> -		error = xfs_alloc_file_space(ip, offset, len);
> +		error = xfs_alloc_file_space(ip, offset, len,
> +				XFS_ALLOC_FILE_SPACE_PREALLOC);
>  	}
>  	if (error)
>  		return error;
> @@ -1432,7 +1433,8 @@ xfs_falloc_unshare_range(
>  	if (error)
>  		return error;
>  
> -	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
> +	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
> +			XFS_ALLOC_FILE_SPACE_PREALLOC);
>  	if (error)
>  		return error;
>  	return xfs_falloc_setsize(file, new_size);
> @@ -1460,7 +1462,8 @@ xfs_falloc_allocate_range(
>  	if (error)
>  		return error;
>  
> -	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
> +	error = xfs_alloc_file_space(XFS_I(inode), offset, len,
> +			XFS_ALLOC_FILE_SPACE_PREALLOC);
>  	if (error)
>  		return error;
>  	return xfs_falloc_setsize(file, new_size);
> -- 
> 2.51.2
> 
> 

  reply	other threads:[~2026-06-24 17:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22  8:31 [PATCH v7 0/2] add FALLOC_FL_WRITE_ZEROES support to xfs Pankaj Raghav
2026-06-22  8:31 ` [PATCH v7 1/2] xfs: add an allocation mode to xfs_alloc_file_space() Pankaj Raghav
2026-06-24 17:47   ` Darrick J. Wong [this message]
2026-06-22  8:31 ` [PATCH v7 2/2] xfs: add support for FALLOC_FL_WRITE_ZEROES Pankaj Raghav
2026-06-23 20:21   ` Pankaj Raghav

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=20260624174720.GT6078@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=andres@anarazel.de \
    --cc=bfoster@redhat.com \
    --cc=cem@kernel.org \
    --cc=dgc@kernel.org \
    --cc=gost.dev@samsung.com \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=kundan.kumar@samsung.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lukas@herbolt.com \
    --cc=p.raghav@samsung.com \
    --cc=pankaj.raghav@linux.dev \
    /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