4 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of version 2 of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # Further, this software is distributed without any warranty that it is
15 # free of the rightful claim of any third person regarding infringement
16 # or the like. Any license provided herein, whether implied or
17 # otherwise, applies only to this software file. Patent licenses, if
18 # any, provided herein do not apply to combinations of this program with
19 # other software, or any other product whatsoever.
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write the Free Software Foundation, Inc., 59
23 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 # Mountain View, CA 94043, or:
30 # For further information regarding this notice, see:
32 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 # we need common.config
36 if ! . ./common.config
38 echo "$iam: failed to source common.config"
42 # make sure we have a standard umask
55 # extra parameters for fsstress
56 FSSTRESS_AVOID="-f resvsp=0 -f unresvsp=0"
58 # env variables for mem checking
59 #EF_PROTECT_FREE=1 # efence
60 #export EF_PROTECT_FREE
61 # Not used because we get weird errors of form:
62 # ElectricFence Exiting: mmap() failed: Cannot allocate memory
64 export AWK_PROG PS_HAVE_BSD PS_ALL_FLAGS PLATFORM
66 # we override mount so we can specify mount options
79 /bin/mount $* $MOUNT_OPTIONS
93 echo "Usage: _get_pids_by_name process-name" 1>&2
97 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
98 # HH:MM:SS before the psargs field, use this as the search anchor.
100 # Matches with $1 (process-name) occur if the first psarg is $1
101 # or ends in /$1 ... the matching uses sed's regular expressions,
102 # so passing a regex into $1 will work.
110 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
111 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
119 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
122 # fix malloc libs output
126 # filter out the Electric Fence notice
129 if (defined $o && /^\s+Electric Fence/) {
135 print $o if (defined $o);
139 print $o if (defined $o);
143 # check if run as root
147 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
150 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
157 # _df_device : get an IRIX style df line for a given device
159 # - returns "" if not mounted
160 # - returns fs type in field two (ala IRIX)
161 # - joins line together if split by fancy df formatting
162 # - strips header etc
169 echo "Usage: _df_device device" 1>&2
173 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
174 match($1,what) && NF==1 {
188 # _df_dir : get an IRIX style df line for device where a directory resides
190 # - returns fs type in field two (ala IRIX)
191 # - joins line together if split by fancy df formatting
192 # - strips header etc
199 echo "Usage: _df_dir device" 1>&2
203 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
219 # return percentage used disk space for mounted device
225 echo "Usage: _used device" 1>&2
229 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
232 # return the FS type of a mounted device
238 echo "Usage: _fs_type device" 1>&2
242 _df_device $1 | $AWK_PROG '{ print $2 }'
245 # return the FS mount options of a mounted device
251 echo "Usage: _fs_options device" 1>&2
255 $AWK_PROG -v dev=$1 '
256 match($1,dev) { print $4 }
261 # returns device number if a file is a block device
267 echo "Usage: _is_block_dev dev" 1>&2
271 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
274 # Do a command, log it to $seq.full, optionally test return status
275 # and die if command fails. If called with one argument _do executes the
276 # command, logs it, and returns its exit status. With two arguments _do
277 # first prints the message passed in the first argument, and then "done"
278 # or "fail" depending on the return status of the command passed in the
279 # second argument. If the command fails and the variable _do_die_on_error
280 # is set to "always" or the two argument form is used and _do_die_on_error
281 # is set to "message_only" _do will print an error message to
286 if [ $# -eq 1 ]; then
288 elif [ $# -eq 2 ]; then
293 echo "Usage: _do [note] cmd" 1>&2
297 (eval "echo '---' \"$_cmd\"") >>$seq.full
298 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
299 cat $tmp._out | _fix_malloc >>$seq.full
300 if [ $# -eq 2 ]; then
301 if [ $ret -eq 0 ]; then
308 && [ "$_do_die_on_error" = "always" \
309 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
312 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
319 # bail out, setting up .notrun file
323 echo "$*" >$seq.notrun
324 echo "$seq not run: $*"
329 # just plain bail out
333 echo "$*" | tee -a $seq.full
334 echo "(see $seq.full for details)"
339 # this test needs a scratch partition - check we're ok & unmount it
344 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
346 _notrun "this test requires a valid \$SCRATCH_DEV"
349 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
351 _notrun "this test requires a valid \$SCRATCH_DEV"
355 if mount | grep -q $SCRATCH_DEV
357 # if it's mounted, make sure its on $SCRATCH_MNT
358 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
360 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
364 # and then unmount it
366 if ! umount $SCRATCH_DEV
368 echo "failed to unmount $SCRATCH_DEV"
377 # this test needs a logdev
381 if [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ]
383 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
387 # this test requires loopback device support
391 if grep loop /proc/devices >/dev/null 2>&1
395 _notrun "This test requires loopback device support"
400 # check that a FS is mounted as XFS. if so, return mount point
406 echo "Usage: _xfs_mounted device" 1>&2
412 if mount | grep $device | $AWK_PROG '
413 /type xfs/ { print $3 ; exit 0 }
417 echo "_xfs_mounted: $device is not a mounted XFS FS"
422 # remount a FS to a new mode (ro or rw)
429 echo "Usage: _remount device ro/rw" 1>&2
435 if ! mount -o remount,$mode $device
437 echo "_remount: failed to remount filesystem on $device as $mode"
441 # we might like to check here later
442 #options=`_fs_options $device`
446 # run xfs_check on a FS.
448 # if the filesystem is mounted, it's either remounted ro before being
449 # checked or it's unmounted and then remounted
458 echo "Usage: _check_fs device" 1>&2
463 type=`_fs_type $device`
466 if [ "$type" = "xfs" ]
470 if [ $USE_REMOUNT -eq 0 ]
472 mountpoint=`_xfs_mounted $device`
479 xfs_logprint -t $device 2>&1 | tee $tmp.fs_check | grep -q "<CLEAN>"
482 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
484 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
485 echo "*** xfs_logprint -t output ***" >>$seq.full
486 cat $tmp.fs_check >>$seq.full
487 echo "*** end xfs_logprint output" >>$seq.full
493 xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
494 if [ -s $tmp.fs_check ]
496 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
498 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
499 echo "*** xfs_check output ***" >>$seq.full
500 cat $tmp.fs_check >>$seq.full
501 echo "*** end xfs_check output" >>$seq.full
506 if ! xfs_repair -n $device >$tmp.fs_check 2>&1
508 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
510 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
511 echo "*** xfs_repair -n output ***" >>$seq.full
512 cat $tmp.fs_check | _fix_malloc >>$seq.full
513 echo "*** end xfs_repair output" >>$seq.full
521 echo "*** mount output ***" >>$seq.full
523 echo "*** end mount output" >>$seq.full
526 if [ "$type" = "xfs" ]
529 if [ $USE_REMOUNT -eq 0 ]
531 if ! mount -t xfs $device $mountpoint
533 echo "!!! failed to remount $device on $mountpoint"
541 [ $ok -eq 0 ] && exit 1
545 ################################################################################
547 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
548 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
553 # make some further configuration checks here
555 if [ "$TEST_DEV" = "" ]
557 echo "common.rc: Error: \$TEST_DEV is not set"
561 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
563 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
570 # check for some required biunaries on our $PATH
572 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
574 if which $exec >/dev/null 2>&1
578 echo "common.rc: cannot find $exec on \$PATH=$PATH"
583 # make sure this script returns success