fsx/fsstress: round blocksize properly
[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 _require_scratch_swapfile
33
34 swapfile="$SCRATCH_MNT/swap"
35
36 _require_scratch_size $((3 * 1024 * 1024)) #kB
37
38 # First, create a 1GB filesystem.
39 fssize=$((1024 * 1024 * 1024))
40 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
41 _scratch_mount
42
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
47
48 # Now fill it up.
49 dd if=/dev/zero of="$SCRATCH_MNT/refill" bs=4096 >> $seqres.full 2>&1
50
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
53 # filesystem.
54 $BTRFS_UTIL_PROG filesystem resize $((3 * fssize)) "$SCRATCH_MNT" | \
55                                                         _filter_scratch
56 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
57 swapon "$swapfile"
58
59 # Free up the first 1GB of the filesystem.
60 rm -f "$SCRATCH_MNT/fill"
61 rm -f "$SCRATCH_MNT/refill"
62
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
66
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"
69
70 swapoff "$swapfile"
71
72 # It should work again after swapoff.
73 $BTRFS_UTIL_PROG filesystem resize $fssize "$SCRATCH_MNT" | _filter_scratch
74
75 status=0
76 exit