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 $@
71 # Prints the md5 checksum of a given file
74 md5sum $1 | cut -d ' ' -f1
77 # Write a byte into a range of a file
85 $XFS_IO_PROG $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
88 # mmap-write a byte into a range of a file
96 $XFS_IO_PROG -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
99 # ls -l w/ selinux sometimes puts a dot at the end:
100 # -rwxrw-r--. id1 id2 file1
101 # Also filter out lost+found directory on extN file system if present
105 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
108 # we need common/config
109 if [ "$iam" != "check" ]
111 if ! . ./common/config
113 echo "$iam: failed to source common/config"
133 echo "$err_msg" | tee -a $seqres.full
134 echo "(see $seqres.full for details)"
137 # make sure we have a standard umask
140 # check for correct setup and source the $FSTYP specific functions now
143 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
144 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
145 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
146 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
151 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
154 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
159 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
162 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
176 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
181 [ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
185 if [ ! -z "$REPORT_LIST" ]; then
192 $MOUNT_PROG `_mount_ops_filter $*`
195 # Call _mount to do mount operation but also save mountpoint to
196 # MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
199 local mnt_point=${!#}
202 if [ $? -eq 0 ]; then
203 MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
209 # Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
210 # and return it to caller
213 local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
215 if [ -n "$last_mnt" ]; then
216 $UMOUNT_PROG $last_mnt
218 MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
221 # Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
224 if [ -n "$MOUNTED_POINT_STACK" ]; then
225 $UMOUNT_PROG $MOUNTED_POINT_STACK
227 MOUNTED_POINT_STACK=""
235 if [ "$FSTYP" != "xfs" ]; then
241 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
250 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
251 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
252 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
253 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
261 if [ "$FSTYP" != "xfs" ]; then
275 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
276 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
277 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
278 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
285 #get mount point to handle dmapi mtpt option correctly
287 [ $last_index -gt 0 ] && shift $last_index
290 echo $params | sed -e 's/dmapi/dmi/' \
291 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
295 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
296 # with the safe set of scratch mount options (e.g. loop image may be
297 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
298 _common_dev_mount_options()
300 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
303 _overlay_basic_mount_options()
305 echo "-o lowerdir=$1/$OVL_LOWER,upperdir=$1/$OVL_UPPER,workdir=$1/$OVL_WORK"
308 _overlay_mount_options()
310 echo `_common_dev_mount_options` \
311 `_overlay_basic_mount_options $1` \
312 $OVERLAY_MOUNT_OPTIONS
315 _scratch_mount_options()
317 _scratch_options mount
319 if [ "$FSTYP" == "overlay" ]; then
320 echo `_overlay_mount_options $OVL_BASE_SCRATCH_MNT`
323 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
324 $SCRATCH_DEV $SCRATCH_MNT
331 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
334 xfs_info $dir | grep -q "ftype=1"
337 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
338 tune2fs -l $dev | grep -q filetype
341 local testfile=$dir/$$.ftype
343 # look for DT_UNKNOWN files
344 local unknowns=$(src/t_dir_type $dir u | wc -l)
346 # 0 unknowns is success
352 # helper function to do the actual overlayfs mount operation
353 _overlay_mount_dirs()
360 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
361 -o workdir=$workdir $*
368 mkdir -p $dir/$OVL_UPPER
369 mkdir -p $dir/$OVL_LOWER
370 mkdir -p $dir/$OVL_WORK
371 mkdir -p $dir/$OVL_MNT
374 # Given a base fs dir, set up overlay directories and mount on the given mnt.
375 # The dir is used as the mount device so it can be seen from df or mount
382 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
386 _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER \
387 $dir/$OVL_WORK $OVERLAY_MOUNT_OPTIONS \
388 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
391 _overlay_base_test_mount()
393 if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \
394 _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \
395 OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR
397 # no base fs or already mounted
401 # base fs mounted but not on mount point
405 _mount $TEST_FS_MOUNT_OPTS \
406 $SELINUX_MOUNT_OPTIONS \
407 $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR
410 _overlay_test_mount()
412 _overlay_base_test_mount && \
413 _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
416 _overlay_base_scratch_mount()
418 if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \
419 _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \
420 OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT
422 # no base fs or already mounted
426 # base fs mounted but not on mount point
430 _mount $OVL_BASE_MOUNT_OPTIONS \
431 $SELINUX_MOUNT_OPTIONS \
432 $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
435 _overlay_base_scratch_unmount()
437 [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
439 $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
442 _overlay_scratch_mount()
444 _overlay_base_scratch_mount && \
445 _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
448 _overlay_base_test_unmount()
450 [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
452 $UMOUNT_PROG $OVL_BASE_TEST_DIR
455 _overlay_test_unmount()
457 $UMOUNT_PROG $TEST_DIR
458 _overlay_base_test_unmount
461 _overlay_scratch_unmount()
463 $UMOUNT_PROG $SCRATCH_MNT
464 _overlay_base_scratch_unmount
469 if [ "$FSTYP" == "overlay" ]; then
470 _overlay_scratch_mount $*
473 _mount -t $FSTYP `_scratch_mount_options $*`
480 _overlay_scratch_unmount
483 $UMOUNT_PROG $SCRATCH_MNT
486 $UMOUNT_PROG $SCRATCH_DEV
495 if test -n "$opts"; then
496 mount -o "remount,$opts" $SCRATCH_MNT
500 _scratch_cycle_mount()
504 if [ "$FSTYP" = tmpfs ]; then
505 _scratch_remount "$opts"
508 if test -n "$opts"; then
512 _scratch_mount "$opts"
517 if [ "$FSTYP" == "overlay" ]; then
518 _overlay_test_mount $*
522 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
527 if [ "$FSTYP" == "overlay" ]; then
528 _overlay_test_unmount
530 $UMOUNT_PROG $TEST_DEV
536 if [ "$FSTYP" = tmpfs ]; then
543 _scratch_mkfs_options()
545 _scratch_options mkfs
546 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
549 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
550 # and user specified mkfs options, if that fails (due to conflicts between mkfs
551 # options), do a second mkfs with only user provided mkfs options.
553 # First param is the mkfs command without any mkfs options and device.
554 # Second param is the filter to remove unnecessary messages from mkfs stderr.
555 # Other extra mkfs options are followed.
561 local extra_mkfs_options=$*
563 local tmp=`mktemp -u`
565 # save mkfs output in case conflict means we need to run again.
566 # only the output for the mkfs that applies should be shown
567 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
568 2>$tmp.mkfserr 1>$tmp.mkfsstd
571 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
572 # $extra_mkfs_options
573 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
575 echo -n "** mkfs failed with extra mkfs options "
576 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
577 echo -n "** attempting to mkfs using only test $seq "
578 echo "options: $extra_mkfs_options **"
581 # running mkfs again. overwrite previous mkfs output files
582 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
583 2>$tmp.mkfserr 1>$tmp.mkfsstd
587 # output stored mkfs output, filtering unnecessary output from stderr
589 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
591 rm -f $tmp.mkfserr $tmp.mkfsstd
601 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
602 options="-l $SCRATCH_LOGDEV"
604 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
607 _setup_large_ext4_fs()
612 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
613 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
614 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
616 # Default free space in the FS is 50GB, but you can specify more via
617 # SCRATCH_DEV_EMPTY_SPACE
618 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
620 # mount the filesystem and create 16TB - 4KB files until we consume
621 # all the necessary space.
622 _scratch_mount 2>&1 >$tmp_dir/mnt.err
624 if [ $status -ne 0 ]; then
626 cat $tmp_dir/mnt.err >&2
627 rm -f $tmp_dir/mnt.err
630 rm -f $tmp_dir/mnt.err
632 file_size=$((16*1024*1024*1024*1024 - 4096))
634 while [ $space_to_consume -gt $file_size ]; do
637 -c "truncate $file_size" \
638 -c "falloc -k 0 $file_size" \
639 $SCRATCH_MNT/.use_space.$nfiles 2>&1
641 if [ $status -ne 0 ]; then
645 space_to_consume=$(( $space_to_consume - $file_size ))
646 nfiles=$(($nfiles + 1))
649 # consume the remaining space.
650 if [ $space_to_consume -gt 0 ]; then
652 -c "truncate $space_to_consume" \
653 -c "falloc -k 0 $space_to_consume" \
654 $SCRATCH_MNT/.use_space.$nfiles 2>&1
657 export NUM_SPACE_FILES=$nfiles
660 if [ $status -ne 0 ]; then
661 echo "large file prealloc failed"
662 cat $tmp_dir/mnt.err >&2
670 local mkfs_cmd="$MKFS_EXT4_PROG -F"
671 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
672 local tmp=`mktemp -u`
675 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
676 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
677 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
679 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
682 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
683 # manually parse the mkfs output to get the fs size in bytes
684 fs_size=`cat $tmp.mkfsstd | awk ' \
685 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
686 / inodes, / { blks = $3 } \
687 /reserved for the super user/ { resv = $1 } \
688 END { fssize = bs * blks - resv; print fssize }'`
690 _setup_large_ext4_fs $fs_size
694 # output mkfs stdout and stderr
697 rm -f $tmp.mkfserr $tmp.mkfsstd
709 # do nothing for cifs
712 # do nothing for ceph
715 # do nothing for glusterfs
718 # do nothing for overlay
721 # do nothing for pvfs2
724 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
727 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
730 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
733 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
740 local tmp=`mktemp -u`
746 # do nothing for overlay
749 # do nothing for pvfs2
752 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
755 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
758 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
759 2>$tmp.mkfserr 1>$tmp.mkfsstd
763 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
764 2>$tmp.mkfserr 1>$tmp.mkfsstd
768 if [ $? -ne 0 ]; then
769 # output stored mkfs output
775 rm -f $tmp.mkfserr $tmp.mkfsstd
778 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
779 _scratch_cleanup_files()
783 # Avoid rm -rf /* if we messed up
784 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
785 _overlay_base_scratch_mount || return 1
786 rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
787 _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
788 # leave base fs mouted so tests can setup lower/upper dir files
791 [ -n "$SCRATCH_MNT" ] || return 1
793 rm -rf $SCRATCH_MNT/*
806 nfs*|cifs|ceph|overlay|glusterfs|pvfs2)
807 # unable to re-create this fstyp, just remove all files in
808 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
809 # created in previous runs
810 _scratch_cleanup_files
814 # do nothing for tmpfs
818 # erase the UBI volume; reformated automatically on next mount
819 $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
823 _scratch_mkfs_ext4 $*
831 mkfs_cmd="$MKFS_UDF_PROG"
835 mkfs_cmd="$MKFS_BTRFS_PROG"
839 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
840 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
842 # put journal on separate device?
843 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
844 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
845 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
848 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
849 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
852 mkfs_cmd="$MKFS_F2FS_PROG"
856 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
857 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
860 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
865 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
869 # Helper function to get a spare or replace-target device from
870 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
871 # before _spare_dev_get(). Replace-target-device/Spare-device will
872 # be assigned to SPARE_DEV.
873 # As of now only one replace-target-device/spare-device can be
877 # _scratch_dev_pool_get() <ndevs>
881 # _scratch_dev_pool_put()
885 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
886 if [ $? -ne 0 ]; then
887 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
890 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
891 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
894 # Check if the spare is already assigned
895 typeset -p SPARE_DEV >/dev/null 2>&1
896 if [ $? -eq 0 ]; then
897 if [ ! -z "$SPARE_DEV" ]; then
898 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
902 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
903 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
905 if [ $ndevs -eq $config_ndevs ]; then
906 _notrun "All devs used no spare"
908 # Get a dev that is not used
909 local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
910 SPARE_DEV=${devs[@]:$ndevs:1}
916 typeset -p SPARE_DEV >/dev/null 2>&1
917 if [ $? -ne 0 ]; then
918 _fail "Bug: unset val, must call _spare_dev_get before its put"
921 if [ -z "$SPARE_DEV" ]; then
922 _fail "Bug: str empty, must call _spare_dev_get before its put"
929 # Generally test cases will have..
930 # _require_scratch_dev_pool X
931 # to make sure it has the enough scratch devices including
932 # replace-target and spare device. Now arg1 here is the
933 # required number of scratch devices by a-test-case excluding
934 # the replace-target and spare device. So this function will
935 # set SCRATCH_DEV_POOL to the specified number of devices.
938 # _scratch_dev_pool_get() <ndevs>
941 # _scratch_dev_pool_put()
943 _scratch_dev_pool_get()
945 if [ $# -ne 1 ]; then
946 _fail "Usage: _scratch_dev_pool_get ndevs"
950 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
951 local -a devs="( $SCRATCH_DEV_POOL )"
953 typeset -p config_ndevs >/dev/null 2>&1
954 if [ $? -ne 0 ]; then
955 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
958 if [ $config_ndevs -lt $test_ndevs ]; then
959 _notrun "Need at least test requested number of ndevs $test_ndevs"
962 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
963 export SCRATCH_DEV_POOL_SAVED
964 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
965 export SCRATCH_DEV_POOL
968 _scratch_dev_pool_put()
970 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
971 if [ $? -ne 0 ]; then
972 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
975 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
976 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
979 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
980 export SCRATCH_DEV_POOL_SAVED=""
987 # if dup profile is in mkfs options call _scratch_mkfs instead
988 # because dup profile only works with single device
989 if [[ "$*" =~ dup ]]; then
992 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
996 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
1001 # Return the amount of free memory available on the system
1002 _free_memory_bytes()
1004 free -b | grep ^Mem | awk '{print $4}'
1007 # Create fs of certain size on scratch device
1008 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
1009 _scratch_mkfs_sized()
1016 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
1018 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2|reiserfs)
1019 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
1026 [ -n "$def_blksz" ] && blocksize=$def_blksz
1027 [ -z "$blocksize" ] && blocksize=4096
1031 if ! [[ $fssize =~ $re ]] ; then
1032 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
1034 if ! [[ $blocksize =~ $re ]] ; then
1035 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1038 blocks=`expr $fssize / $blocksize`
1040 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
1041 devsize=`blockdev --getsize64 $SCRATCH_DEV`
1042 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
1047 # don't override MKFS_OPTIONS that set a block size.
1048 echo $MKFS_OPTIONS |egrep -q "b?size="
1049 if [ $? -eq 0 ]; then
1050 _scratch_mkfs_xfs -d size=$fssize
1052 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
1055 ext2|ext3|ext4|ext4dev)
1056 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1059 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1062 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1066 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1067 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1070 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
1073 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1076 # mkfs.resier4 requires size in KB as input for creating filesystem
1077 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1078 `expr $fssize / 1024`
1081 # mkfs.f2fs requires # of sectors as an input for the size
1082 sector_size=`blockdev --getss $SCRATCH_DEV`
1083 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1086 free_mem=`_free_memory_bytes`
1087 if [ "$free_mem" -lt "$fssize" ] ; then
1088 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1090 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1093 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1098 # Emulate an N-data-disk stripe w/ various stripe units
1099 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1100 _scratch_mkfs_geom()
1105 [ -z "$blocksize" ] && blocksize=4096
1107 let sunit_blocks=$sunit_bytes/$blocksize
1108 let swidth_blocks=$sunit_blocks*$swidth_mult
1112 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1115 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1118 _notrun "can't mkfs $FSTYP with geometry"
1124 # Create fs of certain blocksize on scratch device
1125 # _scratch_mkfs_blocksized blocksize
1126 _scratch_mkfs_blocksized()
1131 if ! [[ $blocksize =~ $re ]] ; then
1132 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1137 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1140 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1143 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1146 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1155 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1163 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1164 # errors found or errors were fixed) and nonzero otherwise; also spits out
1165 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1166 _repair_scratch_fs()
1170 _scratch_xfs_repair "$@" 2>&1
1172 if [ "$res" -ne 0 ]; then
1173 echo "xfs_repair returns $res; replay log?"
1176 if [ "$res" -gt 0 ]; then
1177 echo "mount returns $res; zap log?"
1178 _scratch_xfs_repair -L 2>&1
1179 echo "log zap returns $?"
1181 umount "$SCRATCH_MNT"
1183 _scratch_xfs_repair "$@" 2>&1
1186 if [ $res -ne 0 ]; then
1187 _dump_err2 "xfs_repair failed, err=$res"
1192 # Let's hope fsck -y suffices...
1193 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1200 _dump_err2 "fsck.$FSTYP failed, err=$res"
1212 echo "Usage: _get_pids_by_name process-name" 1>&2
1216 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1217 # HH:MM:SS before the psargs field, use this as the search anchor.
1219 # Matches with $1 (process-name) occur if the first psarg is $1
1220 # or ends in /$1 ... the matching uses sed's regular expressions,
1221 # so passing a regex into $1 will work.
1226 -e 's/[ ][ ]*/ /g' \
1229 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1230 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1233 # fix malloc libs output
1237 # filter out the Electric Fence notice
1240 if (defined $o && /^\s+Electric Fence/) {
1246 print $o if (defined $o);
1250 print $o if (defined $o);
1255 # _df_device : get an IRIX style df line for a given device
1257 # - returns "" if not mounted
1258 # - returns fs type in field two (ala IRIX)
1259 # - joins line together if split by fancy df formatting
1260 # - strips header etc
1267 echo "Usage: _df_device device" 1>&2
1271 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1272 # IPv6 server as a regular expression.
1273 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1274 ($1==what) && (NF==1) {
1288 # _df_dir : get an IRIX style df line for device where a directory resides
1290 # - returns fs type in field two (ala IRIX)
1291 # - joins line together if split by fancy df formatting
1292 # - strips header etc
1299 echo "Usage: _df_dir device" 1>&2
1303 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1319 # return percentage used disk space for mounted device
1325 echo "Usage: _used device" 1>&2
1329 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1332 # return the FS type of a mounted device
1338 echo "Usage: _fs_type device" 1>&2
1343 # The Linux kernel shows NFSv4 filesystems in df output as
1344 # filesystem type nfs4, although we mounted it as nfs earlier.
1345 # Fix the filesystem type up here so that the callers don't
1346 # have to bother with this quirk.
1348 _df_device $1 | $AWK_PROG '{ print $2 }' | \
1349 sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
1352 # return the FS mount options of a mounted device
1354 # should write a version which just parses the output of mount for IRIX
1355 # compatibility, but since this isn't used at all, at the moment I'll leave
1362 echo "Usage: _fs_options device" 1>&2
1366 $AWK_PROG -v dev=$1 '
1367 match($1,dev) { print $4 }
1371 # returns device number if a file is a block device
1377 echo "Usage: _is_block_dev dev" 1>&2
1382 if [ -L "${_dev}" ]; then
1383 _dev=`readlink -f "${_dev}"`
1386 if [ -b "${_dev}" ]; then
1387 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1391 # returns device number if a file is a character device
1395 if [ $# -ne 1 ]; then
1396 echo "Usage: _is_char_dev dev" 1>&2
1401 if [ -L "${_dev}" ]; then
1402 _dev=`readlink -f "${_dev}"`
1405 if [ -c "${_dev}" ]; then
1406 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1410 # Do a command, log it to $seqres.full, optionally test return status
1411 # and die if command fails. If called with one argument _do executes the
1412 # command, logs it, and returns its exit status. With two arguments _do
1413 # first prints the message passed in the first argument, and then "done"
1414 # or "fail" depending on the return status of the command passed in the
1415 # second argument. If the command fails and the variable _do_die_on_error
1416 # is set to "always" or the two argument form is used and _do_die_on_error
1417 # is set to "message_only" _do will print an error message to
1418 # $seqres.out and exit.
1422 if [ $# -eq 1 ]; then
1424 elif [ $# -eq 2 ]; then
1427 echo -n "$_note... "
1429 echo "Usage: _do [note] cmd" 1>&2
1433 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1434 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1435 cat $tmp._out | _fix_malloc >>$seqres.full
1437 if [ $# -eq 2 ]; then
1438 if [ $ret -eq 0 ]; then
1445 && [ "$_do_die_on_error" = "always" \
1446 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1448 [ $# -ne 2 ] && echo
1449 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1456 # bail out, setting up .notrun file. Need to kill the filesystem check files
1457 # here, otherwise they are set incorrectly for the next test.
1461 echo "$*" > $seqres.notrun
1462 echo "$seq not run: $*"
1463 rm -f ${RESULT_DIR}/require_test*
1464 rm -f ${RESULT_DIR}/require_scratch*
1470 # just plain bail out
1474 echo "$*" | tee -a $seqres.full
1475 echo "(see $seqres.full for details)"
1480 # tests whether $FSTYP is one of the supported filesystems for a test
1486 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1492 _notrun "not suitable for this filesystem type: $FSTYP"
1496 # tests whether $FSTYP is one of the supported OSes for a test
1502 if [ "$h" = "$HOSTOS" ]
1508 _notrun "not suitable for this OS: $HOSTOS"
1511 # check if a FS on a device is mounted
1512 # if so, verify that it is mounted on mount point
1513 # if fstype is given as argument, verify that it is also
1514 # mounted with correct fs type
1524 # find $dev as the source, and print result in "$dev $mnt" format
1525 local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
1526 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1528 # if it's mounted, make sure its on $mnt
1529 if [ "$mount_rec" != "$dev $mnt" ]; then
1530 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1531 echo "Already mounted result:"
1533 return 2 # 2 = mounted on wrong mnt
1536 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
1537 echo "$devname=$dev is mounted but not a type $type filesystem"
1538 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1540 return 3 # 3 = mounted as wrong type
1542 return 0 # 0 = mounted as expected
1545 # this test needs a scratch partition - check we're ok & unmount it
1546 # No post-test check of the device is required. e.g. the test intentionally
1547 # finishes the test with the filesystem in a corrupt state
1548 _require_scratch_nocheck()
1552 echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
1553 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1554 _notrun "this test requires a valid \$SCRATCH_DEV"
1556 if [ ! -d "$SCRATCH_MNT" ]; then
1557 _notrun "this test requires a valid \$SCRATCH_MNT"
1561 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1562 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1563 _notrun "this test requires a valid \$SCRATCH_DEV"
1565 if [ ! -d "$SCRATCH_MNT" ]; then
1566 _notrun "this test requires a valid \$SCRATCH_MNT"
1570 echo $SCRATCH_DEV | grep -q "://" > /dev/null 2>&1
1571 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1572 _notrun "this test requires a valid \$SCRATCH_DEV"
1574 if [ ! -d "$SCRATCH_MNT" ]; then
1575 _notrun "this test requires a valid \$SCRATCH_MNT"
1579 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1580 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1581 _notrun "this test requires a valid \$SCRATCH_DEV"
1583 if [ ! -d "$SCRATCH_MNT" ]; then
1584 _notrun "this test requires a valid \$SCRATCH_MNT"
1588 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1589 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1591 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1592 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1593 # and we will create the mount point anyway on _overlay_mount
1594 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1595 _notrun "this test requires a valid \$SCRATCH_MNT"
1599 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1601 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1605 # ubifs needs an UBI volume. This will be a char device, not a block device.
1606 if [ ! -c "$SCRATCH_DEV" ]; then
1607 _notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
1609 if [ ! -d "$SCRATCH_MNT" ]; then
1610 _notrun "this test requires a valid \$SCRATCH_MNT"
1614 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1616 _notrun "this test requires a valid \$SCRATCH_DEV"
1618 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1620 _notrun "this test requires a valid \$SCRATCH_DEV"
1622 if [ ! -d "$SCRATCH_MNT" ]
1624 _notrun "this test requires a valid \$SCRATCH_MNT"
1629 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1631 [ $err -le 1 ] || exit 1
1634 # if it's mounted, unmount it
1635 if ! _scratch_unmount
1637 echo "failed to unmount $SCRATCH_DEV"
1641 rm -f ${RESULT_DIR}/require_scratch
1644 # we need the scratch device and it should be checked post test.
1647 _require_scratch_nocheck
1648 touch ${RESULT_DIR}/require_scratch
1652 # this test needs a test partition - check we're ok & mount it
1658 echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
1659 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1660 _notrun "this test requires a valid \$TEST_DEV"
1662 if [ ! -d "$TEST_DIR" ]; then
1663 _notrun "this test requires a valid \$TEST_DIR"
1667 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1668 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1669 _notrun "this test requires a valid \$TEST_DEV"
1671 if [ ! -d "$TEST_DIR" ]; then
1672 _notrun "this test requires a valid \$TEST_DIR"
1676 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1677 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1678 _notrun "this test requires a valid \$TEST_DEV"
1680 if [ ! -d "$TEST_DIR" ]; then
1681 _notrun "this test requires a valid \$TEST_DIR"
1685 echo $TEST_DEV | grep -q "://" > /dev/null 2>&1
1686 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1687 _notrun "this test requires a valid \$TEST_DIR"
1689 if [ ! -d "$TEST_DIR" ]; then
1690 _notrun "this test requires a valid \$TEST_DIR"
1694 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1695 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1697 if [ ! -d "$TEST_DIR" ]; then
1698 _notrun "this test requires a valid \$TEST_DIR"
1702 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1704 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1708 # ubifs needs an UBI volume. This will be a char device, not a block device.
1709 if [ ! -c "$TEST_DEV" ]; then
1710 _notrun "this test requires a valid UBI volume for \$TEST_DEV"
1712 if [ ! -d "$TEST_DIR" ]; then
1713 _notrun "this test requires a valid \$TEST_DIR"
1717 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1719 _notrun "this test requires a valid \$TEST_DEV"
1721 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1723 _notrun "this test requires a valid \$TEST_DEV"
1725 if [ ! -d "$TEST_DIR" ]
1727 _notrun "this test requires a valid \$TEST_DIR"
1732 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1734 [ $err -le 1 ] || exit 1
1739 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1743 touch ${RESULT_DIR}/require_test
1749 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
1750 [ "$USE_EXTERNAL" != yes ] && ret=1
1755 # this test needs a logdev
1759 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1760 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1761 [ "$USE_EXTERNAL" != yes ] && \
1762 _notrun "This test requires USE_EXTERNAL to be enabled"
1764 # ensure its not mounted
1765 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1768 # this test requires loopback device support
1772 if [ "$HOSTOS" != "Linux" ]
1774 _notrun "This test requires linux for loopback device support"
1777 modprobe loop >/dev/null 2>&1
1778 if grep loop /proc/devices >/dev/null 2>&1
1782 _notrun "This test requires loopback device support"
1786 # this test requires ext2 filesystem support
1790 if [ "$HOSTOS" != "Linux" ]
1792 _notrun "This test requires linux for ext2 filesystem support"
1795 modprobe ext2 >/dev/null 2>&1
1796 if grep ext2 /proc/filesystems >/dev/null 2>&1
1800 _notrun "This test requires ext2 filesystem support"
1804 # this test requires tmpfs filesystem support
1808 modprobe tmpfs >/dev/null 2>&1
1809 grep -q tmpfs /proc/filesystems ||
1810 _notrun "this test requires tmpfs support"
1813 # this test requires that (large) loopback device files are not in use
1815 _require_no_large_scratch_dev()
1817 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1818 _notrun "Large filesystem testing in progress, skipped this test"
1821 # this test requires that a realtime subvolume is in use, and
1822 # that the kernel supports realtime as well.
1826 [ "$USE_EXTERNAL" = yes ] || \
1827 _notrun "External volumes not in use, skipped this test"
1828 [ "$SCRATCH_RTDEV" = "" ] && \
1829 _notrun "Realtime device required, skipped this test"
1832 # this test requires that a specified command (executable) exists
1833 # $1 - command, $2 - name for error message
1835 # Note: the command string might have parameters, so strip them before checking
1836 # whether it is executable.
1839 if [ $# -eq 2 ]; then
1841 elif [ $# -eq 1 ]; then
1844 _fail "usage: _require_command <command> [<name>]"
1847 _command=`echo "$1" | awk '{ print $1 }'`
1848 if [ ! -x "$_command" ]; then
1849 _notrun "$_name utility required, skipped this test"
1853 # this test requires the device to be valid block device
1855 _require_block_device()
1857 if [ -z "$1" ]; then
1858 echo "Usage: _require_block_device <dev>" 1>&2
1861 if [ "`_is_block_dev "$1"`" == "" ]; then
1862 _notrun "require $1 to be valid block disk"
1866 # this test requires a path to refere to a local block or character device
1868 _require_local_device()
1870 if [ -z "$1" ]; then
1871 echo "Usage: _require_local_device <dev>" 1>&2
1874 if [ "`_is_block_dev "$1"`" != "" ]; then
1877 if [ "`_is_char_dev "$1"`" != "" ]; then
1880 _notrun "require $1 to be local device"
1883 # brd based ram disks erase the device when they receive a flush command when no
1884 # active references are present. This causes problems for DM devices sitting on
1885 # top of brd devices as DM doesn't hold active references to the brd device.
1886 _require_sane_bdev_flush()
1888 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1889 if [ $? -eq 0 ]; then
1890 _notrun "This test requires a sane block device flush"
1894 # this test requires a specific device mapper target
1895 _require_dm_target()
1899 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1901 _require_block_device $SCRATCH_DEV
1902 _require_sane_bdev_flush $SCRATCH_DEV
1903 _require_command "$DMSETUP_PROG" dmsetup
1905 modprobe dm-$_target >/dev/null 2>&1
1907 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1908 if [ $? -ne 0 ]; then
1909 _notrun "This test requires dm $_target support"
1913 # this test requires the ext4 kernel support crc feature on scratch device
1915 _require_scratch_ext4_crc()
1917 _scratch_mkfs_ext4 >/dev/null 2>&1
1918 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1919 _scratch_mount >/dev/null 2>&1 \
1920 || _notrun "Kernel doesn't support metadata_csum feature"
1924 # Check the specified feature whether it is available in mkfs.ext4 or not.
1925 _require_ext4_mkfs_feature()
1928 local testfile=/tmp/$$.ext4_mkfs
1930 if [ -z "$feature" ]; then
1931 echo "Usage: _require_ext4_mkfs_feature feature"
1936 local result=$($MKFS_EXT4_PROG -F -O $feature -n $testfile 512m 2>&1)
1938 echo $result | grep -q "Invalid filesystem option" && \
1939 _notrun "mkfs.ext4 doesn't support $feature feature"
1942 # this test requires the ext4 kernel support bigalloc feature
1944 _require_ext4_bigalloc()
1946 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1947 _scratch_mount >/dev/null 2>&1 \
1948 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1952 # this test requires that external log/realtime devices are not in use
1954 _require_nonexternal()
1956 [ "$USE_EXTERNAL" = yes ] && \
1957 _notrun "External device testing in progress, skipped this test"
1960 # this test requires that the kernel supports asynchronous I/O
1963 $here/src/feature -A
1968 _notrun "kernel does not support asynchronous I/O"
1971 _fail "unexpected error testing for asynchronous I/O support"
1976 # this test requires that a (specified) aio-dio executable exists
1977 # and that the kernel supports asynchronous I/O.
1978 # $1 - command (optional)
1984 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1985 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1987 AIO_TEST=src/aio-dio-regress/$1
1988 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1994 # this test requires that a test program exists under src/
1995 # $1 - command (require)
1997 _require_test_program()
2000 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
2003 # run an aio-dio program
2009 echo "usage: _run_aiodio command_name" 2>&1
2015 local testtemp=$TEST_DIR/aio-testfile
2017 $AIO_TEST $testtemp 2>&1
2024 # this test requires y2038 sysfs switch and filesystem
2025 # timestamp ranges support.
2028 local device=${1:-$TEST_DEV}
2029 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
2031 if [ ! -e $sysfsdir ]; then
2032 _notrun "no kernel support for y2038 sysfs switch"
2036 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
2037 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
2038 _notrun "filesystem $FSTYP timestamp bounds are unknown"
2042 _filesystem_timestamp_range()
2044 device=${1:-$TEST_DEV}
2047 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
2048 echo "-2147483648 15032385535"
2050 echo "-2147483648 2147483647"
2055 echo "-2147483648 2147483647"
2061 echo "-2147483648 2147483647"
2069 # indicate whether YP/NIS is active or not
2074 dn=$(domainname 2>/dev/null)
2075 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
2079 # cat the password file
2083 [ $(_yp_active) -eq 0 ] && ypcat passwd
2087 # cat the group file
2091 [ $(_yp_active) -eq 0 ] && ypcat group
2095 # check for a user on the machine, fsgqa as default
2103 _cat_passwd | grep -q $qa_user
2104 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
2105 echo /bin/true | su $qa_user
2106 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
2109 # check for a group on the machine, fsgqa as default
2117 _cat_group | grep -q $qa_group
2118 [ "$?" == "0" ] || _notrun "$qa_group group not defined."
2124 s,.*Permission\sdenied.*,Permission denied,;
2125 s,.*no\saccess\sto\stty.*,,;
2126 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2133 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
2136 _require_xfs_io_command()
2140 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2146 local param_checked=0
2148 testfile=$TEST_DIR/$$.xfs_io
2151 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
2154 testcopy=$TEST_DIR/$$.copy.xfs_io
2155 $XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
2156 testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
2157 rm -f $testcopy > /dev/null 2>&1
2160 testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
2163 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
2164 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2165 -c "$command 4k 8k" $testfile 2>&1`
2168 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2169 -c "fiemap -v $param" $testfile 2>&1`
2173 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2175 echo $testio | egrep -q "invalid option|Is a directory" && \
2176 _notrun "xfs_io $command support is missing"
2179 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
2180 echo $testio | grep -q "Inappropriate ioctl" && \
2181 _notrun "xfs_io $command support is missing"
2184 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
2185 # a new -C flag was introduced to execute one shot commands.
2186 # Check for -C flag support as an indication for the bug fix.
2187 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
2188 echo $testio | grep -q "invalid option" && \
2189 _notrun "xfs_io $command support is missing"
2192 testio=`$XFS_IO_PROG -x -c "$command dummy 0" $TEST_DIR 2>&1`
2193 echo $testio | grep -q "Inappropriate ioctl" && \
2194 _notrun "xfs_io $command support is missing"
2197 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
2200 testio=`$XFS_IO_PROG -c "help $command" 2>&1`
2203 rm -f $testfile 2>&1 > /dev/null
2204 echo $testio | grep -q "not found" && \
2205 _notrun "xfs_io $command support is missing"
2206 echo $testio | grep -q "Operation not supported" && \
2207 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2208 echo $testio | grep -q "Invalid" && \
2209 _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
2210 echo $testio | grep -q "foreign file active" && \
2211 _notrun "xfs_io $command not supported on $FSTYP"
2212 echo $testio | grep -q "Function not implemented" && \
2213 _notrun "xfs_io $command support is missing (missing syscall?)"
2215 if [ -n "$param" -a $param_checked -eq 0 ]; then
2216 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2217 _notrun "xfs_io $command doesn't support $param"
2221 # check that kernel and filesystem support direct I/O
2224 if [ $FSTYP = "ext4" ] ; then
2225 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2226 _notrun "ext4 encryption doesn't support O_DIRECT"
2229 testfile=$TEST_DIR/$$.direct
2230 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2231 if [ $? -ne 0 ]; then
2232 _notrun "O_DIRECT is not supported"
2234 rm -f $testfile 2>&1 > /dev/null
2237 # Check that the filesystem supports swapfiles
2238 _require_scratch_swapfile()
2242 _scratch_mkfs >/dev/null
2245 # Minimum size for mkswap is 10 pages
2246 local size=$(($(get_page_size) * 10))
2248 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
2249 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
2250 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
2252 _notrun "swapfiles are not supported"
2255 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
2259 # Check that a fs has enough free space (in 1024b blocks)
2264 BLOCKS=$2 # in units of 1024
2265 let GB=$BLOCKS/1024/1024
2267 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2268 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2269 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2273 # Check if the filesystem supports sparse files.
2275 # Unfortunately there is no better way to do this than a manual black list.
2277 _require_sparse_files()
2281 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2290 #boot_params always present in debugfs
2291 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2294 _require_fail_make_request()
2296 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2297 || _notrun "$DEBUGFS_MNT/fail_make_request \
2298 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2301 # Disable extent zeroing for ext4 on the given device
2302 _ext4_disable_extent_zeroout()
2304 local dev=${1:-$TEST_DEV}
2305 local sdev=`_short_dev $dev`
2307 [ -f /sys/fs/ext4/$sdev/extent_max_zeroout_kb ] && \
2308 echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
2311 # Check if the file system supports seek_data/hole
2312 _require_seek_data_hole()
2314 local dev=${1:-$TEST_DEV}
2315 local testfile=$TEST_DIR/$$.seek
2316 local testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2318 rm -f $testfile &>/dev/null
2319 echo $testseek | grep -q "Kernel does not support" && \
2320 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2321 # Disable extent zeroing for ext4 as that change where holes are
2323 if [ "$FSTYP" = "ext4" ]; then
2324 _ext4_disable_extent_zeroout $dev
2330 _require_test_program "runas"
2335 "$here/src/runas" "$@"
2338 _require_richacl_prog()
2340 _require_command "$GETRICHACL_PROG" getrichacl
2341 _require_command "$SETRICHACL_PROG" setrichacl
2344 _require_scratch_richacl_xfs()
2346 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2347 || _notrun "mkfs.xfs doesn't have richacl feature"
2348 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2349 _scratch_mount >/dev/null 2>&1 \
2350 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2354 _require_scratch_richacl_ext4()
2356 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2357 || _notrun "can't mkfs $FSTYP with option -O richacl"
2358 _scratch_mount >/dev/null 2>&1 \
2359 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2363 _require_scratch_richacl_support()
2366 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2367 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2371 _require_scratch_richacl()
2374 xfs) _require_scratch_richacl_xfs
2376 ext4) _require_scratch_richacl_ext4
2379 _require_scratch_richacl_support
2381 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2386 _scratch_mkfs_richacl()
2389 xfs) _scratch_mkfs_xfs -m richacl=1
2391 ext4) _scratch_mkfs -O richacl
2399 # check that a FS on a device is mounted
2400 # if so, return mount point
2406 echo "Usage: _is_mounted device" 1>&2
2412 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2413 pattern { print $3 ; exit 0 }
2417 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2422 # remount a FS to a new mode (ro or rw)
2428 echo "Usage: _remount device ro/rw" 1>&2
2434 if ! mount -o remount,$mode $device
2436 echo "_remount: failed to remount filesystem on $device as $mode"
2441 # Run the appropriate repair/check on a filesystem
2443 # if the filesystem is mounted, it's either remounted ro before being
2444 # checked or it's unmounted and then remounted
2447 # If set, we remount ro instead of unmounting for fsck
2450 _umount_or_remount_ro()
2454 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2459 mountpoint=`_is_mounted $device`
2461 if [ $USE_REMOUNT -eq 0 ]; then
2462 $UMOUNT_PROG $device
2469 _mount_or_remount_rw()
2471 if [ $# -ne 3 ]; then
2472 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2479 if [ $USE_REMOUNT -eq 0 ]; then
2480 if [ "$FSTYP" != "overlay" ]; then
2481 _mount -t $FSTYP $mount_opts $device $mountpoint
2483 _overlay_mount $device $mountpoint
2485 if [ $? -ne 0 ]; then
2486 _dump_err "!!! failed to remount $device on $mountpoint"
2496 # Check a generic filesystem in no-op mode; this assumes that the
2497 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2498 # and that it will still return an errno for corruption in this mode.
2500 # Filesystems which don't support this will need to define their
2501 # own check routine.
2503 _check_generic_filesystem()
2507 # If type is set, we're mounted
2508 type=`_fs_type $device`
2511 if [ "$type" = "$FSTYP" ]
2514 mountpoint=`_umount_or_remount_ro $device`
2517 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2520 _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
2521 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2522 cat $tmp.fsck >>$seqres.full
2523 echo "*** end fsck.$FSTYP output" >>$seqres.full
2531 echo "*** mount output ***" >>$seqres.full
2532 _mount >>$seqres.full
2533 echo "*** end mount output" >>$seqres.full
2534 elif [ "$type" = "$FSTYP" ]
2537 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2541 if [ $ok -eq 0 ]; then
2543 if [ "$iam" != "check" ]; then
2552 # Filter the knowen errors the UDF Verifier reports.
2553 _udf_test_known_error_filter()
2555 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."
2559 _check_udf_filesystem()
2561 [ "$DISABLE_UDF_TEST" == "1" ] && return
2563 if [ $# -ne 1 -a $# -ne 2 ]
2565 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2569 if [ ! -x $here/src/udf_test ]
2571 echo "udf_test not installed, please download and build the Philips"
2572 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2573 echo "Then copy the udf_test binary to $here/src/."
2574 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2582 LAST_BLOCK=`expr \( $2 - 1 \)`
2583 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2586 rm -f $seqres.checkfs
2587 sleep 1 # Due to a problem with time stamps in udf_test
2588 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2589 _udf_test_known_error_filter | \
2590 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2591 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2602 # no way to check consistency for nfs
2605 # no way to check consistency for cifs
2608 # no way to check consistency for CephFS
2611 # no way to check consistency for GlusterFS
2614 # no way to check consistency for overlay
2619 # do nothing for now
2622 _check_btrfs_filesystem $TEST_DEV
2625 # no way to check consistency for tmpfs
2628 # there is no fsck program for ubifs yet
2631 _check_generic_filesystem $TEST_DEV
2639 [ $# -eq 1 ] && device=$1
2645 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2646 SCRATCH_LOG="$SCRATCH_LOGDEV"
2648 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2649 SCRATCH_RT="$SCRATCH_RTDEV"
2651 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2654 _check_udf_filesystem $device $udf_fsize
2657 # Don't know how to check an NFS filesystem, yet.
2660 # Don't know how to check a CIFS filesystem, yet.
2663 # no way to check consistency for CephFS
2666 # no way to check consistency for GlusterFS
2669 # no way to check consistency for overlay
2674 _check_btrfs_filesystem $device
2677 # no way to check consistency for tmpfs
2680 # there is no fsck program for ubifs yet
2683 _check_generic_filesystem $device
2688 _full_fstyp_details()
2690 [ -z "$FSTYP" ] && FSTYP=xfs
2691 if [ $FSTYP = xfs ]; then
2692 if [ -d /proc/fs/xfs ]; then
2693 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2694 FSTYP="$FSTYP (non-debug)"
2695 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2696 FSTYP="$FSTYP (debug)"
2699 if uname -a | grep -qi 'debug'; then
2700 FSTYP="$FSTYP (debug)"
2702 FSTYP="$FSTYP (non-debug)"
2709 _full_platform_details()
2715 echo "$os/$platform $host $kernel"
2720 if [ "`uname`" == "Linux" ]; then
2723 echo Unknown operating system: `uname`
2728 _link_out_file_named()
2733 my $feature, $result, $suffix, $opts;
2735 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2736 $feathash{$feature} = 1;
2738 $result = "default";
2743 ($opts, $suffix) = split(/ *: */);
2744 foreach my $opt (split(/,/, $opts)) {
2745 if (!exists($feathash{$opt})) {
2759 ln -fs $SRC.$SUFFIX $1
2764 if [ $# -eq 0 ]; then
2765 FEATURES="$(_get_os_name)"
2766 if [ -n "$MOUNT_OPTIONS" ]; then
2767 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2773 _link_out_file_named $seqfull.out "$FEATURES"
2782 # convert urandom incompressible data to compressible text data
2785 od /dev/urandom | dd iflag=fullblock ${*}
2788 #takes files, randomdata
2796 if [ $size -gt 0 ]; then
2797 if [ "$2" == "false" ]; then
2798 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2799 elif [ "$2" == "comp" ]; then
2800 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2802 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2809 # takes dirname, depth, randomdata
2812 dirname=$1; depth=$2; randomdata=$3
2813 mkdir $dirname || die "mkdir $dirname failed"
2816 _nfiles $files $randomdata # files for this dir and data type
2818 [ $depth -eq 0 ] && return
2819 let deep=$depth-1 # go 1 down
2821 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2824 while [ $d -lt $dirs ]
2826 _descend d$d $deep &
2832 # Populate a filesystem with inodes for performance experiments
2834 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2839 dirs=5 # ndirs in each subdir till leaves
2840 size=0 # sizeof files in K
2841 files=100 # num files in _each_ subdir
2842 depth=2 # depth of tree from root to leaves
2844 root=root # path of initial root of directory tree
2845 randomdata=false # -x data type urandom, zero or compressible
2848 while getopts "d:f:n:r:s:v:x:c" c
2857 x) randomdata=true;;
2858 c) randomdata=comp;;
2862 _descend $root $depth $randomdata
2867 [ $verbose = true ] && echo done
2870 # query whether the given file has the given inode flag set
2877 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2883 # query the given files extsize allocator hint in bytes (if any)
2890 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2891 awk '/^xattr.extsize =/ { print $3 }'`
2892 [ -z "$blocks" ] && blocks="0"
2896 # scratch_dev_pool should contain the disks pool for the btrfs raid
2897 _require_scratch_dev_pool()
2902 if [ -z "$SCRATCH_DEV_POOL" ]; then
2903 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2906 if [ -z "$1" ]; then
2912 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2916 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2917 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2921 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2925 for i in $SCRATCH_DEV_POOL; do
2926 if [ "`_is_block_dev "$i"`" = "" ]; then
2927 _notrun "this test requires valid block disk $i"
2929 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2930 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2932 if _mount | grep -q $i; then
2933 if ! $UMOUNT_PROG $i; then
2934 echo "failed to unmount $i - aborting"
2938 # to help better debug when something fails, we remove
2939 # traces of previous btrfs FS on the dev.
2940 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2944 # ensure devices in SCRATCH_DEV_POOL are of the same size
2945 # must be called after _require_scratch_dev_pool
2946 _require_scratch_dev_pool_equal_size()
2952 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2953 _size=`_get_device_size $SCRATCH_DEV`
2954 for _dev in $SCRATCH_DEV_POOL; do
2955 _newsize=`_get_device_size $_dev`
2956 if [ $_size -ne $_newsize ]; then
2957 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2962 # We will check if the device is deletable
2963 _require_deletable_scratch_dev_pool()
2967 for i in $SCRATCH_DEV_POOL; do
2968 x=`echo $i | cut -d"/" -f 3`
2969 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2970 _notrun "$i is a device which is not deletable"
2975 # Check that fio is present, and it is able to execute given jobfile
2980 _require_command "$FIO_PROG" fio
2981 if [ -z "$1" ]; then
2985 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2986 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2989 # Does freeze work on this fs?
2992 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2994 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2995 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2998 # Does NFS export work on this fs?
3001 _require_test_program "open_by_handle"
3002 mkdir -p "$TEST_DIR"/exportfs_test
3003 $here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
3004 || _notrun "$FSTYP does not support NFS export"
3008 # Does shutdown work on this fs?
3009 _require_scratch_shutdown()
3011 [ -x src/godown ] || _notrun "src/godown executable not found"
3013 _scratch_mkfs > /dev/null 2>&1
3015 src/godown -f $SCRATCH_MNT 2>&1 \
3016 || _notrun "$FSTYP does not support shutdown"
3020 # Does dax mount option work on this dev/fs?
3021 _require_scratch_dax()
3024 _scratch_mkfs > /dev/null 2>&1
3025 _scratch_mount -o dax
3026 # Check options to be sure. XFS ignores dax option
3027 # and goes on if dev underneath does not support dax.
3028 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
3029 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
3033 # Does norecovery support by this fs?
3034 _require_norecovery()
3036 _scratch_mount -o ro,norecovery || \
3037 _notrun "$FSTYP does not support norecovery"
3041 # Does this filesystem support metadata journaling?
3042 # We exclude ones here that don't; otherwise we assume that it does, so the
3043 # test will run, fail, and motivate someone to update this test for a new
3046 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
3047 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
3049 _require_metadata_journaling()
3058 ext2|vfat|msdos|udf)
3059 _notrun "$FSTYP does not support metadata journaling"
3062 # ext4 could be mkfs'd without a journal...
3064 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3065 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3066 # ext4 might not load a journal
3067 _exclude_scratch_mount_option "noload"
3070 # by default we pass; if you need to, add your fs above!
3077 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3082 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3085 _count_attr_extents()
3087 $XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
3090 # arg 1 is dev to remove and is output of the below eg.
3091 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3097 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3099 stat $disk > /dev/null 2>&1
3100 while [ $? -eq 0 ]; do
3102 stat $disk > /dev/null 2>&1
3106 # arg 1 is dev to add and is output of the below eg.
3107 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3112 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3113 h=`echo ${1} | cut -d":" -f 1`
3114 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3116 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3118 # ensure the device comes online
3120 for i in `seq 1 10`; do
3121 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3122 dev=`ls /sys/class/scsi_device/${1}/device/block`
3123 for j in `seq 1 10`;
3125 stat /dev/$dev > /dev/null 2>&1
3126 if [ $? -eq 0 ]; then
3137 if [ $dev_back_oneline -eq 0 ]; then
3138 echo "/dev/$dev online failed" >> $seqres.full
3140 echo "/dev/$dev is back online" >> $seqres.full
3146 if [ -z "$FSTRIM_PROG" ]; then
3147 _notrun "This test requires fstrim utility."
3151 _require_batched_discard()
3153 if [ $# -ne 1 ]; then
3154 echo "Usage: _require_batched_discard mnt_point" 1>&2
3158 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3163 if [ -z "$DUMPE2FS_PROG" ]; then
3164 _notrun "This test requires dumpe2fs utility."
3170 if [ ! -e /proc/self/uid_map ]; then
3171 _notrun "This test requires procfs uid_map support."
3173 if [ ! -e /proc/self/gid_map ]; then
3174 _notrun "This test requires procfs gid_map support."
3180 FSSUM_PROG=$here/src/fssum
3181 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3186 CLONER_PROG=$here/src/cloner
3187 [ -x $CLONER_PROG ] || \
3188 _notrun "cloner binary not present at $CLONER_PROG"
3191 # Normalize mount options from global $MOUNT_OPTIONS
3192 # Convert options like "-o opt1,opt2 -oopt3" to
3194 _normalize_mount_options()
3196 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
3199 # skip test if MOUNT_OPTIONS contains the given strings
3200 _exclude_scratch_mount_option()
3202 local mnt_opts=$(_normalize_mount_options)
3204 while [ $# -gt 0 ]; do
3205 if echo $mnt_opts | grep -qw "$1"; then
3206 _notrun "mount option \"$1\" not allowed in this test"
3214 _exclude_scratch_mount_option "noatime"
3215 if [ "$FSTYP" == "nfs" ]; then
3216 _notrun "atime related mount options have no effect on NFS"
3222 _scratch_mkfs > /dev/null 2>&1
3223 _scratch_mount -o relatime || \
3224 _notrun "relatime not supported by the current kernel"
3230 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3231 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3234 _create_loop_device()
3237 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3241 _destroy_loop_device()
3244 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3247 _scale_fsstress_args()
3250 while [ $# -gt 0 ]; do
3252 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3253 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3254 *) args="$args $1" ;;
3262 # Return the logical block size if running on a block device,
3263 # else substitute the page size.
3265 _min_dio_alignment()
3269 if [ -b "$dev" ]; then
3270 blockdev --getss $dev
3272 $here/src/feature -s
3278 echo "# $@" >> $seqres.full 2>&1
3279 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3282 _require_test_symlinks()
3284 target=`mktemp -p $TEST_DIR`
3285 link=`mktemp -p $TEST_DIR -u`
3286 ln -s `basename $target` $link
3287 if [ "$?" -ne 0 ]; then
3289 _notrun "Require symlinks support"
3294 _require_test_fcntl_advisory_locks()
3296 [ "$FSTYP" != "cifs" ] && return 0
3297 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3298 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3299 _notrun "Require fcntl advisory locks support"
3302 _require_test_lsattr()
3304 testio=$(lsattr -d $TEST_DIR 2>&1)
3305 echo $testio | grep -q "Operation not supported" && \
3306 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3307 echo $testio | grep -q "Inappropriate ioctl for device" && \
3308 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3313 if [ -z "$1" ]; then
3314 echo "Usage: _require_chattr <attr>"
3319 touch $TEST_DIR/syscalltest
3320 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3322 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3323 if [ "$status" -ne 0 ]; then
3324 _notrun "file system doesn't support chattr +$attribute"
3326 cat $TEST_DIR/syscalltest.out >> $seqres.full
3327 rm -f $TEST_DIR/syscalltest.out
3332 if [ -z "$1" ]; then
3333 echo "Usage: _get_total_inode <mnt>"
3337 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3343 if [ -z "$1" ]; then
3344 echo "Usage: _get_used_inode <mnt>"
3348 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3352 _get_used_inode_percent()
3354 if [ -z "$1" ]; then
3355 echo "Usage: _get_used_inode_percent <mnt>"
3359 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3366 if [ -z "$1" ]; then
3367 echo "Usage: _get_free_inode <mnt>"
3371 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3375 # get the available space in bytes
3377 _get_available_space()
3379 if [ -z "$1" ]; then
3380 echo "Usage: _get_available_space <mnt>"
3384 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3385 echo $((avail_kb * 1024))
3388 # return device size in kb
3391 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3394 # check dmesg log for WARNING/Oops/etc.
3397 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3400 rm -f ${RESULT_DIR}/check_dmesg
3402 # default filter is a simple cat command, caller could provide a
3403 # customized filter and pass the name through the first argument, to
3404 # filter out intentional WARNINGs or Oopses
3407 # search the dmesg log of last run of $seqnum for possible failures
3408 # use sed \cregexpc address type, since $seqnum contains "/"
3409 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3410 tac | $filter >$seqres.dmesg
3411 egrep -q -e "kernel BUG at" \
3415 -e "possible recursive locking detected" \
3416 -e "Internal error" \
3417 -e "(INFO|ERR): suspicious RCU usage" \
3418 -e "INFO: possible circular locking dependency detected" \
3419 -e "general protection fault:" \
3421 if [ $? -eq 0 ]; then
3422 _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3430 # don't check dmesg log after test
3431 _disable_dmesg_check()
3433 rm -f ${RESULT_DIR}/check_dmesg
3438 if [ "$iam" == new ]
3442 # make some further configuration checks here
3443 if [ "$TEST_DEV" = "" ]
3445 echo "common/rc: Error: \$TEST_DEV is not set"
3449 # if $TEST_DEV is not mounted, mount it now as XFS
3450 if [ -z "`_fs_type $TEST_DEV`" ]
3452 # $TEST_DEV is not mounted
3455 echo "common/rc: retrying test device mount with external set"
3456 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3459 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3465 # Sanity check that TEST partition is not mounted at another mount point
3466 # or as another fs type
3467 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3468 if [ -n "$SCRATCH_DEV" ]; then
3469 # Sanity check that SCRATCH partition is not mounted at another
3470 # mount point, because it is about to be unmounted and formatted.
3471 # Another fs type for scratch is fine (bye bye old fs type).
3472 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3473 [ $? -le 1 ] || exit 1
3476 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3477 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3478 export XFS_IO_PROG="$XFS_IO_PROG -F"
3480 # xfs_io -i option starts an idle thread for xfs_io.
3481 # With single threaded process, the file table is not shared
3482 # and file structs are not reference counted.
3483 # Spawning an idle thread can help detecting file struct
3484 # reference leaks, so we want to enable the option whenever
3486 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3487 export XFS_IO_PROG="$XFS_IO_PROG -i"
3489 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3490 # can change the UUID on v5 filesystems
3491 if [ "$FSTYP" == "xfs" ]; then
3493 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3494 # xfs_db will return 0 even if it can't generate a new uuid, so
3495 # check the output to make sure if it can change UUID of V5 xfs
3496 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3497 | grep -q "invalid UUID\|supported on V5 fs" \
3498 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3503 # get real device path name by following link
3507 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3508 _dev=`readlink -f "$_dev"`
3513 # basename of a device
3516 echo `basename $(_real_dev $1)`
3521 local _dev=`_real_dev $1`
3522 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3523 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3524 _maj=$(echo "ibase=16; $_maj" | bc)
3525 _min=$(echo "ibase=16; $_min" | bc)
3526 echo /sys/dev/block/$_maj:$_min
3529 # Get the minimum block size of a file. Usually this is the
3530 # minimum fs block size, but some filesystems (ocfs2) do block
3531 # mappings in larger units.
3532 _get_file_block_size()
3534 if [ -z $1 ] || [ ! -d $1 ]; then
3535 echo "Missing mount point argument for _get_file_block_size"
3538 if [ "$FSTYP" = "ocfs2" ]; then
3545 # Get the minimum block size of an fs.
3548 if [ -z $1 ] || [ ! -d $1 ]; then
3549 echo "Missing mount point argument for _get_block_size"
3557 echo $(getconf PAGE_SIZE)
3564 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3565 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3566 echo "$@" >>$seqres.full
3567 rm -f $TEST_DIR/junk
3568 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3569 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3577 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3579 # Only one argument is needed:
3580 # - attr: path name under /sys/fs/$FSTYP/DEV
3583 # _require_fs_sysfs error/fail_at_unmount
3587 local dname=$(_short_dev $TEST_DEV)
3589 if [ -z "$attr" -o -z "$dname" ];then
3590 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3593 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3594 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3600 $here/src/stat_test --check-statx ||
3601 _notrun "This test requires the statx system call"
3604 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3606 # All arguments are necessary, and in this order:
3607 # - dev: device name, e.g. $SCRATCH_DEV
3608 # - attr: path name under /sys/fs/$FSTYP/$dev
3609 # - content: the content of $attr
3612 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3613 _set_fs_sysfs_attr()
3621 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3622 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3625 local dname=$(_short_dev $dev)
3626 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3629 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3631 # All arguments are necessary, and in this order:
3632 # - dev: device name, e.g. $SCRATCH_DEV
3633 # - attr: path name under /sys/fs/$FSTYP/$dev
3636 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3637 _get_fs_sysfs_attr()
3642 if [ ! -b "$dev" -o -z "$attr" ];then
3643 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3646 local dname=$(_short_dev $dev)
3647 cat /sys/fs/${FSTYP}/${dname}/${attr}
3650 # Print the value of a filesystem module parameter
3651 # at /sys/module/$FSTYP/parameters/$PARAM
3653 # Usage example (FSTYP=overlay):
3654 # _get_fs_module_param index
3655 _get_fs_module_param()
3657 cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null
3660 # Generic test for specific filesystem feature.
3661 # Currently only implemented to test overlayfs features.
3662 _require_scratch_feature()
3668 # overalyfs features (e.g. redirect_dir, index) are
3669 # configurable from Kconfig (the build default), by module
3670 # parameter (the system default) and per mount by mount
3671 # option ${feature}=[on|off].
3673 # If the module parameter does not exist then there is no
3674 # point in checking the mount option.
3675 local default=`_get_fs_module_param ${feature}`
3676 [ "$default" = Y ] || [ "$default" = N ] || \
3677 _notrun "feature '${feature}' not supported by ${FSTYP}"
3679 _scratch_mkfs > /dev/null 2>&1
3680 _scratch_mount -o ${feature}=on || \
3681 _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
3682 # Check options to be sure. For example, Overlayfs will fallback to
3683 # index=off if underlying fs does not support file handles.
3684 # Overlayfs only displays mount option if it differs from the default.
3685 # Overlayfs may enable the feature, but fallback to read-only mount.
3686 ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \
3687 ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \
3688 touch $SCRATCH_MNT/foo 2>/dev/null ) || \
3689 _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
3693 _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
3701 ################################################################################
3702 # make sure this script returns success