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 mount -t xfs $TEST_OPTIONS $MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
80 _scratch_mount_options()
83 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
84 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
85 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
86 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
87 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
93 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
94 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
95 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
96 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
97 mount -t xfs $SCRATCH_OPTIONS $MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
100 _scratch_mkfs_options()
103 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
104 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
105 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
106 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
107 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
113 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
114 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
115 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
116 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
117 /sbin/mkfs.xfs -f $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
120 _scratch_xfs_db_options()
123 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
124 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
125 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
128 _scratch_xfs_logprint()
131 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
132 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
133 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
136 _scratch_xfs_repair()
139 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
140 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
141 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
148 echo "Usage: _get_pids_by_name process-name" 1>&2
152 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
153 # HH:MM:SS before the psargs field, use this as the search anchor.
155 # Matches with $1 (process-name) occur if the first psarg is $1
156 # or ends in /$1 ... the matching uses sed's regular expressions,
157 # so passing a regex into $1 will work.
165 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
166 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
174 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
177 # fix malloc libs output
181 # filter out the Electric Fence notice
184 if (defined $o && /^\s+Electric Fence/) {
190 print $o if (defined $o);
194 print $o if (defined $o);
198 # check if run as root
202 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
205 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
212 # _df_device : get an IRIX style df line for a given device
214 # - returns "" if not mounted
215 # - returns fs type in field two (ala IRIX)
216 # - joins line together if split by fancy df formatting
217 # - strips header etc
224 echo "Usage: _df_device device" 1>&2
228 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
229 match($1,what) && NF==1 {
243 # _df_dir : get an IRIX style df line for device where a directory resides
245 # - returns fs type in field two (ala IRIX)
246 # - joins line together if split by fancy df formatting
247 # - strips header etc
254 echo "Usage: _df_dir device" 1>&2
258 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
274 # return percentage used disk space for mounted device
280 echo "Usage: _used device" 1>&2
284 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
287 # return the FS type of a mounted device
293 echo "Usage: _fs_type device" 1>&2
297 _df_device $1 | $AWK_PROG '{ print $2 }'
300 # return the FS mount options of a mounted device
306 echo "Usage: _fs_options device" 1>&2
310 $AWK_PROG -v dev=$1 '
311 match($1,dev) { print $4 }
316 # returns device number if a file is a block device
322 echo "Usage: _is_block_dev dev" 1>&2
326 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
329 # Do a command, log it to $seq.full, optionally test return status
330 # and die if command fails. If called with one argument _do executes the
331 # command, logs it, and returns its exit status. With two arguments _do
332 # first prints the message passed in the first argument, and then "done"
333 # or "fail" depending on the return status of the command passed in the
334 # second argument. If the command fails and the variable _do_die_on_error
335 # is set to "always" or the two argument form is used and _do_die_on_error
336 # is set to "message_only" _do will print an error message to
341 if [ $# -eq 1 ]; then
343 elif [ $# -eq 2 ]; then
348 echo "Usage: _do [note] cmd" 1>&2
352 (eval "echo '---' \"$_cmd\"") >>$seq.full
353 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
354 cat $tmp._out | _fix_malloc >>$seq.full
355 if [ $# -eq 2 ]; then
356 if [ $ret -eq 0 ]; then
363 && [ "$_do_die_on_error" = "always" \
364 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
367 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
374 # bail out, setting up .notrun file
378 echo "$*" >$seq.notrun
379 echo "$seq not run: $*"
384 # just plain bail out
388 echo "$*" | tee -a $seq.full
389 echo "(see $seq.full for details)"
394 # this test needs a scratch partition - check we're ok & unmount it
398 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
400 _notrun "this test requires a valid \$SCRATCH_DEV"
403 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
405 _notrun "this test requires a valid \$SCRATCH_DEV"
409 if mount | grep -q $SCRATCH_DEV
411 # if it's mounted, make sure its on $SCRATCH_MNT
412 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
414 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
417 # and then unmount it
418 if ! umount $SCRATCH_DEV
420 echo "failed to unmount $SCRATCH_DEV"
426 # this test needs a logdev
430 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
431 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
432 [ "$USE_EXTERNAL" != yes ] && \
433 _notrun "This test requires USE_EXTERNAL to be enabled"
435 # ensure its not mounted
436 umount $SCRATCH_LOGDEV 2>/dev/null
439 # this test requires loopback device support
443 modprobe loop >/dev/null 2>&1
444 if grep loop /proc/devices >/dev/null 2>&1
448 _notrun "This test requires loopback device support"
452 # check that a FS is mounted as XFS. if so, return mount point
458 echo "Usage: _xfs_mounted device" 1>&2
464 if mount | grep $device | $AWK_PROG '
465 /type xfs/ { print $3 ; exit 0 }
469 echo "_xfs_mounted: $device is not a mounted XFS FS"
475 # setup the .out file link, depending on which form of quota is
476 # enabled as this often influences how the test output appears.
477 # [NB: SCRATCH_DEV must be mounted for this to work]
481 # this lets us phase use of this into the dump/restore tests easier...
482 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
486 if src/feature -U $SCRATCH_DEV
488 if src/feature -G $SCRATCH_DEV
490 ln $seq.ugquota $seq.out
492 ln $seq.usrquota $seq.out
494 elif src/feature -G $SCRATCH_DEV
496 ln $seq.grpquota $seq.out
498 ln $seq.noquota $seq.out
503 # remount a FS to a new mode (ro or rw)
509 echo "Usage: _remount device ro/rw" 1>&2
515 if ! mount -o remount,$mode $device
517 echo "_remount: failed to remount filesystem on $device as $mode"
521 # we might like to check here later
522 #options=`_fs_options $device`
526 # run xfs_check and friends on a FS.
528 # if the filesystem is mounted, it's either remounted ro before being
529 # checked or it's unmounted and then remounted
536 if [ $# -ne 1 -a $# -ne 2 ]
538 echo "Usage: _check_fs device [logdevice]" 1>&2
543 if [ $# -eq 2 -a "$2" != "" ]; then
544 extra_log_options="-l$2"
545 extra_mount_options="-ologdev=$2"
547 type=`_fs_type $device`
550 if [ "$type" = "xfs" ]
554 if [ $USE_REMOUNT -eq 0 ]
556 mountpoint=`_xfs_mounted $device`
563 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
564 | tee $tmp.fs_check | grep -q "<CLEAN>"
567 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
569 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
570 echo "*** xfs_logprint -t output ***" >>$seq.full
571 cat $tmp.fs_check >>$seq.full
572 echo "*** end xfs_logprint output" >>$seq.full
577 /usr/sbin/xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
578 if [ -s $tmp.fs_check ]
580 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
582 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
583 echo "*** xfs_check output ***" >>$seq.full
584 cat $tmp.fs_check >>$seq.full
585 echo "*** end xfs_check output" >>$seq.full
590 if ! /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
592 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
594 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
595 echo "*** xfs_repair -n output ***" >>$seq.full
596 cat $tmp.fs_check | _fix_malloc >>$seq.full
597 echo "*** end xfs_repair output" >>$seq.full
605 echo "*** mount output ***" >>$seq.full
607 echo "*** end mount output" >>$seq.full
608 elif [ "$type" = "xfs" ]
611 if [ $USE_REMOUNT -eq 0 ]
613 if ! mount -t xfs $extra_mount_options $device $mountpoint
615 echo "!!! failed to remount $device on $mountpoint"
623 [ $ok -eq 0 ] && exit 1
630 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
631 TEST_LOG="$TEST_LOGDEV"
632 _check_filesystem $TEST_DEV $TEST_LOG
638 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
639 SCRATCH_LOG="$SCRATCH_LOGDEV"
640 _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
643 ################################################################################
645 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
646 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
651 # make some further configuration checks here
653 if [ "$TEST_DEV" = "" ]
655 echo "common.rc: Error: \$TEST_DEV is not set"
659 # if $TEST_DEV is not mounted, mount it now as XFS
660 if [ -z "`_fs_type $TEST_DEV`" ]
662 # $TEST_DEV is not mounted
665 echo "common.rc: retrying test device mount with external set"
666 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
669 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
675 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
677 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
684 # check for some required binaries on our $PATH
686 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
688 if which $exec >/dev/null 2>&1
692 echo "common.rc: cannot find $exec on \$PATH=$PATH"
697 # make sure this script returns success