Fast-commit replay loads INODE records as ordinary inodes and rejects internal quota inode 3. On the unmodified ext4 dev tree, growing that inode's quota file followed by a crash made recovery fail to mount. Mark internal quota-inode mapping and logical-size growth ineligible before mutation, including growth within an already mapped block. Recheck ineligibility after active journal handles drain. If another commit was ongoing, complete the ineligible transaction through JBD2 instead of treating that commit as proof of durability. In QEMU, quota-inode mapping and logical-size growth recovered after the full-commit fallback. Ordinary updates to existing quota records remained fast-commit eligible. This does not fix lost quota charges. Xing Ma's separate series addresses the remaining generic fast-commit tracking and waiter races. This contribution was developed with AI assistance. Fixes: 8016e29f4362 ("ext4: fast commit recovery path") Link: https://lore.kernel.org/all/20261201013742.1562967-1-maxing.lan@bytedance.com/ Signed-off-by: Wesley Atwell --- fs/ext4/fast_commit.c | 17 ++++++++++++++++- fs/ext4/fast_commit.h | 1 + fs/ext4/inode.c | 5 +++++ fs/ext4/super.c | 4 ++++ include/trace/events/ext4.h | 4 +++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 9beb423b208f8..0c072cf800a4e 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1414,13 +1414,20 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid) * doing logical-to-physical mapping. */ alloc_ctx = ext4_fc_lock(sb); + /* A drained handle may have made this transaction ineligible. */ + if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) { + ret = -EAGAIN; + goto out_unlock_fc; + } list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { ext4_set_inode_state(&iter->vfs_inode, EXT4_STATE_FC_COMMITTING); } +out_unlock_fc: ext4_fc_unlock(sb, alloc_ctx); - ret = ext4_fc_snapshot_inodes(journal, inodes, inodes_size, + if (!ret) + ret = ext4_fc_snapshot_inodes(journal, inodes, inodes_size, &snap_inodes, &snap_ranges, &snap_err); jbd2_journal_unlock_updates(journal); locked_ns = ktime_to_ns(ktime_sub(ktime_get(), lock_start)); @@ -1604,6 +1611,13 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) restart_fc: ret = jbd2_fc_begin_commit(journal, commit_tid); if (ret == -EALREADY) { + /* An ongoing commit may not cover this ineligible transaction. */ + if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE) && + !jbd2_transaction_committed(journal, commit_tid)) { + ext4_fc_update_stats(sb, EXT4_FC_STATUS_INELIGIBLE, 0, 0, + commit_tid); + return jbd2_complete_transaction(journal, commit_tid); + } /* There was an ongoing commit, check if we need to restart */ if (atomic_read(&sbi->s_fc_subtid) <= subtid && tid_gt(commit_tid, journal->j_commit_sequence)) @@ -2726,6 +2740,7 @@ static const char * const fc_ineligible_reasons[] = { [EXT4_FC_REASON_MIGRATE] = "Inode format migration", [EXT4_FC_REASON_VERITY] = "fs-verity enable", [EXT4_FC_REASON_MOVE_EXT] = "Move extents", + [EXT4_FC_REASON_QUOTA_INODE] = "Quota inode changed", }; int ext4_fc_info_show(struct seq_file *seq, void *v) diff --git a/fs/ext4/fast_commit.h b/fs/ext4/fast_commit.h index 2f77a37fb1018..6889161dbe0b6 100644 --- a/fs/ext4/fast_commit.h +++ b/fs/ext4/fast_commit.h @@ -100,6 +100,7 @@ enum { EXT4_FC_REASON_MIGRATE, EXT4_FC_REASON_VERITY, EXT4_FC_REASON_MOVE_EXT, + EXT4_FC_REASON_QUOTA_INODE, EXT4_FC_REASON_MAX }; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07a62d8569d31..eec8cf33a4e73 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -929,6 +929,11 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, internal_handle = true; } + /* Internal quota inode mappings cannot be replayed by fast commit. */ + if (ext4_is_quota_file(inode) && + is_special_ino(inode->i_sb, inode->i_ino)) + ext4_fc_mark_ineligible(inode->i_sb, + EXT4_FC_REASON_QUOTA_INODE, handle); ext4_fc_track_inode(handle, inode); /* * New blocks allocate and/or writing to unwritten extent diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 880f664d6c04b..76d617e023d2c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7539,6 +7539,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, (unsigned long long)off, (unsigned long long)len); return -EIO; } + /* Size can grow even when the quota inode's last block is mapped. */ + if (inode->i_size < off + len && ext4_is_quota_file(inode) && + is_special_ino(sb, inode->i_ino)) + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_QUOTA_INODE, handle); do { bh = ext4_bread(handle, inode, blk, diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 92048da9dae43..f73288d0d6ffe 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -105,6 +105,7 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_ENCRYPTED_FILENAME); TRACE_DEFINE_ENUM(EXT4_FC_REASON_MIGRATE); TRACE_DEFINE_ENUM(EXT4_FC_REASON_VERITY); TRACE_DEFINE_ENUM(EXT4_FC_REASON_MOVE_EXT); +TRACE_DEFINE_ENUM(EXT4_FC_REASON_QUOTA_INODE); TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX); #undef EM @@ -141,7 +142,8 @@ TRACE_SNAP_ERR { EXT4_FC_REASON_ENCRYPTED_FILENAME, "ENCRYPTED_FILENAME"}, \ { EXT4_FC_REASON_MIGRATE, "MIGRATE"}, \ { EXT4_FC_REASON_VERITY, "VERITY"}, \ - { EXT4_FC_REASON_MOVE_EXT, "MOVE_EXT"}) + { EXT4_FC_REASON_MOVE_EXT, "MOVE_EXT"}, \ + { EXT4_FC_REASON_QUOTA_INODE, "QUOTA_INODE"}) TRACE_DEFINE_ENUM(CR_POWER2_ALIGNED); TRACE_DEFINE_ENUM(CR_GOAL_LEN_FAST); base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1