diff mbox series

[5/6] xfs: hoist multi-fsb allocation unit detection to a helper

Message ID 170900011214.938068.18217925414531189912.stgit@frogsfrogsfrogs (mailing list archive)
State Superseded
Headers show
Series [1/6] xfs: move inode lease breaking functions to xfs_inode.c | expand

Commit Message

Darrick J. Wong Feb. 27, 2024, 2:20 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Replace the open-coded logic to decide if a file has a multi-fsb
allocation unit to a helper to make the code easier to read.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_bmap_util.c |    4 ++--
 fs/xfs/xfs_inode.h     |    5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Feb. 27, 2024, 3:51 p.m. UTC | #1
> +static inline bool xfs_inode_has_bigallocunit(struct xfs_inode *ip)
> +{
> +	return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1;
> +}

Given that bigallocunit is an entirely new term in XFS, maybe add
a big fat comment explaining it?

Otherwise this looks useful.
Darrick J. Wong Feb. 27, 2024, 4:10 p.m. UTC | #2
On Tue, Feb 27, 2024 at 07:51:27AM -0800, Christoph Hellwig wrote:
> > +static inline bool xfs_inode_has_bigallocunit(struct xfs_inode *ip)
> > +{
> > +	return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1;
> > +}
> 
> Given that bigallocunit is an entirely new term in XFS, maybe add
> a big fat comment explaining it?
> 
> Otherwise this looks useful.

How about:

/*
 * Decide if the file data allocation unit for this file is larger than
 * a single filesystem block.
 */

--D
Christoph Hellwig Feb. 27, 2024, 4:57 p.m. UTC | #3
Sounds good.
diff mbox series

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index e58ae3654e7a8..74c42544155d5 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -542,7 +542,7 @@  xfs_can_free_eofblocks(
 	 * forever.
 	 */
 	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip));
-	if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1)
+	if (xfs_inode_has_bigallocunit(ip))
 		end_fsb = xfs_rtb_roundup_rtx(mp, end_fsb);
 	last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
 	if (last_fsb <= end_fsb)
@@ -843,7 +843,7 @@  xfs_free_file_space(
 	endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len);
 
 	/* We can only free complete realtime extents. */
-	if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) {
+	if (xfs_inode_has_bigallocunit(ip)) {
 		startoffset_fsb = xfs_rtb_roundup_rtx(mp, startoffset_fsb);
 		endoffset_fsb = xfs_rtb_rounddown_rtx(mp, endoffset_fsb);
 	}
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index c8799a55d885f..b7b238e88f23a 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -311,6 +311,11 @@  static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)
 	return ip->i_diflags2 & XFS_DIFLAG2_NREXT64;
 }
 
+static inline bool xfs_inode_has_bigallocunit(struct xfs_inode *ip)
+{
+	return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1;
+}
+
 /*
  * Return the buftarg used for data allocations on a given inode.
  */