btrfs: Add a test for dead looping balance after balance cancel
[xfstests-dev.git] / tests / btrfs / 213
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 213
6 #
7 # Test if canceling a running balance can lead to dead looping balance
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         kill $write_pid &> /dev/null
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # Modify as appropriate.
33 _supported_fs btrfs
34 _supported_os Linux
35 _require_scratch
36 _require_xfs_io_command pwrite -D
37
38 _scratch_mkfs >> $seqres.full
39 _scratch_mount
40
41 runtime=4
42
43 # Create enough IO so that we need around $runtime seconds to relocate it.
44 #
45 # Here we don't want any wrapper, as we want full control of the process.
46 $XFS_IO_PROG -f -c "pwrite -D -b 1M 0 1024T" "$SCRATCH_MNT/file" &> /dev/null &
47 write_pid=$!
48 sleep $runtime
49 kill $write_pid
50 wait $write_pid
51
52 # Now balance should take at least $runtime seconds, we can cancel it at
53 # $runtime/2 to ensure a success cancel.
54 _run_btrfs_balance_start -d --bg "$SCRATCH_MNT"
55 sleep $(($runtime / 2))
56 $BTRFS_UTIL_PROG balance cancel "$SCRATCH_MNT"
57
58 # Now check if we can finish relocating metadata, which should finish very
59 # quickly.
60 $BTRFS_UTIL_PROG balance start -m "$SCRATCH_MNT" >> $seqres.full
61
62 echo "Silence is golden"
63
64 # success, all done
65 status=0
66 exit