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 if [ "$USE_BIG_LOOPFS" = yes ]; then
131 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
132 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
137 _scratch_xfs_db_options()
140 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
141 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
142 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
145 _scratch_xfs_logprint()
148 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
149 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
150 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
153 _scratch_xfs_repair()
156 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
157 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
158 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
159 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
166 echo "Usage: _get_pids_by_name process-name" 1>&2
170 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
171 # HH:MM:SS before the psargs field, use this as the search anchor.
173 # Matches with $1 (process-name) occur if the first psarg is $1
174 # or ends in /$1 ... the matching uses sed's regular expressions,
175 # so passing a regex into $1 will work.
183 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
184 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
192 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
195 # fix malloc libs output
199 # filter out the Electric Fence notice
202 if (defined $o && /^\s+Electric Fence/) {
208 print $o if (defined $o);
212 print $o if (defined $o);
216 # check if run as root
220 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
223 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
230 # _df_device : get an IRIX style df line for a given device
232 # - returns "" if not mounted
233 # - returns fs type in field two (ala IRIX)
234 # - joins line together if split by fancy df formatting
235 # - strips header etc
242 echo "Usage: _df_device device" 1>&2
246 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
247 match($1,what) && NF==1 {
261 # _df_dir : get an IRIX style df line for device where a directory resides
263 # - returns fs type in field two (ala IRIX)
264 # - joins line together if split by fancy df formatting
265 # - strips header etc
272 echo "Usage: _df_dir device" 1>&2
276 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
292 # return percentage used disk space for mounted device
298 echo "Usage: _used device" 1>&2
302 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
305 # return the FS type of a mounted device
311 echo "Usage: _fs_type device" 1>&2
315 _df_device $1 | $AWK_PROG '{ print $2 }'
318 # return the FS mount options of a mounted device
324 echo "Usage: _fs_options device" 1>&2
328 $AWK_PROG -v dev=$1 '
329 match($1,dev) { print $4 }
334 # returns device number if a file is a block device
340 echo "Usage: _is_block_dev dev" 1>&2
344 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
347 # Do a command, log it to $seq.full, optionally test return status
348 # and die if command fails. If called with one argument _do executes the
349 # command, logs it, and returns its exit status. With two arguments _do
350 # first prints the message passed in the first argument, and then "done"
351 # or "fail" depending on the return status of the command passed in the
352 # second argument. If the command fails and the variable _do_die_on_error
353 # is set to "always" or the two argument form is used and _do_die_on_error
354 # is set to "message_only" _do will print an error message to
359 if [ $# -eq 1 ]; then
361 elif [ $# -eq 2 ]; then
366 echo "Usage: _do [note] cmd" 1>&2
370 (eval "echo '---' \"$_cmd\"") >>$seq.full
371 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
372 cat $tmp._out | _fix_malloc >>$seq.full
373 if [ $# -eq 2 ]; then
374 if [ $ret -eq 0 ]; then
381 && [ "$_do_die_on_error" = "always" \
382 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
385 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
392 # bail out, setting up .notrun file
396 echo "$*" >$seq.notrun
397 echo "$seq not run: $*"
402 # just plain bail out
406 echo "$*" | tee -a $seq.full
407 echo "(see $seq.full for details)"
412 # this test needs a scratch partition - check we're ok & unmount it
416 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
418 _notrun "this test requires a valid \$SCRATCH_DEV"
421 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
423 _notrun "this test requires a valid \$SCRATCH_DEV"
427 if mount | grep -q $SCRATCH_DEV
429 # if it's mounted, make sure its on $SCRATCH_MNT
430 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
432 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
435 # and then unmount it
436 if ! umount $SCRATCH_DEV
438 echo "failed to unmount $SCRATCH_DEV"
444 # this test needs a logdev
448 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
449 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
450 [ "$USE_EXTERNAL" != yes ] && \
451 _notrun "This test requires USE_EXTERNAL to be enabled"
453 # ensure its not mounted
454 umount $SCRATCH_LOGDEV 2>/dev/null
457 # this test requires loopback device support
461 modprobe loop >/dev/null 2>&1
462 if grep loop /proc/devices >/dev/null 2>&1
466 _notrun "This test requires loopback device support"
470 # this test requires that (large) loopback device files are not in use
472 _require_nobigloopfs()
474 [ "$USE_BIG_LOOPFS" = yes ] && \
475 _notrun "Large filesystem testing in progress, skipped this test"
478 # this test requires that external log/realtime devices are not in use
480 _require_nonexternal()
482 [ "$USE_EXTERNAL" = yes ] && \
483 _notrun "External device testing in progress, skipped this test"
486 # check that a FS is mounted as XFS. if so, return mount point
492 echo "Usage: _xfs_mounted device" 1>&2
498 if mount | grep $device | $AWK_PROG '
499 /type xfs/ { print $3 ; exit 0 }
503 echo "_xfs_mounted: $device is not a mounted XFS FS"
509 # remount a FS to a new mode (ro or rw)
515 echo "Usage: _remount device ro/rw" 1>&2
521 if ! mount -o remount,$mode $device
523 echo "_remount: failed to remount filesystem on $device as $mode"
527 # we might like to check here later
528 #options=`_fs_options $device`
532 # run xfs_check and friends on a FS.
534 # if the filesystem is mounted, it's either remounted ro before being
535 # checked or it's unmounted and then remounted
542 if [ $# -ne 1 -a $# -ne 2 ]
544 echo "Usage: _check_fs device [logdevice]" 1>&2
549 if [ $# -eq 2 -a "$2" != "" ]; then
550 extra_log_options="-l$2"
551 extra_mount_options="-ologdev=$2"
554 [ "$FSTYP" != xfs ] && return 0
556 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
558 type=`_fs_type $device`
561 if [ "$type" = "xfs" ]
565 if [ $USE_REMOUNT -eq 0 ]
567 mountpoint=`_xfs_mounted $device`
574 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
575 | tee $tmp.fs_check | grep -q "<CLEAN>"
578 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
580 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
581 echo "*** xfs_logprint -t output ***" >>$seq.full
582 cat $tmp.fs_check >>$seq.full
583 echo "*** end xfs_logprint output" >>$seq.full
588 /usr/sbin/xfs_check $testoption $device 2>&1 | _fix_malloc >$tmp.fs_check
589 if [ -s $tmp.fs_check ]
591 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
593 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
594 echo "*** xfs_check output ***" >>$seq.full
595 cat $tmp.fs_check >>$seq.full
596 echo "*** end xfs_check output" >>$seq.full
601 # repair doesn't scale massively at this stage, optionally skip it for now
602 [ "$USE_BIG_LOOPFS" = yes ] || \
603 /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
606 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
608 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
609 echo "*** xfs_repair -n output ***" >>$seq.full
610 cat $tmp.fs_check | _fix_malloc >>$seq.full
611 echo "*** end xfs_repair output" >>$seq.full
619 echo "*** mount output ***" >>$seq.full
621 echo "*** end mount output" >>$seq.full
622 elif [ "$type" = "xfs" ]
625 if [ $USE_REMOUNT -eq 0 ]
627 if ! mount -t xfs $extra_mount_options $device $mountpoint
629 echo "!!! failed to remount $device on $mountpoint"
637 [ $ok -eq 0 ] && exit 1
644 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
645 TEST_LOG="$TEST_LOGDEV"
646 _check_filesystem $TEST_DEV $TEST_LOG
652 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
653 SCRATCH_LOG="$SCRATCH_LOGDEV"
654 _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
657 ################################################################################
659 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
660 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
662 if [ "$iam" != new -a "$iam" != bench ]
665 # make some further configuration checks here
667 if [ "$TEST_DEV" = "" ]
669 echo "common.rc: Error: \$TEST_DEV is not set"
673 # if $TEST_DEV is not mounted, mount it now as XFS
674 if [ -z "`_fs_type $TEST_DEV`" ]
676 # $TEST_DEV is not mounted
679 echo "common.rc: retrying test device mount with external set"
680 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
683 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
689 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
691 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
698 # check for some required binaries on our $PATH
700 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
702 if which $exec >/dev/null 2>&1
706 echo "common.rc: cannot find $exec on \$PATH=$PATH"
711 # make sure this script returns success