3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5 # xfscrash - control the XFS crash tests
8 #######################
9 ### configuration stuff ########################################################
10 #######################
12 # remount, repair or corrupt
14 # where to find xfscrash
18 # put output to these places
19 OUTPUT="$LOG/xfscrash.log /dev/tty1 /dev/console"
22 # clear FS if >= this percent full at start of run. 100 is a good
23 # number - only used on corrupt test so far
29 # mount test partition here
31 # build test partition here
33 # backup test partition to here (or empty)
35 # backup block size for dd
43 # mount test partition here
44 TEST_MNT=/mnt/scratch_0
45 # build test partition here
47 # backup test partition to here (or empty)
48 BACKUP_DEV= ;#/dev/sdc6
49 # backup block size for dd
57 echo "!!! no configuration data for host `hostname -s`"
64 AVOID="-f resvsp=0 -f unresvsp=0"
67 STRESS="/usr/local/bin/fsstress -d $TEST_MNT/stress -n 10000000 -p 1 $AVOID"
68 #STRESS="/usr/local/bin/randholes -l 10000000 -c 100000 -b 512 $TEST_MNT/stress/holes"
70 # stress command for the corrupt test
71 CORRUPT_STRESS="/usr/local/bin/fsstress -d $TEST_MNT/stress -n 10000 -p 1 $AVOID"
73 ###########################################################################
79 tee -a $OUTPUT > /dev/null
89 _echo " *** Mounting $TEST_DEV on $TEST_MNT"
90 if ! mount -t xfs $TEST_DEV $TEST_MNT
92 _echo " !!! unable to mount"
99 _echo " *** Unmounting $TEST_DEV"
100 if ! umount $TEST_DEV &> /dev/null
102 _echo " !!! unable to unmount"
114 _echo " *** Checking FS (expecting clean fs)"
116 _echo " *** Checking FS (expecting dirty fs)"
122 _echo " *** xfs_check ($LOG/check_clean.out)"
123 _xfs_check $TEST_DEV &> $LOG/check_clean.out || fail=1
124 [ -s /tmp/xfs_check_clean.out ] && fail=1
126 _echo " *** xfs_check ($LOG/check_dirty.out)"
127 _xfs_check $TEST_DEV &> $LOG/check_dirty.out || fail=1
130 if [ $fail -eq 0 -a $expect -eq 0 ]
132 _echo " *** xfs_repair -n ($LOG/repair_clean.out)"
133 xfs_repair -n $TEST_DEV &> $LOG/repair_clean.out || fail=1
138 _echo " *** FS checks ok"
142 _echo " !!! FS check failed - inconsistent FS"
143 _echo " !!! (see $LOG/*.out for details)"
146 _echo " *** inconsistent fs (as expected)"
155 _echo " !!! core file found!"
164 _echo " *** repair pass 1 (RO)"
165 xfs_repair -n $TEST_DEV &> $LOG/repair_1.out \
166 && _echo " !!! no errors found (eh?)" \
167 || _echo " *** errors found (expected)"
171 _echo " *** repair pass 2 (RW)"
173 if xfs_repair $TEST_DEV &> $LOG/repair_2.out
175 _echo " *** FS checks ok (now)"
177 _echo " !!! xfs_repair returned error code"
178 _echo " !!! (see $LOG/repair_*.out for details)"
184 _echo " *** repair pass 3 (RO)"
185 if xfs_repair -n $TEST_DEV &> $LOG/repair_3.out
187 _echo " *** FS checks ok"
189 _echo " !!! errors found after repair (unexpected)"
190 _echo " !!! (see $LOG/repair_*.out for details)"
199 rm -f $XFSCRASH/counter $XFSCRASH/start $XFSCRASH/stop $XFSCRASH/active
210 od -tu -N 4 /dev/random | gawk -v v=$1 'NR==1 { print $2 % v }'
215 if [ $count -ne 1 -a "$BACKUP_DEV" != "" ]
217 _echo " *** Backing up $TEST_DEV to $BACKUP_DEV"
218 if ! dd if=$TEST_DEV of=$BACKUP_DEV bs=$BACKUP_BS &> $LOG/dd.out
220 _echo " !!! unable to backup fs"
221 _echo " !!! (see $LOG/dd.out)"
225 _echo " *** skipping back up step"
231 _echo " *** dumping log to $LOG/logprint.out"
233 xfs_logprint $TEST_DEV &> $LOG/logprint.out
236 _echo " !!! xfs_logprint dumped core"
237 echo "" >> $LOG/logprint.out
238 echo "*** CORE DUMPED ***" >> $LOG/logprint.out
239 echo "" >> $LOG/logprint.out
242 _echo " *** dumping log (-t -i) to $LOG/logprint_inode.out"
245 xfs_logprint -t -i $TEST_DEV &> $LOG/logprint_inode.out
248 _echo " !!! xfs_logprint dumped core"
249 echo "" >> $LOG/logprint_inode.out
250 echo "*** CORE DUMPED ***" >> $LOG/logprint_inode.out
251 echo "" >> $LOG/logprint_inode.out
254 _echo " *** dumping log (-t -b) to $LOG/logprint_buf.out"
257 xfs_logprint -t -b $TEST_DEV &> $LOG/logprint_buf.out
260 _echo " !!! xfs_logprint dumped core"
261 echo "" >> $LOG/logprint_buf.out
262 echo "*** CORE DUMPED ***" >> $LOG/logprint_buf.out
263 echo "" >> $LOG/logprint_buf.out
267 # _df_device : get an IRIX style df line for a given device
269 # - returns "" if not mounted
270 # - returns fs type in field two (ala IRIX)
271 # - joins line together if split by fancy df formatting
272 # - strips header etc
279 echo "Usage: _df_device device" >&2
283 df -T 2> /dev/null | $AWK_PROG -v what=$1 '
284 match($1,what) && NF==1 {
298 # _df_dir : get an IRIX style df line for device where a directory resides
300 # - returns fs type in field two (ala IRIX)
301 # - joins line together if split by fancy df formatting
302 # - strips header etc
309 echo "Usage: _df_dir device" >&2
313 df -T $1 2> /dev/null | $AWK_PROG -v what=$1 '
329 # return percentage used disk space for mounted device
335 echo "Usage: _used device" >&2
339 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
344 used=`_used $TEST_DEV`
346 if [ $used -ge $FULL_LIMIT ]
348 _echo " *** $used % used on $TEST_DEV - deleting files"
349 rm -rf $TEST_MNT/stress
353 # loop, stressing, unounting and checking
354 # no (expected) rebooting...
359 # don't want to restart if we reboot...
365 if [ -e $XFSCRASH/stop ]
367 _echo "### XFS Crash stopped "
371 _echo "*** run $count"
372 let "count = count + 1"
379 $CORRUPT_STRESS | _log
385 ###########################################################################
389 echo "XFSCRASH [output to $OUTPUT]"
392 if [ "$1" = "start" ]
394 touch $XFSCRASH/start
403 trap "_cleanup; exit \$status" 0 1 2 3 15
406 if [ -e $XFSCRASH/stop ]
408 _echo "### XFS Crash stopped "
412 if [ -e $XFSCRASH/start ]
414 _echo "### XFS Crash started "
416 rm -f $LOG/*.out $LOG/*.log core
418 touch $XFSCRASH/active
420 _echo " *** Building fresh XFS FS"
421 umount $TEST_DEV &> /dev/null
422 if ! mkfs -t xfs -f $TEST_DEV &> $LOG/mkfs.out
424 _echo " !!! unable to mkfs"
425 _echo " !!! (see $LOG/mkfs.out)"
430 if [ ! -e $XFSCRASH/active ]
432 _echo "### XFS Crash inactive "
437 if [ -r $XFSCRASH/counter ]
439 count=`cat $XFSCRASH/counter`
443 _echo "### Crash test run $count (mode=$MODE, log=$LOG/{*.out,*.log})"
445 let "count = count +1"
446 echo $count > $XFSCRASH/counter
448 # real test starts here
450 _echo " *** Checking for R/O root"
451 if ! mount | grep "on / type" | grep -q "(ro)"
453 _echo " !!! root not mounted readonly"
457 _echo " *** Loading XFS modules"
460 _echo " !!! unable to modprobe xfs"
464 _echo " *** Unmounting $TEST_DEV"
465 umount $TEST_DEV &> /dev/null
468 if [ $MODE != "corrupt" ]
476 _check 1 # expect errors
488 _echo "xfscrash: MODE must be remount or repair"
493 _check 0 # don't expect errors
496 _echo " *** Cleaning XFS FS"
497 if ! rm -rf $TEST_MNT/stress $TEST_MNT/lost+found &> $LOG/clean.out
499 _echo " !!! unable to clean XFS FS"
500 _echo " !!! (see $LOG/clean.out)"
504 _echo " *** Making stress directory"
505 if ! mkdir $TEST_MNT/stress
507 _echo " !!! unable to mkdir stress"
511 let "bang = STRESS_TIME + `_random $STRESS_RANDOM`"
513 _echo " *** Preparing random reboot (in $bang seconds)"
516 _echo " *** BANG ****"
521 _echo " *** Causing stress & waiting for the inevitable"