4 # Copyright (c) 2000-2003 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
49 # we override mount and mkfs.xfs so we can specify extra options
62 /bin/mount $* $MOUNT_OPTIONS
73 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
74 TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
75 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
76 TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
77 [ -z "$FSTYP" ] && FSTYP=xfs
78 mount -t $FSTYP $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
81 _scratch_mount_options()
84 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
85 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
86 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
87 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
88 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
94 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
95 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
96 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
97 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
98 [ -z "$FSTYP" ] && FSTYP=xfs
99 mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
102 _scratch_mkfs_options()
105 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
106 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
107 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
108 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
109 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
114 if [ -z "$FSTYP" -o "$FSTYP" = xfs ]; then
117 /sbin/mkfs.$FSTYP $MKFS_OPTIONS $* $SCRATCH_DEV
124 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
125 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
126 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
127 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
128 /sbin/mkfs.xfs -f $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
130 [ "$USE_BIG_LOOPFS" = yes ] && \
131 ./tools/ag-wipe -c $SCRATCH_DEV >/dev/null
135 _scratch_xfs_db_options()
138 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
139 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
140 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
143 _scratch_xfs_logprint()
146 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
147 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
148 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
151 _scratch_xfs_repair()
154 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
155 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
156 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
157 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
164 echo "Usage: _get_pids_by_name process-name" 1>&2
168 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
169 # HH:MM:SS before the psargs field, use this as the search anchor.
171 # Matches with $1 (process-name) occur if the first psarg is $1
172 # or ends in /$1 ... the matching uses sed's regular expressions,
173 # so passing a regex into $1 will work.
181 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
182 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
190 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
193 # fix malloc libs output
197 # filter out the Electric Fence notice
200 if (defined $o && /^\s+Electric Fence/) {
206 print $o if (defined $o);
210 print $o if (defined $o);
214 # check if run as root
218 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
221 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
228 # _df_device : get an IRIX style df line for a given device
230 # - returns "" if not mounted
231 # - returns fs type in field two (ala IRIX)
232 # - joins line together if split by fancy df formatting
233 # - strips header etc
240 echo "Usage: _df_device device" 1>&2
244 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
245 match($1,what) && NF==1 {
259 # _df_dir : get an IRIX style df line for device where a directory resides
261 # - returns fs type in field two (ala IRIX)
262 # - joins line together if split by fancy df formatting
263 # - strips header etc
270 echo "Usage: _df_dir device" 1>&2
274 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
290 # return percentage used disk space for mounted device
296 echo "Usage: _used device" 1>&2
300 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
303 # return the FS type of a mounted device
309 echo "Usage: _fs_type device" 1>&2
313 _df_device $1 | $AWK_PROG '{ print $2 }'
316 # return the FS mount options of a mounted device
322 echo "Usage: _fs_options device" 1>&2
326 $AWK_PROG -v dev=$1 '
327 match($1,dev) { print $4 }
332 # returns device number if a file is a block device
338 echo "Usage: _is_block_dev dev" 1>&2
342 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
345 # Do a command, log it to $seq.full, optionally test return status
346 # and die if command fails. If called with one argument _do executes the
347 # command, logs it, and returns its exit status. With two arguments _do
348 # first prints the message passed in the first argument, and then "done"
349 # or "fail" depending on the return status of the command passed in the
350 # second argument. If the command fails and the variable _do_die_on_error
351 # is set to "always" or the two argument form is used and _do_die_on_error
352 # is set to "message_only" _do will print an error message to
357 if [ $# -eq 1 ]; then
359 elif [ $# -eq 2 ]; then
364 echo "Usage: _do [note] cmd" 1>&2
368 (eval "echo '---' \"$_cmd\"") >>$seq.full
369 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
370 cat $tmp._out | _fix_malloc >>$seq.full
371 if [ $# -eq 2 ]; then
372 if [ $ret -eq 0 ]; then
379 && [ "$_do_die_on_error" = "always" \
380 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
383 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
390 # bail out, setting up .notrun file
394 echo "$*" >$seq.notrun
395 echo "$seq not run: $*"
400 # just plain bail out
404 echo "$*" | tee -a $seq.full
405 echo "(see $seq.full for details)"
410 # this test needs a scratch partition - check we're ok & unmount it
414 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
416 _notrun "this test requires a valid \$SCRATCH_DEV"
419 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
421 _notrun "this test requires a valid \$SCRATCH_DEV"
425 if mount | grep -q $SCRATCH_DEV
427 # if it's mounted, make sure its on $SCRATCH_MNT
428 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
430 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
433 # and then unmount it
434 if ! umount $SCRATCH_DEV
436 echo "failed to unmount $SCRATCH_DEV"
442 # this test needs a logdev
446 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
447 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
448 [ "$USE_EXTERNAL" != yes ] && \
449 _notrun "This test requires USE_EXTERNAL to be enabled"
451 # ensure its not mounted
452 umount $SCRATCH_LOGDEV 2>/dev/null
455 # this test requires loopback device support
459 modprobe loop >/dev/null 2>&1
460 if grep loop /proc/devices >/dev/null 2>&1
464 _notrun "This test requires loopback device support"
468 # this test requires that (large) loopback device files are not in use
470 _require_nobigloopfs()
472 [ "$USE_BIG_LOOPFS" = yes ] && \
473 _notrun "Large filesystem testing in progress, skipped this test"
476 # this test requires that external log/realtime devices are not in use
478 _require_nonexternal()
480 [ "$USE_EXTERNAL" = yes ] && \
481 _notrun "External device testing in progress, skipped this test"
484 # check that a FS is mounted as XFS. if so, return mount point
490 echo "Usage: _xfs_mounted device" 1>&2
496 if mount | grep $device | $AWK_PROG '
497 /type xfs/ { print $3 ; exit 0 }
501 echo "_xfs_mounted: $device is not a mounted XFS FS"
507 # remount a FS to a new mode (ro or rw)
513 echo "Usage: _remount device ro/rw" 1>&2
519 if ! mount -o remount,$mode $device
521 echo "_remount: failed to remount filesystem on $device as $mode"
525 # we might like to check here later
526 #options=`_fs_options $device`
530 # run xfs_check and friends on a FS.
532 # if the filesystem is mounted, it's either remounted ro before being
533 # checked or it's unmounted and then remounted
540 if [ $# -ne 1 -a $# -ne 2 ]
542 echo "Usage: _check_fs device [logdevice]" 1>&2
547 if [ $# -eq 2 -a "$2" != "" ]; then
548 extra_log_options="-l$2"
549 extra_mount_options="-ologdev=$2"
552 [ "$FSTYP" != xfs ] && return 0
554 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
556 type=`_fs_type $device`
559 if [ "$type" = "xfs" ]
563 if [ $USE_REMOUNT -eq 0 ]
565 mountpoint=`_xfs_mounted $device`
572 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
573 | tee $tmp.fs_check | grep -q "<CLEAN>"
576 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
578 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
579 echo "*** xfs_logprint -t output ***" >>$seq.full
580 cat $tmp.fs_check >>$seq.full
581 echo "*** end xfs_logprint output" >>$seq.full
586 /usr/sbin/xfs_check $testoption $device 2>&1 | _fix_malloc >$tmp.fs_check
587 if [ -s $tmp.fs_check ]
589 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
591 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
592 echo "*** xfs_check output ***" >>$seq.full
593 cat $tmp.fs_check >>$seq.full
594 echo "*** end xfs_check output" >>$seq.full
599 if ! /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
601 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
603 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
604 echo "*** xfs_repair -n output ***" >>$seq.full
605 cat $tmp.fs_check | _fix_malloc >>$seq.full
606 echo "*** end xfs_repair output" >>$seq.full
614 echo "*** mount output ***" >>$seq.full
616 echo "*** end mount output" >>$seq.full
617 elif [ "$type" = "xfs" ]
620 if [ $USE_REMOUNT -eq 0 ]
622 if ! mount -t xfs $extra_mount_options $device $mountpoint
624 echo "!!! failed to remount $device on $mountpoint"
632 [ $ok -eq 0 ] && exit 1
639 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
640 TEST_LOG="$TEST_LOGDEV"
641 _check_filesystem $TEST_DEV $TEST_LOG
647 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
648 SCRATCH_LOG="$SCRATCH_LOGDEV"
649 _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
652 ################################################################################
654 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
655 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
657 if [ "$iam" != new -a "$iam" != bench ]
660 # make some further configuration checks here
662 if [ "$TEST_DEV" = "" ]
664 echo "common.rc: Error: \$TEST_DEV is not set"
668 # if $TEST_DEV is not mounted, mount it now as XFS
669 if [ -z "`_fs_type $TEST_DEV`" ]
671 # $TEST_DEV is not mounted
674 echo "common.rc: retrying test device mount with external set"
675 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
678 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
684 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
686 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
693 # check for some required binaries on our $PATH
695 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
697 if which $exec >/dev/null 2>&1
701 echo "common.rc: cannot find $exec on \$PATH=$PATH"
706 # make sure this script returns success