4 # Copyright (c) 2000-2002 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 -f $* $MKFS_OPTIONS
96 echo "Usage: _get_pids_by_name process-name" 1>&2
100 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
101 # HH:MM:SS before the psargs field, use this as the search anchor.
103 # Matches with $1 (process-name) occur if the first psarg is $1
104 # or ends in /$1 ... the matching uses sed's regular expressions,
105 # so passing a regex into $1 will work.
113 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
114 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
122 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
125 # fix malloc libs output
129 # filter out the Electric Fence notice
132 if (defined $o && /^\s+Electric Fence/) {
138 print $o if (defined $o);
142 print $o if (defined $o);
146 # check if run as root
150 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
153 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
160 # _df_device : get an IRIX style df line for a given device
162 # - returns "" if not mounted
163 # - returns fs type in field two (ala IRIX)
164 # - joins line together if split by fancy df formatting
165 # - strips header etc
172 echo "Usage: _df_device device" 1>&2
176 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
177 match($1,what) && NF==1 {
191 # _df_dir : get an IRIX style df line for device where a directory resides
193 # - returns fs type in field two (ala IRIX)
194 # - joins line together if split by fancy df formatting
195 # - strips header etc
202 echo "Usage: _df_dir device" 1>&2
206 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
222 # return percentage used disk space for mounted device
228 echo "Usage: _used device" 1>&2
232 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
235 # return the FS type of a mounted device
241 echo "Usage: _fs_type device" 1>&2
245 _df_device $1 | $AWK_PROG '{ print $2 }'
248 # return the FS mount options of a mounted device
254 echo "Usage: _fs_options device" 1>&2
258 $AWK_PROG -v dev=$1 '
259 match($1,dev) { print $4 }
264 # returns device number if a file is a block device
270 echo "Usage: _is_block_dev dev" 1>&2
274 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
277 # Do a command, log it to $seq.full, optionally test return status
278 # and die if command fails. If called with one argument _do executes the
279 # command, logs it, and returns its exit status. With two arguments _do
280 # first prints the message passed in the first argument, and then "done"
281 # or "fail" depending on the return status of the command passed in the
282 # second argument. If the command fails and the variable _do_die_on_error
283 # is set to "always" or the two argument form is used and _do_die_on_error
284 # is set to "message_only" _do will print an error message to
289 if [ $# -eq 1 ]; then
291 elif [ $# -eq 2 ]; then
296 echo "Usage: _do [note] cmd" 1>&2
300 (eval "echo '---' \"$_cmd\"") >>$seq.full
301 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
302 cat $tmp._out | _fix_malloc >>$seq.full
303 if [ $# -eq 2 ]; then
304 if [ $ret -eq 0 ]; then
311 && [ "$_do_die_on_error" = "always" \
312 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
315 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
322 # bail out, setting up .notrun file
326 echo "$*" >$seq.notrun
327 echo "$seq not run: $*"
332 # just plain bail out
336 echo "$*" | tee -a $seq.full
337 echo "(see $seq.full for details)"
342 # this test needs a scratch partition - check we're ok & unmount it
346 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
348 _notrun "this test requires a valid \$SCRATCH_DEV"
351 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
353 _notrun "this test requires a valid \$SCRATCH_DEV"
357 if mount | grep -q $SCRATCH_DEV
359 # if it's mounted, make sure its on $SCRATCH_MNT
360 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
362 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
365 # and then unmount it
366 if ! umount $SCRATCH_DEV
368 echo "failed to unmount $SCRATCH_DEV"
374 # this test needs a logdev
378 if [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ]
380 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
382 # ensure its not mounted
383 umount $SCRATCH_LOGDEV 2>/dev/null
386 # this test requires loopback device support
390 modprobe loop >/dev/null 2>&1
391 if grep loop /proc/devices >/dev/null 2>&1
395 _notrun "This test requires loopback device support"
399 # check that a FS is mounted as XFS. if so, return mount point
405 echo "Usage: _xfs_mounted device" 1>&2
411 if mount | grep $device | $AWK_PROG '
412 /type xfs/ { print $3 ; exit 0 }
416 echo "_xfs_mounted: $device is not a mounted XFS FS"
422 # setup the .out file link, depending on which form of quota is
423 # enabled as this often influences how the test output appears.
424 # [NB: SCRATCH_DEV must be mounted for this to work]
428 # this lets us phase use of this into the dump/restore tests easier...
429 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
433 if src/feature -U $SCRATCH_DEV
435 if src/feature -G $SCRATCH_DEV
437 ln $seq.ugquota $seq.out
439 ln $seq.usrquota $seq.out
441 elif src/feature -G $SCRATCH_DEV
443 ln $seq.grpquota $seq.out
445 ln $seq.noquota $seq.out
450 # remount a FS to a new mode (ro or rw)
456 echo "Usage: _remount device ro/rw" 1>&2
462 if ! mount -o remount,$mode $device
464 echo "_remount: failed to remount filesystem on $device as $mode"
468 # we might like to check here later
469 #options=`_fs_options $device`
473 # run xfs_check on a FS.
475 # if the filesystem is mounted, it's either remounted ro before being
476 # checked or it's unmounted and then remounted
485 echo "Usage: _check_fs device" 1>&2
490 type=`_fs_type $device`
493 if [ "$type" = "xfs" ]
497 if [ $USE_REMOUNT -eq 0 ]
499 mountpoint=`_xfs_mounted $device`
506 xfs_logprint -t $device 2>&1 | tee $tmp.fs_check | grep -q "<CLEAN>"
509 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
511 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
512 echo "*** xfs_logprint -t output ***" >>$seq.full
513 cat $tmp.fs_check >>$seq.full
514 echo "*** end xfs_logprint output" >>$seq.full
520 xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
521 if [ -s $tmp.fs_check ]
523 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
525 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
526 echo "*** xfs_check output ***" >>$seq.full
527 cat $tmp.fs_check >>$seq.full
528 echo "*** end xfs_check output" >>$seq.full
533 if ! xfs_repair -n $device >$tmp.fs_check 2>&1
535 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
537 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
538 echo "*** xfs_repair -n output ***" >>$seq.full
539 cat $tmp.fs_check | _fix_malloc >>$seq.full
540 echo "*** end xfs_repair output" >>$seq.full
548 echo "*** mount output ***" >>$seq.full
550 echo "*** end mount output" >>$seq.full
553 if [ "$type" = "xfs" ]
556 if [ $USE_REMOUNT -eq 0 ]
558 if ! mount -t xfs $device $mountpoint
560 echo "!!! failed to remount $device on $mountpoint"
568 [ $ok -eq 0 ] && exit 1
572 ################################################################################
574 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
575 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
580 # make some further configuration checks here
582 if [ "$TEST_DEV" = "" ]
584 echo "common.rc: Error: \$TEST_DEV is not set"
588 # if $TEST_DEV is not mounted, mount it now as XFS
589 if [ -z "`_fs_type $TEST_DEV`" ]
591 # $TEST_DEV is not mounted
592 if ! mount -t xfs $TEST_DEV $TEST_DIR
594 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
599 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
601 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
608 # check for some required binaries on our $PATH
610 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
612 if which $exec >/dev/null 2>&1
616 echo "common.rc: cannot find $exec on \$PATH=$PATH"
621 # make sure this script returns success