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:]-]*"
36 # Some tests are not relevant or functional when testing XFS realtime
37 # subvolumes along with the rtinherit=1 mkfs option. In these cases,
38 # this test will opt-out of the test.
39 _require_no_rtinherit()
41 [ "$FSTYP" = "xfs" ] && echo "$MKFS_OPTIONS" |
42 egrep -q "rtinherit([^=]|=1|$)" && \
43 _notrun "rtinherit mkfs option is not supported by this test."
49 _notrun "this test requires 'bc' tool for doing math operations"
55 [ $# -le 0 ] && return
57 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
59 _notrun "this test requires 'bc' tool for doing math operations"
66 if [ "$HOSTOS" == "Linux" ]
68 command dd --help 2>&1 | grep noxfer >/dev/null
72 command dd status=noxfer $@
81 # Prints the md5 checksum of a given file
84 md5sum $1 | cut -d ' ' -f1
87 # Write a byte into a range of a file
95 $XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
98 # mmap-write a byte into a range of a file
106 $XFS_IO_PROG -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
109 # ls -l w/ selinux sometimes puts a dot at the end:
110 # -rwxrw-r--. id1 id2 file1
111 # Also filter out lost+found directory on extN file system if present
115 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
118 # we need common/config
119 if [ "$iam" != "check" ]
121 if ! . ./common/config
123 echo "$iam: failed to source common/config"
143 echo "$err_msg" | tee -a $seqres.full
144 echo "(see $seqres.full for details)"
147 # make sure we have a standard umask
150 # check for correct setup and source the $FSTYP specific functions now
153 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
154 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
155 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
156 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
161 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
164 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
169 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
172 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
189 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
194 [ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
198 if [ ! -z "$REPORT_LIST" ]; then
205 $MOUNT_PROG `_mount_ops_filter $*`
208 # Call _mount to do mount operation but also save mountpoint to
209 # MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
212 local mnt_point=${!#}
213 local mnt_dev=${@:(-2):1}
214 local scratch_opts=""
215 if [ "$mnt_dev" = "$SCRATCH_DEV" ]; then
216 _scratch_options mount
217 scratch_opts="$SCRATCH_OPTIONS"
220 _mount $scratch_opts $*
221 if [ $? -eq 0 ]; then
222 MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
228 # Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
229 # and return it to caller
232 local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
234 if [ -n "$last_mnt" ]; then
235 $UMOUNT_PROG $last_mnt
237 MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
240 # Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
243 if [ -n "$MOUNTED_POINT_STACK" ]; then
244 $UMOUNT_PROG $MOUNTED_POINT_STACK
246 MOUNTED_POINT_STACK=""
254 if [ "$FSTYP" != "xfs" ]; then
260 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
269 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
270 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
271 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
272 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
280 if [ "$FSTYP" != "xfs" ]; then
294 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
295 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
296 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
297 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
304 #get mount point to handle dmapi mtpt option correctly
306 [ $last_index -gt 0 ] && shift $last_index
309 echo $params | sed -e 's/dmapi/dmi/' \
310 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
314 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
315 # with the safe set of scratch mount options (e.g. loop image may be
316 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
317 _common_dev_mount_options()
319 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
322 _scratch_mount_options()
324 _scratch_options mount
326 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
327 $SCRATCH_DEV $SCRATCH_MNT
334 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
337 xfs_info $dir | grep -q "ftype=1"
340 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
341 tune2fs -l $dev | grep -q filetype
344 local testfile=$dir/$$.ftype
346 # look for DT_UNKNOWN files
347 local unknowns=$(src/t_dir_type $dir u | wc -l)
349 # 0 unknowns is success
355 # mount scratch device with given options but don't check mount status
358 if [ "$FSTYP" == "overlay" ]; then
359 _overlay_scratch_mount $*
362 _mount -t $FSTYP `_scratch_mount_options $*`
365 # mount scratch device with given options and _fail if mount fails
368 _try_scratch_mount $* || _fail "mount failed"
375 _overlay_scratch_unmount
378 $UMOUNT_PROG $SCRATCH_MNT
381 $UMOUNT_PROG $SCRATCH_DEV
390 if test -n "$opts"; then
391 mount -o "remount,$opts" $SCRATCH_MNT
395 _scratch_cycle_mount()
399 if [ "$FSTYP" = tmpfs ]; then
400 _scratch_remount "$opts"
403 if test -n "$opts"; then
407 _try_scratch_mount "$opts" || _fail "cycle mount failed"
412 if [ $FSTYP = "overlay" ]; then
413 # In lagacy overlay usage, it may specify directory as
414 # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
415 # will be null, so check OVL_BASE_SCRATCH_DEV before
416 # running shutdown to avoid shutting down base fs accidently.
417 if [ -z $OVL_BASE_SCRATCH_DEV ]; then
418 _fail "_scratch_shutdown: call _require_scratch_shutdown first in test"
420 src/godown $* $OVL_BASE_SCRATCH_MNT
423 src/godown $* $SCRATCH_MNT
429 if [ "$FSTYP" == "overlay" ]; then
430 _overlay_test_mount $*
434 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
439 if [ "$FSTYP" == "overlay" ]; then
440 _overlay_test_unmount
442 $UMOUNT_PROG $TEST_DEV
448 if [ "$FSTYP" = tmpfs ]; then
455 _scratch_mkfs_options()
457 _scratch_options mkfs
458 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
461 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
462 # and user specified mkfs options, if that fails (due to conflicts between mkfs
463 # options), do a second mkfs with only user provided mkfs options.
465 # First param is the mkfs command without any mkfs options and device.
466 # Second param is the filter to remove unnecessary messages from mkfs stderr.
467 # Other extra mkfs options are followed.
473 local extra_mkfs_options=$*
475 local tmp=`mktemp -u`
477 # save mkfs output in case conflict means we need to run again.
478 # only the output for the mkfs that applies should be shown
479 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
480 2>$tmp.mkfserr 1>$tmp.mkfsstd
483 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
484 # $extra_mkfs_options
485 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
487 echo -n "** mkfs failed with extra mkfs options "
488 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
489 echo -n "** attempting to mkfs using only test $seq "
490 echo "options: $extra_mkfs_options **"
493 # running mkfs again. overwrite previous mkfs output files
494 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
495 2>$tmp.mkfserr 1>$tmp.mkfsstd
499 # output stored mkfs output, filtering unnecessary output from stderr
501 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
503 rm -f $tmp.mkfserr $tmp.mkfsstd
513 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
514 options="-l $SCRATCH_LOGDEV"
516 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
519 _setup_large_ext4_fs()
524 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
525 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
526 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
528 # Default free space in the FS is 50GB, but you can specify more via
529 # SCRATCH_DEV_EMPTY_SPACE
530 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
532 # mount the filesystem and create 16TB - 4KB files until we consume
533 # all the necessary space.
534 _try_scratch_mount 2>&1 >$tmp_dir/mnt.err
536 if [ $status -ne 0 ]; then
538 cat $tmp_dir/mnt.err >&2
539 rm -f $tmp_dir/mnt.err
542 rm -f $tmp_dir/mnt.err
544 file_size=$((16*1024*1024*1024*1024 - 4096))
546 while [ $space_to_consume -gt $file_size ]; do
549 -c "truncate $file_size" \
550 -c "falloc -k 0 $file_size" \
551 $SCRATCH_MNT/.use_space.$nfiles 2>&1
553 if [ $status -ne 0 ]; then
557 space_to_consume=$(( $space_to_consume - $file_size ))
558 nfiles=$(($nfiles + 1))
561 # consume the remaining space.
562 if [ $space_to_consume -gt 0 ]; then
564 -c "truncate $space_to_consume" \
565 -c "falloc -k 0 $space_to_consume" \
566 $SCRATCH_MNT/.use_space.$nfiles 2>&1
569 export NUM_SPACE_FILES=$nfiles
572 if [ $status -ne 0 ]; then
573 echo "large file prealloc failed"
574 cat $tmp_dir/mnt.err >&2
582 local mkfs_cmd="$MKFS_EXT4_PROG -F"
583 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
584 local tmp=`mktemp -u`
587 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
588 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
589 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
591 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
594 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
595 # manually parse the mkfs output to get the fs size in bytes
596 fs_size=`cat $tmp.mkfsstd | awk ' \
597 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
598 / inodes, / { blks = $3 } \
599 /reserved for the super user/ { resv = $1 } \
600 END { fssize = bs * blks - resv; print fssize }'`
602 _setup_large_ext4_fs $fs_size
606 # output mkfs stdout and stderr
609 rm -f $tmp.mkfserr $tmp.mkfsstd
621 # do nothing for cifs
627 # do nothing for ceph
630 # do nothing for glusterfs
633 # do nothing for overlay
636 # do nothing for pvfs2
639 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
642 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
645 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
648 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
655 local tmp=`mktemp -u`
664 # do nothing for overlay
667 # do nothing for pvfs2
670 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
673 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
676 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
677 2>$tmp.mkfserr 1>$tmp.mkfsstd
680 $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* \
681 2>$tmp.mkfserr 1>$tmp.mkfsstd
684 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
685 2>$tmp.mkfserr 1>$tmp.mkfsstd
689 if [ $? -ne 0 ]; then
690 # output stored mkfs output
696 rm -f $tmp.mkfserr $tmp.mkfsstd
699 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
700 _scratch_cleanup_files()
704 # Avoid rm -rf /* if we messed up
705 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
706 _overlay_base_scratch_mount || return 1
707 rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
708 _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
709 # leave base fs mouted so tests can setup lower/upper dir files
712 [ -n "$SCRATCH_MNT" ] || return 1
714 rm -rf $SCRATCH_MNT/*
727 nfs*|cifs|ceph|overlay|glusterfs|pvfs2|9p)
728 # unable to re-create this fstyp, just remove all files in
729 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
730 # created in previous runs
731 _scratch_cleanup_files
735 # do nothing for tmpfs
739 # erase the UBI volume; reformated automatically on next mount
740 $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
744 _scratch_mkfs_ext4 $*
752 mkfs_cmd="$MKFS_UDF_PROG"
756 mkfs_cmd="$MKFS_BTRFS_PROG"
760 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
761 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
763 # put journal on separate device?
764 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
765 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
766 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
769 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
770 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
773 mkfs_cmd="$MKFS_F2FS_PROG"
777 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
778 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
781 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
786 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
790 # Helper function to get a spare or replace-target device from
791 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
792 # before _spare_dev_get(). Replace-target-device/Spare-device will
793 # be assigned to SPARE_DEV.
794 # As of now only one replace-target-device/spare-device can be
798 # _scratch_dev_pool_get() <ndevs>
802 # _scratch_dev_pool_put()
806 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
807 if [ $? -ne 0 ]; then
808 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
811 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
812 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
815 # Check if the spare is already assigned
816 typeset -p SPARE_DEV >/dev/null 2>&1
817 if [ $? -eq 0 ]; then
818 if [ ! -z "$SPARE_DEV" ]; then
819 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
823 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
824 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
826 if [ $ndevs -eq $config_ndevs ]; then
827 _notrun "All devs used no spare"
829 # Get a dev that is not used
830 local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
831 SPARE_DEV=${devs[@]:$ndevs:1}
837 typeset -p SPARE_DEV >/dev/null 2>&1
838 if [ $? -ne 0 ]; then
839 _fail "Bug: unset val, must call _spare_dev_get before its put"
842 if [ -z "$SPARE_DEV" ]; then
843 _fail "Bug: str empty, must call _spare_dev_get before its put"
850 # Generally test cases will have..
851 # _require_scratch_dev_pool X
852 # to make sure it has the enough scratch devices including
853 # replace-target and spare device. Now arg1 here is the
854 # required number of scratch devices by a-test-case excluding
855 # the replace-target and spare device. So this function will
856 # set SCRATCH_DEV_POOL to the specified number of devices.
859 # _scratch_dev_pool_get() <ndevs>
862 # _scratch_dev_pool_put()
864 _scratch_dev_pool_get()
866 if [ $# -ne 1 ]; then
867 _fail "Usage: _scratch_dev_pool_get ndevs"
871 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
872 local -a devs="( $SCRATCH_DEV_POOL )"
874 typeset -p config_ndevs >/dev/null 2>&1
875 if [ $? -ne 0 ]; then
876 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
879 if [ $config_ndevs -lt $test_ndevs ]; then
880 _notrun "Need at least test requested number of ndevs $test_ndevs"
883 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
884 export SCRATCH_DEV_POOL_SAVED
885 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
886 export SCRATCH_DEV_POOL
889 _scratch_dev_pool_put()
891 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
892 if [ $? -ne 0 ]; then
893 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
896 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
897 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
900 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
901 export SCRATCH_DEV_POOL_SAVED=""
908 # if dup profile is in mkfs options call _scratch_mkfs instead
909 # because dup profile only works with single device
910 if [[ "$*" =~ dup ]]; then
913 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
917 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
922 # Return the amount of free memory available on the system
925 free -b | grep ^Mem | awk '{print $4}'
928 # Create fs of certain size on scratch device
929 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
930 _scratch_mkfs_sized()
937 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
939 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2|reiserfs)
940 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
947 [ -n "$def_blksz" ] && blocksize=$def_blksz
948 [ -z "$blocksize" ] && blocksize=4096
952 if ! [[ $fssize =~ $re ]] ; then
953 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
955 if ! [[ $blocksize =~ $re ]] ; then
956 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
959 blocks=`expr $fssize / $blocksize`
961 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
962 devsize=`blockdev --getsize64 $SCRATCH_DEV`
963 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
968 # don't override MKFS_OPTIONS that set a block size.
969 echo $MKFS_OPTIONS |egrep -q "b?size="
970 if [ $? -eq 0 ]; then
971 _scratch_mkfs_xfs -d size=$fssize
973 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
976 ext2|ext3|ext4|ext4dev)
977 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
980 # mkfs.gfs2 doesn't automatically shrink journal files on small
981 # filesystems, so the journal files may end up being bigger than the
982 # filesystem, which will cause mkfs.gfs2 to fail. Until that's fixed,
983 # shrink the journal size to at most one eigth of the filesystem and at
984 # least 8 MiB, the minimum size allowed.
986 DEFAULT_JOURNAL_SIZE=128
987 if (( fssize/8 / (1024*1024) < DEFAULT_JOURNAL_SIZE )); then
988 (( JOURNAL_SIZE = fssize/8 / (1024*1024) ))
989 (( JOURNAL_SIZE >= MIN_JOURNAL_SIZE )) || JOURNAL_SIZE=$MIN_JOURNAL_SIZE
990 MKFS_OPTIONS="-J $JOURNAL_SIZE $MKFS_OPTIONS"
992 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
995 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
998 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1002 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1003 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1006 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
1009 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1012 # mkfs.resier4 requires size in KB as input for creating filesystem
1013 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1014 `expr $fssize / 1024`
1017 # mkfs.f2fs requires # of sectors as an input for the size
1018 sector_size=`blockdev --getss $SCRATCH_DEV`
1019 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1022 free_mem=`_free_memory_bytes`
1023 if [ "$free_mem" -lt "$fssize" ] ; then
1024 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1026 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1029 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1034 # Emulate an N-data-disk stripe w/ various stripe units
1035 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1036 _scratch_mkfs_geom()
1041 [ -z "$blocksize" ] && blocksize=4096
1043 let sunit_blocks=$sunit_bytes/$blocksize
1044 let swidth_blocks=$sunit_blocks*$swidth_mult
1048 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1051 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1054 _notrun "can't mkfs $FSTYP with geometry"
1060 # Create fs of certain blocksize on scratch device
1061 # _scratch_mkfs_blocksized blocksize
1062 _scratch_mkfs_blocksized()
1067 if ! [[ $blocksize =~ $re ]] ; then
1068 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1073 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1076 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1079 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
1082 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1085 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1094 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1102 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1103 # errors found or errors were fixed) and nonzero otherwise; also spits out
1104 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1105 _repair_scratch_fs()
1109 _scratch_xfs_repair "$@" 2>&1
1111 if [ "$res" -ne 0 ]; then
1112 echo "xfs_repair returns $res; replay log?"
1115 if [ "$res" -gt 0 ]; then
1116 echo "mount returns $res; zap log?"
1117 _scratch_xfs_repair -L 2>&1
1118 echo "log zap returns $?"
1120 umount "$SCRATCH_MNT"
1122 _scratch_xfs_repair "$@" 2>&1
1125 if [ $res -ne 0 ]; then
1126 _dump_err2 "xfs_repair failed, err=$res"
1131 # Let's hope fsck -y suffices...
1132 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1139 _dump_err2 "fsck.$FSTYP failed, err=$res"
1151 echo "Usage: _get_pids_by_name process-name" 1>&2
1155 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1156 # HH:MM:SS before the psargs field, use this as the search anchor.
1158 # Matches with $1 (process-name) occur if the first psarg is $1
1159 # or ends in /$1 ... the matching uses sed's regular expressions,
1160 # so passing a regex into $1 will work.
1165 -e 's/[ ][ ]*/ /g' \
1168 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1169 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1172 # fix malloc libs output
1176 # filter out the Electric Fence notice
1179 if (defined $o && /^\s+Electric Fence/) {
1185 print $o if (defined $o);
1189 print $o if (defined $o);
1194 # _df_device : get an IRIX style df line for a given device
1196 # - returns "" if not mounted
1197 # - returns fs type in field two (ala IRIX)
1198 # - joins line together if split by fancy df formatting
1199 # - strips header etc
1206 echo "Usage: _df_device device" 1>&2
1210 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1211 # IPv6 server as a regular expression.
1212 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1213 ($1==what) && (NF==1) {
1227 # _df_dir : get an IRIX style df line for device where a directory resides
1229 # - returns fs type in field two (ala IRIX)
1230 # - joins line together if split by fancy df formatting
1231 # - strips header etc
1238 echo "Usage: _df_dir device" 1>&2
1242 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1258 # return percentage used disk space for mounted device
1264 echo "Usage: _used device" 1>&2
1268 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1271 # return the FS type of a mounted device
1277 echo "Usage: _fs_type device" 1>&2
1282 # The Linux kernel shows NFSv4 filesystems in df output as
1283 # filesystem type nfs4, although we mounted it as nfs earlier.
1284 # Fix the filesystem type up here so that the callers don't
1285 # have to bother with this quirk.
1287 _df_device $1 | $AWK_PROG '{ print $2 }' | \
1288 sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
1291 # return the FS mount options of a mounted device
1293 # should write a version which just parses the output of mount for IRIX
1294 # compatibility, but since this isn't used at all, at the moment I'll leave
1301 echo "Usage: _fs_options device" 1>&2
1305 $AWK_PROG -v dev=$1 '
1306 match($1,dev) { print $4 }
1310 # returns device number if a file is a block device
1316 echo "Usage: _is_block_dev dev" 1>&2
1321 if [ -L "${_dev}" ]; then
1322 _dev=`readlink -f "${_dev}"`
1325 if [ -b "${_dev}" ]; then
1326 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1330 # returns device number if a file is a character device
1334 if [ $# -ne 1 ]; then
1335 echo "Usage: _is_char_dev dev" 1>&2
1340 if [ -L "${_dev}" ]; then
1341 _dev=`readlink -f "${_dev}"`
1344 if [ -c "${_dev}" ]; then
1345 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1349 # Do a command, log it to $seqres.full, optionally test return status
1350 # and die if command fails. If called with one argument _do executes the
1351 # command, logs it, and returns its exit status. With two arguments _do
1352 # first prints the message passed in the first argument, and then "done"
1353 # or "fail" depending on the return status of the command passed in the
1354 # second argument. If the command fails and the variable _do_die_on_error
1355 # is set to "always" or the two argument form is used and _do_die_on_error
1356 # is set to "message_only" _do will print an error message to
1357 # $seqres.out and exit.
1361 if [ $# -eq 1 ]; then
1363 elif [ $# -eq 2 ]; then
1366 echo -n "$_note... "
1368 echo "Usage: _do [note] cmd" 1>&2
1372 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1373 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1374 cat $tmp._out | _fix_malloc >>$seqres.full
1376 if [ $# -eq 2 ]; then
1377 if [ $ret -eq 0 ]; then
1384 && [ "$_do_die_on_error" = "always" \
1385 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1387 [ $# -ne 2 ] && echo
1388 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1395 # bail out, setting up .notrun file. Need to kill the filesystem check files
1396 # here, otherwise they are set incorrectly for the next test.
1400 echo "$*" > $seqres.notrun
1401 echo "$seq not run: $*"
1402 rm -f ${RESULT_DIR}/require_test*
1403 rm -f ${RESULT_DIR}/require_scratch*
1409 # just plain bail out
1413 echo "$*" | tee -a $seqres.full
1414 echo "(see $seqres.full for details)"
1419 # tests whether $FSTYP is one of the supported filesystems for a test
1425 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1431 _notrun "not suitable for this filesystem type: $FSTYP"
1435 # tests whether $FSTYP is one of the supported OSes for a test
1441 if [ "$h" = "$HOSTOS" ]
1447 _notrun "not suitable for this OS: $HOSTOS"
1450 # check if a FS on a device is mounted
1451 # if so, verify that it is mounted on mount point
1452 # if fstype is given as argument, verify that it is also
1453 # mounted with correct fs type
1463 # find $dev as the source, and print result in "$dev $mnt" format
1464 local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
1465 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1467 # if it's mounted, make sure its on $mnt
1468 if [ "$mount_rec" != "$dev $mnt" ]; then
1469 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1470 echo "Already mounted result:"
1472 return 2 # 2 = mounted on wrong mnt
1475 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
1476 echo "$devname=$dev is mounted but not a type $type filesystem"
1477 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1479 return 3 # 3 = mounted as wrong type
1481 return 0 # 0 = mounted as expected
1484 # this test needs a scratch partition - check we're ok & unmount it
1485 # No post-test check of the device is required. e.g. the test intentionally
1486 # finishes the test with the filesystem in a corrupt state
1487 _require_scratch_nocheck()
1491 echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
1492 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1493 _notrun "this test requires a valid \$SCRATCH_DEV"
1495 if [ ! -d "$SCRATCH_MNT" ]; then
1496 _notrun "this test requires a valid \$SCRATCH_MNT"
1500 if [ -z "$SCRATCH_DEV" ]; then
1501 _notrun "this test requires a valid \$SCRATCH_DEV"
1503 if [ ! -d "$SCRATCH_MNT" ]; then
1504 _notrun "this test requires a valid \$SCRATCH_MNT"
1508 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1509 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1510 _notrun "this test requires a valid \$SCRATCH_DEV"
1512 if [ ! -d "$SCRATCH_MNT" ]; then
1513 _notrun "this test requires a valid \$SCRATCH_MNT"
1517 echo $SCRATCH_DEV | grep -q "://" > /dev/null 2>&1
1518 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1519 _notrun "this test requires a valid \$SCRATCH_DEV"
1521 if [ ! -d "$SCRATCH_MNT" ]; then
1522 _notrun "this test requires a valid \$SCRATCH_MNT"
1526 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1527 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1528 _notrun "this test requires a valid \$SCRATCH_DEV"
1530 if [ ! -d "$SCRATCH_MNT" ]; then
1531 _notrun "this test requires a valid \$SCRATCH_MNT"
1535 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1536 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1538 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1539 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1540 # and we will create the mount point anyway on _overlay_mount
1541 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1542 _notrun "this test requires a valid \$SCRATCH_MNT"
1546 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1548 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1552 # ubifs needs an UBI volume. This will be a char device, not a block device.
1553 if [ ! -c "$SCRATCH_DEV" ]; then
1554 _notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
1556 if [ ! -d "$SCRATCH_MNT" ]; then
1557 _notrun "this test requires a valid \$SCRATCH_MNT"
1561 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1563 _notrun "this test requires a valid \$SCRATCH_DEV"
1565 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1567 _notrun "this test requires a valid \$SCRATCH_DEV"
1569 if [ ! -d "$SCRATCH_MNT" ]
1571 _notrun "this test requires a valid \$SCRATCH_MNT"
1576 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1578 [ $err -le 1 ] || exit 1
1581 # if it's mounted, unmount it
1582 if ! _scratch_unmount
1584 echo "failed to unmount $SCRATCH_DEV"
1588 rm -f ${RESULT_DIR}/require_scratch
1591 # we need the scratch device and it should be checked post test.
1594 _require_scratch_nocheck
1595 touch ${RESULT_DIR}/require_scratch
1599 # this test needs a test partition - check we're ok & mount it
1605 echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
1606 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1607 _notrun "this test requires a valid \$TEST_DEV"
1609 if [ ! -d "$TEST_DIR" ]; then
1610 _notrun "this test requires a valid \$TEST_DIR"
1614 if [ -z "$TEST_DEV" ]; then
1615 _notrun "this test requires a valid \$TEST_DEV"
1617 if [ ! -d "$TEST_DIR" ]; then
1618 _notrun "this test requires a valid \$TEST_DIR"
1622 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1623 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1624 _notrun "this test requires a valid \$TEST_DEV"
1626 if [ ! -d "$TEST_DIR" ]; then
1627 _notrun "this test requires a valid \$TEST_DIR"
1631 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1632 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1633 _notrun "this test requires a valid \$TEST_DEV"
1635 if [ ! -d "$TEST_DIR" ]; then
1636 _notrun "this test requires a valid \$TEST_DIR"
1640 echo $TEST_DEV | grep -q "://" > /dev/null 2>&1
1641 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1642 _notrun "this test requires a valid \$TEST_DIR"
1644 if [ ! -d "$TEST_DIR" ]; then
1645 _notrun "this test requires a valid \$TEST_DIR"
1649 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1650 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1652 if [ ! -d "$TEST_DIR" ]; then
1653 _notrun "this test requires a valid \$TEST_DIR"
1657 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1659 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1663 # ubifs needs an UBI volume. This will be a char device, not a block device.
1664 if [ ! -c "$TEST_DEV" ]; then
1665 _notrun "this test requires a valid UBI volume for \$TEST_DEV"
1667 if [ ! -d "$TEST_DIR" ]; then
1668 _notrun "this test requires a valid \$TEST_DIR"
1672 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1674 _notrun "this test requires a valid \$TEST_DEV"
1676 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1678 _notrun "this test requires a valid \$TEST_DEV"
1680 if [ ! -d "$TEST_DIR" ]
1682 _notrun "this test requires a valid \$TEST_DIR"
1687 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1689 [ $err -le 1 ] || exit 1
1694 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1698 touch ${RESULT_DIR}/require_test
1704 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
1705 [ "$USE_EXTERNAL" != yes ] && ret=1
1710 # this test needs a logdev
1714 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1715 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1716 [ "$USE_EXTERNAL" != yes ] && \
1717 _notrun "This test requires USE_EXTERNAL to be enabled"
1719 # ensure its not mounted
1720 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1723 # this test requires loopback device support
1727 if [ "$HOSTOS" != "Linux" ]
1729 _notrun "This test requires linux for loopback device support"
1732 modprobe loop >/dev/null 2>&1
1733 if grep loop /proc/devices >/dev/null 2>&1
1737 _notrun "This test requires loopback device support"
1741 # this test requires ext2 filesystem support
1745 if [ "$HOSTOS" != "Linux" ]
1747 _notrun "This test requires linux for ext2 filesystem support"
1750 modprobe ext2 >/dev/null 2>&1
1751 if grep ext2 /proc/filesystems >/dev/null 2>&1
1755 _notrun "This test requires ext2 filesystem support"
1759 # this test requires tmpfs filesystem support
1763 modprobe tmpfs >/dev/null 2>&1
1764 grep -q tmpfs /proc/filesystems ||
1765 _notrun "this test requires tmpfs support"
1768 # this test requires that (large) loopback device files are not in use
1770 _require_no_large_scratch_dev()
1772 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1773 _notrun "Large filesystem testing in progress, skipped this test"
1776 # this test requires that a realtime subvolume is in use, and
1777 # that the kernel supports realtime as well.
1781 [ "$USE_EXTERNAL" = yes ] || \
1782 _notrun "External volumes not in use, skipped this test"
1783 [ "$SCRATCH_RTDEV" = "" ] && \
1784 _notrun "Realtime device required, skipped this test"
1787 # This test requires that a realtime subvolume is not in use
1789 _require_no_realtime()
1791 [ "$USE_EXTERNAL" = "yes" ] && [ -n "$SCRATCH_RTDEV" ] && \
1792 _notrun "Test not compatible with realtime subvolumes, skipped this test"
1795 # this test requires that a specified command (executable) exists
1796 # $1 - command, $2 - name for error message
1798 # Note: the command string might have parameters, so strip them before checking
1799 # whether it is executable.
1802 if [ $# -eq 2 ]; then
1804 elif [ $# -eq 1 ]; then
1807 _fail "usage: _require_command <command> [<name>]"
1810 _command=`echo "$1" | awk '{ print $1 }'`
1811 if [ ! -x "$_command" ]; then
1812 _notrun "$_name utility required, skipped this test"
1816 # this test requires the device to be valid block device
1818 _require_block_device()
1820 if [ -z "$1" ]; then
1821 echo "Usage: _require_block_device <dev>" 1>&2
1824 if [ "`_is_block_dev "$1"`" == "" ]; then
1825 _notrun "require $1 to be valid block disk"
1829 # this test requires a path to refere to a local block or character device
1831 _require_local_device()
1833 if [ -z "$1" ]; then
1834 echo "Usage: _require_local_device <dev>" 1>&2
1837 if [ "`_is_block_dev "$1"`" != "" ]; then
1840 if [ "`_is_char_dev "$1"`" != "" ]; then
1843 _notrun "require $1 to be local device"
1846 # brd based ram disks erase the device when they receive a flush command when no
1847 # active references are present. This causes problems for DM devices sitting on
1848 # top of brd devices as DM doesn't hold active references to the brd device.
1849 _require_sane_bdev_flush()
1851 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1852 if [ $? -eq 0 ]; then
1853 _notrun "This test requires a sane block device flush"
1857 # this test requires a specific device mapper target
1858 _require_dm_target()
1862 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1864 _require_block_device $SCRATCH_DEV
1865 _require_sane_bdev_flush $SCRATCH_DEV
1866 _require_command "$DMSETUP_PROG" dmsetup
1868 modprobe dm-$_target >/dev/null 2>&1
1870 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1871 if [ $? -ne 0 ]; then
1872 _notrun "This test requires dm $_target support"
1876 # this test requires the ext4 kernel support crc feature on scratch device
1878 _require_scratch_ext4_crc()
1880 _scratch_mkfs_ext4 >/dev/null 2>&1
1881 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1882 _try_scratch_mount >/dev/null 2>&1 \
1883 || _notrun "Kernel doesn't support metadata_csum feature"
1887 # Check whether the specified feature whether it is supported by
1888 # mkfs.ext4 and the kernel.
1889 _require_scratch_ext4_feature()
1891 if [ -z "$1" ]; then
1892 echo "Usage: _require_scratch_ext4_feature feature"
1895 $MKFS_EXT4_PROG -F $MKFS_OPTIONS -O "$1" \
1896 $SCRATCH_DEV 512m >/dev/null 2>&1 \
1897 || _notrun "mkfs.ext4 doesn't support $1 feature"
1898 _try_scratch_mount >/dev/null 2>&1 \
1899 || _notrun "Kernel doesn't support the ext4 feature(s): $1"
1903 # this test requires that external log/realtime devices are not in use
1905 _require_nonexternal()
1907 [ "$USE_EXTERNAL" = yes ] && \
1908 _notrun "External device testing in progress, skipped this test"
1911 # this test requires that the kernel supports asynchronous I/O
1914 $here/src/feature -A
1919 _notrun "kernel does not support asynchronous I/O"
1922 _fail "unexpected error testing for asynchronous I/O support"
1927 # this test requires that a (specified) aio-dio executable exists
1928 # and that the kernel supports asynchronous I/O.
1929 # $1 - command (optional)
1935 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1936 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1938 AIO_TEST=src/aio-dio-regress/$1
1939 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1945 # this test requires that a test program exists under src/
1946 # $1 - command (require)
1948 _require_test_program()
1951 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1954 # run an aio-dio program
1960 echo "usage: _run_aiodio command_name" 2>&1
1966 local testtemp=$TEST_DIR/aio-testfile
1968 $AIO_TEST $testtemp 2>&1
1975 # this test requires y2038 sysfs switch and filesystem
1976 # timestamp ranges support.
1979 local device=${1:-$TEST_DEV}
1980 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
1982 if [ ! -e $sysfsdir ]; then
1983 _notrun "no kernel support for y2038 sysfs switch"
1987 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
1988 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
1989 _notrun "filesystem $FSTYP timestamp bounds are unknown"
1993 _filesystem_timestamp_range()
1995 device=${1:-$TEST_DEV}
1998 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
1999 echo "-2147483648 15032385535"
2001 echo "-2147483648 2147483647"
2006 echo "-2147483648 2147483647"
2012 echo "-2147483648 2147483647"
2020 # indicate whether YP/NIS is active or not
2025 dn=$(domainname 2>/dev/null)
2026 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
2030 # cat the password file
2034 [ $(_yp_active) -eq 0 ] && ypcat passwd
2038 # cat the group file
2042 [ $(_yp_active) -eq 0 ] && ypcat group
2046 # check for a user on the machine, fsgqa as default
2054 _cat_passwd | grep -q $qa_user
2055 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
2056 echo /bin/true | su $qa_user
2057 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
2060 # check for a group on the machine, fsgqa as default
2068 _cat_group | grep -q $qa_group
2069 [ "$?" == "0" ] || _notrun "$qa_group group not defined."
2075 s,.*Permission\sdenied.*,Permission denied,;
2076 s,.*no\saccess\sto\stty.*,,;
2077 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2084 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
2087 _require_xfs_io_command()
2091 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2097 local param_checked=0
2100 testfile=$TEST_DIR/$$.xfs_io
2103 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
2106 testcopy=$TEST_DIR/$$.copy.xfs_io
2107 $XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
2108 testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
2109 rm -f $testcopy > /dev/null 2>&1
2112 testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
2115 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
2116 local blocksize=$(_get_block_size $TEST_DIR)
2117 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 $((5 * $blocksize))" \
2118 -c "fsync" -c "$command $blocksize $((2 * $blocksize))" \
2122 # If 'ranged' is passed as argument then we check to see if fiemap supports
2123 # ranged query params
2124 if echo "$param" | grep -q "ranged"; then
2125 param=$(echo "$param" | sed "s/ranged//")
2126 $XFS_IO_PROG -c "help fiemap" | grep -q "\[offset \[len\]\]"
2127 [ $? -eq 0 ] || _notrun "xfs_io $command ranged support is missing"
2129 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2130 -c "fiemap -v $param" $testfile 2>&1`
2134 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2136 echo $testio | egrep -q "invalid option|Is a directory" && \
2137 _notrun "xfs_io $command support is missing"
2140 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
2141 echo $testio | grep -q "Inappropriate ioctl" && \
2142 _notrun "xfs_io $command support is missing"
2145 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
2146 # a new -C flag was introduced to execute one shot commands.
2147 # Check for -C flag support as an indication for the bug fix.
2148 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
2149 echo $testio | grep -q "invalid option" && \
2150 _notrun "xfs_io $command support is missing"
2153 # -N (RWF_NOWAIT) only works with direct vectored I/O writes
2154 local pwrite_opts=" "
2155 if [ "$param" == "-N" ]; then
2157 pwrite_opts+="-V 1 -b 4k"
2159 testio=`$XFS_IO_PROG -f $opts -c \
2160 "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1`
2164 testio=`$XFS_IO_PROG -x -c "$command probe 0" $TEST_DIR 2>&1`
2165 echo $testio | grep -q "Inappropriate ioctl" && \
2166 _notrun "xfs_io $command support is missing"
2169 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
2173 testio=`$XFS_IO_PROG -c "syncfs" $testfile 2>&1`
2176 testio=`$XFS_IO_PROG -c "help $command" 2>&1`
2179 rm -f $testfile 2>&1 > /dev/null
2180 echo $testio | grep -q "not found" && \
2181 _notrun "xfs_io $command support is missing"
2182 echo $testio | grep -q "Operation not supported" && \
2183 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2184 echo $testio | grep -q "Invalid" && \
2185 _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
2186 echo $testio | grep -q "foreign file active" && \
2187 _notrun "xfs_io $command not supported on $FSTYP"
2188 echo $testio | grep -q "Function not implemented" && \
2189 _notrun "xfs_io $command support is missing (missing syscall?)"
2191 [ -n "$param" ] || return
2193 if [ $param_checked -eq 0 ]; then
2194 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2195 _notrun "xfs_io $command doesn't support $param"
2197 # xfs_io could result in "command %c not supported" if it was
2198 # built on kernels not supporting pwritev2() calls
2199 echo $testio | grep -q "\(invalid option\|not supported\)" && \
2200 _notrun "xfs_io $command doesn't support $param"
2204 # check that kernel and filesystem support direct I/O
2207 if [ $FSTYP = "ext4" ] ; then
2208 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2209 _notrun "ext4 encryption doesn't support O_DIRECT"
2210 elif echo "$MOUNT_OPTIONS" | grep -q "data=journal"; then
2211 _notrun "ext4 data journaling doesn't support O_DIRECT"
2214 testfile=$TEST_DIR/$$.direct
2215 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2216 if [ $? -ne 0 ]; then
2217 _notrun "O_DIRECT is not supported"
2219 rm -f $testfile 2>&1 > /dev/null
2222 # Check that the filesystem supports swapfiles
2223 _require_scratch_swapfile()
2227 _scratch_mkfs >/dev/null
2230 # Minimum size for mkswap is 10 pages
2231 local size=$(($(get_page_size) * 10))
2233 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
2234 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
2235 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
2237 _notrun "swapfiles are not supported"
2240 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
2244 # Check that a fs has enough free space (in 1024b blocks)
2249 BLOCKS=$2 # in units of 1024
2250 let GB=$BLOCKS/1024/1024
2252 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2253 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2254 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2258 # Check if the filesystem supports sparse files.
2260 # Unfortunately there is no better way to do this than a manual black list.
2262 _require_sparse_files()
2266 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2275 #boot_params always present in debugfs
2276 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2279 _require_fail_make_request()
2281 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2282 || _notrun "$DEBUGFS_MNT/fail_make_request \
2283 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2286 # Disable extent zeroing for ext4 on the given device
2287 _ext4_disable_extent_zeroout()
2289 local dev=${1:-$TEST_DEV}
2290 local sdev=`_short_dev $dev`
2292 [ -f /sys/fs/ext4/$sdev/extent_max_zeroout_kb ] && \
2293 echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
2296 # Check if the file system supports seek_data/hole
2297 _require_seek_data_hole()
2299 local dev=${1:-$TEST_DEV}
2300 local testfile=$TEST_DIR/$$.seek
2301 local testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2303 rm -f $testfile &>/dev/null
2304 echo $testseek | grep -q "Kernel does not support" && \
2305 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2306 # Disable extent zeroing for ext4 as that change where holes are
2308 if [ "$FSTYP" = "ext4" ]; then
2309 _ext4_disable_extent_zeroout $dev
2315 _require_test_program "runas"
2320 "$here/src/runas" "$@"
2323 _require_richacl_prog()
2325 _require_command "$GETRICHACL_PROG" getrichacl
2326 _require_command "$SETRICHACL_PROG" setrichacl
2329 _require_scratch_richacl_xfs()
2331 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2332 || _notrun "mkfs.xfs doesn't have richacl feature"
2333 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2334 _try_scratch_mount >/dev/null 2>&1 \
2335 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2339 _require_scratch_richacl_ext4()
2341 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2342 || _notrun "can't mkfs $FSTYP with option -O richacl"
2343 _try_scratch_mount >/dev/null 2>&1 \
2344 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2348 _require_scratch_richacl_support()
2351 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2352 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2356 _require_scratch_richacl()
2359 xfs) _require_scratch_richacl_xfs
2361 ext4) _require_scratch_richacl_ext4
2364 _require_scratch_richacl_support
2366 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2371 _scratch_mkfs_richacl()
2374 xfs) _scratch_mkfs_xfs -m richacl=1
2376 ext4) _scratch_mkfs -O richacl
2384 # check if the given device is mounted, if so, return mount point
2388 local fstype=${2:-$FSTYP}
2390 if [ $# -lt 1 ]; then
2391 echo "Usage: _is_dev_mounted <device> [fstype]" 1>&2
2395 findmnt -rncv -S $dev -t $fstype -o TARGET | head -1
2398 # check if the given dir is a mount point, if so, return mount point
2399 _is_dir_mountpoint()
2402 local fstype=${2:-$FSTYP}
2404 if [ $# -lt 1 ]; then
2405 echo "Uasge: _is_dir_mountpoint <dir> [fstype]" 1>&2
2409 findmnt -rncv -t $fstype -o TARGET $dir | head -1
2412 # remount a FS to a new mode (ro or rw)
2418 echo "Usage: _remount device ro/rw" 1>&2
2424 if ! mount -o remount,$mode $device
2426 echo "_remount: failed to remount filesystem on $device as $mode"
2431 # Run the appropriate repair/check on a filesystem
2433 # if the filesystem is mounted, it's either remounted ro before being
2434 # checked or it's unmounted and then remounted
2437 # If set, we remount ro instead of unmounting for fsck
2440 _umount_or_remount_ro()
2444 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2449 mountpoint=`_is_dev_mounted $device`
2451 if [ $USE_REMOUNT -eq 0 ]; then
2452 $UMOUNT_PROG $device
2459 _mount_or_remount_rw()
2461 if [ $# -ne 3 ]; then
2462 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2469 if [ $USE_REMOUNT -eq 0 ]; then
2470 if [ "$FSTYP" != "overlay" ]; then
2471 _mount -t $FSTYP $mount_opts $device $mountpoint
2473 _overlay_mount $device $mountpoint
2475 if [ $? -ne 0 ]; then
2476 _dump_err "!!! failed to remount $device on $mountpoint"
2486 # Check a generic filesystem in no-op mode; this assumes that the
2487 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2488 # and that it will still return an errno for corruption in this mode.
2490 # Filesystems which don't support this will need to define their
2491 # own check routine.
2493 _check_generic_filesystem()
2497 # If type is set, we're mounted
2498 type=`_fs_type $device`
2501 if [ "$type" = "$FSTYP" ]
2504 mountpoint=`_umount_or_remount_ro $device`
2507 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2510 _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
2511 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2512 cat $tmp.fsck >>$seqres.full
2513 echo "*** end fsck.$FSTYP output" >>$seqres.full
2521 echo "*** mount output ***" >>$seqres.full
2522 _mount >>$seqres.full
2523 echo "*** end mount output" >>$seqres.full
2524 elif [ "$type" = "$FSTYP" ]
2527 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2531 if [ $ok -eq 0 ]; then
2533 if [ "$iam" != "check" ]; then
2542 # Filter the knowen errors the UDF Verifier reports.
2543 _udf_test_known_error_filter()
2545 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."
2549 _check_udf_filesystem()
2551 [ "$DISABLE_UDF_TEST" == "1" ] && return
2553 if [ $# -ne 1 -a $# -ne 2 ]
2555 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2559 if [ ! -x $here/src/udf_test ]
2561 echo "udf_test not installed, please download and build the Philips"
2562 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2563 echo "Then copy the udf_test binary to $here/src/."
2564 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2572 LAST_BLOCK=`expr \( $2 - 1 \)`
2573 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2576 rm -f $seqres.checkfs
2577 sleep 1 # Due to a problem with time stamps in udf_test
2578 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2579 _udf_test_known_error_filter | \
2580 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2581 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2592 # no way to check consistency for nfs
2595 # no way to check consistency for cifs
2598 # no way to check consistency for 9p
2601 # no way to check consistency for CephFS
2604 # no way to check consistency for GlusterFS
2607 _check_overlay_test_fs
2612 # do nothing for now
2615 _check_btrfs_filesystem $TEST_DEV
2618 # no way to check consistency for tmpfs
2621 # there is no fsck program for ubifs yet
2624 _check_generic_filesystem $TEST_DEV
2632 [ $# -eq 1 ] && device=$1
2638 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2639 SCRATCH_LOG="$SCRATCH_LOGDEV"
2641 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2642 SCRATCH_RT="$SCRATCH_RTDEV"
2644 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2647 _check_udf_filesystem $device $udf_fsize
2650 # Don't know how to check an NFS filesystem, yet.
2653 # Don't know how to check a CIFS filesystem, yet.
2656 # no way to check consistency for 9p
2659 # no way to check consistency for CephFS
2662 # no way to check consistency for GlusterFS
2665 _check_overlay_scratch_fs
2670 _check_btrfs_filesystem $device
2673 # no way to check consistency for tmpfs
2676 # there is no fsck program for ubifs yet
2679 _check_generic_filesystem $device
2684 _full_fstyp_details()
2686 [ -z "$FSTYP" ] && FSTYP=xfs
2687 if [ $FSTYP = xfs ]; then
2688 if [ -d /proc/fs/xfs ]; then
2689 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2690 FSTYP="$FSTYP (non-debug)"
2691 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2692 FSTYP="$FSTYP (debug)"
2695 if uname -a | grep -qi 'debug'; then
2696 FSTYP="$FSTYP (debug)"
2698 FSTYP="$FSTYP (non-debug)"
2705 _full_platform_details()
2711 echo "$os/$platform $host $kernel"
2716 if [ "`uname`" == "Linux" ]; then
2719 echo Unknown operating system: `uname`
2724 _link_out_file_named()
2729 my $feature, $result, $suffix, $opts;
2731 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2732 $feathash{$feature} = 1;
2734 $result = "default";
2739 ($opts, $suffix) = split(/ *: */);
2740 foreach my $opt (split(/,/, $opts)) {
2741 if (!exists($feathash{$opt})) {
2755 ln -fs $SRC.$SUFFIX $1
2760 if [ $# -eq 0 ]; then
2761 FEATURES="$(_get_os_name)"
2762 if [ -n "$MOUNT_OPTIONS" ]; then
2763 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2769 _link_out_file_named $seqfull.out "$FEATURES"
2778 # convert urandom incompressible data to compressible text data
2781 od /dev/urandom | dd iflag=fullblock ${*}
2784 #takes files, randomdata
2792 if [ $size -gt 0 ]; then
2793 if [ "$2" == "false" ]; then
2794 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2795 elif [ "$2" == "comp" ]; then
2796 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2798 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2805 # takes dirname, depth, randomdata
2808 dirname=$1; depth=$2; randomdata=$3
2809 mkdir $dirname || die "mkdir $dirname failed"
2812 _nfiles $files $randomdata # files for this dir and data type
2814 [ $depth -eq 0 ] && return
2815 let deep=$depth-1 # go 1 down
2817 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2820 while [ $d -lt $dirs ]
2822 _descend d$d $deep &
2828 # Populate a filesystem with inodes for performance experiments
2830 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2835 dirs=5 # ndirs in each subdir till leaves
2836 size=0 # sizeof files in K
2837 files=100 # num files in _each_ subdir
2838 depth=2 # depth of tree from root to leaves
2840 root=root # path of initial root of directory tree
2841 randomdata=false # -x data type urandom, zero or compressible
2844 while getopts "d:f:n:r:s:v:x:c" c
2853 x) randomdata=true;;
2854 c) randomdata=comp;;
2858 _descend $root $depth $randomdata
2863 [ $verbose = true ] && echo done
2866 # query whether the given file has the given inode flag set
2873 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2879 # query the given files extsize allocator hint in bytes (if any)
2886 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2887 awk '/^xattr.extsize =/ { print $3 }'`
2888 [ -z "$blocks" ] && blocks="0"
2892 # scratch_dev_pool should contain the disks pool for the btrfs raid
2893 _require_scratch_dev_pool()
2898 if [ -z "$SCRATCH_DEV_POOL" ]; then
2899 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2902 if [ -z "$1" ]; then
2908 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2912 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2913 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2917 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2921 for i in $SCRATCH_DEV_POOL; do
2922 if [ "`_is_block_dev "$i"`" = "" ]; then
2923 _notrun "this test requires valid block disk $i"
2925 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2926 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2928 if _mount | grep -q $i; then
2929 if ! $UMOUNT_PROG $i; then
2930 echo "failed to unmount $i - aborting"
2934 # to help better debug when something fails, we remove
2935 # traces of previous btrfs FS on the dev.
2936 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2940 # ensure devices in SCRATCH_DEV_POOL are of the same size
2941 # must be called after _require_scratch_dev_pool
2942 _require_scratch_dev_pool_equal_size()
2948 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2949 _size=`_get_device_size $SCRATCH_DEV`
2950 for _dev in $SCRATCH_DEV_POOL; do
2951 _newsize=`_get_device_size $_dev`
2952 if [ $_size -ne $_newsize ]; then
2953 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2958 # We will check if the device is deletable
2959 _require_deletable_scratch_dev_pool()
2963 for i in $SCRATCH_DEV_POOL; do
2964 x=`echo $i | cut -d"/" -f 3`
2965 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2966 _notrun "$i is a device which is not deletable"
2971 # Check that fio is present, and it is able to execute given jobfile
2976 _require_command "$FIO_PROG" fio
2977 if [ -z "$1" ]; then
2981 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2982 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2985 # Does freeze work on this fs?
2988 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2990 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2991 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2994 # Does NFS export work on this fs?
2997 _require_test_program "open_by_handle"
2998 mkdir -p "$TEST_DIR"/exportfs_test
2999 $here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
3000 || _notrun "$FSTYP does not support NFS export"
3004 # Does shutdown work on this fs?
3005 _require_scratch_shutdown()
3007 [ -x src/godown ] || _notrun "src/godown executable not found"
3009 _scratch_mkfs > /dev/null 2>&1 || _notrun "_scratch_mkfs failed on $SCRATCH_DEV"
3012 if [ $FSTYP = "overlay" ]; then
3013 if [ -z $OVL_BASE_SCRATCH_DEV ]; then
3014 # In lagacy overlay usage, it may specify directory as
3015 # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
3016 # will be null, so check OVL_BASE_SCRATCH_DEV before
3017 # running shutdown to avoid shutting down base fs accidently.
3018 _notrun "$SCRATCH_DEV is not a block device"
3020 src/godown -f $OVL_BASE_SCRATCH_MNT 2>&1 \
3021 || _notrun "Underlying filesystem does not support shutdown"
3024 src/godown -f $SCRATCH_MNT 2>&1 \
3025 || _notrun "$FSTYP does not support shutdown"
3031 # Does dax mount option work on this dev/fs?
3032 _require_scratch_dax()
3035 _scratch_mkfs > /dev/null 2>&1
3036 _try_scratch_mount -o dax || \
3037 _notrun "mount $SCRATCH_DEV with dax failed"
3038 # Check options to be sure. XFS ignores dax option
3039 # and goes on if dev underneath does not support dax.
3040 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
3041 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
3045 # Does norecovery support by this fs?
3046 _require_norecovery()
3048 _try_scratch_mount -o ro,norecovery || \
3049 _notrun "$FSTYP does not support norecovery"
3053 # Does this filesystem support metadata journaling?
3054 # We exclude ones here that don't; otherwise we assume that it does, so the
3055 # test will run, fail, and motivate someone to update this test for a new
3058 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
3059 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
3061 _require_metadata_journaling()
3070 ext2|vfat|msdos|udf)
3071 _notrun "$FSTYP does not support metadata journaling"
3074 # ext4 could be mkfs'd without a journal...
3076 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3077 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3078 # ext4 might not load a journal
3079 _exclude_scratch_mount_option "noload"
3082 # metadata journaling check is based on base filesystem configurations
3083 # and because -overlay option saves those configurations to OVL_BASE_*,
3084 # adding restore/override the configurations before/after the check.
3085 if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
3086 _overlay_config_restore
3087 _require_metadata_journaling
3088 _overlay_config_override
3090 _notrun "No metadata journaling support for legacy overlay setup"
3094 # by default we pass; if you need to, add your fs above!
3101 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3106 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3109 _count_attr_extents()
3111 $XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
3114 # arg 1 is dev to remove and is output of the below eg.
3115 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3121 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3123 stat $disk > /dev/null 2>&1
3124 while [ $? -eq 0 ]; do
3126 stat $disk > /dev/null 2>&1
3130 # arg 1 is dev to add and is output of the below eg.
3131 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3136 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3137 h=`echo ${1} | cut -d":" -f 1`
3138 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3140 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3142 # ensure the device comes online
3144 for i in `seq 1 10`; do
3145 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3146 dev=`ls /sys/class/scsi_device/${1}/device/block`
3147 for j in `seq 1 10`;
3149 stat /dev/$dev > /dev/null 2>&1
3150 if [ $? -eq 0 ]; then
3161 if [ $dev_back_oneline -eq 0 ]; then
3162 echo "/dev/$dev online failed" >> $seqres.full
3164 echo "/dev/$dev is back online" >> $seqres.full
3170 if [ -z "$FSTRIM_PROG" ]; then
3171 _notrun "This test requires fstrim utility."
3175 _require_batched_discard()
3177 if [ $# -ne 1 ]; then
3178 echo "Usage: _require_batched_discard mnt_point" 1>&2
3182 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3187 if [ -z "$DUMPE2FS_PROG" ]; then
3188 _notrun "This test requires dumpe2fs utility."
3194 if [ ! -e /proc/self/uid_map ]; then
3195 _notrun "This test requires procfs uid_map support."
3197 if [ ! -e /proc/self/gid_map ]; then
3198 _notrun "This test requires procfs gid_map support."
3204 FSSUM_PROG=$here/src/fssum
3205 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3210 CLONER_PROG=$here/src/cloner
3211 [ -x $CLONER_PROG ] || \
3212 _notrun "cloner binary not present at $CLONER_PROG"
3215 # Normalize mount options from global $MOUNT_OPTIONS
3216 # Convert options like "-o opt1,opt2 -oopt3" to
3218 _normalize_mount_options()
3220 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
3223 # skip test if MOUNT_OPTIONS contains the given strings
3224 _exclude_scratch_mount_option()
3226 local mnt_opts=$(_normalize_mount_options)
3228 while [ $# -gt 0 ]; do
3229 if echo $mnt_opts | grep -qw "$1"; then
3230 _notrun "mount option \"$1\" not allowed in this test"
3238 _exclude_scratch_mount_option "noatime"
3239 if [ "$FSTYP" == "nfs" ]; then
3240 _notrun "atime related mount options have no effect on NFS"
3246 _scratch_mkfs > /dev/null 2>&1
3247 _try_scratch_mount -o relatime || \
3248 _notrun "relatime not supported by the current kernel"
3254 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3255 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3258 _create_loop_device()
3261 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3265 _destroy_loop_device()
3268 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3271 _scale_fsstress_args()
3274 while [ $# -gt 0 ]; do
3276 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3277 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3278 *) args="$args $1" ;;
3286 # Return the logical block size if running on a block device,
3287 # else substitute the page size.
3289 _min_dio_alignment()
3293 if [ -b "$dev" ]; then
3294 blockdev --getss $dev
3296 $here/src/feature -s
3302 echo "# $@" >> $seqres.full 2>&1
3303 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3306 _require_test_symlinks()
3308 target=`mktemp -p $TEST_DIR`
3309 link=`mktemp -p $TEST_DIR -u`
3310 ln -s `basename $target` $link
3311 if [ "$?" -ne 0 ]; then
3313 _notrun "Require symlinks support"
3318 _require_test_fcntl_advisory_locks()
3320 [ "$FSTYP" != "cifs" ] && return 0
3321 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3322 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3323 _notrun "Require fcntl advisory locks support"
3326 _require_ofd_locks()
3328 # Give a test run by getlk wrlck on testfile.
3329 # If the running kernel does not support OFD locks,
3330 # EINVAL will be returned.
3331 _require_test_program "t_ofd_locks"
3332 touch $TEST_DIR/ofd_testfile
3333 src/t_ofd_locks -t $TEST_DIR/ofd_testfile > /dev/null 2>&1
3334 [ $? -eq 22 ] && _notrun "Require OFD locks support"
3337 _require_test_lsattr()
3339 testio=$(lsattr -d $TEST_DIR 2>&1)
3340 echo $testio | grep -q "Operation not supported" && \
3341 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3342 echo $testio | grep -q "Inappropriate ioctl for device" && \
3343 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3348 if [ -z "$1" ]; then
3349 echo "Usage: _require_chattr <attr>"
3354 touch $TEST_DIR/syscalltest
3355 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3357 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3358 if [ "$status" -ne 0 ]; then
3359 _notrun "file system doesn't support chattr +$attribute"
3361 cat $TEST_DIR/syscalltest.out >> $seqres.full
3362 rm -f $TEST_DIR/syscalltest.out
3367 if [ -z "$1" ]; then
3368 echo "Usage: _get_total_inode <mnt>"
3372 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3378 if [ -z "$1" ]; then
3379 echo "Usage: _get_used_inode <mnt>"
3383 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3387 _get_used_inode_percent()
3389 if [ -z "$1" ]; then
3390 echo "Usage: _get_used_inode_percent <mnt>"
3394 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3401 if [ -z "$1" ]; then
3402 echo "Usage: _get_free_inode <mnt>"
3406 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3410 # get the available space in bytes
3412 _get_available_space()
3414 if [ -z "$1" ]; then
3415 echo "Usage: _get_available_space <mnt>"
3419 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3420 echo $((avail_kb * 1024))
3423 # return device size in kb
3426 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3429 # Make sure we actually have dmesg checking set up.
3430 _require_check_dmesg()
3432 test -w /dev/kmsg || \
3433 _notrun "Test requires writable /dev/kmsg."
3436 # Return the dmesg log since the start of this test. Caller must ensure that
3437 # /dev/kmsg was writable when the test was started so that we can find the
3438 # beginning of this test's log messages; _require_check_dmesg does this.
3439 _dmesg_since_test_start()
3441 # search the dmesg log of last run of $seqnum for possible failures
3442 # use sed \cregexpc address type, since $seqnum contains "/"
3443 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3447 # check dmesg log for a specific string, subject to the same requirements as
3448 # _dmesg_since_test_start.
3451 _dmesg_since_test_start | egrep -q "$1"
3454 # check dmesg log for WARNING/Oops/etc.
3457 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3460 rm -f ${RESULT_DIR}/check_dmesg
3462 # default filter is a simple cat command, caller could provide a
3463 # customized filter and pass the name through the first argument, to
3464 # filter out intentional WARNINGs or Oopses
3467 _dmesg_since_test_start | $filter >$seqres.dmesg
3468 egrep -q -e "kernel BUG at" \
3472 -e "possible recursive locking detected" \
3473 -e "Internal error" \
3474 -e "(INFO|ERR): suspicious RCU usage" \
3475 -e "INFO: possible circular locking dependency detected" \
3476 -e "general protection fault:" \
3477 -e "BUG .* remaining" \
3480 if [ $? -eq 0 ]; then
3481 _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3489 # capture the kmemleak report
3492 local _kern_knob="${DEBUGFS_MNT}/kmemleak"
3493 local _leak_file="$1"
3495 # Tell the kernel to scan for memory leaks. Apparently the write
3496 # returns before the scan is complete, so do it twice in the hopes
3497 # that twice is enough to capture all the leaks.
3498 echo "scan" > "${_kern_knob}"
3499 cat "${_kern_knob}" > /dev/null
3500 echo "scan" > "${_kern_knob}"
3501 cat "${_kern_knob}" > "${_leak_file}.tmp"
3502 if [ -s "${_leak_file}.tmp" ]; then
3503 cat > "${_leak_file}" << ENDL
3504 EXPERIMENTAL kmemleak reported some memory leaks! Due to the way kmemleak
3505 works, the leak might be from an earlier test, or something totally unrelated.
3507 cat "${_leak_file}.tmp" >> "${_leak_file}"
3508 rm -rf "${_leak_file}.tmp"
3510 echo "clear" > "${_kern_knob}"
3516 local _kern_knob="${DEBUGFS_MNT}/kmemleak"
3518 if [ ! -w "${_kern_knob}" ]; then
3522 # Disable the automatic scan so that we can control it completely,
3523 # then dump all the leaks recorded so far.
3524 echo "scan=off" > "${_kern_knob}"
3525 _capture_kmemleak /dev/null
3528 # check kmemleak log
3531 local _kern_knob="${DEBUGFS_MNT}/kmemleak"
3532 local _leak_file="${seqres}.kmemleak"
3534 if [ ! -w "${_kern_knob}" ]; then
3538 # Capture and report any leaks
3539 _capture_kmemleak "${_leak_file}"
3540 if [ -s "${_leak_file}" ]; then
3541 _dump_err "_check_kmemleak: something found in kmemleak (see ${_leak_file})"
3544 rm -f "${_leak_file}"
3549 # don't check dmesg log after test
3550 _disable_dmesg_check()
3552 rm -f ${RESULT_DIR}/check_dmesg
3557 if [ "$iam" == new ]
3561 # make some further configuration checks here
3562 if [ "$TEST_DEV" = "" ]
3564 echo "common/rc: Error: \$TEST_DEV is not set"
3568 # if $TEST_DEV is not mounted, mount it now as XFS
3569 if [ -z "`_fs_type $TEST_DEV`" ]
3571 # $TEST_DEV is not mounted
3574 echo "common/rc: retrying test device mount with external set"
3575 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3578 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3584 # Sanity check that TEST partition is not mounted at another mount point
3585 # or as another fs type
3586 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3587 if [ -n "$SCRATCH_DEV" ]; then
3588 # Sanity check that SCRATCH partition is not mounted at another
3589 # mount point, because it is about to be unmounted and formatted.
3590 # Another fs type for scratch is fine (bye bye old fs type).
3591 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3592 [ $? -le 1 ] || exit 1
3595 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3596 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3597 export XFS_IO_PROG="$XFS_IO_PROG -F"
3599 # xfs_io -i option starts an idle thread for xfs_io.
3600 # With single threaded process, the file table is not shared
3601 # and file structs are not reference counted.
3602 # Spawning an idle thread can help detecting file struct
3603 # reference leaks, so we want to enable the option whenever
3605 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3606 export XFS_IO_PROG="$XFS_IO_PROG -i"
3608 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3609 # can change the UUID on v5 filesystems
3610 if [ "$FSTYP" == "xfs" ]; then
3612 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3613 # xfs_db will return 0 even if it can't generate a new uuid, so
3614 # check the output to make sure if it can change UUID of V5 xfs
3615 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3616 | grep -q "invalid UUID\|supported on V5 fs" \
3617 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3622 # get real device path name by following link
3626 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3627 _dev=`readlink -f "$_dev"`
3632 # basename of a device
3635 echo `basename $(_real_dev $1)`
3640 local _dev=`_real_dev $1`
3641 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3642 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3643 _maj=$(echo "ibase=16; $_maj" | bc)
3644 _min=$(echo "ibase=16; $_min" | bc)
3645 echo /sys/dev/block/$_maj:$_min
3648 # Get the minimum block size of a file. Usually this is the
3649 # minimum fs block size, but some filesystems (ocfs2) do block
3650 # mappings in larger units.
3651 _get_file_block_size()
3653 if [ -z $1 ] || [ ! -d $1 ]; then
3654 echo "Missing mount point argument for _get_file_block_size"
3657 if [ "$FSTYP" = "ocfs2" ]; then
3664 # Get the minimum block size of an fs.
3667 if [ -z $1 ] || [ ! -d $1 ]; then
3668 echo "Missing mount point argument for _get_block_size"
3676 echo $(getconf PAGE_SIZE)
3683 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3684 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3685 echo "$@" >>$seqres.full
3686 rm -f $TEST_DIR/junk
3687 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3688 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3696 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3698 # Only one argument is needed:
3699 # - attr: path name under /sys/fs/$FSTYP/DEV
3702 # _require_fs_sysfs error/fail_at_unmount
3706 local dname=$(_short_dev $TEST_DEV)
3708 if [ -z "$attr" -o -z "$dname" ];then
3709 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3712 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3713 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3719 $here/src/stat_test --check-statx ||
3720 _notrun "This test requires the statx system call"
3723 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3725 # All arguments are necessary, and in this order:
3726 # - dev: device name, e.g. $SCRATCH_DEV
3727 # - attr: path name under /sys/fs/$FSTYP/$dev
3728 # - content: the content of $attr
3731 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3732 _set_fs_sysfs_attr()
3740 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3741 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3744 local dname=$(_short_dev $dev)
3745 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3748 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3750 # All arguments are necessary, and in this order:
3751 # - dev: device name, e.g. $SCRATCH_DEV
3752 # - attr: path name under /sys/fs/$FSTYP/$dev
3755 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3756 _get_fs_sysfs_attr()
3761 if [ ! -b "$dev" -o -z "$attr" ];then
3762 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3765 local dname=$(_short_dev $dev)
3766 cat /sys/fs/${FSTYP}/${dname}/${attr}
3769 # Generic test for specific filesystem feature.
3770 # Currently only implemented to test overlayfs features.
3771 _require_scratch_feature()
3777 _require_scratch_overlay_features ${feature}
3780 _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
3787 ################################################################################
3788 # make sure this script returns success