]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: tests: prepare extent map tests for strict alignment checks
authorQu Wenruo <wqu@suse.com>
Wed, 21 Jan 2026 23:07:59 +0000 (09:37 +1030)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 06:56:19 +0000 (07:56 +0100)
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 <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tests/extent-map-tests.c

index aabf825e8d7bccc5896338812a2cd4fd37f75536..811f36d411018fb244419f1c63d5037e27958831 100644 (file)
@@ -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;