f7c2436ee7e46d9699c6c1705cb047fd623d284b
[xfstests-dev.git] / tests / btrfs / 177
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 177
6 #
7 # Test relocation (balance and resize) with an active swap file.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 . ./common/rc
25 . ./common/filter
26 . ./common/btrfs
27
28 rm -f $seqres.full
29
30 # Modify as appropriate.
31 _supported_fs btrfs
32 _supported_os Linux
33 _require_scratch_swapfile
34
35 swapfile="$SCRATCH_MNT/swap"
36
37 _require_scratch_size $((3 * 1024 * 1024)) #kB
38
39 # First, create a 1GB filesystem and fill it up.
40 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
41 _scratch_mount
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
45 # filesystem.
46 $BTRFS_UTIL_PROG filesystem resize 2G "$SCRATCH_MNT" | _filter_scratch
47 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
48 swapon "$swapfile"
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"
60 swapoff "$swapfile"
61 # It should work again after swapoff.
62 $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" | _filter_scratch
63
64 status=0
65 exit