From 385c65f8274b8caff75102474c4c9e8a95e6ec4c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 22 Jan 2026 09:37:59 +1030 Subject: [PATCH] btrfs: tests: prepare extent map tests for strict alignment checks Currently the extent map self tests have the following points that will cause false alerts for the incoming strict extent map alignment checks: - Incorrect inlined extent map size Which is not following what the kernel is doing for inlined extents, as btrfs_extent_item_to_extent_map() always uses the fs block size as the length, not the ram_bytes. Fix it by using SZ_4K as extent map's length. - Incorrect btrfs_fs_info::sectorsize As we always use PAGE_SIZE, which can be values larger than 4K. Meanwhile all the immediate numbers used are based on 4K fs block size in the test case. Fix it by using fixed SZ_4K fs block size when allocating the dummy btrfs_fs_info. Reviewed-by: Filipe Manana Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- fs/btrfs/tests/extent-map-tests.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c index aabf825e8d7bc..811f36d411018 100644 --- a/fs/btrfs/tests/extent-map-tests.c +++ b/fs/btrfs/tests/extent-map-tests.c @@ -173,9 +173,12 @@ static int test_case_2(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) return -ENOMEM; } - /* Add [0, 1K) */ + /* + * Add [0, 1K) which is inlined. And the extent map length must + * be one block. + */ em->start = 0; - em->len = SZ_1K; + em->len = SZ_4K; em->disk_bytenr = EXTENT_MAP_INLINE; em->disk_num_bytes = 0; em->ram_bytes = SZ_1K; @@ -219,7 +222,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) /* Add [0, 1K) */ em->start = 0; - em->len = SZ_1K; + em->len = SZ_4K; em->disk_bytenr = EXTENT_MAP_INLINE; em->disk_num_bytes = 0; em->ram_bytes = SZ_1K; @@ -235,7 +238,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ret = -ENOENT; goto out; } - if (em->start != 0 || btrfs_extent_map_end(em) != SZ_1K || + if (em->start != 0 || btrfs_extent_map_end(em) != SZ_4K || em->disk_bytenr != EXTENT_MAP_INLINE) { test_err( "case2 [0 1K]: ret %d return a wrong em (start %llu len %llu disk_bytenr %llu", @@ -1131,8 +1134,11 @@ int btrfs_test_extent_map(void) /* * Note: the fs_info is not set up completely, we only need * fs_info::fsid for the tracepoint. + * + * And all the immediate numbers are based on 4K blocksize, + * thus we have to use 4K as sectorsize no matter the page size. */ - fs_info = btrfs_alloc_dummy_fs_info(PAGE_SIZE, PAGE_SIZE); + fs_info = btrfs_alloc_dummy_fs_info(SZ_4K, SZ_4K); if (!fs_info) { test_std_err(TEST_ALLOC_FS_INFO); return -ENOMEM; -- 2.47.3