xfs: test that the needsrepair feature works as advertised
[xfstests-dev.git] / soak
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5
6 # get standard environment, filters and checks
7 . ./common/rc
8 . ./common/filter
9
10 tmp=/tmp/$$
11 seq=soak
12 status=1        # failure is the default!
13
14 _cleanup()
15 {
16     echo "        *** umount"
17     _scratch_unmount >/dev/null 2>&1
18 }
19
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 ROOT="."
23 LOG="$ROOT/soak.log"
24 FULL="$ROOT/soak.full"
25
26 _log()
27 {
28     echo "$*" 1>&2
29     echo "$*" >>$LOG
30     echo "$*" >>$FULL
31 }
32
33 _logp()
34 {
35     tee -a $FULL
36 }
37
38 _fail()
39 {
40     _log "$*"
41     status=1
42     exit 1
43 }
44
45 _require_scratch
46
47 passes=-1
48 stress=100000
49 proc=1
50
51 if [ $# -gt 0 ]
52 then
53     passes=$1
54     if [ $# -gt 1 ]
55     then
56         stress=$2
57         if [ $# -gt 2 ]
58         then
59             proc=$3
60         fi
61     fi
62 fi
63
64 echo "" >$FULL
65 echo "" >$LOG
66 _log "*** soak test started (passes=$passes, stress=$stress, proc=$proc)"
67 _log "***     (`date`)"
68
69
70 _log "    *** init"
71 _log "        *** unmounting scratch device"
72
73 _scratch_unmount 2>&1 >>$FULL
74
75 _log "        *** clean scratch device"
76
77 mkfs_xfs -f $SCRATCH_DEV 2>&1 >>$FULL \
78                         || _fail "            !!! failed to mkfs SCRATCH_DEV"
79
80 pass=1
81
82 while [ $pass -le $passes -o $passes -lt 0 ]
83 do
84     _log "    *** pass $pass (`date`)"
85     
86     _log "        *** check"
87     _check_scratch_fs
88     
89     _log "        *** mounting scratch device"
90
91     if ! _scratch_mount 2>&1 | _logp
92     then
93         _fail "            !!! failed to mount"
94     fi
95                         
96     if [ $pass != 1 ]
97     then
98         _log "        *** cleanup"
99         rm -rf $SCRATCH_MNT/soak_test \
100                         || _fail "            !!! couldn't delete old dir"
101
102         _log "        *** check"
103         _check_scratch_fs
104     fi
105
106     _log "        *** mkdir"
107     mkdir $SCRATCH_MNT/soak_test \
108                         || _fail "            !!! couldn't delete old dir"
109     
110     _log "        *** stress"
111     ltp/fsstress -d $SCRATCH_MNT/soak_test -p $proc -n $stress $FSSTRESS_AVOID 2>&1 | \
112         >>$FULL
113
114     _log "        *** unmounting scratch device"
115
116     _scratch_unmount 2>&1 | _logp \
117                             || _fail "            !!! failed to umount"
118     
119     let "pass = pass + 1"
120 done
121