Skip to content

Commit 9a5280b

Browse files
Dave Chinnerdchinner
authored andcommitted
xfs: reorder iunlink remove operation in xfs_ifree
The O_TMPFILE creation implementation creates a specific order of operations for inode allocation/freeing and unlinked list modification. Currently both are serialised by the AGI, so the order doesn't strictly matter as long as the are both in the same transaction. However, if we want to move the unlinked list insertions largely out from under the AGI lock, then we have to be concerned about the order in which we do unlinked list modification operations. O_TMPFILE creation tells us this order is inode allocation/free, then unlinked list modification. Change xfs_ifree() to use this same ordering on unlinked list removal. This way we always guarantee that when we enter the iunlinked list removal code from this path, we already have the AGI locked and we don't have to worry about lock nesting AGI reads inside unlink list locks because it's already locked and attached to the transaction. We can do this safely as the inode freeing and unlinked list removal are done in the same transaction and hence are atomic operations with respect to log recovery. Reported-by: Frank Hofmann <[email protected]> Fixes: 298f7be ("xfs: pin inode backing buffer to the inode log item") Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent d65a92d commit 9a5280b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

fs/xfs/xfs_inode.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,14 +2594,13 @@ xfs_ifree_cluster(
25942594
}
25952595

25962596
/*
2597-
* This is called to return an inode to the inode free list.
2598-
* The inode should already be truncated to 0 length and have
2599-
* no pages associated with it. This routine also assumes that
2600-
* the inode is already a part of the transaction.
2597+
* This is called to return an inode to the inode free list. The inode should
2598+
* already be truncated to 0 length and have no pages associated with it. This
2599+
* routine also assumes that the inode is already a part of the transaction.
26012600
*
2602-
* The on-disk copy of the inode will have been added to the list
2603-
* of unlinked inodes in the AGI. We need to remove the inode from
2604-
* that list atomically with respect to freeing it here.
2601+
* The on-disk copy of the inode will have been added to the list of unlinked
2602+
* inodes in the AGI. We need to remove the inode from that list atomically with
2603+
* respect to freeing it here.
26052604
*/
26062605
int
26072606
xfs_ifree(
@@ -2623,13 +2622,16 @@ xfs_ifree(
26232622
pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
26242623

26252624
/*
2626-
* Pull the on-disk inode from the AGI unlinked list.
2625+
* Free the inode first so that we guarantee that the AGI lock is going
2626+
* to be taken before we remove the inode from the unlinked list. This
2627+
* makes the AGI lock -> unlinked list modification order the same as
2628+
* used in O_TMPFILE creation.
26272629
*/
2628-
error = xfs_iunlink_remove(tp, pag, ip);
2630+
error = xfs_difree(tp, pag, ip->i_ino, &xic);
26292631
if (error)
2630-
goto out;
2632+
return error;
26312633

2632-
error = xfs_difree(tp, pag, ip->i_ino, &xic);
2634+
error = xfs_iunlink_remove(tp, pag, ip);
26332635
if (error)
26342636
goto out;
26352637

0 commit comments

Comments
 (0)