* [PATCH] ext4: keep internal quota inode growth out of fast commits
@ 2026-12-01 22:06 Wesley Atwell
2026-12-01 22:24 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Atwell @ 2026-12-01 22:06 UTC (permalink / raw)
To: Theodore Ts'o
Cc: Andreas Dilger, Baokun Li, Jan Kara, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Steven Rostedt, Masami Hiramatsu,
Mathieu Desnoyers, linux-ext4, linux-kernel, linux-trace-kernel,
Wesley Atwell
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 <atwellwea@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: keep internal quota inode growth out of fast commits
2026-12-01 22:06 [PATCH] ext4: keep internal quota inode growth out of fast commits Wesley Atwell
@ 2026-12-01 22:24 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 22:24 UTC (permalink / raw)
To: Wesley Atwell; +Cc: linux-ext4, linux-trace-kernel, tytso
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ext4: internal quota inode queued on s_fc_q when fallback
clears ineligible flag
- [Medium] ext4: premature return in ext4_fc_commit() when fallback
clears ineligible flag
- [Low] ext4: missing EXT4_FC_REASON_QUOTA_INODE in ext4_fc_stats
tracepoint TP_printk
- [Low] ext4: duplicate ext4_fc_mark_ineligible() call on
block-allocating quota writes
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] ext4: stale FC_Q_STAGING entries survive full commit in
ext4_fc_cleanup() [1]
--
commit dcaa353a248a8dfde49d12865c6eaba385032da3
Author: Wesley Atwell <atwellwea@gmail.com>
ext4: keep internal quota inode growth out of fast commits
This commit marks the filesystem fast-commit ineligible when an internal
quota inode maps blocks or grows in size, and rechecks ineligibility in
ext4_fc_perform_commit() and ext4_fc_commit().
Link: https://lore.kernel.org/all/20261201013742.1562967-1-maxing.lan@bytedance.com/
> 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);
> }
[Severity: High]
This problem wasn't introduced by this patch, but can ext4_fc_cleanup()
promote stale entries [1] from FC_Q_STAGING into FC_Q_MAIN when an
active handle in the committing transaction tracks updates after
JBD2_FULL_COMMIT_ONGOING is set?
CPU0 (transaction T) CPU1 (kjournald2, transaction T)
ext4_unlink()
ext4_journal_start()
jbd2_journal_commit_transaction()
j_flags |= JBD2_FULL_COMMIT_ONGOING
ext4_fc_track_unlink()
__track_dentry_update()
list_add_tail(...,
&s_fc_dentry_q[FC_Q_STAGING])
ext4_journal_stop()
jbd2_journal_wait_updates()
...
ext4_fc_cleanup(journal, 1, T)
/* drains FC_Q_MAIN only */
list_splice_init(
&s_fc_dentry_q[FC_Q_STAGING],
&s_fc_dentry_q[FC_Q_MAIN])
<-- stale T entry in FC_Q_MAIN
__track_dentry_update() and ext4_fc_track_template() queue updates onto
FC_Q_STAGING while JBD2_FULL_COMMIT_ONGOING is set. Because
jbd2_journal_commit_transaction() sets that flag before calling
jbd2_journal_wait_updates(), in-flight handles in transaction T land on
FC_Q_STAGING.
At the end of full commit T, ext4_fc_cleanup() only drains FC_Q_MAIN and
splices FC_Q_STAGING into FC_Q_MAIN for transaction T+1. A fast commit in
T+1 then logs those already-committed updates, so crash recovery replays
them after full commit T and corrupts directory state.
> +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);
> + }
[Severity: Medium]
Can a waiter returning -EALREADY from jbd2_fc_begin_commit() miss
EXT4_MF_FC_INELIGIBLE and return 0 before the fallback full commit of
commit_tid finishes?
CPU0 CPU1 CPU2
/* fast commit on T,
* s_fc_subtid == N,
* past unlock_updates */
ext4_fc_mark_ineligible()
ext4_fc_commit(T)
subtid = N
jbd2_fc_begin_commit(T)
/* sleeps on j_fc_wait */
atomic_inc(&s_fc_subtid)
jbd2_fc_end_commit()
wake_up(&j_fc_wait)
ext4_fc_commit(T)
jbd2_fc_begin_commit(T)
jbd2_fc_end_commit_fallback()
ext4_fc_cleanup(0, T)
clear EXT4_MF_FC_INELIGIBLE
wake_up(&j_fc_wait)
/* wakes, returns -EALREADY */
test EXT4_MF_FC_INELIGIBLE
-> false
s_fc_subtid <= subtid
-> false (N + 1 <= N)
return 0 <-- T not yet committed
jbd2_complete_transaction(T)
Inside jbd2_fc_end_commit_fallback() -> __jbd2_fc_end_commit(),
ext4_fc_cleanup(journal, 0, tid) clears EXT4_MF_FC_INELIGIBLE before
jbd2_complete_transaction(journal, tid) runs. If CPU0's earlier fast
commit already incremented s_fc_subtid without covering CPU1's post-snapshot
ineligible update, CPU1 sees neither EXT4_MF_FC_INELIGIBLE nor
s_fc_subtid <= subtid and returns to ext4_sync_file() while commit_tid is
still uncommitted.
[ ... ]
> 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);
[Severity: Medium]
Can the internal quota inode still be queued onto s_fc_q[FC_Q_STAGING] if a
concurrent fast commit falls back before ext4_fc_track_inode() or
ext4_fc_track_range() runs?
CPU0 (transaction T) CPU1 (transaction T)
ext4_map_blocks(quota_inode)
ext4_fc_mark_ineligible(..., T)
ext4_fc_commit(T)
/* sees EXT4_MF_FC_INELIGIBLE */
jbd2_fc_end_commit_fallback()
ext4_fc_cleanup(journal, 0, T)
clear EXT4_MF_FC_INELIGIBLE
j_flags |= JBD2_FULL_COMMIT_ONGOING
ext4_fc_track_inode(quota_inode)
/* ext4_fc_eligible() is true */
list_add_tail(...,
&s_fc_q[FC_Q_STAGING])
jbd2_complete_transaction(T)
...
ext4_fc_cleanup(journal, 1, T)
list_splice_init(
&s_fc_q[FC_Q_STAGING],
&s_fc_q[FC_Q_MAIN])
<-- quota_inode on FC_Q_MAIN
Both ext4_map_blocks() and ext4_quota_write() (via ext4_mark_inode_dirty())
still call ext4_fc_track_inode() on the internal quota inode after marking
the filesystem ineligible, relying on EXT4_MF_FC_INELIGIBLE to make
ext4_fc_eligible() return false. However, jbd2_fc_end_commit_fallback()
runs ext4_fc_cleanup(journal, 0, tid) before jbd2_complete_transaction()
waits for open handles on tid to drain, and ext4_fc_cleanup() clears
EXT4_MF_FC_INELIGIBLE even when full == 0. Once spliced onto FC_Q_MAIN,
the special quota inode is written out by the next fast commit and causes
mount recovery to fail in ext4_fc_replay_inode().
Should ext4_fc_track_inode() and ext4_fc_track_range() ignore special quota
inodes directly (or should ext4_fc_cleanup() only clear
EXT4_MF_FC_INELIGIBLE when full is set)?
> 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,
[Severity: Low]
When a write to an internal quota file grows i_size and allocates a new
block via ext4_bread(..., EXT4_GET_BLOCKS_CREATE), doesn't this call
ext4_fc_mark_ineligible() twice for the same write—once here and again in
ext4_map_blocks()—taking s_fc_lock twice and double-counting
fc_ineligible_reason_count[EXT4_FC_REASON_QUOTA_INODE]?
> 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
[ ... ]
> @@ -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"})
[Severity: Low]
show_fc_reason() is only used by FC_REASON_NAME_STAT() in
TRACE_EVENT(ext4_fc_stats). Should TP_printk in TRACE_EVENT(ext4_fc_stats)
also be updated to print FC_REASON_NAME_STAT(EXT4_FC_REASON_QUOTA_INODE)?
[1] https://sashiko.dev/#/bug/linux-1abe6f8d-3af8-47e4-9040-53c37377486a
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201.da276679711b4a31aaa4af05bfcbc1be@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 22:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 22:06 [PATCH] ext4: keep internal quota inode growth out of fast commits Wesley Atwell
2026-12-01 22:24 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox