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
277 local upper_fst=$(df --output=fstype $dir | tail -1)
280 if ! xfs_info $dir | grep -q "ftype=1" ; then
281 _notrun "upper fs needs to support d_type"
285 if ! tune2fs -l $(df --output=source $dir | tail -1) | \
286 grep -q filetype ; then
287 _notrun "upper fs needs to support d_type"
292 mkdir -p $dir/$OVERLAY_UPPER_DIR
293 mkdir -p $dir/$OVERLAY_LOWER_DIR
294 mkdir -p $dir/$OVERLAY_WORK_DIR
296 $MOUNT_PROG -t overlay $SELINUX_MOUNT_OPTIONS \
297 -o lowerdir=$dir/$OVERLAY_LOWER_DIR \
298 -o upperdir=$dir/$OVERLAY_UPPER_DIR \
299 -o workdir=$dir/$OVERLAY_WORK_DIR \
300 $OVERLAY_MOUNT_OPTIONS $* \
304 _overlay_test_mount()
306 _overlay_mount $TEST_DEV $TEST_DIR $*
309 _overlay_scratch_mount()
311 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
314 _overlay_test_unmount()
316 $UMOUNT_PROG $TEST_DIR
319 _overlay_scratch_unmount()
321 $UMOUNT_PROG $SCRATCH_MNT
326 if [ "$FSTYP" == "overlay" ]; then
327 _overlay_scratch_mount $*
330 _mount -t $FSTYP `_scratch_mount_options $*`
337 _overlay_scratch_unmount
340 $UMOUNT_PROG $SCRATCH_MNT
343 $UMOUNT_PROG $SCRATCH_DEV
352 if test -n "$opts"; then
353 mount -o "remount,$opts" $SCRATCH_MNT
357 _scratch_cycle_mount()
361 if [ "$FSTYP" = tmpfs ]; then
362 _scratch_remount "$opts"
365 if test -n "$opts"; then
369 _scratch_mount "$opts"
374 if [ "$FSTYP" == "overlay" ]; then
375 _overlay_test_mount $*
379 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
384 if [ "$FSTYP" == "overlay" ]; then
385 _overlay_test_unmount
387 $UMOUNT_PROG $TEST_DEV
393 if [ "$FSTYP" = tmpfs ]; then
400 _scratch_mkfs_options()
402 _scratch_options mkfs
403 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
411 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
412 options="-l $SCRATCH_LOGDEV"
414 xfs_metadump $options $SCRATCH_DEV $dumpfile
417 _setup_large_xfs_fs()
422 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
423 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
424 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
426 # calculate the size of the file we need to allocate.
427 # Default free space in the FS is 50GB, but you can specify more via
428 # SCRATCH_DEV_EMPTY_SPACE
429 file_size=$(($fs_size - 50*1024*1024*1024))
430 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
432 # mount the filesystem, create the file, unmount it
433 _scratch_mount 2>&1 >$tmp_dir/mnt.err
435 if [ $status -ne 0 ]; then
437 cat $tmp_dir/mnt.err >&2
438 rm -f $tmp_dir/mnt.err
441 rm -f $tmp_dir/mnt.err
444 -c "truncate $file_size" \
445 -c "falloc -k 0 $file_size" \
447 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
448 export NUM_SPACE_FILES=1
451 if [ $status -ne 0 ]; then
452 echo "large file prealloc failed"
453 cat $tmp_dir/mnt.err >&2
459 _scratch_mkfs_xfs_opts()
463 # remove metadata related mkfs options if mkfs.xfs doesn't them
464 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
465 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
468 _scratch_options mkfs
470 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
474 _scratch_mkfs_xfs_supported()
478 _scratch_options mkfs
480 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
485 # extra mkfs options can be added by tests
486 local extra_mkfs_options=$*
490 # save mkfs output in case conflict means we need to run again.
491 # only the output for the mkfs that applies should be shown
492 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
493 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
497 # a mkfs failure may be caused by conflicts between
498 # $MKFS_OPTIONS and $extra_mkfs_options
499 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
501 echo -n "** mkfs failed with extra mkfs options "
502 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
503 echo -n "** attempting to mkfs using only test $seq "
504 echo "options: $extra_mkfs_options **"
507 # running mkfs again. overwrite previous mkfs output files
508 _scratch_mkfs_xfs_opts $extra_mkfs_options \
509 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
513 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
514 # manually parse the mkfs output to get the fs size in bytes
516 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
517 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
519 print STDOUT "$size\n";
521 _setup_large_xfs_fs $fs_size
525 # output stored mkfs output, filtering unnecessary warnings from stderr
527 cat $tmp_dir.mkfserr | sed \
528 -e '/less than device physical sector/d' \
529 -e '/switching to logical sector/d' \
531 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
536 # xfs_check script is planned to be deprecated. But, we want to
537 # be able to invoke "xfs_check" behavior in xfstests in order to
538 # maintain the current verification levels.
543 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
545 while getopts "b:fi:l:stvV" c
551 i) OPTS=$OPTS"-i "$OPTARG" ";;
552 b) OPTS=$OPTS"-b "$OPTARG" ";;
553 f) DBOPTS=$DBOPTS" -f";;
554 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
555 V) $XFS_DB_PROG -p xfs_check -V
563 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
573 _setup_large_ext4_fs()
578 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
579 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
580 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
582 # Default free space in the FS is 50GB, but you can specify more via
583 # SCRATCH_DEV_EMPTY_SPACE
584 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
586 # mount the filesystem and create 16TB - 4KB files until we consume
587 # all the necessary space.
588 _scratch_mount 2>&1 >$tmp_dir/mnt.err
590 if [ $status -ne 0 ]; then
592 cat $tmp_dir/mnt.err >&2
593 rm -f $tmp_dir/mnt.err
596 rm -f $tmp_dir/mnt.err
598 file_size=$((16*1024*1024*1024*1024 - 4096))
600 while [ $space_to_consume -gt $file_size ]; do
603 -c "truncate $file_size" \
604 -c "falloc -k 0 $file_size" \
605 $SCRATCH_MNT/.use_space.$nfiles 2>&1
607 if [ $status -ne 0 ]; then
611 space_to_consume=$(( $space_to_consume - $file_size ))
612 nfiles=$(($nfiles + 1))
615 # consume the remaining space.
616 if [ $space_to_consume -gt 0 ]; then
618 -c "truncate $space_to_consume" \
619 -c "falloc -k 0 $space_to_consume" \
620 $SCRATCH_MNT/.use_space.$nfiles 2>&1
623 export NUM_SPACE_FILES=$nfiles
626 if [ $status -ne 0 ]; then
627 echo "large file prealloc failed"
628 cat $tmp_dir/mnt.err >&2
636 # extra mkfs options can be added by tests
637 local extra_mkfs_options=$*
641 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
642 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
645 # a mkfs failure may be caused by conflicts between
646 # $MKFS_OPTIONS and $extra_mkfs_options
647 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
649 echo -n "** mkfs failed with extra mkfs options "
650 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
651 echo -n "** attempting to mkfs using only test $seq "
652 echo "options: $extra_mkfs_options **"
655 # running mkfs again. overwrite previous mkfs output files
656 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
657 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
661 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
662 # manually parse the mkfs output to get the fs size in bytes
663 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
664 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
665 / inodes, / { blks = $3 } \
666 /reserved for the super user/ { resv = $1 } \
667 END { fssize = bs * blks - resv; print fssize }'`
669 _setup_large_ext4_fs $fs_size
673 # output stored mkfs output
674 grep -v -e ^Warning: -e "^mke2fs " $tmp_dir.mkfserr >&2
676 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
688 # do nothing for cifs
691 # do nothing for overlay
694 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
697 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
700 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
703 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
715 # do nothing for overlay
718 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
721 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
724 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
725 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
729 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
730 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
734 if [ $? -ne 0 ]; then
735 # output stored mkfs output
736 cat $tmp_dir.mkfserr >&2
741 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
744 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
745 _scratch_cleanup_files()
749 # $SCRATCH_DEV is a valid directory in overlay case
750 rm -rf $SCRATCH_DEV/*
754 rm -rf $SCRATCH_MNT/*
767 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
768 # avoid EEXIST caused by the leftover files created in previous runs
769 _scratch_cleanup_files
772 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
773 # avoid EEXIST caused by the leftover files created in previous runs
774 _scratch_cleanup_files
777 # unable to re-create overlay, remove all files in $SCRATCH_MNT to
778 # avoid EEXIST caused by the leftover files created in previous runs
779 _scratch_cleanup_files
782 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
785 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
788 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
791 _scratch_mkfs_ext4 $*
794 # do nothing for tmpfs
797 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
800 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
809 # if dup profile is in mkfs options call _scratch_mkfs instead
810 # because dup profile only works with single device
811 if [[ "$*" =~ dup ]]; then
814 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
818 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
823 # Return the amount of free memory available on the system
826 free -b | grep ^Mem | awk '{print $4}'
829 # Create fs of certain size on scratch device
830 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
831 _scratch_mkfs_sized()
838 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
840 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
841 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
845 [ -n "$def_blksz" ] && blocksize=$def_blksz
846 [ -z "$blocksize" ] && blocksize=4096
850 if ! [[ $fssize =~ $re ]] ; then
851 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
853 if ! [[ $blocksize =~ $re ]] ; then
854 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
857 blocks=`expr $fssize / $blocksize`
859 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
860 devsize=`blockdev --getsize64 $SCRATCH_DEV`
861 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
866 # don't override MKFS_OPTIONS that set a block size.
867 echo $MKFS_OPTIONS |egrep -q "b?size="
868 if [ $? -eq 0 ]; then
869 _scratch_mkfs_xfs -d size=$fssize
871 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
874 ext2|ext3|ext4|ext4dev)
875 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
878 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
882 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
883 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
886 # mkfs.resier4 requires size in KB as input for creating filesystem
887 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
888 `expr $fssize / 1024`
891 # mkfs.f2fs requires # of sectors as an input for the size
892 sector_size=`blockdev --getss $SCRATCH_DEV`
893 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
896 free_mem=`_free_memory_bytes`
897 if [ "$free_mem" -lt "$fssize" ] ; then
898 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
900 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
903 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
908 # Emulate an N-data-disk stripe w/ various stripe units
909 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
915 [ -z "$blocksize" ] && blocksize=4096
917 let sunit_blocks=$sunit_bytes/$blocksize
918 let swidth_blocks=$sunit_blocks*$swidth_mult
922 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
925 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
928 _notrun "can't mkfs $FSTYP with geometry"
934 # Create fs of certain blocksize on scratch device
935 # _scratch_mkfs_blocksized blocksize
936 _scratch_mkfs_blocksized()
941 if ! [[ $blocksize =~ $re ]] ; then
942 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
947 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
949 ext2|ext3|ext4|ocfs2)
950 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
953 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
962 xfs_io -x -c "resblks $1" $SCRATCH_MNT
969 _scratch_xfs_db_options()
972 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
973 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
974 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
977 _scratch_xfs_logprint()
980 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
981 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
982 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
988 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
989 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
990 [ "$LARGE_SCRATCH_DEV" = yes ] && \
991 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
992 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
995 _scratch_xfs_repair()
998 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
999 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1000 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1001 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
1002 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
1003 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
1006 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1007 # errors found or errors were fixed) and nonzero otherwise; also spits out
1008 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1009 _repair_scratch_fs()
1013 _scratch_xfs_repair "$@" 2>&1
1015 if [ "$res" -eq 2 ]; then
1016 echo "xfs_repair returns $res; replay log?"
1019 if [ "$res" -gt 0 ]; then
1020 echo "mount returns $res; zap log?"
1021 _scratch_xfs_repair -L 2>&1
1022 echo "log zap returns $?"
1024 umount "$SCRATCH_MNT"
1026 _scratch_xfs_repair "$@" 2>&1
1029 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1033 # Let's hope fsck -y suffices...
1034 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1041 >&2 echo "fsck.$FSTYP failed, err=$res"
1053 echo "Usage: _get_pids_by_name process-name" 1>&2
1057 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1058 # HH:MM:SS before the psargs field, use this as the search anchor.
1060 # Matches with $1 (process-name) occur if the first psarg is $1
1061 # or ends in /$1 ... the matching uses sed's regular expressions,
1062 # so passing a regex into $1 will work.
1067 -e 's/[ ][ ]*/ /g' \
1070 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1071 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1074 # fix malloc libs output
1078 # filter out the Electric Fence notice
1081 if (defined $o && /^\s+Electric Fence/) {
1087 print $o if (defined $o);
1091 print $o if (defined $o);
1096 # _df_device : get an IRIX style df line for a given device
1098 # - returns "" if not mounted
1099 # - returns fs type in field two (ala IRIX)
1100 # - joins line together if split by fancy df formatting
1101 # - strips header etc
1108 echo "Usage: _df_device device" 1>&2
1112 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1113 # IPv6 server as a regular expression.
1114 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1115 ($1==what) && (NF==1) {
1129 # _df_dir : get an IRIX style df line for device where a directory resides
1131 # - returns fs type in field two (ala IRIX)
1132 # - joins line together if split by fancy df formatting
1133 # - strips header etc
1140 echo "Usage: _df_dir device" 1>&2
1144 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1160 # return percentage used disk space for mounted device
1166 echo "Usage: _used device" 1>&2
1170 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1173 # return the FS type of a mounted device
1179 echo "Usage: _fs_type device" 1>&2
1184 # The Linux kernel shows NFSv4 filesystems in df output as
1185 # filesystem type nfs4, although we mounted it as nfs earlier.
1186 # Fix the filesystem type up here so that the callers don't
1187 # have to bother with this quirk.
1189 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1192 # return the FS mount options of a mounted device
1194 # should write a version which just parses the output of mount for IRIX
1195 # compatibility, but since this isn't used at all, at the moment I'll leave
1202 echo "Usage: _fs_options device" 1>&2
1206 $AWK_PROG -v dev=$1 '
1207 match($1,dev) { print $4 }
1211 # returns device number if a file is a block device
1217 echo "Usage: _is_block_dev dev" 1>&2
1222 if [ -L "${_dev}" ]; then
1223 _dev=`readlink -f "${_dev}"`
1226 if [ -b "${_dev}" ]; then
1227 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1231 # Do a command, log it to $seqres.full, optionally test return status
1232 # and die if command fails. If called with one argument _do executes the
1233 # command, logs it, and returns its exit status. With two arguments _do
1234 # first prints the message passed in the first argument, and then "done"
1235 # or "fail" depending on the return status of the command passed in the
1236 # second argument. If the command fails and the variable _do_die_on_error
1237 # is set to "always" or the two argument form is used and _do_die_on_error
1238 # is set to "message_only" _do will print an error message to
1239 # $seqres.out and exit.
1243 if [ $# -eq 1 ]; then
1245 elif [ $# -eq 2 ]; then
1248 echo -n "$_note... "
1250 echo "Usage: _do [note] cmd" 1>&2
1254 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1255 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1256 cat $tmp._out | _fix_malloc >>$seqres.full
1257 if [ $# -eq 2 ]; then
1258 if [ $ret -eq 0 ]; then
1265 && [ "$_do_die_on_error" = "always" \
1266 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1268 [ $# -ne 2 ] && echo
1269 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1276 # bail out, setting up .notrun file. Need to kill the filesystem check files
1277 # here, otherwise they are set incorrectly for the next test.
1281 echo "$*" > $seqres.notrun
1282 echo "$seq not run: $*"
1283 rm -f ${RESULT_DIR}/require_test
1284 rm -f ${RESULT_DIR}/require_scratch
1289 # just plain bail out
1293 echo "$*" | tee -a $seqres.full
1294 echo "(see $seqres.full for details)"
1299 # tests whether $FSTYP is one of the supported filesystems for a test
1305 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1311 _notrun "not suitable for this filesystem type: $FSTYP"
1315 # tests whether $FSTYP is one of the supported OSes for a test
1321 if [ "$h" = "$HOSTOS" ]
1327 _notrun "not suitable for this OS: $HOSTOS"
1330 # this test needs a scratch partition - check we're ok & unmount it
1331 # No post-test check of the device is required. e.g. the test intentionally
1332 # finishes the test with the filesystem in a corrupt state
1333 _require_scratch_nocheck()
1337 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1338 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1339 _notrun "this test requires a valid \$SCRATCH_DEV"
1341 if [ ! -d "$SCRATCH_MNT" ]; then
1342 _notrun "this test requires a valid \$SCRATCH_MNT"
1346 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1347 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1348 _notrun "this test requires a valid \$SCRATCH_DEV"
1350 if [ ! -d "$SCRATCH_MNT" ]; then
1351 _notrun "this test requires a valid \$SCRATCH_MNT"
1355 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1356 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1358 if [ ! -d "$SCRATCH_MNT" ]; then
1359 _notrun "this test requires a valid \$SCRATCH_MNT"
1363 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1365 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1369 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1371 _notrun "this test requires a valid \$SCRATCH_DEV"
1373 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1375 _notrun "this test requires a valid \$SCRATCH_DEV"
1377 if [ ! -d "$SCRATCH_MNT" ]
1379 _notrun "this test requires a valid \$SCRATCH_MNT"
1385 # Note that we use -F here so grep doesn't try to interpret an NFS over
1386 # IPv6 server as a regular expression.
1387 mount_rec=`_mount | grep -F $SCRATCH_DEV`
1390 # if it's mounted, make sure its on $SCRATCH_MNT
1391 if ! echo $mount_rec | grep -q $SCRATCH_MNT
1393 echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
1394 echo "Already mounted result:"
1398 # and then unmount it
1399 if ! _scratch_unmount
1401 echo "failed to unmount $SCRATCH_DEV"
1405 rm -f ${RESULT_DIR}/require_scratch
1408 # we need the scratch device and it should be checked post test.
1411 _require_scratch_nocheck
1412 touch ${RESULT_DIR}/require_scratch
1416 # this test needs a test partition - check we're ok & mount it
1422 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1423 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1424 _notrun "this test requires a valid \$TEST_DIR"
1426 if [ ! -d "$TEST_DIR" ]; then
1427 _notrun "this test requires a valid \$TEST_DIR"
1431 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1432 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1433 _notrun "this test requires a valid \$TEST_DEV"
1435 if [ ! -d "$TEST_DIR" ]; then
1436 _notrun "this test requires a valid \$TEST_DIR"
1440 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1441 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1443 if [ ! -d "$TEST_DIR" ]; then
1444 _notrun "this test requires a valid \$TEST_DIR"
1448 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1450 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1454 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1456 _notrun "this test requires a valid \$TEST_DEV"
1458 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1460 _notrun "this test requires a valid \$TEST_DEV"
1462 if [ ! -d "$TEST_DIR" ]
1464 _notrun "this test requires a valid \$TEST_DIR"
1470 # Note that we use -F here so grep doesn't try to interpret an NFS over
1471 # IPv6 server as a regular expression.
1472 mount_rec=`_mount | grep -F $TEST_DEV`
1475 # if it's mounted, make sure its on $TEST_DIR
1476 if ! echo $mount_rec | grep -q $TEST_DIR
1478 echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
1479 echo "Already mounted result:"
1484 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1485 if [ $? -ne 1 ]; then
1490 touch ${RESULT_DIR}/require_test
1493 # this test needs a logdev
1497 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1498 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1499 [ "$USE_EXTERNAL" != yes ] && \
1500 _notrun "This test requires USE_EXTERNAL to be enabled"
1502 # ensure its not mounted
1503 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1506 # this test requires loopback device support
1510 if [ "$HOSTOS" != "Linux" ]
1512 _notrun "This test requires linux for loopback device support"
1515 modprobe loop >/dev/null 2>&1
1516 if grep loop /proc/devices >/dev/null 2>&1
1520 _notrun "This test requires loopback device support"
1524 # this test requires ext2 filesystem support
1528 if [ "$HOSTOS" != "Linux" ]
1530 _notrun "This test requires linux for ext2 filesystem support"
1533 modprobe ext2 >/dev/null 2>&1
1534 if grep ext2 /proc/filesystems >/dev/null 2>&1
1538 _notrun "This test requires ext2 filesystem support"
1542 # this test requires that (large) loopback device files are not in use
1544 _require_no_large_scratch_dev()
1546 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1547 _notrun "Large filesystem testing in progress, skipped this test"
1550 # this test requires that a realtime subvolume is in use, and
1551 # that the kernel supports realtime as well.
1555 [ "$USE_EXTERNAL" = yes ] || \
1556 _notrun "External volumes not in use, skipped this test"
1557 [ "$SCRATCH_RTDEV" = "" ] && \
1558 _notrun "Realtime device required, skipped this test"
1561 # this test requires that a specified command (executable) exists
1562 # $1 - command, $2 - name for error message
1564 # Note: the command string might have parameters, so strip them before checking
1565 # whether it is executable.
1568 if [ $# -eq 2 ]; then
1570 elif [ $# -eq 1 ]; then
1573 _fail "usage: _require_command <command> [<name>]"
1576 _command=`echo "$1" | awk '{ print $1 }'`
1577 if [ ! -x "$_command" ]; then
1578 _notrun "$_name utility required, skipped this test"
1582 # this test requires the device to be valid block device
1584 _require_block_device()
1586 if [ -z "$1" ]; then
1587 echo "Usage: _require_block_device <dev>" 1>&2
1590 if [ "`_is_block_dev "$1"`" == "" ]; then
1591 _notrun "require $1 to be valid block disk"
1595 # brd based ram disks erase the device when they receive a flush command when no
1596 # active references are present. This causes problems for DM devices sitting on
1597 # top of brd devices as DM doesn't hold active references to the brd device.
1598 _require_sane_bdev_flush()
1600 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1601 if [ $? -eq 0 ]; then
1602 _notrun "This test requires a sane block device flush"
1606 # this test requires a specific device mapper target
1607 _require_dm_target()
1611 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1613 _require_block_device $SCRATCH_DEV
1614 _require_sane_bdev_flush $SCRATCH_DEV
1615 _require_command "$DMSETUP_PROG" dmsetup
1617 modprobe dm-$_target >/dev/null 2>&1
1619 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1620 if [ $? -ne 0 ]; then
1621 _notrun "This test requires dm $_target support"
1625 # this test requires the projid32bit feature to be available in mkfs.xfs.
1627 _require_projid32bit()
1629 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1630 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1633 _require_projid16bit()
1635 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1636 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1639 # this test requires the crc feature to be available in mkfs.xfs
1641 _require_xfs_mkfs_crc()
1643 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1644 || _notrun "mkfs.xfs doesn't have crc feature"
1647 # this test requires the xfs kernel support crc feature
1651 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1652 _scratch_mount >/dev/null 2>&1 \
1653 || _notrun "Kernel doesn't support crc feature"
1657 # this test requires the ext4 kernel support crc feature on scratch device
1659 _require_scratch_ext4_crc()
1661 _scratch_mkfs_ext4 >/dev/null 2>&1
1662 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1663 _scratch_mount >/dev/null 2>&1 \
1664 || _notrun "Kernel doesn't support metadata_csum feature"
1668 # this test requires the xfs kernel support crc feature on scratch device
1670 _require_scratch_xfs_crc()
1672 _scratch_mkfs_xfs >/dev/null 2>&1
1673 _scratch_mount >/dev/null 2>&1 \
1674 || _notrun "Kernel doesn't support crc feature"
1675 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1679 # this test requires the bigalloc feature to be available in mkfs.ext4
1681 _require_ext4_mkfs_bigalloc()
1683 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1684 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1687 # this test requires the ext4 kernel support bigalloc feature
1689 _require_ext4_bigalloc()
1691 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1692 _scratch_mount >/dev/null 2>&1 \
1693 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1697 # this test requires the finobt feature to be available in mkfs.xfs
1699 _require_xfs_mkfs_finobt()
1701 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1702 || _notrun "mkfs.xfs doesn't have finobt feature"
1705 # this test requires the xfs kernel support finobt feature
1707 _require_xfs_finobt()
1709 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1710 _scratch_mount >/dev/null 2>&1 \
1711 || _notrun "Kernel doesn't support finobt feature"
1715 # this test requires xfs sysfs attribute support
1717 _require_xfs_sysfs()
1720 sysfsdir=/sys/fs/xfs
1722 if [ ! -e $sysfsdir ]; then
1723 _notrun "no kernel support for XFS sysfs attributes"
1726 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1727 _notrun "sysfs attribute '$attr' is not supported"
1731 # this test requires the xfs sparse inode feature
1733 _require_xfs_sparse_inodes()
1735 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1736 || _notrun "mkfs.xfs does not support sparse inodes"
1737 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1738 _scratch_mount >/dev/null 2>&1 \
1739 || _notrun "kernel does not support sparse inodes"
1743 # this test requires that external log/realtime devices are not in use
1745 _require_nonexternal()
1747 [ "$USE_EXTERNAL" = yes ] && \
1748 _notrun "External device testing in progress, skipped this test"
1751 # this test requires that a (specified) aio-dio executable exists
1752 # $1 - command (optional)
1758 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1759 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1761 AIO_TEST=src/aio-dio-regress/$1
1762 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1767 # this test requires that a test program exists under src/
1768 # $1 - command (require)
1770 _require_test_program()
1773 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1776 # run an aio-dio program
1782 echo "usage: _run_aiodio command_name" 2>&1
1788 local testtemp=$TEST_DIR/aio-testfile
1790 $AIO_TEST $testtemp 2>&1
1797 # indicate whether YP/NIS is active or not
1802 dn=$(domainname 2>/dev/null)
1803 test -n "${dn}" -a "${dn}" != "(none)"
1807 # cat the password file
1811 [ $(_yp_active) -eq 0 ] && ypcat passwd
1815 # cat the group file
1819 [ $(_yp_active) -eq 0 ] && ypcat group
1823 # check for a user on the machine, fsgqa as default
1831 _cat_passwd | grep -q $qa_user
1832 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1833 echo /bin/true | su $qa_user
1834 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1837 # check for a group on the machine, fsgqa as default
1845 _cat_group | grep -q $qa_group
1846 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1852 s,.*Permission\sdenied.*,Permission denied,;
1853 s,.*no\saccess\sto\stty.*,,;
1854 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1861 if [ "$HOSTOS" == "IRIX" ]
1863 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1865 echo $1 | su $qa_user 2>&1 | _filter_user_do
1869 _require_xfs_io_command()
1873 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
1880 testfile=$TEST_DIR/$$.xfs_io
1883 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1885 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1886 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1887 -c "$command 4k 8k" $testfile 2>&1`
1890 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1891 -c "fiemap -v" $testfile 2>&1`
1894 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1896 echo $testio | egrep -q "invalid option|Is a directory" && \
1897 _notrun "xfs_io $command support is missing"
1900 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1903 rm -f $testfile 2>&1 > /dev/null
1904 echo $testio | grep -q "not found" && \
1905 _notrun "xfs_io $command support is missing"
1906 echo $testio | grep -q "Operation not supported" && \
1907 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1909 test -z "$param" && return
1910 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
1911 _notrun "xfs_io $command doesn't support $param"
1914 # check that xfs_db supports a specific command
1915 _require_xfs_db_command()
1919 echo "Usage: _require_xfs_db_command command" 1>&2
1924 $XFS_DB_PROG -x -c "help" $SCRATCH_DEV | grep $command > /dev/null || \
1925 _notrun "xfs_db $command support is missing"
1928 # check that kernel and filesystem support direct I/O
1931 if [ $FSTYP = "ext4" ] ; then
1932 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
1933 _notrun "ext4 encryption doesn't support O_DIRECT"
1936 testfile=$TEST_DIR/$$.direct
1937 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1938 if [ $? -ne 0 ]; then
1939 _notrun "O_DIRECT is not supported"
1941 rm -f $testfile 2>&1 > /dev/null
1944 # Check that a fs has enough free space (in 1024b blocks)
1949 BLOCKS=$2 # in units of 1024
1950 let GB=$BLOCKS/1024/1024
1952 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
1953 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1954 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1958 # Check if the filesystem supports sparse files.
1960 # Unfortunately there is no better way to do this than a manual black list.
1962 _require_sparse_files()
1966 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1975 #boot_params always present in debugfs
1976 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1979 _require_fail_make_request()
1981 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1982 || _notrun "$DEBUGFS_MNT/fail_make_request \
1983 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1987 # Check if the file system supports seek_data/hole
1989 _require_seek_data_hole()
1991 testfile=$TEST_DIR/$$.seek
1992 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1993 rm -f $testfile &>/dev/null
1994 echo $testseek | grep -q "Kernel does not support" && \
1995 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2000 _require_test_program "runas"
2005 "$here/src/runas" "$@"
2008 _require_richacl_prog()
2010 _require_command "$GETRICHACL_PROG" getrichacl
2011 _require_command "$SETRICHACL_PROG" setrichacl
2014 _require_scratch_richacl_xfs()
2016 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2017 || _notrun "mkfs.xfs doesn't have richacl feature"
2018 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2019 _scratch_mount >/dev/null 2>&1 \
2020 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2024 _require_scratch_richacl_ext4()
2026 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2027 || _notrun "can't mkfs $FSTYP with option -O richacl"
2028 _scratch_mount >/dev/null 2>&1 \
2029 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2033 _require_scratch_richacl_support()
2036 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2037 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2041 _require_scratch_richacl()
2044 xfs) _require_scratch_richacl_xfs
2046 ext4) _require_scratch_richacl_ext4
2049 _require_scratch_richacl_support
2051 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2056 _scratch_mkfs_richacl()
2059 xfs) _scratch_mkfs_xfs -m richacl=1
2061 ext4) _scratch_mkfs -O richacl
2069 # check that a FS on a device is mounted
2070 # if so, return mount point
2076 echo "Usage: _is_mounted device" 1>&2
2082 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2083 pattern { print $3 ; exit 0 }
2087 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2092 # remount a FS to a new mode (ro or rw)
2098 echo "Usage: _remount device ro/rw" 1>&2
2104 if ! mount -o remount,$mode $device
2106 echo "_remount: failed to remount filesystem on $device as $mode"
2111 # Run the appropriate repair/check on a filesystem
2113 # if the filesystem is mounted, it's either remounted ro before being
2114 # checked or it's unmounted and then remounted
2117 # If set, we remount ro instead of unmounting for fsck
2120 _umount_or_remount_ro()
2124 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2129 mountpoint=`_is_mounted $device`
2131 if [ $USE_REMOUNT -eq 0 ]; then
2132 $UMOUNT_PROG $device
2139 _mount_or_remount_rw()
2141 if [ $# -ne 3 ]; then
2142 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2149 if [ $USE_REMOUNT -eq 0 ]; then
2150 if [ "$FSTYP" != "overlay" ]; then
2151 _mount -t $FSTYP $mount_opts $device $mountpoint
2153 _overlay_mount $device $mountpoint
2155 if [ $? -ne 0 ]; then
2156 echo "!!! failed to remount $device on $mountpoint"
2166 # Check a generic filesystem in no-op mode; this assumes that the
2167 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2168 # and that it will still return an errno for corruption in this mode.
2170 # Filesystems which don't support this will need to define their
2171 # own check routine.
2173 _check_generic_filesystem()
2177 # If type is set, we're mounted
2178 type=`_fs_type $device`
2181 if [ "$type" = "$FSTYP" ]
2184 mountpoint=`_umount_or_remount_ro $device`
2187 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2190 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2192 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2193 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2194 cat $tmp.fsck >>$seqres.full
2195 echo "*** end fsck.$FSTYP output" >>$seqres.full
2203 echo "*** mount output ***" >>$seqres.full
2204 _mount >>$seqres.full
2205 echo "*** end mount output" >>$seqres.full
2206 elif [ "$type" = "$FSTYP" ]
2209 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2213 if [ $ok -eq 0 ]; then
2215 if [ "$iam" != "check" ]; then
2224 # run xfs_check and friends on a FS.
2226 _check_xfs_filesystem()
2230 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
2234 extra_mount_options=""
2235 extra_log_options=""
2238 if [ -f $device ];then
2242 if [ "$2" != "none" ]; then
2243 extra_log_options="-l$2"
2244 extra_mount_options="-ologdev=$2"
2247 if [ "$3" != "none" ]; then
2248 extra_rt_options="-r$3"
2249 extra_mount_options=$extra_mount_options" -ortdev=$3"
2251 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
2253 [ "$FSTYP" != xfs ] && return 0
2255 type=`_fs_type $device`
2258 if [ "$type" = "xfs" ]
2261 mountpoint=`_umount_or_remount_ro $device`
2264 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
2265 | tee $tmp.logprint | grep -q "<CLEAN>"
2266 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
2268 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
2270 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
2271 echo "*** xfs_logprint -t output ***" >>$seqres.full
2272 cat $tmp.logprint >>$seqres.full
2273 echo "*** end xfs_logprint output" >>$seqres.full
2278 # xfs_check runs out of memory on large files, so even providing the test
2279 # option (-t) to avoid indexing the free space trees doesn't make it pass on
2280 # large filesystems. Avoid it.
2281 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
2282 _xfs_check $extra_log_options $device 2>&1 |\
2283 _fix_malloc >$tmp.fs_check
2285 if [ -s $tmp.fs_check ]
2287 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
2289 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2290 echo "*** xfs_check output ***" >>$seqres.full
2291 cat $tmp.fs_check >>$seqres.full
2292 echo "*** end xfs_check output" >>$seqres.full
2297 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2300 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
2302 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2303 echo "*** xfs_repair -n output ***" >>$seqres.full
2304 cat $tmp.repair | _fix_malloc >>$seqres.full
2305 echo "*** end xfs_repair output" >>$seqres.full
2309 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
2313 echo "*** mount output ***" >>$seqres.full
2314 _mount >>$seqres.full
2315 echo "*** end mount output" >>$seqres.full
2316 elif [ "$type" = "xfs" ]
2318 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
2321 if [ $ok -eq 0 ]; then
2323 if [ "$iam" != "check" ]; then
2332 # Filter the knowen errors the UDF Verifier reports.
2333 _udf_test_known_error_filter()
2335 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."
2339 _check_udf_filesystem()
2341 [ "$DISABLE_UDF_TEST" == "1" ] && return
2343 if [ $# -ne 1 -a $# -ne 2 ]
2345 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2349 if [ ! -x $here/src/udf_test ]
2351 echo "udf_test not installed, please download and build the Philips"
2352 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2353 echo "Then copy the udf_test binary to $here/src/."
2354 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2362 LAST_BLOCK=`expr \( $2 - 1 \)`
2363 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2366 rm -f $seqres.checkfs
2367 sleep 1 # Due to a problem with time stamps in udf_test
2368 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2369 _udf_test_known_error_filter | \
2370 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2371 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2375 _check_xfs_test_fs()
2379 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2380 TEST_LOG="$TEST_LOGDEV"
2382 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2383 TEST_RT="$TEST_RTDEV"
2385 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2387 # check for ipath consistency
2388 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2389 # errors go to stderr
2390 xfs_check_ipaths $TEST_DIR >/dev/null
2391 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2395 _check_btrfs_filesystem()
2399 # If type is set, we're mounted
2400 type=`_fs_type $device`
2403 if [ "$type" = "$FSTYP" ]
2406 mountpoint=`_umount_or_remount_ro $device`
2409 btrfsck $device >$tmp.fsck 2>&1
2412 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2414 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2415 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2416 cat $tmp.fsck >>$seqres.full
2417 echo "*** end fsck.$FSTYP output" >>$seqres.full
2425 echo "*** mount output ***" >>$seqres.full
2426 _mount >>$seqres.full
2427 echo "*** end mount output" >>$seqres.full
2428 elif [ "$type" = "$FSTYP" ]
2431 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2435 if [ $ok -eq 0 ]; then
2437 if [ "$iam" != "check" ]; then
2453 # no way to check consistency for nfs
2456 # no way to check consistency for cifs
2459 # no way to check consistency for overlay
2462 # do nothing for now
2465 _check_btrfs_filesystem $TEST_DEV
2468 # no way to check consistency for tmpfs
2471 _check_generic_filesystem $TEST_DEV
2479 [ $# -eq 1 ] && device=$1
2485 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2486 SCRATCH_LOG="$SCRATCH_LOGDEV"
2488 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2489 SCRATCH_RT="$SCRATCH_RTDEV"
2491 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2494 _check_udf_filesystem $device $udf_fsize
2497 # Don't know how to check an NFS filesystem, yet.
2500 # Don't know how to check a CIFS filesystem, yet.
2503 # no way to check consistency for overlay
2506 _check_btrfs_filesystem $device
2509 # no way to check consistency for tmpfs
2512 _check_generic_filesystem $device
2517 _full_fstyp_details()
2519 [ -z "$FSTYP" ] && FSTYP=xfs
2520 if [ $FSTYP = xfs ]; then
2521 if [ -d /proc/fs/xfs ]; then
2522 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2523 FSTYP="$FSTYP (non-debug)"
2524 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2525 FSTYP="$FSTYP (debug)"
2528 if uname -a | grep -qi 'debug'; then
2529 FSTYP="$FSTYP (debug)"
2531 FSTYP="$FSTYP (non-debug)"
2538 _full_platform_details()
2544 echo "$os/$platform $host $kernel"
2549 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2551 elif [ "`uname`" == "Linux" ]; then
2554 echo Unknown operating system: `uname`
2559 _link_out_file_named()
2564 my $feature, $result, $suffix, $opts;
2566 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2567 $feathash{$feature} = 1;
2569 $result = "default";
2574 ($opts, $suffix) = split(/ *: */);
2575 foreach my $opt (split(/,/, $opts)) {
2576 if (!exists($feathash{$opt})) {
2590 ln -fs $SRC.$SUFFIX $1
2595 if [ $# -eq 0 ]; then
2596 FEATURES="$(_get_os_name)"
2597 if [ -n "$MOUNT_OPTIONS" ]; then
2598 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2604 _link_out_file_named $seqfull.out "$FEATURES"
2613 #takes files, randomdata
2621 if [ $size -gt 0 ]; then
2622 if [ "$2" == "false" ]; then
2623 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2625 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2632 # takes dirname, depth, randomdata
2635 dirname=$1; depth=$2; randomdata=$3
2636 mkdir $dirname || die "mkdir $dirname failed"
2639 _nfiles $files $randomdata # files for this dir and data type
2641 [ $depth -eq 0 ] && return
2642 let deep=$depth-1 # go 1 down
2644 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2647 while [ $d -lt $dirs ]
2649 _descend d$d $deep &
2655 # Populate a filesystem with inodes for performance experiments
2657 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2662 dirs=5 # ndirs in each subdir till leaves
2663 size=0 # sizeof files in K
2664 files=100 # num files in _each_ subdir
2665 depth=2 # depth of tree from root to leaves
2667 root=root # path of initial root of directory tree
2668 randomdata=false # -x data type urandom or zero
2671 while getopts "d:f:n:r:s:v:x" c
2680 x) randomdata=true;;
2684 _descend $root $depth $randomdata
2689 [ $verbose = true ] && echo done
2692 # query whether the given file has the given inode flag set
2699 if which $XFS_IO_PROG >/dev/null; then
2700 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2707 # query the given files extsize allocator hint in bytes (if any)
2714 if which $XFS_IO_PROG >/dev/null; then
2715 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2716 awk '/^xattr.extsize =/ { print $3 }'`
2718 [ -z "$blocks" ] && blocks="0"
2722 # scratch_dev_pool should contain the disks pool for the btrfs raid
2723 _require_scratch_dev_pool()
2728 if [ -z "$SCRATCH_DEV_POOL" ]; then
2729 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2732 if [ -z "$1" ]; then
2738 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2742 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2743 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2747 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2751 for i in $SCRATCH_DEV_POOL; do
2752 if [ "`_is_block_dev "$i"`" = "" ]; then
2753 _notrun "this test requires valid block disk $i"
2755 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2756 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2758 if _mount | grep -q $i; then
2759 if ! $UMOUNT_PROG $i; then
2760 echo "failed to unmount $i - aborting"
2764 # to help better debug when something fails, we remove
2765 # traces of previous btrfs FS on the dev.
2766 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2770 # ensure devices in SCRATCH_DEV_POOL are of the same size
2771 # must be called after _require_scratch_dev_pool
2772 _require_scratch_dev_pool_equal_size()
2778 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2779 _size=`_get_device_size $SCRATCH_DEV`
2780 for _dev in $SCRATCH_DEV_POOL; do
2781 _newsize=`_get_device_size $_dev`
2782 if [ $_size -ne $_newsize ]; then
2783 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2788 # We will check if the device is deletable
2789 _require_deletable_scratch_dev_pool()
2793 for i in $SCRATCH_DEV_POOL; do
2794 x=`echo $i | cut -d"/" -f 3`
2795 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2796 _notrun "$i is a device which is not deletable"
2801 # We check for btrfs and (optionally) features of the btrfs command
2805 _require_command "$BTRFS_UTIL_PROG" btrfs
2806 if [ -z "$1" ]; then
2809 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2810 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2813 # Check that fio is present, and it is able to execute given jobfile
2818 _require_command "$FIO_PROG" fio
2819 if [ -z "$1" ]; then
2823 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2824 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2827 # Does freeze work on this fs?
2830 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2832 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2833 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2836 # Does shutdown work on this fs?
2837 _require_scratch_shutdown()
2839 [ -x src/godown ] || _notrun "src/godown executable not found"
2841 _scratch_mkfs > /dev/null 2>&1
2843 src/godown -f $SCRATCH_MNT 2>&1 \
2844 || _notrun "$FSTYP does not support shutdown"
2848 # Does norecovery support by this fs?
2849 _require_norecovery()
2851 _scratch_mount -o ro,norecovery || \
2852 _notrun "$FSTYP does not support norecovery"
2856 # Does this filesystem support metadata journaling?
2857 # We exclude ones here that don't; otherwise we assume that it does, so the
2858 # test will run, fail, and motivate someone to update this test for a new
2861 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2862 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2864 _require_metadata_journaling()
2874 _notrun "$FSTYP does not support metadata journaling"
2877 # ext4 could be mkfs'd without a journal...
2879 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2880 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2883 # by default we pass; if you need to, add your fs above!
2888 # Does fiemap support?
2891 _require_xfs_io_command "fiemap"
2896 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2901 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2904 # arg 1 is dev to remove and is output of the below eg.
2905 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2911 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2913 stat $disk > /dev/null 2>&1
2914 while [ $? -eq 0 ]; do
2916 stat $disk > /dev/null 2>&1
2920 # arg 1 is dev to add and is output of the below eg.
2921 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2926 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2927 h=`echo ${1} | cut -d":" -f 1`
2928 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2930 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2932 # ensure the device comes online
2934 for i in `seq 1 10`; do
2935 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2936 dev=`ls /sys/class/scsi_device/${1}/device/block`
2937 for j in `seq 1 10`;
2939 stat /dev/$dev > /dev/null 2>&1
2940 if [ $? -eq 0 ]; then
2951 if [ $dev_back_oneline -eq 0 ]; then
2952 echo "/dev/$dev online failed" >> $seqres.full
2954 echo "/dev/$dev is back online" >> $seqres.full
2960 if [ -z "$FSTRIM_PROG" ]; then
2961 _notrun "This test requires fstrim utility."
2965 _require_batched_discard()
2967 if [ $# -ne 1 ]; then
2968 echo "Usage: _require_batched_discard mnt_point" 1>&2
2972 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2977 if [ -z "$DUMPE2FS_PROG" ]; then
2978 _notrun "This test requires dumpe2fs utility."
2984 if [ ! -e /proc/self/uid_map ]; then
2985 _notrun "This test requires procfs uid_map support."
2987 if [ ! -e /proc/self/gid_map ]; then
2988 _notrun "This test requires procfs gid_map support."
2994 FSSUM_PROG=$here/src/fssum
2995 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3000 CLONER_PROG=$here/src/cloner
3001 [ -x $CLONER_PROG ] || \
3002 _notrun "cloner binary not present at $CLONER_PROG"
3005 # skip test if MKFS_OPTIONS contains the given string
3006 _exclude_scratch_mount_option()
3008 if echo $MOUNT_OPTIONS | grep -q "$1"; then
3009 _notrun "mount option \"$1\" not allowed in this test"
3015 _exclude_scratch_mount_option "noatime"
3016 if [ "$FSTYP" == "nfs" ]; then
3017 _notrun "atime related mount options have no effect on NFS"
3023 _scratch_mkfs > /dev/null 2>&1
3024 _scratch_mount -o relatime || \
3025 _notrun "relatime not supported by the current kernel"
3031 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3032 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3035 _create_loop_device()
3038 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3042 _destroy_loop_device()
3045 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3048 _scale_fsstress_args()
3051 while [ $# -gt 0 ]; do
3053 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3054 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3055 *) args="$args $1" ;;
3063 # Return the logical block size if running on a block device,
3064 # else substitute the page size.
3066 _min_dio_alignment()
3070 if [ -b "$dev" ]; then
3071 blockdev --getss $dev
3073 $here/src/feature -s
3079 echo "# $@" >> $seqres.full 2>&1
3080 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3083 _run_btrfs_util_prog()
3085 run_check $BTRFS_UTIL_PROG $*
3088 _require_btrfs_send_stream_version()
3090 $BTRFS_UTIL_PROG send 2>&1 | \
3091 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
3092 if [ $? -ne 0 ]; then
3093 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
3096 # test if btrfs kernel supports send stream version 2
3097 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
3098 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
3102 _require_btrfs_mkfs_feature()
3105 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
3109 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
3110 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
3112 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
3115 _require_btrfs_fs_feature()
3118 echo "Missing feature name argument for _require_btrfs_fs_feature"
3122 modprobe btrfs > /dev/null 2>&1
3123 [ -e /sys/fs/btrfs/features/$feat ] || \
3124 _notrun "Feature $feat not supported by the available btrfs version"
3127 _require_test_symlinks()
3129 # IRIX UDF does not support symlinks
3130 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3131 _notrun "Require symlinks support"
3132 target=`mktemp -p $TEST_DIR`
3133 link=`mktemp -p $TEST_DIR -u`
3134 ln -s `basename $target` $link
3135 if [ "$?" -ne 0 ]; then
3137 _notrun "Require symlinks support"
3142 _require_test_fcntl_advisory_locks()
3144 [ "$FSTYP" != "cifs" ] && return 0
3145 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3146 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3147 _notrun "Require fcntl advisory locks support"
3150 # XFS ability to change UUIDs on V5/CRC filesystems
3152 _require_meta_uuid()
3154 # This will create a crc fs on $SCRATCH_DEV
3157 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
3158 | grep -q "invalid UUID\|supported on V5 fs" \
3159 && _notrun "Userspace doesn't support meta_uuid feature"
3161 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
3163 _scratch_mount >/dev/null 2>&1 \
3164 || _notrun "Kernel doesn't support meta_uuid feature"
3168 _require_btrfs_dev_del_by_devid()
3170 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
3171 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
3172 "(must support 'btrfs device delete <devid> /<mnt>')"
3175 _require_test_lsattr()
3177 testio=$(lsattr -d $TEST_DIR 2>&1)
3178 echo $testio | grep -q "Operation not supported" && \
3179 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3180 echo $testio | grep -q "Inappropriate ioctl for device" && \
3181 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3184 _require_xfs_test_rmapbt()
3188 if [ "$(xfs_info "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
3189 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
3193 _require_xfs_scratch_rmapbt()
3197 _scratch_mkfs > /dev/null
3199 if [ "$(xfs_info "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
3201 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
3222 "$XFS_IO_PROG" -c "bmap -${param}lpv" "$file" | grep -c "$@"
3229 touch $TEST_DIR/syscalltest
3230 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3232 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3233 if [ "$status" -ne 0 ]; then
3234 _notrun "file system doesn't support chattr +$attribute"
3236 cat $TEST_DIR/syscalltest.out >> $seqres.full
3238 rm -f $TEST_DIR/syscalltest.out
3243 if [ -z "$1" ]; then
3244 echo "Usage: _get_total_inode <mnt>"
3248 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3254 if [ -z "$1" ]; then
3255 echo "Usage: _get_used_inode <mnt>"
3259 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3263 _get_used_inode_percent()
3265 if [ -z "$1" ]; then
3266 echo "Usage: _get_used_inode_percent <mnt>"
3270 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3277 if [ -z "$1" ]; then
3278 echo "Usage: _get_free_inode <mnt>"
3282 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3286 # get the available space in bytes
3288 _get_available_space()
3290 if [ -z "$1" ]; then
3291 echo "Usage: _get_available_space <mnt>"
3295 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3296 echo $((avail_kb * 1024))
3299 # get btrfs profile configs being tested
3301 # A set of pre-set profile configs are exported via _btrfs_profile_configs
3302 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
3303 # var in the format "metadata_profile:data_profile", multiple configs can be
3304 # seperated by space, e.g.
3305 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
3306 _btrfs_get_profile_configs()
3308 if [ "$FSTYP" != "btrfs" ]; then
3312 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3313 # Default configurations to test.
3325 # User-provided configurations.
3326 local configs=(${BTRFS_PROFILE_CONFIGS[@]})
3329 _btrfs_profile_configs=()
3330 for cfg in "${configs[@]}"; do
3331 local supported=true
3332 local profiles=(${cfg/:/ })
3333 if [ "$1" == "replace" ]; then
3334 # We can't do replace with these profiles because they
3335 # imply only one device ($SCRATCH_DEV), and we need to
3336 # keep $SCRATCH_DEV around for _scratch_mount
3337 # and _check_scratch_fs.
3341 elif [ "$1" == "replace-missing" ]; then
3342 # We can't replace missing devices with these profiles
3343 # because there isn't enough redundancy.
3350 local unsupported=()
3352 for unsupp in "${unsupported[@]}"; do
3353 if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then
3354 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3355 # For the default config, just omit it.
3358 # For user-provided config, don't run the test.
3359 _notrun "Profile $unsupp not supported for $1"
3363 if "$supported"; then
3364 _btrfs_profile_configs+=("-m ${profiles[0]} -d ${profiles[1]}")
3367 export _btrfs_profile_configs
3370 # stress btrfs by running balance operation in a loop
3371 _btrfs_stress_balance()
3375 $BTRFS_UTIL_PROG balance start $options
3379 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
3380 _btrfs_stress_subvolume()
3384 local subvol_name=$3
3388 mkdir -p $subvol_mnt
3389 while [ ! -e $stop_file ]; do
3390 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
3391 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
3392 $UMOUNT_PROG $subvol_mnt
3393 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
3397 # stress btrfs by running scrub in a loop
3398 _btrfs_stress_scrub()
3402 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
3406 # stress btrfs by defragmenting every file/dir in a loop and compress file
3407 # contents while defragmenting if second argument is not "nocompress"
3408 _btrfs_stress_defrag()
3414 if [ "$compress" == "nocompress" ]; then
3415 find $btrfs_mnt \( -type f -o -type d \) -exec \
3416 $BTRFS_UTIL_PROG filesystem defrag {} \;
3418 find $btrfs_mnt \( -type f -o -type d \) -exec \
3419 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
3420 find $btrfs_mnt \( -type f -o -type d \) -exec \
3421 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
3426 # stress btrfs by remounting it with different compression algorithms in a loop
3427 # run this with fsstress running at background could exercise the compression
3428 # code path and ensure no race when switching compression algorithm with constant
3430 _btrfs_stress_remount_compress()
3434 for algo in no zlib lzo; do
3435 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
3440 # stress btrfs by replacing devices in a loop
3441 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
3442 # device should be free(not used by btrfs)
3443 _btrfs_stress_replace()
3447 # The device number in SCRATCH_DEV_POOL should be at least 3,
3448 # one is SCRATCH_DEV, one is to be replaced, one is free device
3449 # we won't replace SCRATCH_DEV, see below for reason
3450 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
3451 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
3455 # take the last device as the first free_dev
3456 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
3458 # free_dev should be really free
3459 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
3460 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3464 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3465 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3466 # _scratch_mount and _check_scratch_fs etc.
3467 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3468 -e "s# *$free_dev *##"`
3470 # set the first device in dev_pool as the first src_dev to be replaced
3471 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3473 echo "dev_pool=$dev_pool"
3474 echo "free_dev=$free_dev, src_dev=$src_dev"
3476 echo "Replacing $src_dev with $free_dev"
3477 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3478 if [ $? -ne 0 ]; then
3479 # don't update src_dev and free_dev if replace failed
3482 dev_pool="$dev_pool $free_dev"
3483 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3485 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3489 # find the right option to force output in bytes, older versions of btrfs-progs
3490 # print that by default, newer print human readable numbers with unit suffix
3491 _btrfs_qgroup_units()
3493 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3496 # return device size in kb
3499 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3502 # check dmesg log for WARNING/Oops/etc.
3505 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3508 rm -f ${RESULT_DIR}/check_dmesg
3510 # default filter is a simple cat command, caller could provide a
3511 # customized filter and pass the name through the first argument, to
3512 # filter out intentional WARNINGs or Oopses
3515 # search the dmesg log of last run of $seqnum for possible failures
3516 # use sed \cregexpc address type, since $seqnum contains "/"
3517 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3518 tac | $filter >$seqres.dmesg
3519 grep -q -e "kernel BUG at" \
3523 -e "possible recursive locking detected" \
3524 -e "Internal error" \
3525 -e "INFO: suspicious RCU usage" \
3526 -e "INFO: possible circular locking dependency detected" \
3527 -e "general protection fault:" \
3529 if [ $? -eq 0 ]; then
3530 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3538 # don't check dmesg log after test
3539 _disable_dmesg_check()
3541 rm -f ${RESULT_DIR}/check_dmesg
3546 if [ "$iam" == new ]
3550 # make some further configuration checks here
3551 if [ "$TEST_DEV" = "" ]
3553 echo "common/rc: Error: \$TEST_DEV is not set"
3557 # if $TEST_DEV is not mounted, mount it now as XFS
3558 if [ -z "`_fs_type $TEST_DEV`" ]
3560 # $TEST_DEV is not mounted
3563 echo "common/rc: retrying test device mount with external set"
3564 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3567 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3573 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3575 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3576 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
3577 _df_device $TEST_DEV
3580 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3581 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3582 export XFS_IO_PROG="$XFS_IO_PROG -F"
3584 # xfs_copy doesn't work on v5 xfs yet without -d option
3585 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3586 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3590 # get real device path name by following link
3594 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3595 _dev=`readlink -f "$_dev"`
3600 # basename of a device
3603 echo `basename $(_real_dev $1)`
3609 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3610 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3611 _maj=$(echo "ibase=16; $_maj" | bc)
3612 _min=$(echo "ibase=16; $_min" | bc)
3613 echo /sys/dev/block/$_maj:$_min
3618 if [ -z $1 ] || [ ! -d $1 ]; then
3619 echo "Missing mount point argument for get_block_size"
3622 echo `stat -f -c %S $1`
3627 echo $(getconf PAGE_SIZE)
3634 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3635 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3636 echo "$@" >>$seqres.full
3637 rm -f $TEST_DIR/junk
3638 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3639 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3647 ################################################################################
3648 # make sure this script returns success