btrfs/177: fix for nodesize 64K and type single
[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.
40 fssize=$((1024 * 1024 * 1024))
41 _scratch_mkfs_sized $fssize >> $seqres.full 2>&1
42 _scratch_mount
43
44 # Create a small file and run balance so we shall deal with the chunk
45 # size as allocated by the kernel, mkfs allocated chunks are smaller.
46 dd if=/dev/zero of="$SCRATCH_MNT/fill" bs=4096 count=1 >> $seqres.full 2>&1
47 _run_btrfs_balance_start "$SCRATCH_MNT"
48
49 # Now fill it up.
50 dd if=/dev/zero of="$SCRATCH_MNT/refill" bs=4096 >> $seqres.full 2>&1
51
52 # Now add more space and create a swap file. We know that the first $fssize
53 # of the filesystem was used, so the swap file must be in the new part of the
54 # filesystem.
55 $BTRFS_UTIL_PROG filesystem resize $((3 * fssize)) "$SCRATCH_MNT" | \
56                                                         _filter_scratch
57 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
58 swapon "$swapfile"
59
60 # Free up the first 1GB of the filesystem.
61 rm -f "$SCRATCH_MNT/fill"
62 rm -f "$SCRATCH_MNT/refill"
63
64 # Get rid of empty block groups and also make sure that balance skips block
65 # groups containing active swap files.
66 _run_btrfs_balance_start "$SCRATCH_MNT"
67
68 # Try to shrink away the area occupied by the swap file, which should fail.
69 $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" 2>&1 | grep -o "Text file busy"
70
71 swapoff "$swapfile"
72
73 # It should work again after swapoff.
74 $BTRFS_UTIL_PROG filesystem resize $fssize "$SCRATCH_MNT" | _filter_scratch
75
76 status=0
77 exit