All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: fix incorrect i_nlink caused by inode racing
@ 2022-11-07 14:36 Long Li
  2022-11-07 16:38 ` Darrick J. Wong
  2022-11-11 20:52 ` Dave Chinner
  0 siblings, 2 replies; 7+ messages in thread
From: Long Li @ 2022-11-07 14:36 UTC (permalink / raw)
  To: djwong; +Cc: houtao1, yi.zhang, guoxuenan, linux-xfs

The following error occurred during the fsstress test:

XFS: Assertion failed: VFS_I(ip)->i_nlink >= 2, file: fs/xfs/xfs_inode.c, line: 2925

The problem was that inode race condition causes incorrect i_nlink to be
written to disk, and then it is read into memory. Consider the following
call graph, inodes that are marked as both XFS_IFLUSHING and
XFS_IRECLAIMABLE, i_nlink will be reset to 1 and then restored to original
value in xfs_reinit_inode(). Therefore, the i_nlink of directory on disk
may be set to 1.

  xfsaild
      xfs_inode_item_push
          xfs_iflush_cluster
              xfs_iflush
                  xfs_inode_to_disk

  xfs_iget
      xfs_iget_cache_hit
          xfs_iget_recycle
              xfs_reinit_inode
  	          inode_init_always

So skip inodes that being flushed and markded as XFS_IRECLAIMABLE, prevent
concurrent read and write to inodes.

Signed-off-by: Long Li <leo.lilong@huawei.com>
---
 fs/xfs/xfs_icache.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index eae7427062cf..cc68b0ff50ce 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -514,6 +514,11 @@ xfs_iget_cache_hit(
 	    (ip->i_flags & XFS_IRECLAIMABLE))
 		goto out_skip;
 
+	/* Skip inodes that being flushed */
+	if ((ip->i_flags & XFS_IFLUSHING) &&
+	    (ip->i_flags & XFS_IRECLAIMABLE))
+		goto out_skip;
+
 	/* The inode fits the selection criteria; process it. */
 	if (ip->i_flags & XFS_IRECLAIMABLE) {
 		/* Drops i_flags_lock and RCU read lock. */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-15 14:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 14:36 [PATCH] xfs: fix incorrect i_nlink caused by inode racing Long Li
2022-11-07 16:38 ` Darrick J. Wong
2022-11-10  1:42   ` Long Li
2022-11-11 20:52 ` Dave Chinner
2022-11-14 13:34   ` Long Li
2022-11-15  0:23     ` Dave Chinner
2022-11-15 14:33       ` Long Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.