xfs: move the xfs_can_free_eofblocks call under the IOLOCK
authorDarrick J. Wong <djwong@kernel.org>
Tue, 23 Mar 2021 23:59:31 +0000 (16:59 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 7 Apr 2021 21:38:16 +0000 (14:38 -0700)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_icache.c

index 2fd4a39acb46f6d70ac57ffe1a7f5111383cf128..3c81daca0e9a0697482f52eac6f130a8bb6fd9d7 100644 (file)
@@ -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;
 }
 
 /*