From: Long Li <leo.lilong@huawei.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: <houtao1@huawei.com>, <yi.zhang@huawei.com>,
<guoxuenan@huawei.com>, <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs: fix incorrect i_nlink caused by inode racing
Date: Thu, 10 Nov 2022 09:42:04 +0800 [thread overview]
Message-ID: <20221110014204.GA4006730@ceph-admin> (raw)
In-Reply-To: <Y2k0lSx4aBYHoJs6@magnolia>
On Mon, Nov 07, 2022 at 08:38:45AM -0800, Darrick J. Wong wrote:
> On Mon, Nov 07, 2022 at 10:36:48PM +0800, Long Li wrote:
> > 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
>
> What kernel is this? xfs_inode.c line 2925 is in the middle of
> xfs_rename and doesn't have any assertions on nlink.
>
> The only assertion on nlink in the entire xfs codebase is in xfs_remove,
> and that's not what's going on here.
>
> <confused>
Sorry for the confusion, I found this issue in Linux 5.10, so the assertion
on nlink is in xfs_remove(). I've reproduced it on the mainline kernel, the
probability of this problem is very low and it is very difficult to reproduce.
The mainline kernel assertion error prints is as follows:
XFS: Assertion failed: VFS_I(ip)->i_nlink >= 2, file: fs/xfs/xfs_inode.c, line: 2452
Thanks,
Long Li
>
> --D
>
> > 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
> >
next prev parent reply other threads:[~2022-11-10 1:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221110014204.GA4006730@ceph-admin \
--to=leo.lilong@huawei.com \
--cc=djwong@kernel.org \
--cc=guoxuenan@huawei.com \
--cc=houtao1@huawei.com \
--cc=linux-xfs@vger.kernel.org \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox