common: use mount/umount helpers everywhere
[xfstests-dev.git] / soak
1 #!/bin/bash
2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 #
18 #-----------------------------------------------------------------------
19 #
20
21 # get standard environment, filters and checks
22 . ./common/rc
23 . ./common/filter
24
25 tmp=/tmp/$$
26 seq=soak
27 status=1        # failure is the default!
28
29 _cleanup()
30 {
31     echo "        *** umount"
32     _scratch_unmount >/dev/null 2>&1
33 }
34
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 ROOT="."
38 LOG="$ROOT/soak.log"
39 FULL="$ROOT/soak.full"
40
41 _log()
42 {
43     echo "$*" 1>&2
44     echo "$*" >>$LOG
45     echo "$*" >>$FULL
46 }
47
48 _logp()
49 {
50     tee -a $FULL
51 }
52
53 _fail()
54 {
55     _log "$*"
56     status=1
57     exit 1
58 }
59
60 _require_scratch
61
62 passes=-1
63 stress=100000
64 proc=1
65
66 if [ $# -gt 0 ]
67 then
68     passes=$1
69     if [ $# -gt 1 ]
70     then
71         stress=$2
72         if [ $# -gt 2 ]
73         then
74             proc=$3
75         fi
76     fi
77 fi
78
79 echo "" >$FULL
80 echo "" >$LOG
81 _log "*** soak test started (passes=$passes, stress=$stress, proc=$proc)"
82 _log "***     (`date`)"
83
84
85 _log "    *** init"
86 _log "        *** unmounting scratch device"
87
88 _scratch_unmount 2>&1 |  _fix_malloc >>$FULL
89
90 _log "        *** clean scratch device"
91
92 mkfs_xfs -f $SCRATCH_DEV 2>&1 |  _fix_malloc >>$FULL \
93                         || _fail "            !!! failed to mkfs SCRATCH_DEV"
94
95 pass=1
96
97 while [ $pass -le $passes -o $passes -lt 0 ]
98 do
99     _log "    *** pass $pass (`date`)"
100     
101     _log "        *** check"
102     _check_scratch_fs
103     
104     _log "        *** mounting scratch device"
105
106     if ! _scratch_mount 2>&1 | _logp
107     then
108         _fail "            !!! failed to mount"
109     fi
110                         
111     if [ $pass != 1 ]
112     then
113         _log "        *** cleanup"
114         rm -rf $SCRATCH_MNT/soak_test \
115                         || _fail "            !!! couldn't delete old dir"
116
117         _log "        *** check"
118         _check_scratch_fs
119     fi
120
121     _log "        *** mkdir"
122     mkdir $SCRATCH_MNT/soak_test \
123                         || _fail "            !!! couldn't delete old dir"
124     
125     _log "        *** stress"
126     ltp/fsstress -d $SCRATCH_MNT/soak_test -p $proc -n $stress $FSSTRESS_AVOID 2>&1 | \
127         _fix_malloc >>$FULL
128
129     _log "        *** unmounting scratch device"
130
131     _scratch_unmount 2>&1 | _logp \
132                             || _fail "            !!! failed to umount"
133     
134     let "pass = pass + 1"
135 done
136