Skip to contentSkip to conversation

btrfs: tests: fix dummy fs_info geometry setup

PATCH New Abdullah Zulfiqar 1 participant 3 messages Nov 25 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: tests: fix dummy fs_info geometry setup

This small series fixes two geometry initialization bugs in Btrfs selftests:

1. raid-stripe-tree-tests.c passes (sectorsize, nodesize) in reversed order to btrfs_alloc_dummy_fs_info(nodesize, sectorsize), so raid-stripe-tree selftests always ran with fs_info->nodesize == 4096 and fs_info->sectorsize > fs_info->nodesize on larger node sizes.
2. btrfs_alloc_dummy_fs_info() leaves fs_info->nodesize_bits as 0, causing buffer_tree entries to be indexed by raw byte offsets instead of (start >> nodesize_bits).

Tested by building with CONFIG_BTRFS_FS_RUN_SANITY_TESTS=y, CONFIG_BTRFS_DEBUG=y, CONFIG_BTRFS_ASSERT=y, and CONFIG_BLK_DEV_ZONED=y and running the full selftest suite across 4K..64K node sizes in QEMU.

Abdullah Zulfiqar (2):
btrfs: tests: fix swapped nodesize and sectorsize in raid-stripe-tree
tests
btrfs: tests: initialize fs_info->nodesize_bits in dummy fs_info

 fs/btrfs/tests/btrfs-tests.c            | 1 +
 fs/btrfs/tests/raid-stripe-tree-tests.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.56.1
#1 lore raw

PATCH 1/2 btrfs: tests: fix swapped nodesize and sectorsize in raid-stripe-tree tests

btrfs_alloc_dummy_fs_info() takes (nodesize, sectorsize), but run_test() in raid-stripe-tree-tests.c passes (sectorsize, nodesize).

When btrfs_run_sanity_tests() iterates over nodesize values larger than sectorsize (8K..64K with 4K sectorsize), fs_info->nodesize is set to 4096 while fs_info->sectorsize is set to the larger nodesize value, and root->node is always allocated with length 4096 instead of nodesize.

Swap the arguments to match btrfs_alloc_dummy_fs_info() and all other Btrfs selftests.

Fixes 506be4d56575 ("btrfs: tests: add selftests for raid-stripe-tree")
---
 fs/btrfs/tests/raid-stripe-tree-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tests/raid-stripe-tree-tests.c +1 -1
index a7bc58a5c..3ae103e32 100644
@@ -1088,7 +1088,7 @@ static int run_test(test_func_t test, u32 sectorsize, u32 nodesize)
 	struct btrfs_root *root = NULL;
 	int ret;
 
-	fs_info = btrfs_alloc_dummy_fs_info(sectorsize, nodesize);
+	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
 		test_std_err(TEST_ALLOC_FS_INFO);
 		ret = -ENOMEM;
Signature · 1 line
2.56.1
#2 lore raw

PATCH 2/2 btrfs: tests: initialize fs_info->nodesize_bits in dummy fs_info

In reply to Abdullah Zulfiqar

Commit f2cb97ee964a ("btrfs: index buffer_tree using node size") added fs_info->nodesize_bits, initialized it in open_ctree(), and updated alloc_test_extent_buffer() and buffer_tree lookups to index by (start >> fs_info->nodesize_bits), but missed initializing nodesize_bits in btrfs_alloc_dummy_fs_info().

As a result, fs_info->nodesize_bits remains 0 throughout all Btrfs selftests, causing buffer_tree entries to be indexed by raw byte offsets instead of node indices and any shift by nodesize_bits to evaluate as zero.

Initialize fs_info->nodesize_bits = ilog2(nodesize) alongside nodesize in btrfs_alloc_dummy_fs_info().

Fixes f2cb97ee964a ("btrfs: index buffer_tree using node size")
---
 fs/btrfs/tests/btrfs-tests.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/tests/btrfs-tests.c +1 -0
index cebc9a17b..c96fcd4de 100644
@@ -138,6 +138,7 @@ struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
 	btrfs_init_fs_info(fs_info);
 
 	fs_info->nodesize = nodesize;
+	fs_info->nodesize_bits = ilog2(nodesize);
 	fs_info->sectorsize = sectorsize;
 	fs_info->sectorsize_bits = ilog2(sectorsize);
 
Signature · 1 line
2.56.1