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.
33 _require_scratch_swapfile
35 swapfile="$SCRATCH_MNT/swap"
37 _require_scratch_size $((3 * 1024 * 1024)) #kB
39 # First, create a 1GB filesystem and fill it up.
40 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
42 dd if=/dev/zero of="$SCRATCH_MNT/fill" bs=1024k >> $seqres.full 2>&1
43 # Now add more space and create a swap file. We know that the first 1GB of the
44 # filesystem was used, so the swap file must be in the new part of the
46 $BTRFS_UTIL_PROG filesystem resize 2G "$SCRATCH_MNT" | _filter_scratch
47 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
49 # Add even more space which we know is unused.
50 $BTRFS_UTIL_PROG filesystem resize 3G "$SCRATCH_MNT" | _filter_scratch
51 # Free up the first 1GB of the filesystem.
52 rm -f "$SCRATCH_MNT/fill"
53 # Get rid of empty block groups and also make sure that balance skips block
54 # groups containing active swap files.
55 _run_btrfs_balance_start "$SCRATCH_MNT"
56 # Shrink away the unused space.
57 $BTRFS_UTIL_PROG filesystem resize 2G "$SCRATCH_MNT" | _filter_scratch
58 # Try to shrink away the area occupied by the swap file, which should fail.
59 $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
61 # It should work again after swapoff.
62 $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" | _filter_scratch