diff mbox series

[1/2] xfs: move the xfs_can_free_eofblocks call under the IOLOCK

Message ID 161671806513.621829.6973192250605604420.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs: make xfs_can_free_eofblocks a predicate | expand

Commit Message

Darrick J. Wong March 26, 2021, 12:21 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

In xfs_inode_free_eofblocks, move the xfs_can_free_eofblocks call
further down in the function to the point where we have taken the
IOLOCK.  This is preparation for the next patch, where we will need that
lock (or equivalent) so that we can check if there are any post-eof
blocks to clean out.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_icache.c |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Christoph Hellwig March 26, 2021, 5:59 a.m. UTC | #1
On Thu, Mar 25, 2021 at 05:21:05PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> In xfs_inode_free_eofblocks, move the xfs_can_free_eofblocks call
> further down in the function to the point where we have taken the
> IOLOCK.  This is preparation for the next patch, where we will need that
> lock (or equivalent) so that we can check if there are any post-eof
> blocks to clean out.

I kinda prefer the old style that did the exception path inside the
branch.  But that is just sugacoating, the actual change looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 2fd4a39acb46..3c81daca0e9a 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1296,13 +1296,6 @@  xfs_inode_free_eofblocks(
 	if (!xfs_iflags_test(ip, XFS_IEOFBLOCKS))
 		return 0;
 
-	if (!xfs_can_free_eofblocks(ip, false)) {
-		/* inode could be preallocated or append-only */
-		trace_xfs_inode_free_eofblocks_invalid(ip);
-		xfs_inode_clear_eofblocks_tag(ip);
-		return 0;
-	}
-
 	/*
 	 * If the mapping is dirty the operation can block and wait for some
 	 * time. Unless we are waiting, skip it.
@@ -1324,7 +1317,13 @@  xfs_inode_free_eofblocks(
 	}
 	*lockflags |= XFS_IOLOCK_EXCL;
 
-	return xfs_free_eofblocks(ip);
+	if (xfs_can_free_eofblocks(ip, false))
+		return xfs_free_eofblocks(ip);
+
+	/* inode could be preallocated or append-only */
+	trace_xfs_inode_free_eofblocks_invalid(ip);
+	xfs_inode_clear_eofblocks_tag(ip);
+	return 0;
 }
 
 /*