2016-10-13 09:22:27 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# confirm that clearing space cache works
|
|
|
|
|
2018-02-08 06:34:19 +00:00
|
|
|
source "$TEST_TOP/common"
|
2016-10-13 09:22:27 +00:00
|
|
|
|
|
|
|
check_prereq btrfs
|
|
|
|
check_prereq mkfs.btrfs
|
|
|
|
|
|
|
|
setup_root_helper
|
2017-10-27 13:50:34 +00:00
|
|
|
prepare_test_dev
|
2016-10-13 09:22:27 +00:00
|
|
|
|
2019-06-05 17:09:38 +00:00
|
|
|
run_check_mkfs_test_dev
|
2016-10-13 09:22:27 +00:00
|
|
|
run_check_mount_test_dev
|
|
|
|
|
|
|
|
# Create files that takes at least 3 data chunks, while
|
|
|
|
# can still be removed to create free space inside one chunk.
|
|
|
|
|
|
|
|
for i in $(seq 0 6); do
|
2017-04-24 13:29:40 +00:00
|
|
|
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file_${i}" bs=1M \
|
2016-10-13 09:22:27 +00:00
|
|
|
count=64 > /dev/null 2>&1
|
|
|
|
done
|
|
|
|
sync
|
|
|
|
|
|
|
|
# Remove file 1 3 5 to create holes
|
|
|
|
for i in 1 3 5; do
|
2017-04-24 13:29:40 +00:00
|
|
|
run_check $SUDO_HELPER rm "$TEST_MNT/file_${i}"
|
2016-10-13 09:22:27 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
sync
|
|
|
|
|
|
|
|
run_check_umount_test_dev
|
|
|
|
|
|
|
|
# Clear space cache and re-check fs
|
2017-04-24 13:29:40 +00:00
|
|
|
run_check "$TOP/btrfs" check --clear-space-cache v1 "$TEST_DEV"
|
|
|
|
run_check "$TOP/btrfs" check "$TEST_DEV"
|
2016-10-13 09:22:27 +00:00
|
|
|
|
|
|
|
# Manually recheck space cache and super space cache generation
|
2017-04-24 13:29:40 +00:00
|
|
|
run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \
|
2016-10-13 09:22:27 +00:00
|
|
|
grep -q FREE_SPACE
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
_fail "clear space cache doesn't clear all space cache"
|
|
|
|
fi
|
|
|
|
|
2017-04-24 13:29:40 +00:00
|
|
|
run_check_stdout $TOP/btrfs inspect-internal dump-super "$TEST_DEV" |
|
2016-10-13 09:22:27 +00:00
|
|
|
grep -q 'cache_generation.*18446744073709551615'
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
_fail "clear space cache doesn't set cache_generation correctly"
|
|
|
|
fi
|