btrfs-progs: tests: test check --clear-ino-cache

Pre-created image contains a subvolume and a snapshot so that cleaning
of multiple roots is also tested. The mount option 'inode_cache' will be
removed so we need the crafted image.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Nikolay Borisov 2020-12-03 10:17:42 +02:00 committed by David Sterba
parent 04f1977832
commit 92e15c97de
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,50 @@
#!/bin/bash
# Ensure that clearning ino cache removes all related items
source "$TEST_TOP/common"
check_prereq btrfs
setup_root_helper
image=$(extract_image "./ino-cache-enabled.raw.xz")
run_check "$TOP/btrfs" check --clear-ino-cache "$image"
run_check "$TOP/btrfs" check "$image"
# Check for FREE_INO items for toplevel subvol
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t fs "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "FREE_INO items for toplevel subvolume present"
# Check for bitmap item for toplevel subvol
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t fs "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for toplevel subvolume present"
# Check for FREE_INO items for subvolume
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 256 "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "ino cache items for subvolume present"
# Check for bitmap item for subvolume
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 256 "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for subvolume present"
# Check for FREE_INO items for snapshot
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 257 "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "ino cache items for snapshot present"
# Check for bitmap item for snapshot
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 257 "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for snapshot present"
# Finally test that the csum tree is empty as ino cache also uses it. At this
# point all ino items/extents should have been deleted hence the csum tree should
# be empty
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t csum "$image" |
sed -n -e 's/^.* items \([0-9]*\).*/\1/p')
[ $item_count -eq 0 ] || _fail "csum tree not empty"
rm -f -- "$image"