misc: move exit status into trap handler
[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 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 7 15
17
18 _cleanup()
19 {
20         cd /
21         $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT > /dev/null 2>&1
22         rm -rf $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/fuzzy
29 . ./common/inject
30 . ./common/xfs
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_xfs_scratch_rmapbt
35 _require_xfs_io_command "fsmap"
36 _require_command "$KILLALL_PROG" killall
37
38 echo "Format and populate"
39 _scratch_mkfs > "$seqres.full" 2>&1
40 _scratch_mount
41
42 STRESS_DIR="$SCRATCH_MNT/testdir"
43 mkdir -p $STRESS_DIR
44
45 for i in $(seq 0 9); do
46         mkdir -p $STRESS_DIR/$i
47         for j in $(seq 0 9); do
48                 mkdir -p $STRESS_DIR/$i/$j
49                 for k in $(seq 0 9); do
50                         echo x > $STRESS_DIR/$i/$j/$k
51                 done
52         done
53 done
54
55 cpus=$(( $(src/feature -o) * 4 * LOAD_FACTOR))
56
57 echo "Concurrent fsmap and freeze"
58 filter_output() {
59         egrep -v '(Device or resource busy|Invalid argument)'
60 }
61 freeze_loop() {
62         end="$1"
63
64         while [ "$(date +%s)" -lt $end ]; do
65                 $XFS_IO_PROG -x -c 'freeze' $SCRATCH_MNT 2>&1 | filter_output
66                 $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT 2>&1 | filter_output
67         done
68 }
69 fsmap_loop() {
70         end="$1"
71
72         while [ "$(date +%s)" -lt $end ]; do
73                 $XFS_IO_PROG -c 'fsmap -v' $SCRATCH_MNT > /dev/null
74         done
75 }
76 stress_loop() {
77         end="$1"
78
79         FSSTRESS_ARGS=$(_scale_fsstress_args -p 4 -d $SCRATCH_MNT -n 2000 $FSSTRESS_AVOID)
80         while [ "$(date +%s)" -lt $end ]; do
81                 $FSSTRESS_PROG $FSSTRESS_ARGS >> $seqres.full
82         done
83 }
84
85 start=$(date +%s)
86 end=$((start + (30 * TIME_FACTOR) ))
87
88 echo "Loop started at $(date --date="@${start}"), ending at $(date --date="@${end}")" >> $seqres.full
89 stress_loop $end &
90 freeze_loop $end &
91 fsmap_loop $end &
92
93 # Wait until 2 seconds after the loops should have finished...
94 while [ "$(date +%s)" -lt $((end + 2)) ]; do
95         sleep 1
96 done
97
98 # ...and clean up after the loops in case they didn't do it themselves.
99 $KILLALL_PROG -TERM xfs_io fsstress >> $seqres.full 2>&1
100 $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT >> $seqres.full 2>&1
101
102 echo "Loop finished at $(date)" >> $seqres.full
103 echo "Test done"
104
105 # success, all done
106 status=0
107 exit