Skip to content

Commit bdc8a53

Browse files
Xin Yintytso
authored andcommitted
ext4: fast commit may miss file actions
in the follow scenario: 1. jbd start transaction n 2. task A get new handle for transaction n+1 3. task A do some actions and add inode to FC_Q_MAIN fc_q 4. jbd complete transaction n and clear FC_Q_MAIN fc_q 5. task A call fsync Fast commit will lost the file actions during a full commit. we should also add updates to staging queue during a full commit. and in ext4_fc_cleanup(), when reset a inode's fc track range, check it's i_sync_tid, if it bigger than current transaction tid, do not rest it, or we will lost the track range. And EXT4_MF_FC_COMMITTING is not needed anymore, so drop it. Signed-off-by: Xin Yin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent e85c81b commit bdc8a53

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,10 +1795,7 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
17951795
enum {
17961796
EXT4_MF_MNTDIR_SAMPLED,
17971797
EXT4_MF_FS_ABORTED, /* Fatal error detected */
1798-
EXT4_MF_FC_INELIGIBLE, /* Fast commit ineligible */
1799-
EXT4_MF_FC_COMMITTING /* File system underoing a fast
1800-
* commit.
1801-
*/
1798+
EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */
18021799
};
18031800

18041801
static inline void ext4_set_mount_flag(struct super_block *sb, int bit)

fs/ext4/fast_commit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ static int ext4_fc_track_template(
375375
spin_lock(&sbi->s_fc_lock);
376376
if (list_empty(&EXT4_I(inode)->i_fc_list))
377377
list_add_tail(&EXT4_I(inode)->i_fc_list,
378-
(ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_COMMITTING)) ?
378+
(sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING ||
379+
sbi->s_journal->j_flags & JBD2_FAST_COMMIT_ONGOING) ?
379380
&sbi->s_fc_q[FC_Q_STAGING] :
380381
&sbi->s_fc_q[FC_Q_MAIN]);
381382
spin_unlock(&sbi->s_fc_lock);
@@ -428,7 +429,8 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
428429
node->fcd_name.len = dentry->d_name.len;
429430

430431
spin_lock(&sbi->s_fc_lock);
431-
if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_COMMITTING))
432+
if (sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING ||
433+
sbi->s_journal->j_flags & JBD2_FAST_COMMIT_ONGOING)
432434
list_add_tail(&node->fcd_list,
433435
&sbi->s_fc_dentry_q[FC_Q_STAGING]);
434436
else
@@ -893,7 +895,6 @@ static int ext4_fc_submit_inode_data_all(journal_t *journal)
893895
int ret = 0;
894896

895897
spin_lock(&sbi->s_fc_lock);
896-
ext4_set_mount_flag(sb, EXT4_MF_FC_COMMITTING);
897898
list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) {
898899
ext4_set_inode_state(&ei->vfs_inode, EXT4_STATE_FC_COMMITTING);
899900
while (atomic_read(&ei->i_fc_updates)) {
@@ -1211,7 +1212,8 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
12111212
list_del_init(&iter->i_fc_list);
12121213
ext4_clear_inode_state(&iter->vfs_inode,
12131214
EXT4_STATE_FC_COMMITTING);
1214-
ext4_fc_reset_inode(&iter->vfs_inode);
1215+
if (iter->i_sync_tid <= tid)
1216+
ext4_fc_reset_inode(&iter->vfs_inode);
12151217
/* Make sure EXT4_STATE_FC_COMMITTING bit is clear */
12161218
smp_mb();
12171219
#if (BITS_PER_LONG < 64)
@@ -1240,7 +1242,6 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
12401242
list_splice_init(&sbi->s_fc_q[FC_Q_STAGING],
12411243
&sbi->s_fc_q[FC_Q_MAIN]);
12421244

1243-
ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
12441245
if (tid >= sbi->s_fc_ineligible_tid) {
12451246
sbi->s_fc_ineligible_tid = 0;
12461247
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);

fs/ext4/super.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5083,7 +5083,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
50835083
INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_STAGING]);
50845084
sbi->s_fc_bytes = 0;
50855085
ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
5086-
ext4_clear_mount_flag(sb, EXT4_MF_FC_COMMITTING);
50875086
sbi->s_fc_ineligible_tid = 0;
50885087
spin_lock_init(&sbi->s_fc_lock);
50895088
memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats));

0 commit comments

Comments
 (0)