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 $TOP/tests/common
9 check_prereq mkfs.btrfs
14 min_size=$($SUDO_HELPER $TOP/btrfs filesystem resize get_min_size $TEST_MNT)
16 _fail "Failed to get minimum size"
18 min_size=$(echo $min_size | cut -d ' ' -f 1)
19 echo "min size = ${min_size}" >> $RESULTS
20 run_check $SUDO_HELPER $TOP/btrfs filesystem resize $min_size $TEST_MNT
23 run_check truncate -s 20G $IMAGE
24 run_check $TOP/mkfs.btrfs -f $IMAGE
25 run_check $SUDO_HELPER mount $IMAGE $TEST_MNT
26 run_check $SUDO_HELPER chmod a+rw $TEST_MNT
28 # Create 7 data block groups, each with a size of 1Gb.
29 for ((i = 1; i <= 7; i++)); do
30 run_check fallocate -l 1G $TEST_MNT/foo$i
33 # Make sure they are persisted (all the chunk, device and block group items
34 # added to the chunk/dev/extent trees).
35 run_check $TOP/btrfs filesystem sync $TEST_MNT
37 # Now remove 3 of those 1G files. This will result in 3 block groups becoming
38 # unused, which will be automatically deleted by the cleaner kthread, and this
39 # will result in 3 holes (unallocated space) in the device (each with a size
42 run_check rm -f $TEST_MNT/foo2
43 run_check rm -f $TEST_MNT/foo4
44 run_check rm -f $TEST_MNT/foo6
46 # Sync once to wake up the cleaner kthread which will delete the unused block
47 # groups - it could have been sleeping when they became unused. Then wait a bit
48 # to allow the cleaner kthread to delete them and then finally ensure the
49 # transaction started by the cleaner kthread is committed.
50 run_check $TOP/btrfs filesystem sync $TEST_MNT
52 run_check $TOP/btrfs filesystem sync $TEST_MNT
54 # Now attempt to get the minimum size we can resize the filesystem to and verify
55 # the resize operation succeeds. This size closely matches the sum of the size
56 # of all the allocated device extents.
57 for ((i = 1; i <= 3; i++)); do
61 # Now convert metadata and system chunks to the single profile and check we are
62 # still able to get a correct minimum size and shrink to that size.
63 run_check $SUDO_HELPER $TOP/btrfs balance start -mconvert=single \
64 -sconvert=single -f $TEST_MNT
65 for ((i = 1; i <= 3; i++)); do
69 run_check $SUDO_HELPER umount $TEST_MNT