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
131 _scratch_xfs_db_options()
134 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
135 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
136 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
139 _scratch_xfs_logprint()
142 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
143 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
144 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
147 _scratch_xfs_repair()
150 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
151 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
152 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
159 echo "Usage: _get_pids_by_name process-name" 1>&2
163 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
164 # HH:MM:SS before the psargs field, use this as the search anchor.
166 # Matches with $1 (process-name) occur if the first psarg is $1
167 # or ends in /$1 ... the matching uses sed's regular expressions,
168 # so passing a regex into $1 will work.
176 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
177 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
185 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
188 # fix malloc libs output
192 # filter out the Electric Fence notice
195 if (defined $o && /^\s+Electric Fence/) {
201 print $o if (defined $o);
205 print $o if (defined $o);
209 # check if run as root
213 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
216 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
223 # _df_device : get an IRIX style df line for a given device
225 # - returns "" if not mounted
226 # - returns fs type in field two (ala IRIX)
227 # - joins line together if split by fancy df formatting
228 # - strips header etc
235 echo "Usage: _df_device device" 1>&2
239 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
240 match($1,what) && NF==1 {
254 # _df_dir : get an IRIX style df line for device where a directory resides
256 # - returns fs type in field two (ala IRIX)
257 # - joins line together if split by fancy df formatting
258 # - strips header etc
265 echo "Usage: _df_dir device" 1>&2
269 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
285 # return percentage used disk space for mounted device
291 echo "Usage: _used device" 1>&2
295 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
298 # return the FS type of a mounted device
304 echo "Usage: _fs_type device" 1>&2
308 _df_device $1 | $AWK_PROG '{ print $2 }'
311 # return the FS mount options of a mounted device
317 echo "Usage: _fs_options device" 1>&2
321 $AWK_PROG -v dev=$1 '
322 match($1,dev) { print $4 }
327 # returns device number if a file is a block device
333 echo "Usage: _is_block_dev dev" 1>&2
337 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
340 # Do a command, log it to $seq.full, optionally test return status
341 # and die if command fails. If called with one argument _do executes the
342 # command, logs it, and returns its exit status. With two arguments _do
343 # first prints the message passed in the first argument, and then "done"
344 # or "fail" depending on the return status of the command passed in the
345 # second argument. If the command fails and the variable _do_die_on_error
346 # is set to "always" or the two argument form is used and _do_die_on_error
347 # is set to "message_only" _do will print an error message to
352 if [ $# -eq 1 ]; then
354 elif [ $# -eq 2 ]; then
359 echo "Usage: _do [note] cmd" 1>&2
363 (eval "echo '---' \"$_cmd\"") >>$seq.full
364 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
365 cat $tmp._out | _fix_malloc >>$seq.full
366 if [ $# -eq 2 ]; then
367 if [ $ret -eq 0 ]; then
374 && [ "$_do_die_on_error" = "always" \
375 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
378 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
385 # bail out, setting up .notrun file
389 echo "$*" >$seq.notrun
390 echo "$seq not run: $*"
395 # just plain bail out
399 echo "$*" | tee -a $seq.full
400 echo "(see $seq.full for details)"
405 # this test needs a scratch partition - check we're ok & unmount it
409 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
411 _notrun "this test requires a valid \$SCRATCH_DEV"
414 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
416 _notrun "this test requires a valid \$SCRATCH_DEV"
420 if mount | grep -q $SCRATCH_DEV
422 # if it's mounted, make sure its on $SCRATCH_MNT
423 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
425 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
428 # and then unmount it
429 if ! umount $SCRATCH_DEV
431 echo "failed to unmount $SCRATCH_DEV"
437 # this test needs a logdev
441 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
442 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
443 [ "$USE_EXTERNAL" != yes ] && \
444 _notrun "This test requires USE_EXTERNAL to be enabled"
446 # ensure its not mounted
447 umount $SCRATCH_LOGDEV 2>/dev/null
450 # this test requires loopback device support
454 modprobe loop >/dev/null 2>&1
455 if grep loop /proc/devices >/dev/null 2>&1
459 _notrun "This test requires loopback device support"
463 # check that a FS is mounted as XFS. if so, return mount point
469 echo "Usage: _xfs_mounted device" 1>&2
475 if mount | grep $device | $AWK_PROG '
476 /type xfs/ { print $3 ; exit 0 }
480 echo "_xfs_mounted: $device is not a mounted XFS FS"
486 # setup the .out file link, depending on which form of quota is
487 # enabled as this often influences how the test output appears.
488 # [NB: SCRATCH_DEV must be mounted for this to work]
492 # this lets us phase use of this into the dump/restore tests easier...
493 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
497 if src/feature -U $SCRATCH_DEV
499 if src/feature -G $SCRATCH_DEV
501 ln $seq.ugquota $seq.out
503 ln $seq.usrquota $seq.out
505 elif src/feature -G $SCRATCH_DEV
507 ln $seq.grpquota $seq.out
509 ln $seq.noquota $seq.out
514 # remount a FS to a new mode (ro or rw)
520 echo "Usage: _remount device ro/rw" 1>&2
526 if ! mount -o remount,$mode $device
528 echo "_remount: failed to remount filesystem on $device as $mode"
532 # we might like to check here later
533 #options=`_fs_options $device`
537 # run xfs_check and friends on a FS.
539 # if the filesystem is mounted, it's either remounted ro before being
540 # checked or it's unmounted and then remounted
547 if [ $# -ne 1 -a $# -ne 2 ]
549 echo "Usage: _check_fs device [logdevice]" 1>&2
554 if [ $# -eq 2 -a "$2" != "" ]; then
555 extra_log_options="-l$2"
556 extra_mount_options="-ologdev=$2"
559 [ "$FSTYP" != xfs ] && return 0
561 type=`_fs_type $device`
564 if [ "$type" = "xfs" ]
568 if [ $USE_REMOUNT -eq 0 ]
570 mountpoint=`_xfs_mounted $device`
577 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
578 | tee $tmp.fs_check | grep -q "<CLEAN>"
581 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
583 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
584 echo "*** xfs_logprint -t output ***" >>$seq.full
585 cat $tmp.fs_check >>$seq.full
586 echo "*** end xfs_logprint output" >>$seq.full
591 /usr/sbin/xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
592 if [ -s $tmp.fs_check ]
594 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
596 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
597 echo "*** xfs_check output ***" >>$seq.full
598 cat $tmp.fs_check >>$seq.full
599 echo "*** end xfs_check output" >>$seq.full
604 if ! /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