3 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like. Any license provided herein, whether implied or
16 # otherwise, applies only to this software file. Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA 94043, or:
29 # For further information regarding this notice, see:
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 # xfscrash - control the XFS crash tests
36 #######################
37 ### configuration stuff ########################################################
38 #######################
40 # remount, repair or corrupt
42 # where to find xfscrash
46 # put output to these places
47 OUTPUT="$LOG/xfscrash.log /dev/tty1 /dev/console"
50 # clear FS if >= this percent full at start of run. 100 is a good
51 # number - only used on corrupt test so far
57 # mount test partition here
59 # build test partition here
61 # backup test partition to here (or empty)
63 # backup block size for dd
71 # mount test partition here
72 TEST_MNT=/mnt/scratch_0
73 # build test partition here
75 # backup test partition to here (or empty)
76 BACKUP_DEV= ;#/dev/sdc6
77 # backup block size for dd
85 echo "!!! no configuration data for host `hostname -s`"
92 AVOID="-f resvsp=0 -f unresvsp=0"
95 STRESS="/usr/local/bin/fsstress -d $TEST_MNT/stress -n 10000000 -p 1 $AVOID"
96 #STRESS="/usr/local/bin/randholes -l 10000000 -c 100000 -b 512 $TEST_MNT/stress/holes"
98 # stress command for the corrupt test
99 CORRUPT_STRESS="/usr/local/bin/fsstress -d $TEST_MNT/stress -n 10000 -p 1 $AVOID"
101 ###########################################################################
107 tee -a $OUTPUT > /dev/null
117 _echo " *** Mounting $TEST_DEV on $TEST_MNT"
118 if ! mount -t xfs $TEST_DEV $TEST_MNT
120 _echo " !!! unable to mount"
127 _echo " *** Unmounting $TEST_DEV"
128 if ! umount $TEST_DEV &> /dev/null
130 _echo " !!! unable to unmount"
142 _echo " *** Checking FS (expecting clean fs)"
144 _echo " *** Checking FS (expecting dirty fs)"
150 _echo " *** xfs_check ($LOG/check_clean.out)"
151 xfs_check $TEST_DEV &> $LOG/check_clean.out || fail=1
152 [ -s /tmp/xfs_check_clean.out ] && fail=1
154 _echo " *** xfs_check ($LOG/check_dirty.out)"
155 xfs_check $TEST_DEV &> $LOG/check_dirty.out || fail=1
158 if [ $fail -eq 0 -a $expect -eq 0 ]
160 _echo " *** xfs_repair -n ($LOG/repair_clean.out)"
161 xfs_repair -n $TEST_DEV &> $LOG/repair_clean.out || fail=1
166 _echo " *** FS checks ok"
170 _echo " !!! FS check failed - inconsistent FS"
171 _echo " !!! (see $LOG/*.out for details)"
174 _echo " *** inconsistent fs (as expected)"
183 _echo " !!! core file found!"
192 _echo " *** repair pass 1 (RO)"
193 xfs_repair -n $TEST_DEV &> $LOG/repair_1.out \
194 && _echo " !!! no errors found (eh?)" \
195 || _echo " *** errors found (expected)"
199 _echo " *** repair pass 2 (RW)"
201 if xfs_repair $TEST_DEV &> $LOG/repair_2.out
203 _echo " *** FS checks ok (now)"
205 _echo " !!! xfs_repair returned error code"
206 _echo " !!! (see $LOG/repair_*.out for details)"
212 _echo " *** repair pass 3 (RO)"
213 if xfs_repair -n $TEST_DEV &> $LOG/repair_3.out
215 _echo " *** FS checks ok"
217 _echo " !!! errors found after repair (unexpected)"
218 _echo " !!! (see $LOG/repair_*.out for details)"
227 rm -f $XFSCRASH/counter $XFSCRASH/start $XFSCRASH/stop $XFSCRASH/active
238 od -tu -N 4 /dev/random | gawk -v v=$1 'NR==1 { print $2 % v }'
243 if [ $count -ne 1 -a "$BACKUP_DEV" != "" ]
245 _echo " *** Backing up $TEST_DEV to $BACKUP_DEV"
246 if ! dd if=$TEST_DEV of=$BACKUP_DEV bs=$BACKUP_BS &> $LOG/dd.out
248 _echo " !!! unable to backup fs"
249 _echo " !!! (see $LOG/dd.out)"
253 _echo " *** skipping back up step"
259 _echo " *** dumping log to $LOG/logprint.out"
261 xfs_logprint $TEST_DEV &> $LOG/logprint.out
264 _echo " !!! xfs_logprint dumped core"
265 echo "" >> $LOG/logprint.out
266 echo "*** CORE DUMPED ***" >> $LOG/logprint.out
267 echo "" >> $LOG/logprint.out
270 _echo " *** dumping log (-t -i) to $LOG/logprint_inode.out"
273 xfs_logprint -t -i $TEST_DEV &> $LOG/logprint_inode.out
276 _echo " !!! xfs_logprint dumped core"
277 echo "" >> $LOG/logprint_inode.out
278 echo "*** CORE DUMPED ***" >> $LOG/logprint_inode.out
279 echo "" >> $LOG/logprint_inode.out
282 _echo " *** dumping log (-t -b) to $LOG/logprint_buf.out"
285 xfs_logprint -t -b $TEST_DEV &> $LOG/logprint_buf.out
288 _echo " !!! xfs_logprint dumped core"
289 echo "" >> $LOG/logprint_buf.out
290 echo "*** CORE DUMPED ***" >> $LOG/logprint_buf.out
291 echo "" >> $LOG/logprint_buf.out
295 # _df_device : get an IRIX style df line for a given device
297 # - returns "" if not mounted
298 # - returns fs type in field two (ala IRIX)
299 # - joins line together if split by fancy df formatting
300 # - strips header etc
307 echo "Usage: _df_device device" >&2
311 df -T 2> /dev/null | $AWK_PROG -v what=$1 '
312 match($1,what) && NF==1 {
326 # _df_dir : get an IRIX style df line for device where a directory resides
328 # - returns fs type in field two (ala IRIX)
329 # - joins line together if split by fancy df formatting
330 # - strips header etc
337 echo "Usage: _df_dir device" >&2
341 df -T $1 2> /dev/null | $AWK_PROG -v what=$1 '
357 # return percentage used disk space for mounted device
363 echo "Usage: _used device" >&2
367 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
372 used=`_used $TEST_DEV`
374 if [ $used -ge $FULL_LIMIT ]
376 _echo " *** $used % used on $TEST_DEV - deleting files"
377 rm -rf $TEST_MNT/stress
381 # loop, stressing, unounting and checking
382 # no (expected) rebooting...
387 # don't want to restart if we reboot...
393 if [ -e $XFSCRASH/stop ]
395 _echo "### XFS Crash stopped "
399 _echo "*** run $count"
400 let "count = count + 1"
407 $CORRUPT_STRESS | _log
413 ###########################################################################
417 echo "XFSCRASH [output to $OUTPUT]"
420 if [ "$1" = "start" ]
422 touch $XFSCRASH/start
431 trap "_cleanup; exit \$status" 0 1 2 3 15
434 if [ -e $XFSCRASH/stop ]
436 _echo "### XFS Crash stopped "
440 if [ -e $XFSCRASH/start ]
442 _echo "### XFS Crash started "
444 rm -f $LOG/*.out $LOG/*.log core
446 touch $XFSCRASH/active
448 _echo " *** Building fresh XFS FS"
449 umount $TEST_DEV &> /dev/null
450 if ! mkfs -t xfs -f $TEST_DEV &> $LOG/mkfs.out
452 _echo " !!! unable to mkfs"
453 _echo " !!! (see $LOG/mkfs.out)"
458 if [ ! -e $XFSCRASH/active ]
460 _echo "### XFS Crash inactive "
465 if [ -r $XFSCRASH/counter ]
467 count=`cat $XFSCRASH/counter`
471 _echo "### Crash test run $count (mode=$MODE, log=$LOG/{*.out,*.log})"
473 let "count = count +1"
474 echo $count > $XFSCRASH/counter
476 # real test starts here
478 _echo " *** Checking for R/O root"
479 if ! mount | grep "on / type" | grep -q "(ro)"
481 _echo " !!! root not mounted readonly"
485 _echo " *** Loading XFS modules"
488 _echo " !!! unable to modprobe xfs"
492 _echo " *** Unmounting $TEST_DEV"
493 umount $TEST_DEV &> /dev/null
496 if [ $MODE != "corrupt" ]
504 _check 1 # expect errors
516 _echo "xfscrash: MODE must be remount or repair"
521 _check 0 # don't expect errors
524 _echo " *** Cleaning XFS FS"
525 if ! rm -rf $TEST_MNT/stress $TEST_MNT/lost+found &> $LOG/clean.out
527 _echo " !!! unable to clean XFS FS"
528 _echo " !!! (see $LOG/clean.out)"
532 _echo " *** Making stress directory"
533 if ! mkdir $TEST_MNT/stress
535 _echo " !!! unable to mkdir stress"
539 let "bang = STRESS_TIME + `_random $STRESS_RANDOM`"
541 _echo " *** Preparing random reboot (in $bang seconds)"
544 _echo " *** BANG ****"
549 _echo " *** Causing stress & waiting for the inevitable"