In both __jbd2_fc_end_commit() and jbd2_journal_commit_transaction(), j_fc_cleanup_callback (ext4_fc_cleanup()) splices FC_Q_STAGING into FC_Q_MAIN and releases s_fc_lock BEFORE JBD2_FAST_COMMIT_ONGOING / JBD2_FULL_COMMIT_ONGOING is cleared under j_state_lock. If a concurrent writer calls ext4_fc_track_template() or __track_dentry_update() in that window, it still observes the ONGOING flag set and inserts its inode or dentry update onto FC_Q_STAGING after ext4_fc_cleanup() has already drained it. When that writer then calls fsync() after the flag clears, ext4_fc_perform_commit() only processes FC_Q_MAIN and writes an empty fast commit while the update remains stranded on FC_Q_STAGING. Splice s_fc_dentry_q[FC_Q_STAGING] and s_fc_q[FC_Q_STAGING] onto the tail of FC_Q_MAIN under s_fc_lock at Step 1 of ext4_fc_perform_commit() so any stranded updates are included in chronological order. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/fast_commit.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 03ab9b8a2d983..e03a829e2a10a 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1353,11 +1353,17 @@ static int ext4_fc_perform_commit(journal_t *journal, tid_t commit_tid) u64 locked_ns; /* - * Step 1: Mark all inodes on s_fc_q[MAIN] with - * EXT4_STATE_FC_FLUSHING_DATA. This prevents these inodes from being - * freed until the data flush is over. + * Step 1: Splice any entries that landed on STAGING while the + * previous commit was clearing its ONGOING flag, then mark all + * inodes on s_fc_q[MAIN] with EXT4_STATE_FC_FLUSHING_DATA. This + * prevents these inodes from being freed until the data flush is + * over. */ alloc_ctx = ext4_fc_lock(sb); + list_splice_tail_init(&sbi->s_fc_dentry_q[FC_Q_STAGING], + &sbi->s_fc_dentry_q[FC_Q_MAIN]); + list_splice_tail_init(&sbi->s_fc_q[FC_Q_STAGING], + &sbi->s_fc_q[FC_Q_MAIN]); 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_FLUSHING_DATA); -- 2.39.5