mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ravi Singh <ravising@redhat.com>
To: Carlos Maiolino <cem@kernel.org>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dave Chinner <dgc@kernel.org>, Ravi Singh <ravising@redhat.com>
Subject: [PATCH] xfs: mark i_mode=0 and shut down on attr fork inactivation failure
Date: Wed, 21 Oct 2026 08:33:29 +0200	[thread overview]
Message-ID: <20261021063329.2853484-1-ravising@redhat.com> (raw)

xfs_attr_inactive() can fail on an I/O error reading the attribute
fork's btree blocks, for example from fault injection such as the
dm-flakey errors used by xfstests generic/475. On failure,
xfs_ifork_zap_attr() zeros af_nextents without freeing the attribute
blocks or decrementing i_nblocks, leaving the inode in an
inconsistent in-memory state.

The inode is marked XFS_IRECLAIMABLE and remains in the cache. If a
concurrent operation (e.g., XFS_IOC_FSBULKSTAT) calls xfs_iget() on
this inode, xfs_iget_check_free_state() will allow recycling if
i_mode != 0. The recycled inode reuses the stale in-memory state
(af_nextents=0, i_nblocks=1).

When the recycled inode is queued for inactivation again,
xfs_attr_inactive() sees af_nextents=0 and skips truncation, leaving
i_nblocks non-zero. This triggers the assertion in xfs_ifree():

  XFS: Assertion failed: ip->i_nblocks == 0

Clear i_mode so the stale inode cannot be recycled, and force a
shutdown so log recovery frees the still-unlinked inode on the next
mount.

Suggested-by: Dave Chinner <dgc@kernel.org>
Signed-off-by: Ravi Singh <ravising@redhat.com>
---
 fs/xfs/xfs_inode.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 05a14da28..fceedb699 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1481,8 +1481,17 @@ xfs_inactive(
 	 */
 	if (xfs_inode_has_attr_fork(ip)) {
 		error = xfs_attr_inactive(ip);
-		if (error)
+		if (error) {
+			/*
+			 * Attr teardown failed, leaking blocks with no in-core
+			 * record. Clear i_mode to block xfs_iget() recycling,
+			 * then shut down so recovery cleans up the inode.
+			 */
+			VFS_I(ip)->i_mode = 0;
+			if (!xfs_is_shutdown(mp))
+				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
 			goto out;
+		}
 	}
 
 	ASSERT(ip->i_forkoff == 0);
-- 
2.56.0


                 reply	other threads:[~2026-10-21  6:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261021063329.2853484-1-ravising@redhat.com \
    --to=ravising@redhat.com \
    --cc=cem@kernel.org \
    --cc=dgc@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®