ext4_fc_replay_inode() writes the replayed on-disk inode and then flushes the file system device's cache, but it ignores the result of the flush. If the flush fails, fast commit replay reports success even though the replayed inode may not have reached stable storage, and journal recovery completes as if the inode had been replayed. Return the error from ext4_fc_issue_flush() so that a failed flush aborts the replay. The other ignored cache flush errors, in ext4_init_inode_table() and in ext4_fc_perform_commit(), have been fixed by commit baf9a298bdd7 ("ext4: check return value of blkdev_issue_flush() when initializing inode tables") and commit 49ac01dd7d43 ("ext4: check return value of blkdev_issue_flush() when starting a fast commit"). Extend ext4_fast_commit_test to verify that a flush failure during inode replay is propagated, and that a flush failure before fast commit blocks are written to an external journal falls back to a full commit. Make the lazy inode table zeroing test in ext4_ialloc_test check that the barrier flag is passed down to ext4_itable_zeroout(). Fixes: 8016e29f4362 ("ext4: fast commit recovery path") Cc: stable@kernel.org Signed-off-by: Theodore Ts'o --- fs/ext4/fast_commit-test.c | 28 +++++++++++++++++++++++++++- fs/ext4/fast_commit.c | 2 +- fs/ext4/ialloc-test.c | 5 +++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fs/ext4/fast_commit-test.c b/fs/ext4/fast_commit-test.c index 07cb9c043cd2..55b33f0d6e0a 100644 --- a/fs/ext4/fast_commit-test.c +++ b/fs/ext4/fast_commit-test.c @@ -117,6 +117,7 @@ struct fc_test_ctx { int fail_fc_get_buf_on_call; int fc_get_buf_calls; bool fail_fc_wait_bufs; + int fail_fc_flush; int submit_inode_data_err; unsigned int fc_submit_bh_calls; @@ -794,7 +795,7 @@ static int stub_fc_issue_flush(struct block_device *bdev) ctx->fc_flush_calls++; ctx->last_flushed_bdev = bdev; - return 0; + return ctx->fail_fc_flush; } static int mock_submit_inode_data_buffers(struct jbd2_inode *jinode) @@ -1993,6 +1994,21 @@ static void test_fc_commit_paths(struct kunit *test) memcpy(&tl, ctx->fc_buf_data[1], EXT4_FC_TAG_BASE_LEN); KUNIT_EXPECT_EQ(test, le16_to_cpu(tl.fc_tag), (u16)EXT4_FC_TAG_INODE); + /* External journal flush failure falls back to full commit */ + { + unsigned int failed_before = sbi->s_fc_stats.fc_failed_commits; + + ctx->fail_fc_flush = -EIO; + ctx->fc_submit_bh_calls = 0; + ext4_fc_track_inode(&ctx->handle, file1); + KUNIT_EXPECT_EQ(test, ext4_fc_commit(&ctx->journal, 10), 0); + KUNIT_EXPECT_EQ(test, atomic_read(&sbi->s_fc_subtid), 2); + KUNIT_EXPECT_EQ(test, ctx->fc_submit_bh_calls, 0U); + KUNIT_EXPECT_EQ(test, sbi->s_fc_stats.fc_failed_commits, + failed_before + 1); + ctx->fail_fc_flush = 0; + } + ctx->journal.j_fs_dev = &ctx->bdev; } @@ -2448,6 +2464,16 @@ static void test_fc_replay_inode_and_dentries(struct kunit *test) KUNIT_EXPECT_EQ(test, le32_to_cpu(de->inode), (u32)TEST_FILE2_INO); brelse(bh); + + /* 3) Flush failure during INODE replay propagates -EIO */ + sbi->s_fc_replay_state.fc_replay_num_tags = 5; + ctx->fail_fc_flush = -EIO; + KUNIT_EXPECT_EQ(test, + ext4_fc_replay_test(&ctx->journal, + &ctx->fc_bhs[0], + PASS_REPLAY, 0, 10), + -EIO); + ctx->fail_fc_flush = 0; } ext4_fc_replay_cleanup(sb); diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 9beb423b208f..d56c45ee0d61 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -2041,7 +2041,7 @@ static int ext4_fc_replay_inode(struct super_block *sb, out: iput(inode); if (!ret) - ext4_fc_issue_flush(sb->s_bdev); + ret = ext4_fc_issue_flush(sb->s_bdev); return ret; } diff --git a/fs/ext4/ialloc-test.c b/fs/ext4/ialloc-test.c index c68b60c95961..fede9fd0772d 100644 --- a/fs/ext4/ialloc-test.c +++ b/fs/ext4/ialloc-test.c @@ -2670,12 +2670,13 @@ static void ialloc_test_init_inode_table(struct kunit *test) !!(le16_to_cpu(ctx->gdps[0].bg_flags) & EXT4_BG_INODE_ZEROED)); - /* 7. Zeroout I/O failure (-EIO) and emergency RO (-EROFS) */ + /* 7. Zeroout/flush I/O failure (-EIO) and emergency RO (-EROFS) */ ctx->gdps[3].bg_flags = cpu_to_le16(EXT4_BG_INODE_UNINIT); ctx->fail_itable_zeroout_err = -EIO; - err = ext4_init_inode_table(sb, 3, 0); + err = ext4_init_inode_table(sb, 3, 1); ctx->fail_itable_zeroout_err = 0; KUNIT_EXPECT_EQ(test, err, -EIO); + KUNIT_EXPECT_EQ(test, ctx->last_zeroout_barrier, 1); KUNIT_EXPECT_FALSE(test, !!(le16_to_cpu(ctx->gdps[3].bg_flags) & EXT4_BG_INODE_ZEROED)); -- 2.56.1.708.g77570a6a1d-goog