diff options
author | Josef Bacik <josef@toxicpanda.com> | 2023-08-17 22:57:32 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2023-08-21 14:54:49 +0200 |
commit | f345dbdf2c9c4733d52b9389da6c02672f3b8672 (patch) | |
tree | 43f3a53660f3a0270091934e77491d796e7b31de /fs/btrfs | |
parent | btrfs: tests: add extent_map tests for dropping with odd layouts (diff) | |
download | linux-f345dbdf2c9c4733d52b9389da6c02672f3b8672.tar.xz linux-f345dbdf2c9c4733d52b9389da6c02672f3b8672.zip |
btrfs: tests: add a test for btrfs_add_extent_mapping
This helper is different from the normal add_extent_mapping in that it
will stuff an em into a gap that exists between overlapping em's in the
tree. It appeared there was a bug so I wrote a self test to validate it
did the correct thing when it worked with two side by side ems.
Thankfully it is correct, but more testing is better.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/tests/extent-map-tests.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c index cf85c7795686..31de4cd0666f 100644 --- a/fs/btrfs/tests/extent-map-tests.c +++ b/fs/btrfs/tests/extent-map-tests.c @@ -655,6 +655,59 @@ out: return ret; } +/* + * Test the btrfs_add_extent_mapping helper which will attempt to create an em + * for areas between two existing ems. Validate it doesn't do this when there + * are two unmerged em's side by side. + */ +static int test_case_6(struct btrfs_fs_info *fs_info, struct extent_map_tree *em_tree) +{ + struct extent_map *em = NULL; + int ret; + + ret = add_compressed_extent(em_tree, 0, SZ_4K, 0); + if (ret) + goto out; + + ret = add_compressed_extent(em_tree, SZ_4K, SZ_4K, 0); + if (ret) + goto out; + + em = alloc_extent_map(); + if (!em) { + test_std_err(TEST_ALLOC_EXTENT_MAP); + return -ENOMEM; + } + + em->start = SZ_4K; + em->len = SZ_4K; + em->block_start = SZ_16K; + em->block_len = SZ_16K; + write_lock(&em_tree->lock); + ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, 0, SZ_8K); + write_unlock(&em_tree->lock); + + if (ret != 0) { + test_err("got an error when adding our em: %d", ret); + goto out; + } + + ret = -EINVAL; + if (em->start != 0) { + test_err("unexpected em->start at %llu, wanted 0", em->start); + goto out; + } + if (em->len != SZ_4K) { + test_err("unexpected em->len %llu, expected 4K", em->len); + goto out; + } + ret = 0; +out: + free_extent_map(em); + free_extent_map_tree(em_tree); + return ret; +} + struct rmap_test_vector { u64 raid_type; u64 physical_start; @@ -837,6 +890,9 @@ int btrfs_test_extent_map(void) ret = test_case_5(); if (ret) goto out; + ret = test_case_6(fs_info, em_tree); + if (ret) + goto out; test_msg("running rmap tests"); for (i = 0; i < ARRAY_SIZE(rmap_tests); i++) { |