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