btrfs-progs: fix the overly strict chunk type check on dump-tree
cover btrfs-progs: fix the overly strict chunk type check on dump-tree
Commit 408e45feb325 ("btrfs-progs: dump-tree: add extra chunk type checks") introduced a chunk type check before dumping the tree.
However it's too strict as I'm a total idiot, and forgot to we still need to dump chunk tree blocks.
Fix it and add a regression test.
Qu Wenruo (2):
btrfs-progs: dump-tree: fix the chunk type check for system chunks
btrfs-progs: misc-tests: add a regression test case for dump tree
cmds/inspect-dump-tree.c | 5 ++-- .../072-dump-tree-chunk-bytenr/test.sh | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 tests/misc-tests/072-dump-tree-chunk-bytenr/test.sh
--
2.54.0
PATCH 1/2 btrfs-progs: dump-tree: fix the chunk type check for system chunks
[BUG]
Commit 408e45feb325 ("btrfs-progs: dump-tree: add extra chunk type checks") introduced one extra check on when using "btrfs ins dump-tree -b <bytenr>" option, to prevent end users from passing logical address belonging to data chunks.
However that check forget that we also have metadata in system chunks, thus will cause the following false alerts:
# mkfs.btrfs -f $dev # btrfs ins dump-tree -t chunk $dev | grep "owner CHUNK_TREE" leaf 22036480 items 4 free space 15781 generation 8 owner CHUNK_TREE ^^^ This means we can still print the chunk tree
# btrfs ins dump-tree -b 22036480 $dev btrfs-progs v6.19.1 ERROR: logical 22036480 is not in a metadata chunk, found chunk 22020096 len 8388608 flags 0x22
[CAUSE]
I'm an idiot and forgot to check system chunks.
[FIX]
Add system chunk type into the check.
--- cmds/inspect-dump-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
cmds/inspect-dump-tree.c +3 -2
@@ -206,8 +206,9 @@ static int check_metadata_logical(struct btrfs_fs_info *fs_info, u64 logical)return -ENOENT ; } map = container_of(ce, struct map_lookup, ce); -if (!(map->type &BTRFS_BLOCK_GROUP_METADATA )) { -error ("logical %llu is not in a metadata chunk, found chunk %llu len %llu flags 0x%llx" , +if (!(map->type & (BTRFS_BLOCK_GROUP_METADATA | +BTRFS_BLOCK_GROUP_SYSTEM ))) { +error ("logical %llu is not in a metadata/system chunk, found chunk %llu len %llu flags 0x%llx" , logical, ce->start, ce->size, map->type);return -EINVAL ; }
Signature · 1 line
2.54.0
PATCH 2/2 btrfs-progs: misc-tests: add a regression test case for dump tree
In reply to Qu WenruoThe new test case will:
- Create an empty btrfs
- Grab the chunk tree root bytenr
- Pass that bytenr into "btrfs ins dump-tree -b <bytenr>" That must success.
This is for the regression introduced by commit 408e45feb325 ("btrfs-progs: dump-tree: add extra chunk type checks").
--- .../072-dump-tree-chunk-bytenr/test.sh | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tests/misc-tests/072-dump-tree-chunk-bytenr/test.sh
tests/misc-tests/072-dump-tree-chunk-bytenr/test.sh new file +25 -0
@@ -0,0 +1,25 @@ +#!/bin/bash +# Test "btrfs ins dump-tree -b <bytenr>" when the bytenr belongs to a chunk +# tree block. +# +# This is a regression test for commit 408e45feb325 ("btrfs-progs: +# dump-tree: add extra chunk type checks"), which is too strict and +# rejects chunk tree blocks. + +source "$TEST_TOP/common" || exit +source "$TEST_TOP/common.convert" || exit + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check_mkfs_test_dev +chunk_root=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t chunk "$TEST_DEV" |\ + grep "owner CHUNK_TREE" | cut -f 2 -d\ ) +if [ -z "$chunk_root" ]; then + _fail "unable to get the chunk root bytenr" +fi + +run_check "$TOP/btrfs" inspect-internal dump-tree -b "$chunk_root" "$TEST_DEV"
Signature · 1 line
2.54.0