From: "Xing Ma" <maxing.lan@bytedance.com>
To: <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Jan Kara" <jack@suse.cz>,
"Baokun Li" <libaokun@linux.alibaba.com>,
"Ojaswin Mujoo" <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
"Zhang Yi" <yi.zhang@huawei.com>,
"Harshad Shirwadkar" <harshadshirwadkar@gmail.com>,
<stable@vger.kernel.org>
Subject: [PATCH v3 1/2] ext4: fall back to full commit for unlinked or orphan inodes in fast commit
Date: Tue, 01 Dec 2026 07:05:59 +0800 [thread overview]
Message-ID: <20261201070558.4017023-2-maxing.lan@bytedance.com> (raw)
In-Reply-To: <20261201070558.4017023-1-maxing.lan@bytedance.com>
Fast commit does not log orphan list updates (s_last_orphan or orphan
file). When a fast commit snapshots a tracked inode that is unlinked
or on the orphan list, crash recovery fails in two ways:
1. Unlinked open inode (open+unlink, overwrite rename over an open
file, or O_TMPFILE): the inode has i_nlink == 0 and stays on s_fc_q
until closed. Emitting EXT4_FC_TAG_INODE with i_links_count == 0
causes ext4_fc_replay_inode() to reload it via ext4_iget() without
EXT4_ORPHAN_FS, turning -ESTALE into -EFSCORRUPTED and aborting
journal recovery ("JBD2: journal recovery failed"). This is
deterministically reproduced by xfstests generic/764 with
-O fast_commit.
2. Mid-truncate orphan inode: ext4_truncate_down() adds the inode to
the orphan list, shrinks i_size/i_disksize, and stops its handle
before ext4_truncate() frees blocks. Snapshotting the inode in
this window logs the shrunk i_size with unfreed extents and no
orphan entry, causing e2fsck to report "end of extent exceeds
allowed value".
Return -ECANCELED from ext4_fc_snapshot_inode() when i_nlink == 0,
ext4_inode_orphan_tracked(inode) is true, or raw i_links_count == 0 so
ext4_fc_commit() falls back to a full JBD2 commit. Normal unlinks of
closed files and completed truncates remain fast-commit eligible.
Also add KUnit coverage in test_fc_snapshot_inode_and_ranges() for
i_nlink == 0 and EXT4_STATE_ORPHAN_FILE fallback.
Fixes: 8016e29f4362 ("ext4: fast commit recovery path")
Cc: stable@vger.kernel.org
Signed-off-by: Xing Ma <maxing.lan@bytedance.com>
---
fs/ext4/fast_commit-test.c | 18 ++++++++++++++++++
fs/ext4/fast_commit.c | 17 +++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/fs/ext4/fast_commit-test.c b/fs/ext4/fast_commit-test.c
index 07cb9c043cd2c..2d342cabb4cf7 100644
--- a/fs/ext4/fast_commit-test.c
+++ b/fs/ext4/fast_commit-test.c
@@ -1752,6 +1752,24 @@ static void test_fc_snapshot_inode_and_ranges(struct kunit *test)
ext4_test_inode_state(file2, EXT4_STATE_FC_COMMITTING));
KUNIT_EXPECT_NOT_NULL(test, EXT4_I(file2)->i_fc_snap);
kvfree(inodes);
+
+ /*
+ * 8) Unlinked (i_nlink == 0) or orphan-tracked inodes force fallback
+ * via -ECANCELED.
+ */
+ clear_nlink(file1);
+ KUNIT_EXPECT_EQ(test,
+ ext4_fc_snapshot_inode_test(file1, 0, &nr_ranges,
+ &snap_err),
+ -ECANCELED);
+ set_nlink(file1, 1);
+
+ ext4_set_inode_state(file1, EXT4_STATE_ORPHAN_FILE);
+ KUNIT_EXPECT_EQ(test,
+ ext4_fc_snapshot_inode_test(file1, 0, &nr_ranges,
+ &snap_err),
+ -ECANCELED);
+ ext4_clear_inode_state(file1, EXT4_STATE_ORPHAN_FILE);
}
/* =========================================================================
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 9beb423b208f8..fd98f7b54fc0f 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1119,6 +1119,18 @@ static int ext4_fc_snapshot_inode(struct inode *inode,
int ret;
int alloc_ctx;
+ /*
+ * Fast commit does not log orphan list updates, and
+ * ext4_fc_replay_inode() reloads replayed inodes with
+ * EXT4_IGET_NORMAL, which rejects i_nlink == 0 inodes with
+ * -ESTALE (causing journal recovery to abort with -EFSCORRUPTED).
+ * Fall back to a full commit whenever a tracked inode is
+ * currently unlinked or on the orphan list (e.g., open-unlinked,
+ * rename-overwritten while open, O_TMPFILE, or mid-truncate).
+ */
+ if (inode->i_nlink == 0 || ext4_inode_orphan_tracked(inode))
+ return -ECANCELED;
+
ret = ext4_get_inode_loc_noio(inode, &iloc);
if (ret) {
atomic64_inc(&stats->snap_fail_inode_loc);
@@ -1126,6 +1138,11 @@ static int ext4_fc_snapshot_inode(struct inode *inode,
return ret;
}
+ if (le16_to_cpu(ext4_raw_inode(&iloc)->i_links_count) == 0) {
+ brelse(iloc.bh);
+ return -ECANCELED;
+ }
+
if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA))
inode_len = EXT4_INODE_SIZE(inode->i_sb);
else if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE)
--
2.39.5
next prev parent reply other threads:[~2026-11-30 23:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 23:05 [PATCH v3 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking Xing Ma
2026-11-30 23:05 ` Xing Ma [this message]
2026-11-30 23:06 ` [PATCH v3 2/2] ext4: track truncated block range in ext4_truncate() for fast commit Xing Ma
2026-11-30 23:28 ` sashiko-bot
2026-11-30 23:28 ` [PATCH v3 0/2] ext4: fix fast commit orphan inode replay and truncate range tracking sashiko-bot
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=20261201070558.4017023-2-maxing.lan@bytedance.com \
--to=maxing.lan@bytedance.com \
--cc=adilger.kernel@dilger.ca \
--cc=harshadshirwadkar@gmail.com \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
--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 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.