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=
25 # Valid test names start with 3 digits "NNN":
27 # followed by an optional "-":
29 # followed by an optional combination of alphanumeric and "-" chars:
31 # e.g. 999-the-mark-of-fstests
33 VALID_TEST_ID="[0-9]\{3\}"
34 VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"
39 _notrun "this test requires 'bc' tool for doing math operations"
45 [ $# -le 0 ] && return
47 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
49 _notrun "this test requires 'bc' tool for doing math operations"
56 if [ "$HOSTOS" == "Linux" ]
58 command dd --help 2>&1 | grep noxfer >/dev/null
62 command dd status=noxfer $@
76 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
79 # Prints the md5 checksum of a given file
82 md5sum $1 | cut -d ' ' -f1
85 # Write a byte into a range of a file
93 "$XFS_IO_PROG" $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
96 # mmap-write a byte into a range of a file
104 "$XFS_IO_PROG" -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
107 # ls -l w/ selinux sometimes puts a dot at the end:
108 # -rwxrw-r--. id1 id2 file1
109 # Also filter out lost+found directory on extN file system if present
113 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
116 # we need common/config
117 if [ "$iam" != "check" ]
119 if ! . ./common/config
121 echo "$iam: failed to source common/config"
126 # check for correct setup
129 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
130 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
131 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
132 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
135 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
138 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
141 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
144 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
153 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
157 # make sure we have a standard umask
162 $MOUNT_PROG `_mount_ops_filter $*`
170 if [ "$FSTYP" != "xfs" ]; then
176 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
185 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
186 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
187 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
188 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
196 if [ "$FSTYP" != "xfs" ]; then
210 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
211 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
212 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
213 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
220 #get mount point to handle dmapi mtpt option correctly
222 [ $last_index -gt 0 ] && shift $last_index
225 # irix is fussy about how it is fed its mount options
226 # - multiple -o's are not allowed
227 # - no spaces between comma delimitered options
228 # the sed script replaces all -o's (except the first) with a comma
229 # not required for linux, but won't hurt
231 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
232 | sed -e 's/dmapi/dmi/' \
233 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
237 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
238 # with the safe set of scratch mount options (e.g. loop image may be
239 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
240 _common_dev_mount_options()
242 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
245 _overlay_basic_mount_options()
247 echo "-o lowerdir=$1/$OVERLAY_LOWER_DIR,upperdir=$1/$OVERLAY_UPPER_DIR,workdir=$1/$OVERLAY_WORK_DIR"
250 _overlay_mount_options()
252 echo `_common_dev_mount_options` \
253 `_overlay_basic_mount_options $1` \
254 $OVERLAY_MOUNT_OPTIONS
257 _scratch_mount_options()
259 _scratch_options mount
261 if [ "$FSTYP" == "overlay" ]; then
262 echo `_overlay_mount_options $SCRATCH_DEV`
265 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
266 $SCRATCH_DEV $SCRATCH_MNT
269 # Given a dir, set up 3 subdirectories and mount on the given mnt.
270 # The dir is used as the mount device so it can be seen from df or mount
276 mkdir -p $dir/$OVERLAY_UPPER_DIR
277 mkdir -p $dir/$OVERLAY_LOWER_DIR
278 mkdir -p $dir/$OVERLAY_WORK_DIR
280 $MOUNT_PROG -t overlay $SELINUX_MOUNT_OPTIONS \
281 -o lowerdir=$dir/$OVERLAY_LOWER_DIR \
282 -o upperdir=$dir/$OVERLAY_UPPER_DIR \
283 -o workdir=$dir/$OVERLAY_WORK_DIR \
284 $OVERLAY_MOUNT_OPTIONS $* \
288 _overlay_test_mount()
290 _overlay_mount $TEST_DEV $TEST_DIR $*
293 _overlay_scratch_mount()
295 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
298 _overlay_test_unmount()
300 $UMOUNT_PROG $TEST_DIR
303 _overlay_scratch_unmount()
305 $UMOUNT_PROG $SCRATCH_MNT
310 if [ "$FSTYP" == "overlay" ]; then
311 _overlay_scratch_mount $*
314 _mount -t $FSTYP `_scratch_mount_options $*`
321 _overlay_scratch_unmount
324 $UMOUNT_PROG $SCRATCH_MNT
327 $UMOUNT_PROG $SCRATCH_DEV
336 if test -n "$opts"; then
337 mount -o "remount,$opts" $SCRATCH_MNT
341 _scratch_cycle_mount()
345 if [ "$FSTYP" = tmpfs ]; then
346 _scratch_remount "$opts"
349 if test -n "$opts"; then
353 _scratch_mount "$opts"
358 if [ "$FSTYP" == "overlay" ]; then
359 _overlay_test_mount $*
363 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
368 if [ "$FSTYP" == "overlay" ]; then
369 _overlay_test_unmount
371 $UMOUNT_PROG $TEST_DEV
377 if [ "$FSTYP" = tmpfs ]; then
384 _scratch_mkfs_options()
386 _scratch_options mkfs
387 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
395 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
396 options="-l $SCRATCH_LOGDEV"
398 xfs_metadump $options $SCRATCH_DEV $dumpfile
401 _setup_large_xfs_fs()
406 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
407 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
408 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
410 # calculate the size of the file we need to allocate.
411 # Default free space in the FS is 50GB, but you can specify more via
412 # SCRATCH_DEV_EMPTY_SPACE
413 file_size=$(($fs_size - 50*1024*1024*1024))
414 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
416 # mount the filesystem, create the file, unmount it
417 _scratch_mount 2>&1 >$tmp_dir/mnt.err
419 if [ $status -ne 0 ]; then
421 cat $tmp_dir/mnt.err >&2
422 rm -f $tmp_dir/mnt.err
425 rm -f $tmp_dir/mnt.err
428 -c "truncate $file_size" \
429 -c "falloc -k 0 $file_size" \
431 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
432 export NUM_SPACE_FILES=1
435 if [ $status -ne 0 ]; then
436 echo "large file prealloc failed"
437 cat $tmp_dir/mnt.err >&2
443 _scratch_mkfs_xfs_opts()
447 # remove metadata related mkfs options if mkfs.xfs doesn't them
448 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
449 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
452 _scratch_options mkfs
454 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
458 _scratch_mkfs_xfs_supported()
462 _scratch_options mkfs
464 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
469 # extra mkfs options can be added by tests
470 local extra_mkfs_options=$*
474 # save mkfs output in case conflict means we need to run again.
475 # only the output for the mkfs that applies should be shown
476 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
477 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
481 # a mkfs failure may be caused by conflicts between
482 # $MKFS_OPTIONS and $extra_mkfs_options
483 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
485 echo -n "** mkfs failed with extra mkfs options "
486 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
487 echo -n "** attempting to mkfs using only test $seq "
488 echo "options: $extra_mkfs_options **"
491 # running mkfs again. overwrite previous mkfs output files
492 _scratch_mkfs_xfs_opts $extra_mkfs_options \
493 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
497 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
498 # manually parse the mkfs output to get the fs size in bytes
500 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
501 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
503 print STDOUT "$size\n";
505 _setup_large_xfs_fs $fs_size
509 # output stored mkfs output, filtering unnecessary warnings from stderr
511 cat $tmp_dir.mkfserr | sed \
512 -e '/less than device physical sector/d' \
513 -e '/switching to logical sector/d' \
515 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
520 # xfs_check script is planned to be deprecated. But, we want to
521 # be able to invoke "xfs_check" behavior in xfstests in order to
522 # maintain the current verification levels.
527 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
529 while getopts "b:fi:l:stvV" c
535 i) OPTS=$OPTS"-i "$OPTARG" ";;
536 b) OPTS=$OPTS"-b "$OPTARG" ";;
537 f) DBOPTS=$DBOPTS" -f";;
538 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
539 V) $XFS_DB_PROG -p xfs_check -V
547 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
557 _setup_large_ext4_fs()
562 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
563 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
564 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
566 # Default free space in the FS is 50GB, but you can specify more via
567 # SCRATCH_DEV_EMPTY_SPACE
568 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
570 # mount the filesystem and create 16TB - 4KB files until we consume
571 # all the necessary space.
572 _scratch_mount 2>&1 >$tmp_dir/mnt.err
574 if [ $status -ne 0 ]; then
576 cat $tmp_dir/mnt.err >&2
577 rm -f $tmp_dir/mnt.err
580 rm -f $tmp_dir/mnt.err
582 file_size=$((16*1024*1024*1024*1024 - 4096))
584 while [ $space_to_consume -gt $file_size ]; do
587 -c "truncate $file_size" \
588 -c "falloc -k 0 $file_size" \
589 $SCRATCH_MNT/.use_space.$nfiles 2>&1
591 if [ $status -ne 0 ]; then
595 space_to_consume=$(( $space_to_consume - $file_size ))
596 nfiles=$(($nfiles + 1))
599 # consume the remaining space.
600 if [ $space_to_consume -gt 0 ]; then
602 -c "truncate $space_to_consume" \
603 -c "falloc -k 0 $space_to_consume" \
604 $SCRATCH_MNT/.use_space.$nfiles 2>&1
607 export NUM_SPACE_FILES=$nfiles
610 if [ $status -ne 0 ]; then
611 echo "large file prealloc failed"
612 cat $tmp_dir/mnt.err >&2
620 # extra mkfs options can be added by tests
621 local extra_mkfs_options=$*
625 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
626 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
629 # a mkfs failure may be caused by conflicts between
630 # $MKFS_OPTIONS and $extra_mkfs_options
631 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
633 echo -n "** mkfs failed with extra mkfs options "
634 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
635 echo -n "** attempting to mkfs using only test $seq "
636 echo "options: $extra_mkfs_options **"
639 # running mkfs again. overwrite previous mkfs output files
640 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
641 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
645 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
646 # manually parse the mkfs output to get the fs size in bytes
647 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
648 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
649 / inodes, / { blks = $3 } \
650 /reserved for the super user/ { resv = $1 } \
651 END { fssize = bs * blks - resv; print fssize }'`
653 _setup_large_ext4_fs $fs_size
657 # output stored mkfs output
658 grep -v -e ^Warning: -e "^mke2fs " $tmp_dir.mkfserr >&2
660 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
672 # do nothing for cifs
675 # do nothing for overlay
678 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
681 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
684 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
687 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
699 # do nothing for overlay
702 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
705 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
708 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
709 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
713 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
714 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
718 if [ $? -ne 0 ]; then
719 # output stored mkfs output
720 cat $tmp_dir.mkfserr >&2
725 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
728 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
729 _scratch_cleanup_files()
733 # $SCRATCH_DEV is a valid directory in overlay case
734 rm -rf $SCRATCH_DEV/*
738 rm -rf $SCRATCH_MNT/*
751 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
752 # avoid EEXIST caused by the leftover files created in previous runs
753 _scratch_cleanup_files
756 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
757 # avoid EEXIST caused by the leftover files created in previous runs
758 _scratch_cleanup_files
761 # unable to re-create overlay, remove all files in $SCRATCH_MNT to
762 # avoid EEXIST caused by the leftover files created in previous runs
763 _scratch_cleanup_files
766 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
769 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
772 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
775 _scratch_mkfs_ext4 $*
778 # do nothing for tmpfs
781 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
784 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
793 # if dup profile is in mkfs options call _scratch_mkfs instead
794 # because dup profile only works with single device
795 if [[ "$*" =~ dup ]]; then
798 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
802 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
807 # Return the amount of free memory available on the system
810 free -b | grep ^Mem | awk '{print $4}'
813 # Create fs of certain size on scratch device
814 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
815 _scratch_mkfs_sized()
822 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
824 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
825 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
829 [ -n "$def_blksz" ] && blocksize=$def_blksz
830 [ -z "$blocksize" ] && blocksize=4096
834 if ! [[ $fssize =~ $re ]] ; then
835 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
837 if ! [[ $blocksize =~ $re ]] ; then
838 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
841 blocks=`expr $fssize / $blocksize`
843 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
844 devsize=`blockdev --getsize64 $SCRATCH_DEV`
845 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
850 # don't override MKFS_OPTIONS that set a block size.
851 echo $MKFS_OPTIONS |egrep -q "b?size="
852 if [ $? -eq 0 ]; then
853 _scratch_mkfs_xfs -d size=$fssize
855 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
858 ext2|ext3|ext4|ext4dev)
859 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
862 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
866 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
867 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
870 # mkfs.resier4 requires size in KB as input for creating filesystem
871 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
872 `expr $fssize / 1024`
875 # mkfs.f2fs requires # of sectors as an input for the size
876 sector_size=`blockdev --getss $SCRATCH_DEV`
877 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
880 free_mem=`_free_memory_bytes`
881 if [ "$free_mem" -lt "$fssize" ] ; then
882 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
884 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
887 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
892 # Emulate an N-data-disk stripe w/ various stripe units
893 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
899 [ -z "$blocksize" ] && blocksize=4096
901 let sunit_blocks=$sunit_bytes/$blocksize
902 let swidth_blocks=$sunit_blocks*$swidth_mult
906 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
909 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
912 _notrun "can't mkfs $FSTYP with geometry"
918 # Create fs of certain blocksize on scratch device
919 # _scratch_mkfs_blocksized blocksize
920 _scratch_mkfs_blocksized()
925 if ! [[ $blocksize =~ $re ]] ; then
926 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
931 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
933 ext2|ext3|ext4|ocfs2)
934 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
937 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
946 xfs_io -x -c "resblks $1" $SCRATCH_MNT
953 _scratch_xfs_db_options()
956 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
957 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
958 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
961 _scratch_xfs_logprint()
964 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
965 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
966 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
972 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
973 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
974 [ "$LARGE_SCRATCH_DEV" = yes ] && \
975 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
976 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
979 _scratch_xfs_repair()
982 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
983 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
984 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
985 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
986 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
987 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
990 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
991 # errors found or errors were fixed) and nonzero otherwise; also spits out
992 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
997 _scratch_xfs_repair "$@" 2>&1
999 if [ "$res" -eq 2 ]; then
1000 echo "xfs_repair returns $res; replay log?"
1003 if [ "$res" -gt 0 ]; then
1004 echo "mount returns $res; zap log?"
1005 _scratch_xfs_repair -L 2>&1
1006 echo "log zap returns $?"
1008 umount "$SCRATCH_MNT"
1010 _scratch_xfs_repair "$@" 2>&1
1013 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1017 # Let's hope fsck -y suffices...
1018 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1025 >&2 echo "fsck.$FSTYP failed, err=$res"
1037 echo "Usage: _get_pids_by_name process-name" 1>&2
1041 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1042 # HH:MM:SS before the psargs field, use this as the search anchor.
1044 # Matches with $1 (process-name) occur if the first psarg is $1
1045 # or ends in /$1 ... the matching uses sed's regular expressions,
1046 # so passing a regex into $1 will work.
1051 -e 's/[ ][ ]*/ /g' \
1054 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1055 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1058 # fix malloc libs output
1062 # filter out the Electric Fence notice
1065 if (defined $o && /^\s+Electric Fence/) {
1071 print $o if (defined $o);
1075 print $o if (defined $o);
1080 # _df_device : get an IRIX style df line for a given device
1082 # - returns "" if not mounted
1083 # - returns fs type in field two (ala IRIX)
1084 # - joins line together if split by fancy df formatting
1085 # - strips header etc
1092 echo "Usage: _df_device device" 1>&2
1096 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1097 # IPv6 server as a regular expression.
1098 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1099 ($1==what) && (NF==1) {
1113 # _df_dir : get an IRIX style df line for device where a directory resides
1115 # - returns fs type in field two (ala IRIX)
1116 # - joins line together if split by fancy df formatting
1117 # - strips header etc
1124 echo "Usage: _df_dir device" 1>&2
1128 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1144 # return percentage used disk space for mounted device
1150 echo "Usage: _used device" 1>&2
1154 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1157 # return the FS type of a mounted device
1163 echo "Usage: _fs_type device" 1>&2
1168 # The Linux kernel shows NFSv4 filesystems in df output as
1169 # filesystem type nfs4, although we mounted it as nfs earlier.
1170 # Fix the filesystem type up here so that the callers don't
1171 # have to bother with this quirk.
1173 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1176 # return the FS mount options of a mounted device
1178 # should write a version which just parses the output of mount for IRIX
1179 # compatibility, but since this isn't used at all, at the moment I'll leave
1186 echo "Usage: _fs_options device" 1>&2
1190 $AWK_PROG -v dev=$1 '
1191 match($1,dev) { print $4 }
1195 # returns device number if a file is a block device
1201 echo "Usage: _is_block_dev dev" 1>&2
1206 if [ -L "${_dev}" ]; then
1207 _dev=`readlink -f "${_dev}"`
1210 if [ -b "${_dev}" ]; then
1211 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1215 # Do a command, log it to $seqres.full, optionally test return status
1216 # and die if command fails. If called with one argument _do executes the
1217 # command, logs it, and returns its exit status. With two arguments _do
1218 # first prints the message passed in the first argument, and then "done"
1219 # or "fail" depending on the return status of the command passed in the
1220 # second argument. If the command fails and the variable _do_die_on_error
1221 # is set to "always" or the two argument form is used and _do_die_on_error
1222 # is set to "message_only" _do will print an error message to
1223 # $seqres.out and exit.
1227 if [ $# -eq 1 ]; then
1229 elif [ $# -eq 2 ]; then
1232 echo -n "$_note... "
1234 echo "Usage: _do [note] cmd" 1>&2
1238 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1239 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1240 cat $tmp._out | _fix_malloc >>$seqres.full
1241 if [ $# -eq 2 ]; then
1242 if [ $ret -eq 0 ]; then
1249 && [ "$_do_die_on_error" = "always" \
1250 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1252 [ $# -ne 2 ] && echo
1253 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1260 # bail out, setting up .notrun file. Need to kill the filesystem check files
1261 # here, otherwise they are set incorrectly for the next test.
1265 echo "$*" > $seqres.notrun
1266 echo "$seq not run: $*"
1267 rm -f ${RESULT_DIR}/require_test
1268 rm -f ${RESULT_DIR}/require_scratch
1273 # just plain bail out
1277 echo "$*" | tee -a $seqres.full
1278 echo "(see $seqres.full for details)"
1283 # tests whether $FSTYP is one of the supported filesystems for a test
1289 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1295 _notrun "not suitable for this filesystem type: $FSTYP"
1299 # tests whether $FSTYP is one of the supported OSes for a test
1305 if [ "$h" = "$HOSTOS" ]
1311 _notrun "not suitable for this OS: $HOSTOS"
1314 # this test needs a scratch partition - check we're ok & unmount it
1315 # No post-test check of the device is required. e.g. the test intentionally
1316 # finishes the test with the filesystem in a corrupt state
1317 _require_scratch_nocheck()
1321 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1322 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1323 _notrun "this test requires a valid \$SCRATCH_DEV"
1325 if [ ! -d "$SCRATCH_MNT" ]; then
1326 _notrun "this test requires a valid \$SCRATCH_MNT"
1330 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1331 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1332 _notrun "this test requires a valid \$SCRATCH_DEV"
1334 if [ ! -d "$SCRATCH_MNT" ]; then
1335 _notrun "this test requires a valid \$SCRATCH_MNT"
1339 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1340 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1342 if [ ! -d "$SCRATCH_MNT" ]; then
1343 _notrun "this test requires a valid \$SCRATCH_MNT"
1347 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1349 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1353 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1355 _notrun "this test requires a valid \$SCRATCH_DEV"
1357 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1359 _notrun "this test requires a valid \$SCRATCH_DEV"
1361 if [ ! -d "$SCRATCH_MNT" ]
1363 _notrun "this test requires a valid \$SCRATCH_MNT"
1369 # Note that we use -F here so grep doesn't try to interpret an NFS over
1370 # IPv6 server as a regular expression.
1371 mount_rec=`_mount | grep -F $SCRATCH_DEV`
1374 # if it's mounted, make sure its on $SCRATCH_MNT
1375 if ! echo $mount_rec | grep -q $SCRATCH_MNT
1377 echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
1378 echo "Already mounted result:"
1382 # and then unmount it
1383 if ! _scratch_unmount
1385 echo "failed to unmount $SCRATCH_DEV"
1389 rm -f ${RESULT_DIR}/require_scratch
1392 # we need the scratch device and it should be checked post test.
1395 _require_scratch_nocheck
1396 touch ${RESULT_DIR}/require_scratch
1400 # this test needs a test partition - check we're ok & mount it
1406 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1407 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1408 _notrun "this test requires a valid \$TEST_DIR"
1410 if [ ! -d "$TEST_DIR" ]; then
1411 _notrun "this test requires a valid \$TEST_DIR"
1415 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1416 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1417 _notrun "this test requires a valid \$TEST_DEV"
1419 if [ ! -d "$TEST_DIR" ]; then
1420 _notrun "this test requires a valid \$TEST_DIR"
1424 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1425 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1427 if [ ! -d "$TEST_DIR" ]; then
1428 _notrun "this test requires a valid \$TEST_DIR"
1432 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1434 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1438 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1440 _notrun "this test requires a valid \$TEST_DEV"
1442 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1444 _notrun "this test requires a valid \$TEST_DEV"
1446 if [ ! -d "$TEST_DIR" ]
1448 _notrun "this test requires a valid \$TEST_DIR"
1454 # Note that we use -F here so grep doesn't try to interpret an NFS over
1455 # IPv6 server as a regular expression.
1456 mount_rec=`_mount | grep -F $TEST_DEV`
1459 # if it's mounted, make sure its on $TEST_DIR
1460 if ! echo $mount_rec | grep -q $TEST_DIR
1462 echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
1463 echo "Already mounted result:"
1468 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1469 if [ $? -ne 1 ]; then
1474 touch ${RESULT_DIR}/require_test
1477 # this test needs a logdev
1481 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1482 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1483 [ "$USE_EXTERNAL" != yes ] && \
1484 _notrun "This test requires USE_EXTERNAL to be enabled"
1486 # ensure its not mounted
1487 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1490 # this test requires loopback device support
1494 if [ "$HOSTOS" != "Linux" ]
1496 _notrun "This test requires linux for loopback device support"
1499 modprobe loop >/dev/null 2>&1
1500 if grep loop /proc/devices >/dev/null 2>&1
1504 _notrun "This test requires loopback device support"
1508 # this test requires ext2 filesystem support
1512 if [ "$HOSTOS" != "Linux" ]
1514 _notrun "This test requires linux for ext2 filesystem support"
1517 modprobe ext2 >/dev/null 2>&1
1518 if grep ext2 /proc/filesystems >/dev/null 2>&1
1522 _notrun "This test requires ext2 filesystem support"
1526 # this test requires that (large) loopback device files are not in use
1528 _require_no_large_scratch_dev()
1530 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1531 _notrun "Large filesystem testing in progress, skipped this test"
1534 # this test requires that a realtime subvolume is in use, and
1535 # that the kernel supports realtime as well.
1539 [ "$USE_EXTERNAL" = yes ] || \
1540 _notrun "External volumes not in use, skipped this test"
1541 [ "$SCRATCH_RTDEV" = "" ] && \
1542 _notrun "Realtime device required, skipped this test"
1545 # this test requires that a specified command (executable) exists
1546 # $1 - command, $2 - name for error message
1548 # Note: the command string might have parameters, so strip them before checking
1549 # whether it is executable.
1552 if [ $# -eq 2 ]; then
1554 elif [ $# -eq 1 ]; then
1557 _fail "usage: _require_command <command> [<name>]"
1560 _command=`echo "$1" | awk '{ print $1 }'`
1561 if [ ! -x "$_command" ]; then
1562 _notrun "$_name utility required, skipped this test"
1566 # this test requires the device to be valid block device
1568 _require_block_device()
1570 if [ -z "$1" ]; then
1571 echo "Usage: _require_block_device <dev>" 1>&2
1574 if [ "`_is_block_dev "$1"`" == "" ]; then
1575 _notrun "require $1 to be valid block disk"
1579 # brd based ram disks erase the device when they receive a flush command when no
1580 # active references are present. This causes problems for DM devices sitting on
1581 # top of brd devices as DM doesn't hold active references to the brd device.
1582 _require_sane_bdev_flush()
1584 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1585 if [ $? -eq 0 ]; then
1586 _notrun "This test requires a sane block device flush"
1590 # this test requires a specific device mapper target
1591 _require_dm_target()
1595 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1597 _require_block_device $SCRATCH_DEV
1598 _require_sane_bdev_flush $SCRATCH_DEV
1599 _require_command "$DMSETUP_PROG" dmsetup
1601 modprobe dm-$_target >/dev/null 2>&1
1603 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1604 if [ $? -ne 0 ]; then
1605 _notrun "This test requires dm $_target support"
1609 # this test requires the projid32bit feature to be available in mkfs.xfs.
1611 _require_projid32bit()
1613 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1614 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1617 _require_projid16bit()
1619 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1620 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1623 # this test requires the crc feature to be available in mkfs.xfs
1625 _require_xfs_mkfs_crc()
1627 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1628 || _notrun "mkfs.xfs doesn't have crc feature"
1631 # this test requires the xfs kernel support crc feature
1635 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1636 _scratch_mount >/dev/null 2>&1 \
1637 || _notrun "Kernel doesn't support crc feature"
1641 # this test requires the ext4 kernel support crc feature on scratch device
1643 _require_scratch_ext4_crc()
1645 _scratch_mkfs_ext4 >/dev/null 2>&1
1646 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1647 _scratch_mount >/dev/null 2>&1 \
1648 || _notrun "Kernel doesn't support metadata_csum feature"
1652 # this test requires the xfs kernel support crc feature on scratch device
1654 _require_scratch_xfs_crc()
1656 _scratch_mkfs_xfs >/dev/null 2>&1
1657 _scratch_mount >/dev/null 2>&1 \
1658 || _notrun "Kernel doesn't support crc feature"
1659 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1663 # this test requires the bigalloc feature to be available in mkfs.ext4
1665 _require_ext4_mkfs_bigalloc()
1667 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1668 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1671 # this test requires the ext4 kernel support bigalloc feature
1673 _require_ext4_bigalloc()
1675 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1676 _scratch_mount >/dev/null 2>&1 \
1677 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1681 # this test requires the finobt feature to be available in mkfs.xfs
1683 _require_xfs_mkfs_finobt()
1685 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1686 || _notrun "mkfs.xfs doesn't have finobt feature"
1689 # this test requires the xfs kernel support finobt feature
1691 _require_xfs_finobt()
1693 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1694 _scratch_mount >/dev/null 2>&1 \
1695 || _notrun "Kernel doesn't support finobt feature"
1699 # this test requires xfs sysfs attribute support
1701 _require_xfs_sysfs()
1704 sysfsdir=/sys/fs/xfs
1706 if [ ! -e $sysfsdir ]; then
1707 _notrun "no kernel support for XFS sysfs attributes"
1710 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1711 _notrun "sysfs attribute '$attr' is not supported"
1715 # this test requires the xfs sparse inode feature
1717 _require_xfs_sparse_inodes()
1719 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1720 || _notrun "mkfs.xfs does not support sparse inodes"
1721 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1722 _scratch_mount >/dev/null 2>&1 \
1723 || _notrun "kernel does not support sparse inodes"
1727 # this test requires that external log/realtime devices are not in use
1729 _require_nonexternal()
1731 [ "$USE_EXTERNAL" = yes ] && \
1732 _notrun "External device testing in progress, skipped this test"
1735 # this test requires that a (specified) aio-dio executable exists
1736 # $1 - command (optional)
1742 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1743 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1745 AIO_TEST=src/aio-dio-regress/$1
1746 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1751 # this test requires that a test program exists under src/
1752 # $1 - command (require)
1754 _require_test_program()
1757 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1760 # run an aio-dio program
1766 echo "usage: _run_aiodio command_name" 2>&1
1772 local testtemp=$TEST_DIR/aio-testfile
1774 $AIO_TEST $testtemp 2>&1
1781 # indicate whether YP/NIS is active or not
1786 dn=$(domainname 2>/dev/null)
1787 test -n "${dn}" -a "${dn}" != "(none)"
1791 # cat the password file
1795 [ $(_yp_active) -eq 0 ] && ypcat passwd
1799 # cat the group file
1803 [ $(_yp_active) -eq 0 ] && ypcat group
1807 # check for a user on the machine, fsgqa as default
1815 _cat_passwd | grep -q $qa_user
1816 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1817 echo /bin/true | su $qa_user
1818 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1821 # check for a group on the machine, fsgqa as default
1829 _cat_group | grep -q $qa_group
1830 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1836 s,.*Permission\sdenied.*,Permission denied,;
1837 s,.*no\saccess\sto\stty.*,,;
1838 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1845 if [ "$HOSTOS" == "IRIX" ]
1847 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1849 echo $1 | su $qa_user 2>&1 | _filter_user_do
1853 _require_xfs_io_command()
1857 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
1863 testfile=$TEST_DIR/$$.xfs_io
1866 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1868 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1869 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1870 -c "$command 4k 8k" $testfile 2>&1`
1873 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1874 -c "fiemap -v" $testfile 2>&1`
1877 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1879 echo $testio | egrep -q "invalid option|Is a directory" && \
1880 _notrun "xfs_io $command support is missing"
1883 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1886 rm -f $testfile 2>&1 > /dev/null
1887 echo $testio | grep -q "not found" && \
1888 _notrun "xfs_io $command support is missing"
1889 echo $testio | grep -q "Operation not supported" && \
1890 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1892 test -z "$param" && return
1893 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
1894 _notrun "xfs_io $command doesn't support $param"
1897 # check that xfs_db supports a specific command
1898 _require_xfs_db_command()
1902 echo "Usage: _require_xfs_db_command command" 1>&2
1907 $XFS_DB_PROG -x -c "help" $SCRATCH_DEV | grep $command > /dev/null || \
1908 _notrun "xfs_db $command support is missing"
1911 # check that kernel and filesystem support direct I/O
1914 testfile=$TEST_DIR/$$.direct
1915 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1916 if [ $? -ne 0 ]; then
1917 _notrun "O_DIRECT is not supported"
1919 rm -f $testfile 2>&1 > /dev/null
1922 # Check that a fs has enough free space (in 1024b blocks)
1927 BLOCKS=$2 # in units of 1024
1928 let GB=$BLOCKS/1024/1024
1930 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
1931 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1932 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1936 # Check if the filesystem supports sparse files.
1938 # Unfortunately there is no better way to do this than a manual black list.
1940 _require_sparse_files()
1944 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1953 #boot_params always present in debugfs
1954 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1957 _require_fail_make_request()
1959 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1960 || _notrun "$DEBUGFS_MNT/fail_make_request \
1961 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1965 # Check if the file system supports seek_data/hole
1967 _require_seek_data_hole()
1969 testfile=$TEST_DIR/$$.seek
1970 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1971 rm -f $testfile &>/dev/null
1972 echo $testseek | grep -q "Kernel does not support" && \
1973 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1976 # check that a FS on a device is mounted
1977 # if so, return mount point
1983 echo "Usage: _is_mounted device" 1>&2
1989 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1990 pattern { print $3 ; exit 0 }
1994 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1999 # remount a FS to a new mode (ro or rw)
2005 echo "Usage: _remount device ro/rw" 1>&2
2011 if ! mount -o remount,$mode $device
2013 echo "_remount: failed to remount filesystem on $device as $mode"
2018 # Run the appropriate repair/check on a filesystem
2020 # if the filesystem is mounted, it's either remounted ro before being
2021 # checked or it's unmounted and then remounted
2024 # If set, we remount ro instead of unmounting for fsck
2027 _umount_or_remount_ro()
2031 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2036 mountpoint=`_is_mounted $device`
2038 if [ $USE_REMOUNT -eq 0 ]; then
2039 $UMOUNT_PROG $device
2046 _mount_or_remount_rw()
2048 if [ $# -ne 3 ]; then
2049 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2056 if [ $USE_REMOUNT -eq 0 ]; then
2057 if [ "$FSTYP" != "overlay" ]; then
2058 _mount -t $FSTYP $mount_opts $device $mountpoint
2060 _overlay_mount $device $mountpoint
2062 if [ $? -ne 0 ]; then
2063 echo "!!! failed to remount $device on $mountpoint"
2073 # Check a generic filesystem in no-op mode; this assumes that the
2074 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2075 # and that it will still return an errno for corruption in this mode.
2077 # Filesystems which don't support this will need to define their
2078 # own check routine.
2080 _check_generic_filesystem()
2084 # If type is set, we're mounted
2085 type=`_fs_type $device`
2088 if [ "$type" = "$FSTYP" ]
2091 mountpoint=`_umount_or_remount_ro $device`
2094 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2097 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2099 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2100 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2101 cat $tmp.fsck >>$seqres.full
2102 echo "*** end fsck.$FSTYP output" >>$seqres.full
2110 echo "*** mount output ***" >>$seqres.full
2111 _mount >>$seqres.full
2112 echo "*** end mount output" >>$seqres.full
2113 elif [ "$type" = "$FSTYP" ]
2116 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2120 if [ $ok -eq 0 ]; then
2122 if [ "$iam" != "check" ]; then
2131 # run xfs_check and friends on a FS.
2133 _check_xfs_filesystem()
2137 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
2141 extra_mount_options=""
2142 extra_log_options=""
2145 if [ -f $device ];then
2149 if [ "$2" != "none" ]; then
2150 extra_log_options="-l$2"
2151 extra_mount_options="-ologdev=$2"
2154 if [ "$3" != "none" ]; then
2155 extra_rt_options="-r$3"
2156 extra_mount_options=$extra_mount_options" -ortdev=$3"
2158 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
2160 [ "$FSTYP" != xfs ] && return 0
2162 type=`_fs_type $device`
2165 if [ "$type" = "xfs" ]
2168 mountpoint=`_umount_or_remount_ro $device`
2171 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
2172 | tee $tmp.logprint | grep -q "<CLEAN>"
2173 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
2175 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
2177 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
2178 echo "*** xfs_logprint -t output ***" >>$seqres.full
2179 cat $tmp.logprint >>$seqres.full
2180 echo "*** end xfs_logprint output" >>$seqres.full
2185 # xfs_check runs out of memory on large files, so even providing the test
2186 # option (-t) to avoid indexing the free space trees doesn't make it pass on
2187 # large filesystems. Avoid it.
2188 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
2189 _xfs_check $extra_log_options $device 2>&1 |\
2190 _fix_malloc >$tmp.fs_check
2192 if [ -s $tmp.fs_check ]
2194 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
2196 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2197 echo "*** xfs_check output ***" >>$seqres.full
2198 cat $tmp.fs_check >>$seqres.full
2199 echo "*** end xfs_check output" >>$seqres.full
2204 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2207 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
2209 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2210 echo "*** xfs_repair -n output ***" >>$seqres.full
2211 cat $tmp.repair | _fix_malloc >>$seqres.full
2212 echo "*** end xfs_repair output" >>$seqres.full
2216 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
2220 echo "*** mount output ***" >>$seqres.full
2221 _mount >>$seqres.full
2222 echo "*** end mount output" >>$seqres.full
2223 elif [ "$type" = "xfs" ]
2225 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
2228 if [ $ok -eq 0 ]; then
2230 if [ "$iam" != "check" ]; then
2239 # Filter the knowen errors the UDF Verifier reports.
2240 _udf_test_known_error_filter()
2242 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."
2246 _check_udf_filesystem()
2248 [ "$DISABLE_UDF_TEST" == "1" ] && return
2250 if [ $# -ne 1 -a $# -ne 2 ]
2252 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2256 if [ ! -x $here/src/udf_test ]
2258 echo "udf_test not installed, please download and build the Philips"
2259 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2260 echo "Then copy the udf_test binary to $here/src/."
2261 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2269 LAST_BLOCK=`expr \( $2 - 1 \)`
2270 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2273 rm -f $seqres.checkfs
2274 sleep 1 # Due to a problem with time stamps in udf_test
2275 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2276 _udf_test_known_error_filter | \
2277 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2278 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2282 _check_xfs_test_fs()
2286 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2287 TEST_LOG="$TEST_LOGDEV"
2289 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2290 TEST_RT="$TEST_RTDEV"
2292 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2294 # check for ipath consistency
2295 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2296 # errors go to stderr
2297 xfs_check_ipaths $TEST_DIR >/dev/null
2298 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2302 _check_btrfs_filesystem()
2306 # If type is set, we're mounted
2307 type=`_fs_type $device`
2310 if [ "$type" = "$FSTYP" ]
2313 mountpoint=`_umount_or_remount_ro $device`
2316 btrfsck $device >$tmp.fsck 2>&1
2319 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2321 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2322 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2323 cat $tmp.fsck >>$seqres.full
2324 echo "*** end fsck.$FSTYP output" >>$seqres.full
2332 echo "*** mount output ***" >>$seqres.full
2333 _mount >>$seqres.full
2334 echo "*** end mount output" >>$seqres.full
2335 elif [ "$type" = "$FSTYP" ]
2338 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2342 if [ $ok -eq 0 ]; then
2344 if [ "$iam" != "check" ]; then
2360 # no way to check consistency for nfs
2363 # no way to check consistency for cifs
2366 # no way to check consistency for overlay
2369 # do nothing for now
2372 _check_btrfs_filesystem $TEST_DEV
2375 # no way to check consistency for tmpfs
2378 _check_generic_filesystem $TEST_DEV
2386 [ $# -eq 1 ] && device=$1
2392 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2393 SCRATCH_LOG="$SCRATCH_LOGDEV"
2395 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2396 SCRATCH_RT="$SCRATCH_RTDEV"
2398 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2401 _check_udf_filesystem $device $udf_fsize
2404 # Don't know how to check an NFS filesystem, yet.
2407 # Don't know how to check a CIFS filesystem, yet.
2410 # no way to check consistency for overlay
2413 _check_btrfs_filesystem $device
2416 # no way to check consistency for tmpfs
2419 _check_generic_filesystem $device
2424 _full_fstyp_details()
2426 [ -z "$FSTYP" ] && FSTYP=xfs
2427 if [ $FSTYP = xfs ]; then
2428 if [ -d /proc/fs/xfs ]; then
2429 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2430 FSTYP="$FSTYP (non-debug)"
2431 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2432 FSTYP="$FSTYP (debug)"
2435 if uname -a | grep -qi 'debug'; then
2436 FSTYP="$FSTYP (debug)"
2438 FSTYP="$FSTYP (non-debug)"
2445 _full_platform_details()
2451 echo "$os/$platform $host $kernel"
2456 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2458 elif [ "`uname`" == "Linux" ]; then
2461 echo Unknown operating system: `uname`
2466 _link_out_file_named()
2471 my $feature, $result, $suffix, $opts;
2473 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2474 $feathash{$feature} = 1;
2476 $result = "default";
2481 ($opts, $suffix) = split(/ *: */);
2482 foreach my $opt (split(/,/, $opts)) {
2483 if (!exists($feathash{$opt})) {
2497 ln -fs $SRC.$SUFFIX $1
2502 if [ $# -eq 0 ]; then
2503 FEATURES="$(_get_os_name)"
2504 if [ -n "$MOUNT_OPTIONS" ]; then
2505 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2511 _link_out_file_named $seqfull.out "$FEATURES"
2520 #takes files, randomdata
2528 if [ $size -gt 0 ]; then
2529 if [ "$2" == "false" ]; then
2530 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2532 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2539 # takes dirname, depth, randomdata
2542 dirname=$1; depth=$2; randomdata=$3
2543 mkdir $dirname || die "mkdir $dirname failed"
2546 _nfiles $files $randomdata # files for this dir and data type
2548 [ $depth -eq 0 ] && return
2549 let deep=$depth-1 # go 1 down
2551 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2554 while [ $d -lt $dirs ]
2556 _descend d$d $deep &
2562 # Populate a filesystem with inodes for performance experiments
2564 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2569 dirs=5 # ndirs in each subdir till leaves
2570 size=0 # sizeof files in K
2571 files=100 # num files in _each_ subdir
2572 depth=2 # depth of tree from root to leaves
2574 root=root # path of initial root of directory tree
2575 randomdata=false # -x data type urandom or zero
2578 while getopts "d:f:n:r:s:v:x" c
2587 x) randomdata=true;;
2591 _descend $root $depth $randomdata
2596 [ $verbose = true ] && echo done
2599 # query whether the given file has the given inode flag set
2606 if which $XFS_IO_PROG >/dev/null; then
2607 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2614 # query the given files extsize allocator hint in bytes (if any)
2621 if which $XFS_IO_PROG >/dev/null; then
2622 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2623 awk '/^xattr.extsize =/ { print $3 }'`
2625 [ -z "$blocks" ] && blocks="0"
2629 # scratch_dev_pool should contain the disks pool for the btrfs raid
2630 _require_scratch_dev_pool()
2635 if [ -z "$SCRATCH_DEV_POOL" ]; then
2636 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2639 if [ -z "$1" ]; then
2645 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2649 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2650 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2654 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2658 for i in $SCRATCH_DEV_POOL; do
2659 if [ "`_is_block_dev "$i"`" = "" ]; then
2660 _notrun "this test requires valid block disk $i"
2662 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2663 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2665 if _mount | grep -q $i; then
2666 if ! $UMOUNT_PROG $i; then
2667 echo "failed to unmount $i - aborting"
2671 # to help better debug when something fails, we remove
2672 # traces of previous btrfs FS on the dev.
2673 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2677 # ensure devices in SCRATCH_DEV_POOL are of the same size
2678 # must be called after _require_scratch_dev_pool
2679 _require_scratch_dev_pool_equal_size()
2685 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2686 _size=`_get_device_size $SCRATCH_DEV`
2687 for _dev in $SCRATCH_DEV_POOL; do
2688 _newsize=`_get_device_size $_dev`
2689 if [ $_size -ne $_newsize ]; then
2690 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2695 # We will check if the device is deletable
2696 _require_deletable_scratch_dev_pool()
2700 for i in $SCRATCH_DEV_POOL; do
2701 x=`echo $i | cut -d"/" -f 3`
2702 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2703 _notrun "$i is a device which is not deletable"
2708 # We check for btrfs and (optionally) features of the btrfs command
2712 _require_command "$BTRFS_UTIL_PROG" btrfs
2713 if [ -z "$1" ]; then
2716 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2717 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2720 # Check that fio is present, and it is able to execute given jobfile
2725 _require_command "$FIO_PROG" fio
2726 if [ -z "$1" ]; then
2730 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2731 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2734 # Does freeze work on this fs?
2737 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2739 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2740 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2743 # Does shutdown work on this fs?
2744 _require_scratch_shutdown()
2746 [ -x src/godown ] || _notrun "src/godown executable not found"
2748 _scratch_mkfs > /dev/null 2>&1
2750 src/godown -f $SCRATCH_MNT 2>&1 \
2751 || _notrun "$FSTYP does not support shutdown"
2755 # Does norecovery support by this fs?
2756 _require_norecovery()
2758 _scratch_mount -o ro,norecovery || \
2759 _notrun "$FSTYP does not support norecovery"
2763 # Does this filesystem support metadata journaling?
2764 # We exclude ones here that don't; otherwise we assume that it does, so the
2765 # test will run, fail, and motivate someone to update this test for a new
2768 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2769 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2771 _require_metadata_journaling()
2781 _notrun "$FSTYP does not support metadata journaling"
2784 # ext4 could be mkfs'd without a journal...
2786 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2787 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2790 # by default we pass; if you need to, add your fs above!
2795 # Does fiemap support?
2798 _require_xfs_io_command "fiemap"
2803 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2808 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2811 # arg 1 is dev to remove and is output of the below eg.
2812 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2818 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2820 stat $disk > /dev/null 2>&1
2821 while [ $? -eq 0 ]; do
2823 stat $disk > /dev/null 2>&1
2827 # arg 1 is dev to add and is output of the below eg.
2828 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2833 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2834 h=`echo ${1} | cut -d":" -f 1`
2835 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2837 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2839 # ensure the device comes online
2841 for i in `seq 1 10`; do
2842 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2843 dev=`ls /sys/class/scsi_device/${1}/device/block`
2844 for j in `seq 1 10`;
2846 stat /dev/$dev > /dev/null 2>&1
2847 if [ $? -eq 0 ]; then
2858 if [ $dev_back_oneline -eq 0 ]; then
2859 echo "/dev/$dev online failed" >> $seqres.full
2861 echo "/dev/$dev is back online" >> $seqres.full
2867 if [ -z "$FSTRIM_PROG" ]; then
2868 _notrun "This test requires fstrim utility."
2872 _require_batched_discard()
2874 if [ $# -ne 1 ]; then
2875 echo "Usage: _require_batched_discard mnt_point" 1>&2
2879 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2884 if [ -z "$DUMPE2FS_PROG" ]; then
2885 _notrun "This test requires dumpe2fs utility."
2891 if [ ! -e /proc/self/uid_map ]; then
2892 _notrun "This test requires procfs uid_map support."
2894 if [ ! -e /proc/self/gid_map ]; then
2895 _notrun "This test requires procfs gid_map support."
2901 FSSUM_PROG=$here/src/fssum
2902 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2907 CLONER_PROG=$here/src/cloner
2908 [ -x $CLONER_PROG ] || \
2909 _notrun "cloner binary not present at $CLONER_PROG"
2914 if [ "$FSTYP" == "nfs" ]; then
2915 _notrun "atime related mount options have no effect on NFS"
2921 _scratch_mkfs > /dev/null 2>&1
2922 _scratch_mount -o relatime || \
2923 _notrun "relatime not supported by the current kernel"
2929 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2930 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2933 _create_loop_device()
2936 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2940 _destroy_loop_device()
2943 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2946 _scale_fsstress_args()
2949 while [ $# -gt 0 ]; do
2951 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2952 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2953 *) args="$args $1" ;;
2961 # Return the logical block size if running on a block device,
2962 # else substitute the page size.
2964 _min_dio_alignment()
2968 if [ -b "$dev" ]; then
2969 blockdev --getss $dev
2971 $here/src/feature -s
2977 echo "# $@" >> $seqres.full 2>&1
2978 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2981 _run_btrfs_util_prog()
2983 run_check $BTRFS_UTIL_PROG $*
2986 _require_btrfs_send_stream_version()
2988 $BTRFS_UTIL_PROG send 2>&1 | \
2989 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2990 if [ $? -ne 0 ]; then
2991 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2994 # test if btrfs kernel supports send stream version 2
2995 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2996 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
3000 _require_btrfs_mkfs_feature()
3003 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
3007 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
3008 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
3010 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
3013 _require_btrfs_fs_feature()
3016 echo "Missing feature name argument for _require_btrfs_fs_feature"
3020 modprobe btrfs > /dev/null 2>&1
3021 [ -e /sys/fs/btrfs/features/$feat ] || \
3022 _notrun "Feature $feat not supported by the available btrfs version"
3025 _require_test_symlinks()
3027 # IRIX UDF does not support symlinks
3028 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3029 _notrun "Require symlinks support"
3030 target=`mktemp -p $TEST_DIR`
3031 link=`mktemp -p $TEST_DIR -u`
3032 ln -s `basename $target` $link
3033 if [ "$?" -ne 0 ]; then
3035 _notrun "Require symlinks support"
3040 _require_test_fcntl_advisory_locks()
3042 [ "$FSTYP" != "cifs" ] && return 0
3043 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3044 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3045 _notrun "Require fcntl advisory locks support"
3048 # XFS ability to change UUIDs on V5/CRC filesystems
3050 _require_meta_uuid()
3052 # This will create a crc fs on $SCRATCH_DEV
3055 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
3056 | grep -q "invalid UUID\|supported on V5 fs" \
3057 && _notrun "Userspace doesn't support meta_uuid feature"
3059 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
3061 _scratch_mount >/dev/null 2>&1 \
3062 || _notrun "Kernel doesn't support meta_uuid feature"
3066 _require_btrfs_dev_del_by_devid()
3068 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
3069 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
3070 "(must support 'btrfs device delete <devid> /<mnt>')"
3073 _require_test_lsattr()
3075 testio=$(lsattr -d $TEST_DIR 2>&1)
3076 echo $testio | grep -q "Operation not supported" && \
3077 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3078 echo $testio | grep -q "Inappropriate ioctl for device" && \
3079 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3082 _require_xfs_test_rmapbt()
3086 if [ "$(xfs_info "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
3087 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
3091 _require_xfs_scratch_rmapbt()
3095 _scratch_mkfs > /dev/null
3097 if [ "$(xfs_info "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
3099 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
3120 "$XFS_IO_PROG" -c "bmap -${param}lpv" "$file" | grep -c "$@"
3127 touch $TEST_DIR/syscalltest
3128 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3130 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3131 if [ "$status" -ne 0 ]; then
3132 _notrun "file system doesn't support chattr +$attribute"
3134 cat $TEST_DIR/syscalltest.out >> $seqres.full
3136 rm -f $TEST_DIR/syscalltest.out
3141 if [ -z "$1" ]; then
3142 echo "Usage: _get_total_inode <mnt>"
3146 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3152 if [ -z "$1" ]; then
3153 echo "Usage: _get_used_inode <mnt>"
3157 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3161 _get_used_inode_percent()
3163 if [ -z "$1" ]; then
3164 echo "Usage: _get_used_inode_percent <mnt>"
3168 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3175 if [ -z "$1" ]; then
3176 echo "Usage: _get_free_inode <mnt>"
3180 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3184 # get the available space in bytes
3186 _get_available_space()
3188 if [ -z "$1" ]; then
3189 echo "Usage: _get_available_space <mnt>"
3193 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3194 echo $((avail_kb * 1024))
3197 # get btrfs profile configs being tested
3199 # A set of pre-set profile configs are exported via _btrfs_profile_configs
3200 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
3201 # var in the format "metadata_profile:data_profile", multiple configs can be
3202 # seperated by space, e.g.
3203 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
3204 _btrfs_get_profile_configs()
3206 if [ "$FSTYP" != "btrfs" ]; then
3210 # no user specified btrfs profile configs, export the default configs
3211 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3213 _btrfs_profile_configs=(
3214 "-m single -d single"
3219 "-m raid10 -d raid10"
3224 # remove dup/raid5/raid6 profiles if we're doing device replace
3225 # dup profile indicates only one device being used (SCRATCH_DEV),
3226 # but we don't want to replace SCRATCH_DEV, which will be used in
3227 # _scratch_mount/_check_scratch_fs etc.
3228 # and raid5/raid6 doesn't support replace yet
3229 if [ "$1" == "replace" ]; then
3230 _btrfs_profile_configs=(
3231 "-m single -d single"
3235 "-m raid10 -d raid10"
3236 # add these back when raid5/6 is working with replace
3237 #"-m raid5 -d raid5"
3238 #"-m raid6 -d raid6"
3241 export _btrfs_profile_configs
3245 # parse user specified btrfs profile configs
3248 for cfg in $BTRFS_PROFILE_CONFIGS; do
3249 # turn "metadata:data" format to "-m metadata -d data"
3250 # and assign it to _btrfs_profile_configs array
3251 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
3252 _btrfs_profile_configs[$i]="$cfg"
3256 if [ "$1" == "replace" ]; then
3257 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
3258 _notrun "RAID5/6 doesn't support btrfs device replace yet"
3260 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
3261 _notrun "Do not set dup profile in btrfs device replace test"
3264 export _btrfs_profile_configs
3267 # stress btrfs by running balance operation in a loop
3268 _btrfs_stress_balance()
3272 $BTRFS_UTIL_PROG balance start $btrfs_mnt
3276 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
3277 _btrfs_stress_subvolume()
3281 local subvol_name=$3
3285 mkdir -p $subvol_mnt
3286 while [ ! -e $stop_file ]; do
3287 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
3288 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
3289 $UMOUNT_PROG $subvol_mnt
3290 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
3294 # stress btrfs by running scrub in a loop
3295 _btrfs_stress_scrub()
3299 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
3303 # stress btrfs by defragmenting every file/dir in a loop and compress file
3304 # contents while defragmenting if second argument is not "nocompress"
3305 _btrfs_stress_defrag()
3311 if [ "$compress" == "nocompress" ]; then
3312 find $btrfs_mnt \( -type f -o -type d \) -exec \
3313 $BTRFS_UTIL_PROG filesystem defrag {} \;
3315 find $btrfs_mnt \( -type f -o -type d \) -exec \
3316 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
3317 find $btrfs_mnt \( -type f -o -type d \) -exec \
3318 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
3323 # stress btrfs by remounting it with different compression algorithms in a loop
3324 # run this with fsstress running at background could exercise the compression
3325 # code path and ensure no race when switching compression algorithm with constant
3327 _btrfs_stress_remount_compress()
3331 for algo in no zlib lzo; do
3332 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
3337 # stress btrfs by replacing devices in a loop
3338 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
3339 # device should be free(not used by btrfs)
3340 _btrfs_stress_replace()
3344 # The device number in SCRATCH_DEV_POOL should be at least 3,
3345 # one is SCRATCH_DEV, one is to be replaced, one is free device
3346 # we won't replace SCRATCH_DEV, see below for reason
3347 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
3348 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
3352 # take the last device as the first free_dev
3353 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
3355 # free_dev should be really free
3356 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
3357 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3361 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3362 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3363 # _scratch_mount and _check_scratch_fs etc.
3364 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3365 -e "s# *$free_dev *##"`
3367 # set the first device in dev_pool as the first src_dev to be replaced
3368 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3370 echo "dev_pool=$dev_pool"
3371 echo "free_dev=$free_dev, src_dev=$src_dev"
3373 echo "Replacing $src_dev with $free_dev"
3374 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3375 if [ $? -ne 0 ]; then
3376 # don't update src_dev and free_dev if replace failed
3379 dev_pool="$dev_pool $free_dev"
3380 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3382 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3386 # find the right option to force output in bytes, older versions of btrfs-progs
3387 # print that by default, newer print human readable numbers with unit suffix
3388 _btrfs_qgroup_units()
3390 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3393 # return device size in kb
3396 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3399 # check dmesg log for WARNING/Oops/etc.
3402 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3405 rm -f ${RESULT_DIR}/check_dmesg
3407 # default filter is a simple cat command, caller could provide a
3408 # customized filter and pass the name through the first argument, to
3409 # filter out intentional WARNINGs or Oopses
3412 # search the dmesg log of last run of $seqnum for possible failures
3413 # use sed \cregexpc address type, since $seqnum contains "/"
3414 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3415 tac | $filter >$seqres.dmesg
3416 grep -q -e "kernel BUG at" \
3420 -e "possible recursive locking detected" \
3421 -e "Internal error" \
3422 -e "INFO: suspicious RCU usage" \
3423 -e "INFO: possible circular locking dependency detected" \
3424 -e "general protection fault:" \
3426 if [ $? -eq 0 ]; then
3427 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3435 # don't check dmesg log after test
3436 _disable_dmesg_check()
3438 rm -f ${RESULT_DIR}/check_dmesg
3443 if [ "$iam" == new ]
3447 # make some further configuration checks here
3448 if [ "$TEST_DEV" = "" ]
3450 echo "common/rc: Error: \$TEST_DEV is not set"
3454 # if $TEST_DEV is not mounted, mount it now as XFS
3455 if [ -z "`_fs_type $TEST_DEV`" ]
3457 # $TEST_DEV is not mounted
3460 echo "common/rc: retrying test device mount with external set"
3461 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3464 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3470 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3472 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3473 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
3474 _df_device $TEST_DEV
3477 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3478 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3479 export XFS_IO_PROG="$XFS_IO_PROG -F"
3481 # xfs_copy doesn't work on v5 xfs yet without -d option
3482 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3483 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3487 # get real device path name by following link
3491 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3492 _dev=`readlink -f "$_dev"`
3497 # basename of a device
3500 echo `basename $(_real_dev $1)`
3506 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3507 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3508 _maj=$(echo "ibase=16; $_maj" | bc)
3509 _min=$(echo "ibase=16; $_min" | bc)
3510 echo /sys/dev/block/$_maj:$_min
3515 if [ -z $1 ] || [ ! -d $1 ]; then
3516 echo "Missing mount point argument for get_block_size"
3519 echo `stat -f -c %S $1`
3524 echo $(getconf PAGE_SIZE)
3531 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3532 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3533 echo "$@" >>$seqres.full
3534 rm -f $TEST_DIR/junk
3535 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3536 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3544 ################################################################################
3545 # make sure this script returns success