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
48 # extra parameters for fsstress
49 FSSTRESS_AVOID="-f resvsp=0 -f unresvsp=0"
51 export AWK_PROG FSSTRESS_AVOID
53 # we override mount and mkfs.xfs so we can specify extra options
66 /bin/mount $* $MOUNT_OPTIONS
77 [ -z "$TEST_RTDEV" ] || TEST_OPTIONS="$TEST_OPTIONS -ortdev=$TEST_RTDEV"
78 [ -z "$TEST_LOGDEV" ] || TEST_OPTIONS="$TEST_OPTIONS -ologdev=$TEST_LOGDEV"
79 mount -t xfs $TEST_OPTIONS $* $TEST_DEV $TEST_DIR
82 _scratch_mount_options()
85 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
86 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
87 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
88 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
89 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
95 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
96 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ortdev=$SCRATCH_RTDEV"
97 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
98 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -ologdev=$SCRATCH_LOGDEV"
99 mount -t xfs $SCRATCH_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
115 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
116 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -rrtdev=$SCRATCH_RTDEV"
117 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
118 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -llogdev=$SCRATCH_LOGDEV"
119 /sbin/mkfs.xfs -f $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
122 _scratch_xfs_db_options()
125 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
126 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
127 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
130 _scratch_xfs_logprint()
133 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
134 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
135 /usr/sbin/xfs_logprint $SCRATCH_OPTIONS $* $SCRATCH_DEV
138 _scratch_xfs_repair()
141 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
142 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
143 /sbin/xfs_repair $SCRATCH_OPTIONS $* $SCRATCH_DEV
150 echo "Usage: _get_pids_by_name process-name" 1>&2
154 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
155 # HH:MM:SS before the psargs field, use this as the search anchor.
157 # Matches with $1 (process-name) occur if the first psarg is $1
158 # or ends in /$1 ... the matching uses sed's regular expressions,
159 # so passing a regex into $1 will work.
167 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
168 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
176 nslookup $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
179 # fix malloc libs output
183 # filter out the Electric Fence notice
186 if (defined $o && /^\s+Electric Fence/) {
192 print $o if (defined $o);
196 print $o if (defined $o);
200 # check if run as root
204 id=`id | sed -e 's/(.*//' -e 's/.*=//'`
207 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
214 # _df_device : get an IRIX style df line for a given device
216 # - returns "" if not mounted
217 # - returns fs type in field two (ala IRIX)
218 # - joins line together if split by fancy df formatting
219 # - strips header etc
226 echo "Usage: _df_device device" 1>&2
230 df -T 2>/dev/null | $AWK_PROG -v what=$1 '
231 match($1,what) && NF==1 {
245 # _df_dir : get an IRIX style df line for device where a directory resides
247 # - returns fs type in field two (ala IRIX)
248 # - joins line together if split by fancy df formatting
249 # - strips header etc
256 echo "Usage: _df_dir device" 1>&2
260 df -T $1 2>/dev/null | $AWK_PROG -v what=$1 '
276 # return percentage used disk space for mounted device
282 echo "Usage: _used device" 1>&2
286 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
289 # return the FS type of a mounted device
295 echo "Usage: _fs_type device" 1>&2
299 _df_device $1 | $AWK_PROG '{ print $2 }'
302 # return the FS mount options of a mounted device
308 echo "Usage: _fs_options device" 1>&2
312 $AWK_PROG -v dev=$1 '
313 match($1,dev) { print $4 }
318 # returns device number if a file is a block device
324 echo "Usage: _is_block_dev dev" 1>&2
328 [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
331 # Do a command, log it to $seq.full, optionally test return status
332 # and die if command fails. If called with one argument _do executes the
333 # command, logs it, and returns its exit status. With two arguments _do
334 # first prints the message passed in the first argument, and then "done"
335 # or "fail" depending on the return status of the command passed in the
336 # second argument. If the command fails and the variable _do_die_on_error
337 # is set to "always" or the two argument form is used and _do_die_on_error
338 # is set to "message_only" _do will print an error message to
343 if [ $# -eq 1 ]; then
345 elif [ $# -eq 2 ]; then
350 echo "Usage: _do [note] cmd" 1>&2
354 (eval "echo '---' \"$_cmd\"") >>$seq.full
355 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
356 cat $tmp._out | _fix_malloc >>$seq.full
357 if [ $# -eq 2 ]; then
358 if [ $ret -eq 0 ]; then
365 && [ "$_do_die_on_error" = "always" \
366 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
369 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
376 # bail out, setting up .notrun file
380 echo "$*" >$seq.notrun
381 echo "$seq not run: $*"
386 # just plain bail out
390 echo "$*" | tee -a $seq.full
391 echo "(see $seq.full for details)"
396 # this test needs a scratch partition - check we're ok & unmount it
400 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
402 _notrun "this test requires a valid \$SCRATCH_DEV"
405 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
407 _notrun "this test requires a valid \$SCRATCH_DEV"
411 if mount | grep -q $SCRATCH_DEV
413 # if it's mounted, make sure its on $SCRATCH_MNT
414 if ! mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
416 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
419 # and then unmount it
420 if ! umount $SCRATCH_DEV
422 echo "failed to unmount $SCRATCH_DEV"
428 # this test needs a logdev
432 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
433 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
434 [ "$USE_EXTERNAL" != yes ] && \
435 _notrun "This test requires USE_EXTERNAL to be enabled"
437 # ensure its not mounted
438 umount $SCRATCH_LOGDEV 2>/dev/null
441 # this test requires loopback device support
445 modprobe loop >/dev/null 2>&1
446 if grep loop /proc/devices >/dev/null 2>&1
450 _notrun "This test requires loopback device support"
454 # check that a FS is mounted as XFS. if so, return mount point
460 echo "Usage: _xfs_mounted device" 1>&2
466 if mount | grep $device | $AWK_PROG '
467 /type xfs/ { print $3 ; exit 0 }
471 echo "_xfs_mounted: $device is not a mounted XFS FS"
477 # setup the .out file link, depending on which form of quota is
478 # enabled as this often influences how the test output appears.
479 # [NB: SCRATCH_DEV must be mounted for this to work]
483 # this lets us phase use of this into the dump/restore tests easier...
484 [ -f $seq.ugquota -a -f $seq.noquota -a $seq.usrquota -a $seq.grpquota ] \
488 if src/feature -U $SCRATCH_DEV
490 if src/feature -G $SCRATCH_DEV
492 ln $seq.ugquota $seq.out
494 ln $seq.usrquota $seq.out
496 elif src/feature -G $SCRATCH_DEV
498 ln $seq.grpquota $seq.out
500 ln $seq.noquota $seq.out
505 # remount a FS to a new mode (ro or rw)
511 echo "Usage: _remount device ro/rw" 1>&2
517 if ! mount -o remount,$mode $device
519 echo "_remount: failed to remount filesystem on $device as $mode"
523 # we might like to check here later
524 #options=`_fs_options $device`
528 # run xfs_check and friends on a FS.
530 # if the filesystem is mounted, it's either remounted ro before being
531 # checked or it's unmounted and then remounted
538 if [ $# -ne 1 -a $# -ne 2 ]
540 echo "Usage: _check_fs device [logdevice]" 1>&2
545 if [ $# -eq 2 -a "$2" != "" ]; then
546 extra_log_options="-l$2"
547 extra_mount_options="-ologdev=$2"
549 type=`_fs_type $device`
552 if [ "$type" = "xfs" ]
556 if [ $USE_REMOUNT -eq 0 ]
558 mountpoint=`_xfs_mounted $device`
565 /usr/sbin/xfs_logprint -t $device $extra_log_options 2>&1 \
566 | tee $tmp.fs_check | grep -q "<CLEAN>"
569 echo "_check_fs: filesystem on $device has dirty log (see $seq.full)"
571 echo "_check_fs: filesystem on $device has dirty log" >>$seq.full
572 echo "*** xfs_logprint -t output ***" >>$seq.full
573 cat $tmp.fs_check >>$seq.full
574 echo "*** end xfs_logprint output" >>$seq.full
579 /usr/sbin/xfs_check $device 2>&1 | _fix_malloc >$tmp.fs_check
580 if [ -s $tmp.fs_check ]
582 echo "_check_fs: filesystem on $device is inconsistent (c) (see $seq.full)"
584 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
585 echo "*** xfs_check output ***" >>$seq.full
586 cat $tmp.fs_check >>$seq.full
587 echo "*** end xfs_check output" >>$seq.full
592 if ! /sbin/xfs_repair -n $device $extra_log_options >$tmp.fs_check 2>&1
594 echo "_check_fs: filesystem on $device is inconsistent (r) (see $seq.full)"
596 echo "_check_fs: filesystem on $device is inconsistent" >>$seq.full
597 echo "*** xfs_repair -n output ***" >>$seq.full
598 cat $tmp.fs_check | _fix_malloc >>$seq.full
599 echo "*** end xfs_repair output" >>$seq.full
607 echo "*** mount output ***" >>$seq.full
609 echo "*** end mount output" >>$seq.full
612 if [ "$type" = "xfs" ]
615 if [ $USE_REMOUNT -eq 0 ]
617 if ! mount -t xfs $extra_mount_options $device $mountpoint
619 echo "!!! failed to remount $device on $mountpoint"
627 [ $ok -eq 0 ] && exit 1
633 _check_filesystem $TEST_DEV $TEST_LOGDEV
639 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
640 SCRATCH_LOG="$SCRATCH_LOGDEV"
641 _check_filesystem $SCRATCH_DEV $SCRATCH_LOG
644 ################################################################################
646 [ -d /usr/bsd ] && PATH=$PATH:/usr/bsd
647 [ -d /usr/freeware/bin ] && PATH=$PATH:/usr/freeware/bin
652 # make some further configuration checks here
654 if [ "$TEST_DEV" = "" ]
656 echo "common.rc: Error: \$TEST_DEV is not set"
660 # if $TEST_DEV is not mounted, mount it now as XFS
661 if [ -z "`_fs_type $TEST_DEV`" ]
663 # $TEST_DEV is not mounted
666 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
671 if [ "`_fs_type $TEST_DEV`" != "xfs" ]
673 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED XFS filesystem"
680 # check for some required binaries on our $PATH
682 for exec in mkfs.xfs xfs_logprint xfs_check xfs_repair xfs_db
684 if which $exec >/dev/null 2>&1
688 echo "common.rc: cannot find $exec on \$PATH=$PATH"
693 # make sure this script returns success