btrfs: Add a test for leaking root crash at unmount time
[xfstests-dev.git] / tests / btrfs / 212
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 212
6 #
7 # Test if unmounting a fs with balance canceled can lead to crash.
8 # This needs CONFIG_BTRFS_DEBUG compiled, which adds extra unmount time self-test
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23         kill $balance_pid &> /dev/null
24         kill $cancel_pid &> /dev/null
25         "$KILLALL_PROG" -q $FSSTRESS_PROG &> /dev/null
26         $BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
27         wait
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs btrfs
41 _supported_os Linux
42 _require_scratch
43 _require_command "$KILLALL_PROG" killall
44
45 _scratch_mkfs >> $seqres.full
46 _scratch_mount
47
48 runtime=15
49
50 balance_workload()
51 {
52         trap "wait; exit" SIGTERM
53         while true; do
54                 _run_btrfs_balance_start &> /dev/null
55         done
56 }
57
58 cancel_workload()
59 {
60         trap "wait; exit" SIGTERM
61         while true; do
62                 $BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
63                 sleep 2
64         done
65 }
66
67 $FSSTRESS_PROG -d $SCRATCH_MNT -w -n 100000  >> $seqres.full 2>/dev/null &
68 balance_workload &
69 balance_pid=$!
70
71 cancel_workload &
72 cancel_pid=$!
73
74 sleep $runtime
75
76 kill $balance_pid
77 kill $cancel_pid
78 "$KILLALL_PROG" -q $FSSTRESS_PROG &> /dev/null
79 $BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
80 wait
81
82 echo "Silence is golden"
83 # success, all done
84 status=0
85 exit