xfs/{422,517}: kill background jobs on test termination
[xfstests-dev.git] / tests / xfs / 517
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2020 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 517
6 #
7 # Race freeze and fsmap for a while to see if we crash or livelock.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick fsmap freeze
11
12 _register_cleanup "_cleanup" BUS
13
14 # First kill and wait the freeze loop so it won't try to freeze fs again
15 # Then make sure fs is not frozen
16 # Then kill and wait for the rest of the workers
17 # Because if fs is frozen a killed writer will never exit
18 kill_loops() {
19         local sig=$1
20
21         [ -n "$freeze_pid" ] && kill $sig $freeze_pid
22         wait $freeze_pid
23         unset freeze_pid
24         $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT
25         [ -n "$stress_pid" ] && kill $sig $stress_pid
26         [ -n "$fsmap_pid" ] && kill $sig $fsmap_pid
27         wait
28         unset stress_pid
29         unset fsmap_pid
30 }
31
32 # Override the default cleanup function.
33 _cleanup()
34 {
35         kill_loops -9 > /dev/null 2>&1
36         cd /
37         rm -rf $tmp.*
38 }
39
40 # Import common functions.
41 . ./common/filter
42 . ./common/fuzzy
43 . ./common/inject
44
45 # real QA test starts here
46 _supported_fs xfs
47 _require_xfs_scratch_rmapbt
48 _require_xfs_io_command "fsmap"
49 _require_command "$KILLALL_PROG" killall
50 _require_freeze
51
52 echo "Format and populate"
53 _scratch_mkfs > "$seqres.full" 2>&1
54 _scratch_mount
55
56 STRESS_DIR="$SCRATCH_MNT/testdir"
57 mkdir -p $STRESS_DIR
58
59 for i in $(seq 0 9); do
60         mkdir -p $STRESS_DIR/$i
61         for j in $(seq 0 9); do
62                 mkdir -p $STRESS_DIR/$i/$j
63                 for k in $(seq 0 9); do
64                         echo x > $STRESS_DIR/$i/$j/$k
65                 done
66         done
67 done
68
69 cpus=$(( $(src/feature -o) * 4 * LOAD_FACTOR))
70
71 echo "Concurrent fsmap and freeze"
72 filter_output() {
73         egrep -v '(Device or resource busy|Invalid argument)'
74 }
75 freeze_loop() {
76         end="$1"
77
78         while [ "$(date +%s)" -lt $end ]; do
79                 $XFS_IO_PROG -x -c 'freeze' $SCRATCH_MNT 2>&1 | filter_output
80                 $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT 2>&1 | filter_output
81         done
82 }
83 fsmap_loop() {
84         end="$1"
85
86         while [ "$(date +%s)" -lt $end ]; do
87                 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT > /dev/null
88         done
89 }
90 stress_loop() {
91         end="$1"
92
93         FSSTRESS_ARGS=$(_scale_fsstress_args -p 4 -d $SCRATCH_MNT -n 2000 $FSSTRESS_AVOID)
94         while [ "$(date +%s)" -lt $end ]; do
95                 $FSSTRESS_PROG $FSSTRESS_ARGS >> $seqres.full
96         done
97 }
98
99 start=$(date +%s)
100 end=$((start + (30 * TIME_FACTOR) ))
101
102 echo "Loop started at $(date --date="@${start}"), ending at $(date --date="@${end}")" >> $seqres.full
103 stress_loop $end &
104 stress_pid=$!
105 freeze_loop $end &
106 freeze_pid=$!
107 fsmap_loop $end &
108 fsmap_pid=$!
109
110 # Wait until 2 seconds after the loops should have finished...
111 while [ "$(date +%s)" -lt $((end + 2)) ]; do
112         sleep 1
113 done
114
115 # ...and clean up after the loops in case they didn't do it themselves.
116 kill_loops >> $seqres.full 2>&1
117
118 echo "Loop finished at $(date)" >> $seqres.full
119 echo "Test done"
120
121 # success, all done
122 status=0
123 exit