Re: [PATCH v3 08/14] xfs: Update xfs_inode_alloc_unitsize() for forcealign

Darrick J. Wong
2024-08-06T19:02:41Z

On Thu, Aug 01, 2024 at 04:30:51PM +0000, John Garry wrote:
> For forcealign enabled, the allocation unit size is in ip->i_extsize, and
> this must never be zero.
>
> Add helper xfs_inode_alloc_fsbsize() to return alloc unit in FSBs, and use
> it in xfs_inode_alloc_unitsize().
>
> Signed-off-by: John Garry <john.g.garry@oracle.com>

Looks good,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
> fs/xfs/xfs_inode.c | 17 +++++++++++++----
> fs/xfs/xfs_inode.h | 1 +
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index 7dc6f326936c..5af12f35062d 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -3107,17 +3107,26 @@ xfs_break_layouts(
> return error;
> }
>
> -/* Returns the size of fundamental allocation unit for a file, in bytes. */
> unsigned int
> -xfs_inode_alloc_unitsize(
> +xfs_inode_alloc_fsbsize(
> struct xfs_inode *ip)
> {
> unsigned int blocks = 1;
>
> - if (XFS_IS_REALTIME_INODE(ip))
> + if (xfs_inode_has_forcealign(ip))
> + blocks = ip->i_extsize;
> + else if (XFS_IS_REALTIME_INODE(ip))
> blocks = ip->i_mount->m_sb.sb_rextsize;
>
> - return XFS_FSB_TO_B(ip->i_mount, blocks);
> + return blocks;
> +}
> +
> +/* Returns the size of fundamental allocation unit for a file, in bytes. */
> +unsigned int
> +xfs_inode_alloc_unitsize(
> + struct xfs_inode *ip)
> +{
> + return XFS_FSB_TO_B(ip->i_mount, xfs_inode_alloc_fsbsize(ip));
> }
>
> /* Should we always be using copy on write for file writes? */
> diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
> index 3e7664ec4d6c..158afad8c7a4 100644
> --- a/fs/xfs/xfs_inode.h
> +++ b/fs/xfs/xfs_inode.h
> @@ -641,6 +641,7 @@ int xfs_inode_reload_unlinked(struct xfs_inode *ip);
> bool xfs_ifork_zapped(const struct xfs_inode *ip, int whichfork);
> void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
> xfs_filblks_t *dblocks, xfs_filblks_t *rblocks);
> +unsigned int xfs_inode_alloc_fsbsize(struct xfs_inode *ip);
> unsigned int xfs_inode_alloc_unitsize(struct xfs_inode *ip);
>
> int xfs_icreate_dqalloc(const struct xfs_icreate_args *args,
> --
> 2.31.1
>
>