2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook. All Rights Reserved.
7 # Test relocation (balance and resize) with an active swap file.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # Modify as appropriate.
32 _require_scratch_swapfile
34 swapfile="$SCRATCH_MNT/swap"
36 _require_scratch_size $((3 * 1024 * 1024)) #kB
38 # First, create a 1GB filesystem.
39 fssize=$((1024 * 1024 * 1024))
40 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
43 # Create a small file and run balance so we shall deal with the chunk
44 # size as allocated by the kernel, mkfs allocated chunks are smaller.
45 dd if=/dev/zero of="$SCRATCH_MNT/fill" bs=4096 count=1 >> $seqres.full 2>&1
46 _run_btrfs_balance_start "$SCRATCH_MNT" >>$seqres.full
49 dd if=/dev/zero of="$SCRATCH_MNT/refill" bs=4096 >> $seqres.full 2>&1
51 # Now add more space and create a swap file. We know that the first $fssize
52 # of the filesystem was used, so the swap file must be in the new part of the
54 $BTRFS_UTIL_PROG filesystem resize $((3 * fssize)) "$SCRATCH_MNT" | \
56 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
59 # Free up the first 1GB of the filesystem.
60 rm -f "$SCRATCH_MNT/fill"
61 rm -f "$SCRATCH_MNT/refill"
63 # Get rid of empty block groups and also make sure that balance skips block
64 # groups containing active swap files.
65 _run_btrfs_balance_start "$SCRATCH_MNT" >>$seqres.full
67 # Try to shrink away the area occupied by the swap file, which should fail.
68 $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
72 # It should work again after swapoff.
73 $BTRFS_UTIL_PROG filesystem resize $fssize "$SCRATCH_MNT" | _filter_scratch