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 and mkfs.xfs so we can specify extra options
79 /bin/mount $* $MOUNT_OPTIONS
89 /sbin/mkfs.xfs $* $MKFS_OPTIONS
98 echo "Usage: _get_pids_by_name process-name" 1>&2
102 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
103 # HH:MM:SS before the psargs field, use this as the search anchor.
105 # Matches with $1 (process-name) occur if the first psarg is $1
106 # or ends in /$1 ... the matching uses sed's regular expressions,
107 # so passing a regex into $1 will work.
115 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
116 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
124 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
127 # fix malloc libs output
131 # filter out the Electric Fence notice
134 if (defined $o && /^\s+Electric Fence/) {
140 print $o if (defined $o);
144 print $o if (defined $o);
148 # check if run as root
152 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
155 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
162 # _df_device : get an IRIX style df line for a given device
164 # - returns "" if not mounted
165 # - returns fs type in field two (ala IRIX)
166 # - joins line together if split by fancy df formatting
167 # - strips header etc
174 echo "Usage: _df_device device" 1>&2
178 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
179 match($1,what) && NF==1 {
193 # _df_dir : get an IRIX style df line for device where a directory resides
195 # - returns fs type in field two (ala IRIX)
196 # - joins line together if split by fancy df formatting
197 # - strips header etc
204 echo "Usage: _df_dir device" 1>&2
208 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
224 # return percentage used disk space for mounted device
230 echo "Usage: _used device" 1>&2
234 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
237 # return the FS type of a mounted device
243 echo "Usage: _fs_type device" 1>&2
247 _df_device $1 | $AWK_PROG '{ print $2 }'
250 # return the FS mount options of a mounted device
256 echo "Usage: _fs_options device" 1>&2
260 $AWK_PROG -v dev=$1 '
261 match($1,dev) { print $4 }
266 # returns device number if a file is a block device
272 echo "Usage: _is_block_dev dev" 1>&2
276 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
279 # Do a command, log it to $seq.full, optionally test return status
280 # and die if command fails. If called with one argument _do executes the
281 # command, logs it, and returns its exit status. With two arguments _do
282 # first prints the message passed in the first argument, and then "done"
283 # or "fail" depending on the return status of the command passed in the
284 # second argument. If the command fails and the variable _do_die_on_error
285 # is set to "always" or the two argument form is used and _do_die_on_error
286 # is set to "message_only" _do will print an error message to
291 if [ $# -eq 1 ]; then
293 elif [ $# -eq 2 ]; then
298 echo "Usage: _do [note] cmd" 1>&2
302 (eval "echo '---' \"$_cmd\"") >>$seq.full
303 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
304 cat $tmp._out | _fix_malloc >>$seq.full
305 if [ $# -eq 2 ]; then
306 if [ $ret -eq 0 ]; then
313 && [ "$_do_die_on_error" = "always" \
314 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
317 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
324 # bail out, setting up .notrun file
328 echo "$*" >$seq.notrun
329 echo "$seq not run: $*"
334 # just plain bail out
338 echo "$*" | tee -a $seq.full
339 echo "(see $seq.full for details)"
344 # this test needs a scratch partition - check we're ok & unmount it
349 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
351 _notrun "this test requires a valid \$SCRATCH_DEV"
354 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
356 _notrun "this test requires a valid \$SCRATCH_DEV"
360 if mount | grep -q $SCRATCH_DEV
362 # if it's mounted, make sure its on $SCRATCH_MNT
363 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
365 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
369 # and then unmount it
371 if ! umount $SCRATCH_DEV
373 echo "failed to unmount $SCRATCH_DEV"
382 # this test needs a logdev
386 if [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ]
388 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
392 # this test requires loopback device support
396 if grep loop /proc/devices >/dev/null 2>&1
400 _notrun "This test requires loopback device support"
405 # check that a FS is mounted as XFS. if so, return mount point
411 echo "Usage: _xfs_mounted device" 1>&2
417 if mount | grep $device | $AWK_PROG '
418 /type xfs/ { print $3 ; exit 0 }
422 echo "_xfs_mounted: $device is not a mounted XFS FS"
428 # setup the .out file link, depending on which form of quota is
429 # enabled as this often influences how the test output appears.
430 # [NB: SCRATCH_DEV must be mounted for this to work]
434 # this lets us phase use of this into the dump/restore tests easier...
435 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
439 if src/feature -U $SCRATCH_DEV
441 if src/feature -G $SCRATCH_DEV
443 ln $seq.ugquota $seq.out
445 ln $seq.usrquota $seq.out
447 elif src/feature -G $SCRATCH_DEV
449 ln $seq.grpquota $seq.out
451 ln $seq.noquota $seq.out
456 # remount a FS to a new mode (ro or rw)
462 echo "Usage: _remount device ro/rw" 1>&2
468 if ! mount -o remount,$mode $device
470 echo "_remount: failed to remount filesystem on $device as $mode"
474 # we might like to check here later
475 #options=`_fs_options $device`
479 # run xfs_check on a FS.
481 # if the filesystem is mounted, it's either remounted ro before being
482 # checked or it's unmounted and then remounted
491 echo "Usage: _check_fs device" 1>&2
496 type=`_fs_type $device`
499 if [ "$type" = "xfs" ]
503 if [ $USE_REMOUNT -eq 0 ]
505 mountpoint=`_xfs_mounted $device`
512 xfs_logprint -t $device 2>&1 | tee $tmp.fs_check | grep -q "<CLEAN>"
515 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
517 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
518 echo "*** xfs_logprint -t output ***" >>$seq.full
519 cat $tmp.fs_check >>$seq.full
520 echo "*** end xfs_logprint output" >>$seq.full
526 xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
527 if [ -s $tmp.fs_check ]
529 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
531 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
532 echo "*** xfs_check output ***" >>$seq.full
533 cat $tmp.fs_check >>$seq.full
534 echo "*** end xfs_check output" >>$seq.full
539 if ! xfs_repair -n $device >$tmp.fs_check 2>&1
541 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
543 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
544 echo "*** xfs_repair -n output ***" >>$seq.full
545 cat $tmp.fs_check | _fix_malloc >>$seq.full
546 echo "*** end xfs_repair output" >>$seq.full
554 echo "*** mount output ***" >>$seq.full
556 echo "*** end mount output" >>$seq.full
559 if [ "$type" = "xfs" ]
562 if [ $USE_REMOUNT -eq 0 ]
564 if ! mount -t xfs $device $mountpoint
566 echo "!!! failed to remount $device on $mountpoint"
574 [ $ok -eq 0 ] && exit 1
578 ################################################################################
580 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
581 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
586 # make some further configuration checks here
588 if [ "$TEST_DEV" = "" ]
590 echo "common.rc: Error: \$TEST_DEV is not set"
594 # if $TEST_DEV is not mounted, mount it now as XFS
595 if [ -z "`_fs_type $TEST_DEV`" ]
597 # $TEST_DEV is not mounted
598 if ! mount -t xfs $TEST_DEV $TEST_DIR
600 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
605 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
607 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
614 # check for some required binaries on our $PATH
616 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
618 if which $exec >/dev/null 2>&1
622 echo "common.rc: cannot find $exec on \$PATH=$PATH"
627 # make sure this script returns success