2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
23 BC=$(which bc 2> /dev/null) || BC=
28 _notrun "this test requires 'bc' tool for doing math operations"
34 [ $# -le 0 ] && return
36 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
38 _notrun "this test requires 'bc' tool for doing math operations"
45 if [ "$HOSTOS" == "Linux" ]
47 command dd --help | grep noxfer > /dev/null 2>&1
51 command dd status=noxfer $@
60 # ls -l w/ selinux sometimes puts a dot at the end:
61 # -rwxrw-r--. id1 id2 file1
65 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /"
70 # SELinux adds extra xattrs which can mess up our expected output.
71 # So, mount with a context, and they won't be created
72 # nfs_t is a "liberal" context so we can use it.
73 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
74 SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
79 export SELINUX_MOUNT_OPTIONS
80 export MOUNT_OPTIONS=$XFS_MOUNT_OPTIONS
83 export MOUNT_OPTIONS=$UDF_MOUNT_OPTIONS
86 export MOUNT_OPTIONS=$NFS_MOUNT_OPTIONS
88 ext2|ext3|ext4|ext4dev)
89 # acls & xattrs aren't turned on by default on ext$FOO
90 export MOUNT_OPTIONS="-o acl,user_xattr $EXT_MOUNT_OPTIONS"
93 # acls & xattrs aren't turned on by default on reiserfs
94 export MOUNT_OPTIONS="-o acl,user_xattr $REISERFS_MOUNT_OPTIONS"
97 # acls aren't turned on by default on gfs2
98 export MOUNT_OPTIONS="-o acl $GFS2_MOUNT_OPTIONS"
109 export MKFS_OPTIONS=$XFS_MKFS_OPTIONS
112 [ ! -z "$udf_fsize" ] && \
113 UDF_MKFS_OPTIONS="$UDF_MKFS_OPTIONS -s $udf_fsize"
114 export MKFS_OPTIONS=$UDF_MKFS_OPTIONS
117 export MKFS_OPTIONS=$NFS_MKFS_OPTIONS
120 export MKFS_OPTIONS="$REISERFS_MKFS_OPTIONS -q"
123 export MKFS_OPTIONS="$GFS2_MKFS_OPTIONS -O -p lock_nolock"
126 export MKFS_OPTIONS="$JFS_MKFS_OPTIONS -q"
136 ext2|ext3|ext4|ext4dev)
137 export FSCK_OPTIONS="-nf"
140 export FSCK_OPTIONS="--yes"
143 export FSCK_OPTIONS="-n"
148 [ -z "$FSTYP" ] && FSTYP=xfs
149 [ -z "$MOUNT_OPTIONS" ] && _mount_opts
150 [ -z "$MKFS_OPTIONS" ] && _mkfs_opts
151 [ -z "$FSCK_OPTIONS" ] && _fsck_opts
154 # we need common.config
155 if [ "$iam" != "check" ]
157 if ! . ./common.config
159 echo "$iam: failed to source common.config"
164 # make sure we have a standard umask
169 $MOUNT_PROG `_mount_ops_filter $*`
177 if [ "$FSTYP" != "xfs" ]; then
183 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
192 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
193 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
194 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
195 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
203 if [ "$FSTYP" != "xfs" ]; then
217 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
218 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
219 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
220 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
227 #get mount point to handle dmapi mtpt option correctly
229 [ $last_index -gt 0 ] && shift $last_index
232 # irix is fussy about how it is fed its mount options
233 # - multiple -o's are not allowed
234 # - no spaces between comma delimitered options
235 # the sed script replaces all -o's (except the first) with a comma
236 # not required for linux, but won't hurt
238 echo $params | sed -e 's/[[:space:]]*-o[[:space:]]*/UnIqUe/1; s/[[:space:]]*-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
239 | sed -e 's/dmapi/dmi/' \
240 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
244 _scratch_mount_options()
246 _scratch_options mount
248 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
253 _mount -t $FSTYP `_scratch_mount_options $*`
258 $UMOUNT_PROG $SCRATCH_DEV
270 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
273 _scratch_mkfs_options()
275 _scratch_options mkfs
276 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
281 # extra mkfs options can be added by tests
282 local extra_mkfs_options=$*
286 _scratch_options mkfs
288 # save mkfs output in case conflict means we need to run again.
289 # only the output for the mkfs that applies should be shown
290 $MKFS_XFS_PROG $SCRATCH_OPTIONS $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
291 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
294 # a mkfs failure may be caused by conflicts between
295 # $MKFS_OPTIONS and $extra_mkfs_options
297 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
298 echo "** mkfs failed with extra mkfs options added to \"$MKFS_OPTIONS\" by test $seq **" \
300 echo "** attempting to mkfs using only test $seq options: $extra_mkfs_options **" \
302 # running mkfs again. overwrite previous mkfs output files
303 $MKFS_XFS_PROG $SCRATCH_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
304 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
308 # output stored mkfs output
309 cat $tmp_dir.mkfserr >&2
311 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
313 if [ "$USE_BIG_LOOPFS" = yes ]; then
314 [ -z "$RETAIN_AG_BYTES" ] && RETAIN_AG_BYTES=0
315 ./tools/ag-wipe -q -r $RETAIN_AG_BYTES $SCRATCH_DEV
331 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
334 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
337 /sbin/mkfs -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
342 # Create fs of certain size on scratch device
343 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
344 _scratch_mkfs_sized()
348 [ -z "$blocksize" ] && blocksize=4096
349 blocks=`expr $fssize / $blocksize`
353 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
355 ext2|ext3|ext4|ext4dev)
356 /sbin/mkfs.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
359 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
362 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
367 # Emulate an N-data-disk stripe w/ various stripe units
368 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
374 [ -z "$blocksize" ] && blocksize=4096
376 let sunit_blocks=$sunit_bytes/$blocksize
377 let swidth_blocks=$sunit_blocks*$swidth_mult
381 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
384 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
387 _notrun "can't mkfs $FSTYP with geometry"
397 xfs_io -x -c "resblks $1" $SCRATCH_MNT
404 _scratch_xfs_db_options()
407 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
408 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
409 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
412 _scratch_xfs_logprint()
415 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
416 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
417 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
423 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
424 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
425 $XFS_CHECK_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
428 _scratch_xfs_repair()
431 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
432 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
433 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
434 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
435 [ "$USE_BIG_LOOPFS" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
436 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
443 echo "Usage: _get_pids_by_name process-name" 1>&2
447 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
448 # HH:MM:SS before the psargs field, use this as the search anchor.
450 # Matches with $1 (process-name) occur if the first psarg is $1
451 # or ends in /$1 ... the matching uses sed's regular expressions,
452 # so passing a regex into $1 will work.
460 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
461 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
464 # fix malloc libs output
468 # filter out the Electric Fence notice
471 if (defined $o && /^\s+Electric Fence/) {
477 print $o if (defined $o);
481 print $o if (defined $o);
485 # check if run as root
489 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
492 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
499 # _df_device : get an IRIX style df line for a given device
501 # - returns "" if not mounted
502 # - returns fs type in field two (ala IRIX)
503 # - joins line together if split by fancy df formatting
504 # - strips header etc
511 echo "Usage: _df_device device" 1>&2
515 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
516 match($1,what) && NF==1 {
530 # _df_dir : get an IRIX style df line for device where a directory resides
532 # - returns fs type in field two (ala IRIX)
533 # - joins line together if split by fancy df formatting
534 # - strips header etc
541 echo "Usage: _df_dir device" 1>&2
545 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
561 # return percentage used disk space for mounted device
567 echo "Usage: _used device" 1>&2
571 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
574 # return the FS type of a mounted device
580 echo "Usage: _fs_type device" 1>&2
585 # The Linux kernel shows NFSv4 filesystems in df output as
586 # filesystem type nfs4, although we mounted it as nfs earlier.
587 # Fix the filesystem type up here so that the callers don't
588 # have to bother with this quirk.
590 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
593 # return the FS mount options of a mounted device
595 # should write a version which just parses the output of mount for IRIX
596 # compatibility, but since this isn't used at all, at the moment I'll leave
603 echo "Usage: _fs_options device" 1>&2
607 $AWK_PROG -v dev=$1 '
608 match($1,dev) { print $4 }
612 # returns device number if a file is a block device
618 echo "Usage: _is_block_dev dev" 1>&2
623 if [ -L "${_dev}" ]; then
624 _dev=`readlink -f ${_dev}`
627 if [ -b "${_dev}" ]; then
628 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
632 # Do a command, log it to $seq.full, optionally test return status
633 # and die if command fails. If called with one argument _do executes the
634 # command, logs it, and returns its exit status. With two arguments _do
635 # first prints the message passed in the first argument, and then "done"
636 # or "fail" depending on the return status of the command passed in the
637 # second argument. If the command fails and the variable _do_die_on_error
638 # is set to "always" or the two argument form is used and _do_die_on_error
639 # is set to "message_only" _do will print an error message to
644 if [ $# -eq 1 ]; then
646 elif [ $# -eq 2 ]; then
651 echo "Usage: _do [note] cmd" 1>&2
655 (eval "echo '---' \"$_cmd\"") >>$here/$seq.full
656 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
657 cat $tmp._out | _fix_malloc >>$here/$seq.full
658 if [ $# -eq 2 ]; then
659 if [ $ret -eq 0 ]; then
666 && [ "$_do_die_on_error" = "always" \
667 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
670 eval "echo \"$_cmd\" failed \(returned $ret\): see $seq.full"
677 # bail out, setting up .notrun file
681 echo "$*" >$seq.notrun
682 echo "$seq not run: $*"
687 # just plain bail out
691 echo "$*" | tee -a $here/$seq.full
692 echo "(see $seq.full for details)"
697 # tests whether $FSTYP is one of the supported filesystems for a test
703 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
709 _notrun "not suitable for this filesystem type: $FSTYP"
712 # tests whether $FSTYP is one of the supported OSes for a test
718 if [ "$h" = "$HOSTOS" ]
724 _notrun "not suitable for this OS: $HOSTOS"
727 # this test needs a scratch partition - check we're ok & unmount it
733 echo $SCRATCH_DEV | grep -q ":" > /dev/null 2>&1
734 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]
736 _notrun "this test requires a valid \$SCRATCH_DEV"
740 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
742 _notrun "this test requires a valid \$SCRATCH_DEV"
744 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
746 _notrun "this test requires a valid \$SCRATCH_DEV"
748 if [ ! -d "$SCRATCH_MNT" ]
750 _notrun "this test requires a valid \$SCRATCH_MNT"
756 if _mount | grep -q $SCRATCH_DEV
758 # if it's mounted, make sure its on $SCRATCH_MNT
759 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
761 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
764 # and then unmount it
765 if ! $UMOUNT_PROG $SCRATCH_DEV
767 echo "failed to unmount $SCRATCH_DEV"
773 # this test needs a logdev
777 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
778 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
779 [ "$USE_EXTERNAL" != yes ] && \
780 _notrun "This test requires USE_EXTERNAL to be enabled"
782 # ensure its not mounted
783 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
786 # this test requires loopback device support
790 if [ "$HOSTOS" != "Linux" ]
792 _notrun "This test requires linux for loopback device support"
795 modprobe loop >/dev/null 2>&1
796 if grep loop /proc/devices >/dev/null 2>&1
800 _notrun "This test requires loopback device support"
804 # this test requires ext2 filesystem support
808 if [ "$HOSTOS" != "Linux" ]
810 _notrun "This test requires linux for ext2 filesystem support"
813 modprobe ext2 >/dev/null 2>&1
814 if grep ext2 /proc/filesystems >/dev/null 2>&1
818 _notrun "This test requires ext2 filesystem support"
822 # this test requires that (large) loopback device files are not in use
824 _require_nobigloopfs()
826 [ "$USE_BIG_LOOPFS" = yes ] && \
827 _notrun "Large filesystem testing in progress, skipped this test"
830 # this test requires that a realtime subvolume is in use, and
831 # that the kernel supports realtime as well.
835 [ "$USE_EXTERNAL" = yes ] || \
836 _notrun "External volumes not in use, skipped this test"
837 [ "$SCRATCH_RTDEV" = "" ] && \
838 _notrun "Realtime device required, skipped this test"
841 # this test requires that a specified command (executable) exists
842 # $1 - command, $2 - name for error message
846 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
847 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
850 # this test requires the projid32bit feature to be available in
853 _require_projid32bit()
855 _scratch_mkfs_xfs -f -i projid32bit=0 2>&1 >/dev/null \
856 || _notrun "mkfs.xfs doesn't have projid32bit feature"
859 # this test requires that external log/realtime devices are not in use
861 _require_nonexternal()
863 [ "$USE_EXTERNAL" = yes ] && \
864 _notrun "External device testing in progress, skipped this test"
867 # indicate whether YP/NIS is active or not
872 dn=$(domainname 2>/dev/null)
873 test -n "${dn}" -a "${dn}" != "(none)"
877 # cat the password file
881 [ $(_yp_active) -eq 0 ] && ypcat passwd
889 [ $(_yp_active) -eq 0 ] && ypcat group
893 # check for the fsgqa user on the machine
898 _cat_passwd | grep -q $qa_user
899 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
905 s,.*Permission\sdenied.*,Permission denied,;
906 s,.*no\saccess\sto\stty.*,,;
907 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
914 if [ "$HOSTOS" == "IRIX" ]
916 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
918 echo $1 | su $qa_user 2>&1 | _filter_user_do
922 # check that xfs_io, glibc, kernel, and filesystem all (!) support
925 _require_xfs_io_falloc()
927 testfile=$TEST_DIR/$$.falloc
928 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
929 rm -f $testfile 2>&1 > /dev/null
930 echo $testio | grep -q "not found" && \
931 _notrun "xfs_io fallocate support is missing"
932 echo $testio | grep -q "Operation not supported" && \
933 _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
936 # check that xfs_io, kernel and filesystem all support fallocate with hole
938 _require_xfs_io_falloc_punch()
940 testfile=$TEST_DIR/$$.falloc
941 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
942 -c "fpunch 4k 8k" $testfile 2>&1`
943 rm -f $testfile 2>&1 > /dev/null
944 echo $testio | grep -q "not found" && \
945 _notrun "xfs_io fallocate punch support is missing"
946 echo $testio | grep -q "Operation not supported" && \
947 _notrun "xfs_io fallocate punch command failed (no fs support?)"
950 # check that xfs_io, kernel and filesystem support fiemap
951 _require_xfs_io_fiemap()
953 testfile=$TEST_DIR/$$.fiemap
954 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
955 -c "fiemap -v" $testfile 2>&1`
956 rm -f $testfile 2>&1 > /dev/null
957 echo $testio | grep -q "not found" && \
958 _notrun "xfs_io fiemap support is missing"
959 echo $testio | grep -q "Operation not supported" && \
960 _notrun "xfs_io fiemap command failed (no fs support?)"
963 # Check that a fs has enough free space (in 1024b blocks)
968 BLOCKS=$2 # in units of 1024
969 let GB=$BLOCKS/1024/1024
971 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
972 [ $FREE_BLOCKS -lt $BLOCKS ] && \
973 _notrun "This test requires at least ${GB}GB free on $MNT to run"
977 # Check if the filesystem supports sparse files.
979 # Unfortunately there is no better way to do this than a manual black list.
981 _require_sparse_files()
985 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
992 # check that a FS on a device is mounted
993 # if so, return mount point
999 echo "Usage: _is_mounted device" 1>&2
1005 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1006 pattern { print $3 ; exit 0 }
1010 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1015 # remount a FS to a new mode (ro or rw)
1021 echo "Usage: _remount device ro/rw" 1>&2
1027 if ! mount -o remount,$mode $device
1029 echo "_remount: failed to remount filesystem on $device as $mode"
1034 # Run the appropriate repair/check on a filesystem
1036 # if the filesystem is mounted, it's either remounted ro before being
1037 # checked or it's unmounted and then remounted
1040 # If set, we remount ro instead of unmounting for fsck
1043 _umount_or_remount_ro()
1047 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1052 mountpoint=`_is_mounted $device`
1054 if [ $USE_REMOUNT -eq 0 ]; then
1055 $UMOUNT_PROG $device
1062 _mount_or_remount_rw()
1066 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1073 if [ $USE_REMOUNT -eq 0 ]
1075 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1077 echo "!!! failed to remount $device on $mountpoint"
1087 # Check a generic filesystem in no-op mode; this assumes that the
1088 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1089 # and that it will still return an errno for corruption in this mode.
1091 # Filesystems which don't support this will need to define their
1092 # own check routine.
1094 _check_generic_filesystem()
1098 # If type is set, we're mounted
1099 type=`_fs_type $device`
1102 if [ "$type" = "$FSTYP" ]
1105 mountpoint=`_umount_or_remount_ro $device`
1108 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1111 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seq.full)"
1113 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1114 echo "*** fsck.$FSTYP output ***" >>$here/$seq.full
1115 cat $tmp.fsck >>$here/$seq.full
1116 echo "*** end fsck.$FSTYP output" >>$here/$seq.full
1124 echo "*** mount output ***" >>$here/$seq.full
1125 _mount >>$here/$seq.full
1126 echo "*** end mount output" >>$here/$seq.full
1127 elif [ "$type" = "$FSTYP" ]
1130 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1134 if [ $ok -eq 0 ]; then
1142 # run xfs_check and friends on a FS.
1144 _check_xfs_filesystem()
1148 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1152 extra_mount_options=""
1154 if [ "$2" != "none" ]; then
1155 extra_log_options="-l$2"
1156 extra_mount_options="-ologdev=$2"
1159 if [ "$3" != "none" ]; then
1160 extra_rt_options="-r$3"
1161 extra_mount_options=$extra_mount_options" -ortdev=$3"
1163 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1165 [ "$FSTYP" != xfs ] && return 0
1167 [ "$USE_BIG_LOOPFS" = yes ] && testoption=-t
1169 type=`_fs_type $device`
1172 if [ "$type" = "xfs" ]
1175 mountpoint=`_umount_or_remount_ro $device`
1178 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1179 | tee $tmp.logprint | grep -q "<CLEAN>"
1180 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1182 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seq.full)"
1184 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$here/$seq.full
1185 echo "*** xfs_logprint -t output ***" >>$here/$seq.full
1186 cat $tmp.logprint >>$here/$seq.full
1187 echo "*** end xfs_logprint output" >>$here/$seq.full
1192 $XFS_CHECK_PROG $testoption $extra_log_options $device 2>&1 |\
1193 _fix_malloc >$tmp.fs_check
1194 if [ -s $tmp.fs_check ]
1196 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seq.full)"
1198 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1199 echo "*** xfs_check output ***" >>$here/$seq.full
1200 cat $tmp.fs_check >>$here/$seq.full
1201 echo "*** end xfs_check output" >>$here/$seq.full
1205 # repair doesn't scale massively at this stage, optionally skip it for now
1206 [ "$USE_BIG_LOOPFS" = yes ] || \
1207 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1210 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seq.full)"
1212 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
1213 echo "*** xfs_repair -n output ***" >>$here/$seq.full
1214 cat $tmp.repair | _fix_malloc >>$here/$seq.full
1215 echo "*** end xfs_repair output" >>$here/$seq.full
1219 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1223 echo "*** mount output ***" >>$here/$seq.full
1224 _mount >>$here/$seq.full
1225 echo "*** end mount output" >>$here/$seq.full
1226 elif [ "$type" = "xfs" ]
1228 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1231 if [ $ok -eq 0 ]; then
1239 # Filter the knowen errors the UDF Verifier reports.
1240 _udf_test_known_error_filter()
1242 egrep -v "PVD 60 Error: Interchange Level: 1, Maximum Interchange Level: 0|FSD 28 Error: Interchange Level: 1, Maximum Interchange Level: 1,|PVD 72 Warning: Volume Set Identifier: \"\*IRIX UDF\",|Warning: [0-9]+ unused blocks NOT marked as unallocated."
1246 _check_udf_filesystem()
1248 [ "$DISABLE_UDF_TEST" == "1" ] && return
1250 if [ $# -ne 1 -a $# -ne 2 ]
1252 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1256 if [ ! -x $here/src/udf_test ]
1258 echo "udf_test not installed, please download and build the Philips"
1259 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1260 echo "Then copy the udf_test binary to $here/src/."
1261 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1269 LAST_BLOCK=`expr \( $2 - 1 \)`
1270 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1274 sleep 1 # Due to a problem with time stamps in udf_test
1275 $here/src/udf_test $OPT_ARG $device | tee $here/$seq.checkfs | egrep "Error|Warning" | \
1276 _udf_test_known_error_filter | \
1277 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" | \
1278 sed "s/^.*$/Warning UDF Verifier reported errors see $seq.checkfs./g"
1282 _check_xfs_test_fs()
1286 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1287 TEST_LOG="$TEST_LOGDEV"
1289 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1290 TEST_RT="$TEST_RTDEV"
1292 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1294 # check for ipath consistency
1295 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1296 # errors go to stderr
1297 xfs_check_ipaths $TEST_DIR >/dev/null
1298 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1309 # no way to check consistency for nfs
1312 # do nothing for now
1315 _check_generic_filesystem $TEST_DEV
1326 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1327 SCRATCH_LOG="$SCRATCH_LOGDEV"
1329 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1330 SCRATCH_RT="$SCRATCH_RTDEV"
1332 _check_xfs_filesystem $SCRATCH_DEV $SCRATCH_LOG $SCRATCH_RT
1335 _check_udf_filesystem $SCRATCH_DEV $udf_fsize
1338 # Don't know how to check an NFS filesystem, yet.
1341 _check_generic_filesystem $SCRATCH_DEV
1346 _full_fstyp_details()
1348 [ -z "$FSTYP" ] && FSTYP=xfs
1349 if [ $FSTYP = xfs ]; then
1350 if [ -d /proc/fs/xfs ]; then
1351 if grep -q 'debug 0' /proc/fs/xfs/stat; then
1352 FSTYP="$FSTYP (non-debug)"
1353 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
1354 FSTYP="$FSTYP (debug)"
1357 if uname -a | grep -qi 'debug'; then
1358 FSTYP="$FSTYP (debug)"
1360 FSTYP="$FSTYP (non-debug)"
1367 _full_platform_details()
1373 echo "$os/$platform $host $kernel"
1376 _setup_udf_scratchdir()
1378 [ "$FSTYP" != "udf" ] \
1379 && _fail "setup_udf_testdir: \$FSTYP is not udf"
1380 [ -z "$SCRATCH_DEV" -o ! -b "$SCRATCH_DEV" ] \
1381 && _notrun "this test requires a valid \$SCRATCH_DEV"
1382 [ -z "$SCRATCH_MNT" ] \
1383 && _notrun "this test requires a valid \$SCRATCH_MNT"
1386 if _mount | grep -q $SCRATCH_DEV
1388 # if it's mounted, make sure its on $TEST_RW_DIR
1389 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1391 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1393 $UMOUNT_PROG $SCRATCH_DEV
1399 testdir=$SCRATCH_MNT
1402 _setup_nfs_scratchdir()
1404 [ "$FSTYP" != "nfs" ] \
1405 && _fail "setup_nfs_testdir: \$FSTYP is not nfs"
1406 [ -z "$SCRATCH_DEV" ] \
1407 && _notrun "this test requires a valid host fs for \$SCRATCH_DEV"
1408 [ -z "$SCRATCH_MNT" ] \
1409 && _notrun "this test requires a valid \$SCRATCH_MNT"
1412 if _mount | grep -q $SCRATCH_DEV
1414 # if it's mounted, make sure its on $SCRATCH_MNT
1415 if ! _mount | grep $SCRATCH_DEV | grep -q $SCRATCH_MNT
1417 _fail "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1419 $UMOUNT_PROG $SCRATCH_DEV
1425 testdir=$SCRATCH_MNT
1429 # Warning for UDF and NFS:
1430 # this function calls _setup_udf_scratchdir and _setup_udf_scratchdir
1431 # which actually uses the scratch dir for the test dir.
1433 # This was done because testdir was intended to be a persistent
1434 # XFS only partition. This should eventually change, and treat
1435 # at least local filesystems all the same.
1441 _setup_udf_scratchdir
1444 _setup_nfs_scratchdir
1456 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1457 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1460 # umount testdir as it is $SCRATCH_MNT which could be used by xfs next
1461 [ -n "$testdir" ] && $UMOUNT_PROG $testdir
1464 # do nothing, testdir is $TEST_DIR
1472 if [ -z "$1" ]; then
1473 echo Error must pass \$seq.
1477 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
1479 elif [ "`uname`" == "Linux" ]; then
1482 echo Error test $seq does not run on the operating system: `uname`
1500 if [ $size -gt 0 ]; then
1501 dd if=/dev/zero of=$file bs=1024 count=$size
1507 # takes dirname, depth
1510 dirname=$1; depth=$2
1511 mkdir $dirname || die "mkdir $dirname failed"
1514 _nfiles $files # files for this dir
1516 [ $depth -eq 0 ] && return
1517 let deep=$depth-1 # go 1 down
1519 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
1522 while [ $d -lt $dirs ]
1524 _descend d$d $deep &
1530 # Populate a filesystem with inodes for performance experiments
1532 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size]
1537 dirs=5 # ndirs in each subdir till leaves
1538 size=0 # sizeof files in K
1539 files=100 # num files in _each_ subdir
1540 depth=2 # depth of tree from root to leaves
1542 root=root # path of initial root of directory tree
1544 while getopts "d:f:n:r:s:v" c
1556 _descend $root $depth
1561 [ $verbose = true ] && echo done
1564 # query whether the given file has the given inode flag set
1571 if which $XFS_IO_PROG >/dev/null; then
1572 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
1579 # query the given files extsize allocator hint in bytes (if any)
1586 if which $XFS_IO_PROG >/dev/null; then
1587 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
1588 awk '/^xattr.extsize =/ { print $3 }'`
1590 [ -z "$blocks" ] && blocks="0"
1595 ################################################################################
1597 if [ "$iam" != new -a "$iam" != bench ]
1599 # make some further configuration checks here
1601 if [ "$TEST_DEV" = "" ]
1603 echo "common.rc: Error: \$TEST_DEV is not set"
1607 # if $TEST_DEV is not mounted, mount it now as XFS
1608 if [ -z "`_fs_type $TEST_DEV`" ]
1610 # $TEST_DEV is not mounted
1613 echo "common.rc: retrying test device mount with external set"
1614 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
1617 echo "common.rc: could not mount $TEST_DEV on $TEST_DIR"
1623 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
1625 echo "common.rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
1631 # make sure this script returns success