After a delalloc conversion of inline data, buffered writes can leave a folio past the first one partially uptodate until writeback. Add a case to the inline data KUnit tests that checks that ext4_readpage_inline() keeps the uptodate buffer of such a folio, zeroes the other buffers and marks all of them uptodate. Signed-off-by: Florian Schmaus --- fs/ext4/inline-test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/ext4/inline-test.c b/fs/ext4/inline-test.c index b3d7c51ad216..1558454d9d8b 100644 --- a/fs/ext4/inline-test.c +++ b/fs/ext4/inline-test.c @@ -895,6 +895,7 @@ static void test_readpage_inline_link_and_iomap(struct kunit *test) { struct inline_test_ctx *ctx = test->priv; struct inode *inode = &ctx->ei.vfs_inode; + struct buffer_head *head, *bh; struct folio *folio; struct iomap iomap = { 0 }; char content[85]; @@ -960,6 +961,41 @@ static void test_readpage_inline_link_and_iomap(struct kunit *test) kunmap_local(kaddr); folio_put(folio); + /* + * 3b. ext4_readpage_inline on folio->index > 0 with only some buffers + * uptodate: keeps their data, zeroes the other buffers and marks all + * of them uptodate. Buffered writes after a delalloc conversion + * leave such a folio behind until writeback destroys the inline data. + */ + folio = __filemap_get_folio(&inode->i_data, 2, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, + GFP_KERNEL); + KUNIT_ASSERT_FALSE(test, IS_ERR(folio)); + kaddr = kmap_local_folio(folio, 0); + memset(kaddr, 0xff, PAGE_SIZE); + memset(kaddr + TEST_BLOCK_SIZE, 0xab, TEST_BLOCK_SIZE); + kunmap_local(kaddr); + head = create_empty_buffers(folio, TEST_BLOCK_SIZE, 0); + set_buffer_uptodate(head->b_this_page); + + ret = ext4_readpage_inline(inode, folio); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_TRUE(test, folio_test_uptodate(folio)); + KUNIT_EXPECT_FALSE(test, folio_test_locked(folio)); + kaddr = kmap_local_folio(folio, 0); + KUNIT_EXPECT_NULL(test, memchr_inv(kaddr, 0, TEST_BLOCK_SIZE)); + KUNIT_EXPECT_NULL(test, memchr_inv(kaddr + TEST_BLOCK_SIZE, 0xab, + TEST_BLOCK_SIZE)); + KUNIT_EXPECT_NULL(test, memchr_inv(kaddr + 2 * TEST_BLOCK_SIZE, 0, + PAGE_SIZE - 2 * TEST_BLOCK_SIZE)); + kunmap_local(kaddr); + bh = head; + do { + KUNIT_EXPECT_TRUE(test, buffer_uptodate(bh)); + bh = bh->b_this_page; + } while (bh != head); + folio_put(folio); + /* 4. ext4_readpage_inline when ext4_get_inode_loc fails -> propagates error */ truncate_inode_pages(&inode->i_data, 0); ctx->get_inode_loc_err = -EIO; -- 2.56.1