misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 168
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020-2021 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 168
6 #
7 # XFS online shrinkfs stress test
8 #
9 # This test attempts to shrink unused space as much as possible with
10 # background fsstress workload. It will decrease the shrink size if
11 # larger size fails. And totally repeat 2 * TIME_FACTOR times.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
21
22 # get standard environment, filters and checks
23 . ./common/rc
24 . ./common/filter
25
26 create_scratch()
27 {
28         _scratch_mkfs_xfs $@ | tee -a $seqres.full | \
29                 _filter_mkfs 2>$tmp.mkfs >/dev/null
30         . $tmp.mkfs
31
32         _scratch_mount
33         # fix the reserve block pool to a known size so that the enospc
34         # calculations work out correctly.
35         _scratch_resvblks 1024 > /dev/null 2>&1
36 }
37
38 fill_scratch()
39 {
40         $XFS_IO_PROG -f -c "falloc 0 $1" $SCRATCH_MNT/resvfile
41 }
42
43 stress_scratch()
44 {
45         local procs=3
46         local nops=1000
47         # -w ensures that the only ops are ones which cause write I/O
48         local FSSTRESS_ARGS=`_scale_fsstress_args -d $SCRATCH_MNT -w \
49                 -p $procs -n $nops $FSSTRESS_AVOID`
50         $FSSTRESS_PROG $FSSTRESS_ARGS >> $seqres.full 2>&1
51 }
52
53 # real QA test starts here
54 _supported_fs xfs
55 _require_scratch_xfs_shrink
56 _require_xfs_io_command "falloc"
57
58 rm -f $seqres.full
59 _scratch_mkfs_xfs | tee -a $seqres.full | _filter_mkfs 2>$tmp.mkfs >/dev/null
60 . $tmp.mkfs     # extract blocksize and data size for scratch device
61
62 endsize=`expr 125 \* 1048576`   # stop after shrinking this big
63 [ `expr $endsize / $dbsize` -lt $dblocks ] || _notrun "Scratch device too small"
64
65 nags=2
66 totalcount=$((2 * TIME_FACTOR))
67
68 while [ $totalcount -gt 0 ]; do
69         size=`expr 1010 \* 1048576`     # 1010 megabytes initially
70         logblks=$(_scratch_find_xfs_min_logblocks -dsize=${size} -dagcount=${nags})
71
72         create_scratch -lsize=${logblks}b -dsize=${size} -dagcount=${nags}
73
74         for i in `seq 125 -1 90`; do
75                 fillsize=`expr $i \* 1048576`
76                 out="$(fill_scratch $fillsize 2>&1)"
77                 echo "$out" | grep -q 'No space left on device' && continue
78                 test -n "${out}" && echo "$out"
79                 break
80         done
81
82         # shrink in chunks of this size at most
83         decsize=`expr  41 \* 1048576 + 1 + $RANDOM \* $RANDOM % 1048576`
84
85         while [ $size -gt $endsize ]; do
86                 stress_scratch &
87                 sleep 1
88
89                 decb=`expr $decsize / $dbsize`    # in data blocks
90                 while [ $decb -gt 0 ]; do
91                         sizeb=`expr $size / $dbsize - $decb`
92
93                         $XFS_GROWFS_PROG -D ${sizeb} $SCRATCH_MNT \
94                                 >> $seqres.full 2>&1 && break
95
96                         [ $decb -gt 100 ] && decb=`expr $decb + $RANDOM % 10`
97                         decb=`expr $decb / 2`
98                 done
99
100                 wait
101                 [ $decb -eq 0 ] && break
102
103                 # get latest dblocks
104                 $XFS_INFO_PROG $SCRATCH_MNT 2>&1 | _filter_mkfs 2>$tmp.growfs >/dev/null
105                 . $tmp.growfs
106
107                 size=`expr $dblocks \* $dbsize`
108                 _scratch_unmount
109                 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
110                         _fail "xfs_repair failed with shrinking $sizeb"
111                 _scratch_mount
112         done
113
114         _scratch_unmount
115         _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
116                 _fail "xfs_repair failed with shrinking $sizeb"
117         totalcount=`expr $totalcount - 1`
118 done
119
120 echo "Silence is golden"
121 status=0
122 exit