]> www.infradead.org Git - users/hch/xfsprogs.git/commit
xfs: Fix deadlock between AGI and AGF when target_ip exists in xfs_rename()
authorkaixuxia <xiakaixu1987@gmail.com>
Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:44 +0000 (11:29 -0500)
commite9861d1b05b8f93bdfba111810152782627de653
tree66708181019866addc8bdc2cf0fe9cfb06d11bf5
parent7773baf31e8ac7ebdf71672acf43d5acd77100f6
xfs: Fix deadlock between AGI and AGF when target_ip exists in xfs_rename()

Source kernel commit: 93597ae8dac0149b5c00b787cba6bf7ba213e666

When target_ip exists in xfs_rename(), the xfs_dir_replace() call may
need to hold the AGF lock to allocate more blocks, and then invoking
the xfs_droplink() call to hold AGI lock to drop target_ip onto the
unlinked list, so we get the lock order AGF->AGI. This would break the
ordering constraint on AGI and AGF locking - inode allocation locks
the AGI, then can allocate a new extent for new inodes, locking the
AGF after the AGI.

In this patch we check whether the replace operation need more
blocks firstly. If so, acquire the agi lock firstly to preserve
locking order(AGI/AGF). Actually, the locking order problem only
occurs when we are locking the AGI/AGF of the same AG. For multiple
AGs the AGI lock will be released after the transaction committed.

Signed-off-by: kaixuxia <kaixuxia@tencent.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: reword the comment]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_dir2.h
libxfs/xfs_dir2_sf.c