3 # Test getting the minimum size a filesystem can be resized to and verify we
4 # are able to resize (shrink) it to that size.
7 source "$TEST_TOP/common"
9 check_prereq mkfs.btrfs
14 # Optionally take id of the device to shrink
17 min_size=$(run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal min-dev-size ${1:+--id $1} $TEST_MNT)
18 min_size=$(echo $min_size | cut -d ' ' -f 1)
19 echo "min size = ${min_size}" >> $RESULTS
20 if [ -z "$min_size" ]; then
21 _fail "Failed to parse minimum size"
23 run_check $SUDO_HELPER $TOP/btrfs filesystem resize $min_size $TEST_MNT
26 run_check truncate -s 20G $IMAGE
27 run_check $TOP/mkfs.btrfs -f $IMAGE
28 run_check $SUDO_HELPER mount $IMAGE $TEST_MNT
29 run_check $SUDO_HELPER chmod a+rw $TEST_MNT
31 # Create 7 data block groups, each with a size of 1Gb.
32 for ((i = 1; i <= 7; i++)); do
33 run_check fallocate -l 1G $TEST_MNT/foo$i
36 # Make sure they are persisted (all the chunk, device and block group items
37 # added to the chunk/dev/extent trees).
38 run_check $TOP/btrfs filesystem sync $TEST_MNT
40 # Now remove 3 of those 1G files. This will result in 3 block groups becoming
41 # unused, which will be automatically deleted by the cleaner kthread, and this
42 # will result in 3 holes (unallocated space) in the device (each with a size
45 run_check rm -f $TEST_MNT/foo2
46 run_check rm -f $TEST_MNT/foo4
47 run_check rm -f $TEST_MNT/foo6
49 # Sync once to wake up the cleaner kthread which will delete the unused block
50 # groups - it could have been sleeping when they became unused. Then wait a bit
51 # to allow the cleaner kthread to delete them and then finally ensure the
52 # transaction started by the cleaner kthread is committed.
53 run_check $TOP/btrfs filesystem sync $TEST_MNT
55 run_check $TOP/btrfs filesystem sync $TEST_MNT
57 # Now attempt to get the minimum size we can resize the filesystem to and verify
58 # the resize operation succeeds. This size closely matches the sum of the size
59 # of all the allocated device extents.
60 for ((i = 1; i <= 3; i++)); do
64 # Now convert metadata and system chunks to the single profile and check we are
65 # still able to get a correct minimum size and shrink to that size.
66 run_check $SUDO_HELPER $TOP/btrfs balance start -mconvert=single \
67 -sconvert=single -f $TEST_MNT
68 for ((i = 1; i <= 3; i++)); do
72 run_check $SUDO_HELPER umount $TEST_MNT