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 [ "$HOSTOS" != "IRIX" ] && 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 # irix is fussy about how it is fed its mount options
291 # - multiple -o's are not allowed
292 # - no spaces between comma delimitered options
293 # the sed script replaces all -o's (except the first) with a comma
294 # not required for linux, but won't hurt
296 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
297 | sed -e 's/dmapi/dmi/' \
298 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
302 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
303 # with the safe set of scratch mount options (e.g. loop image may be
304 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
305 _common_dev_mount_options()
307 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
310 _overlay_basic_mount_options()
312 echo "-o lowerdir=$1/$OVL_LOWER,upperdir=$1/$OVL_UPPER,workdir=$1/$OVL_WORK"
315 _overlay_mount_options()
317 echo `_common_dev_mount_options` \
318 `_overlay_basic_mount_options $1` \
319 $OVERLAY_MOUNT_OPTIONS
322 _scratch_mount_options()
324 _scratch_options mount
326 if [ "$FSTYP" == "overlay" ]; then
327 echo `_overlay_mount_options $OVL_BASE_SCRATCH_MNT`
330 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
331 $SCRATCH_DEV $SCRATCH_MNT
338 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
341 xfs_info $dir | grep -q "ftype=1"
344 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
345 tune2fs -l $dev | grep -q filetype
348 local testfile=$dir/$$.ftype
350 # look for DT_UNKNOWN files
351 local unknowns=$(src/t_dir_type $dir u | wc -l)
353 # 0 unknowns is success
359 # helper function to do the actual overlayfs mount operation
360 _overlay_mount_dirs()
367 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
368 -o workdir=$workdir $*
375 mkdir -p $dir/$OVL_UPPER
376 mkdir -p $dir/$OVL_LOWER
377 mkdir -p $dir/$OVL_WORK
378 mkdir -p $dir/$OVL_MNT
381 # Given a base fs dir, set up overlay directories and mount on the given mnt.
382 # The dir is used as the mount device so it can be seen from df or mount
389 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
393 _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER \
394 $dir/$OVL_WORK $OVERLAY_MOUNT_OPTIONS \
395 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
398 _overlay_base_test_mount()
400 if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \
401 _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \
402 OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR
404 # no base fs or already mounted
408 # base fs mounted but not on mount point
412 _mount $TEST_FS_MOUNT_OPTS \
413 $SELINUX_MOUNT_OPTIONS \
414 $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR
417 _overlay_test_mount()
419 _overlay_base_test_mount && \
420 _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
423 _overlay_base_scratch_mount()
425 if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \
426 _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \
427 OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT
429 # no base fs or already mounted
433 # base fs mounted but not on mount point
437 _mount $OVL_BASE_MOUNT_OPTIONS \
438 $SELINUX_MOUNT_OPTIONS \
439 $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
442 _overlay_base_scratch_unmount()
444 [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
446 $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
449 _overlay_scratch_mount()
451 _overlay_base_scratch_mount && \
452 _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
455 _overlay_base_test_unmount()
457 [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
459 $UMOUNT_PROG $OVL_BASE_TEST_DIR
462 _overlay_test_unmount()
464 $UMOUNT_PROG $TEST_DIR
465 _overlay_base_test_unmount
468 _overlay_scratch_unmount()
470 $UMOUNT_PROG $SCRATCH_MNT
471 _overlay_base_scratch_unmount
476 if [ "$FSTYP" == "overlay" ]; then
477 _overlay_scratch_mount $*
480 _mount -t $FSTYP `_scratch_mount_options $*`
487 _overlay_scratch_unmount
490 $UMOUNT_PROG $SCRATCH_MNT
493 $UMOUNT_PROG $SCRATCH_DEV
502 if test -n "$opts"; then
503 mount -o "remount,$opts" $SCRATCH_MNT
507 _scratch_cycle_mount()
511 if [ "$FSTYP" = tmpfs ]; then
512 _scratch_remount "$opts"
515 if test -n "$opts"; then
519 _scratch_mount "$opts"
524 if [ "$FSTYP" == "overlay" ]; then
525 _overlay_test_mount $*
529 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
534 if [ "$FSTYP" == "overlay" ]; then
535 _overlay_test_unmount
537 $UMOUNT_PROG $TEST_DEV
543 if [ "$FSTYP" = tmpfs ]; then
550 _scratch_mkfs_options()
552 _scratch_options mkfs
553 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
556 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
557 # and user specified mkfs options, if that fails (due to conflicts between mkfs
558 # options), do a second mkfs with only user provided mkfs options.
560 # First param is the mkfs command without any mkfs options and device.
561 # Second param is the filter to remove unnecessary messages from mkfs stderr.
562 # Other extra mkfs options are followed.
568 local extra_mkfs_options=$*
572 # save mkfs output in case conflict means we need to run again.
573 # only the output for the mkfs that applies should be shown
574 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
575 2>$tmp.mkfserr 1>$tmp.mkfsstd
578 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
579 # $extra_mkfs_options
580 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
582 echo -n "** mkfs failed with extra mkfs options "
583 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
584 echo -n "** attempting to mkfs using only test $seq "
585 echo "options: $extra_mkfs_options **"
588 # running mkfs again. overwrite previous mkfs output files
589 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
590 2>$tmp.mkfserr 1>$tmp.mkfsstd
594 # output stored mkfs output, filtering unnecessary output from stderr
596 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
608 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
609 options="-l $SCRATCH_LOGDEV"
611 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
614 _setup_large_ext4_fs()
619 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
620 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
621 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
623 # Default free space in the FS is 50GB, but you can specify more via
624 # SCRATCH_DEV_EMPTY_SPACE
625 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
627 # mount the filesystem and create 16TB - 4KB files until we consume
628 # all the necessary space.
629 _scratch_mount 2>&1 >$tmp_dir/mnt.err
631 if [ $status -ne 0 ]; then
633 cat $tmp_dir/mnt.err >&2
634 rm -f $tmp_dir/mnt.err
637 rm -f $tmp_dir/mnt.err
639 file_size=$((16*1024*1024*1024*1024 - 4096))
641 while [ $space_to_consume -gt $file_size ]; do
644 -c "truncate $file_size" \
645 -c "falloc -k 0 $file_size" \
646 $SCRATCH_MNT/.use_space.$nfiles 2>&1
648 if [ $status -ne 0 ]; then
652 space_to_consume=$(( $space_to_consume - $file_size ))
653 nfiles=$(($nfiles + 1))
656 # consume the remaining space.
657 if [ $space_to_consume -gt 0 ]; then
659 -c "truncate $space_to_consume" \
660 -c "falloc -k 0 $space_to_consume" \
661 $SCRATCH_MNT/.use_space.$nfiles 2>&1
664 export NUM_SPACE_FILES=$nfiles
667 if [ $status -ne 0 ]; then
668 echo "large file prealloc failed"
669 cat $tmp_dir/mnt.err >&2
677 local mkfs_cmd="$MKFS_EXT4_PROG -F"
678 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
682 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
683 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
684 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
686 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
689 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
690 # manually parse the mkfs output to get the fs size in bytes
691 fs_size=`cat $tmp.mkfsstd | awk ' \
692 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
693 / inodes, / { blks = $3 } \
694 /reserved for the super user/ { resv = $1 } \
695 END { fssize = bs * blks - resv; print fssize }'`
697 _setup_large_ext4_fs $fs_size
701 # output mkfs stdout and stderr
715 # do nothing for cifs
718 # do nothing for ceph
721 # do nothing for glusterfs
724 # do nothing for overlay
727 # do nothing for pvfs2
730 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
733 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
736 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
739 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
751 # do nothing for overlay
754 # do nothing for pvfs2
757 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
760 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
763 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
764 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
768 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
769 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
773 if [ $? -ne 0 ]; then
774 # output stored mkfs output
775 cat $tmp_dir.mkfserr >&2
780 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
783 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
784 _scratch_cleanup_files()
788 # Avoid rm -rf /* if we messed up
789 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
790 _overlay_base_scratch_mount || return 1
791 rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
792 _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
793 # leave base fs mouted so tests can setup lower/upper dir files
796 [ -n "$SCRATCH_MNT" ] || return 1
798 rm -rf $SCRATCH_MNT/*
811 nfs*|cifs|ceph|overlay|glusterfs|pvfs2)
812 # unable to re-create this fstyp, just remove all files in
813 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
814 # created in previous runs
815 _scratch_cleanup_files
819 # do nothing for tmpfs
823 # erase the UBI volume; reformated automatically on next mount
824 $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
828 _scratch_mkfs_ext4 $*
836 mkfs_cmd="$MKFS_UDF_PROG"
840 mkfs_cmd="$MKFS_BTRFS_PROG"
844 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
845 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
847 # put journal on separate device?
848 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
849 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
850 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
853 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
854 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
857 mkfs_cmd="$MKFS_F2FS_PROG"
861 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
862 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
865 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
870 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
874 # Helper function to get a spare or replace-target device from
875 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
876 # before _spare_dev_get(). Replace-target-device/Spare-device will
877 # be assigned to SPARE_DEV.
878 # As of now only one replace-target-device/spare-device can be
882 # _scratch_dev_pool_get() <ndevs>
886 # _scratch_dev_pool_put()
890 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
891 if [ $? -ne 0 ]; then
892 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
895 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
896 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
899 # Check if the spare is already assigned
900 typeset -p SPARE_DEV >/dev/null 2>&1
901 if [ $? -eq 0 ]; then
902 if [ ! -z "$SPARE_DEV" ]; then
903 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
907 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
908 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
910 if [ $ndevs -eq $config_ndevs ]; then
911 _notrun "All devs used no spare"
913 # Get a dev that is not used
914 local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
915 SPARE_DEV=${devs[@]:$ndevs:1}
921 typeset -p SPARE_DEV >/dev/null 2>&1
922 if [ $? -ne 0 ]; then
923 _fail "Bug: unset val, must call _spare_dev_get before its put"
926 if [ -z "$SPARE_DEV" ]; then
927 _fail "Bug: str empty, must call _spare_dev_get before its put"
934 # Generally test cases will have..
935 # _require_scratch_dev_pool X
936 # to make sure it has the enough scratch devices including
937 # replace-target and spare device. Now arg1 here is the
938 # required number of scratch devices by a-test-case excluding
939 # the replace-target and spare device. So this function will
940 # set SCRATCH_DEV_POOL to the specified number of devices.
943 # _scratch_dev_pool_get() <ndevs>
946 # _scratch_dev_pool_put()
948 _scratch_dev_pool_get()
950 if [ $# -ne 1 ]; then
951 _fail "Usage: _scratch_dev_pool_get ndevs"
955 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
956 local -a devs="( $SCRATCH_DEV_POOL )"
958 typeset -p config_ndevs >/dev/null 2>&1
959 if [ $? -ne 0 ]; then
960 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
963 if [ $config_ndevs -lt $test_ndevs ]; then
964 _notrun "Need at least test requested number of ndevs $test_ndevs"
967 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
968 export SCRATCH_DEV_POOL_SAVED
969 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
970 export SCRATCH_DEV_POOL
973 _scratch_dev_pool_put()
975 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
976 if [ $? -ne 0 ]; then
977 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
980 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
981 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
984 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
985 export SCRATCH_DEV_POOL_SAVED=""
992 # if dup profile is in mkfs options call _scratch_mkfs instead
993 # because dup profile only works with single device
994 if [[ "$*" =~ dup ]]; then
997 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
1001 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
1006 # Return the amount of free memory available on the system
1007 _free_memory_bytes()
1009 free -b | grep ^Mem | awk '{print $4}'
1012 # Create fs of certain size on scratch device
1013 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
1014 _scratch_mkfs_sized()
1021 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
1023 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
1024 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
1031 [ -n "$def_blksz" ] && blocksize=$def_blksz
1032 [ -z "$blocksize" ] && blocksize=4096
1036 if ! [[ $fssize =~ $re ]] ; then
1037 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
1039 if ! [[ $blocksize =~ $re ]] ; then
1040 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1043 blocks=`expr $fssize / $blocksize`
1045 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
1046 devsize=`blockdev --getsize64 $SCRATCH_DEV`
1047 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
1052 # don't override MKFS_OPTIONS that set a block size.
1053 echo $MKFS_OPTIONS |egrep -q "b?size="
1054 if [ $? -eq 0 ]; then
1055 _scratch_mkfs_xfs -d size=$fssize
1057 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
1060 ext2|ext3|ext4|ext4dev)
1061 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1064 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1067 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1071 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1072 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1075 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
1078 # mkfs.resier4 requires size in KB as input for creating filesystem
1079 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1080 `expr $fssize / 1024`
1083 # mkfs.f2fs requires # of sectors as an input for the size
1084 sector_size=`blockdev --getss $SCRATCH_DEV`
1085 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1088 free_mem=`_free_memory_bytes`
1089 if [ "$free_mem" -lt "$fssize" ] ; then
1090 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1092 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1095 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1100 # Emulate an N-data-disk stripe w/ various stripe units
1101 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1102 _scratch_mkfs_geom()
1107 [ -z "$blocksize" ] && blocksize=4096
1109 let sunit_blocks=$sunit_bytes/$blocksize
1110 let swidth_blocks=$sunit_blocks*$swidth_mult
1114 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1117 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1120 _notrun "can't mkfs $FSTYP with geometry"
1126 # Create fs of certain blocksize on scratch device
1127 # _scratch_mkfs_blocksized blocksize
1128 _scratch_mkfs_blocksized()
1133 if ! [[ $blocksize =~ $re ]] ; then
1134 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1139 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1142 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1145 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1148 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1157 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1165 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1166 # errors found or errors were fixed) and nonzero otherwise; also spits out
1167 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1168 _repair_scratch_fs()
1172 _scratch_xfs_repair "$@" 2>&1
1174 if [ "$res" -ne 0 ]; then
1175 echo "xfs_repair returns $res; replay log?"
1178 if [ "$res" -gt 0 ]; then
1179 echo "mount returns $res; zap log?"
1180 _scratch_xfs_repair -L 2>&1
1181 echo "log zap returns $?"
1183 umount "$SCRATCH_MNT"
1185 _scratch_xfs_repair "$@" 2>&1
1188 if [ $res -ne 0 ]; then
1189 _dump_err2 "xfs_repair failed, err=$res"
1194 # Let's hope fsck -y suffices...
1195 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1202 _dump_err2 "fsck.$FSTYP failed, err=$res"
1214 echo "Usage: _get_pids_by_name process-name" 1>&2
1218 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1219 # HH:MM:SS before the psargs field, use this as the search anchor.
1221 # Matches with $1 (process-name) occur if the first psarg is $1
1222 # or ends in /$1 ... the matching uses sed's regular expressions,
1223 # so passing a regex into $1 will work.
1228 -e 's/[ ][ ]*/ /g' \
1231 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1232 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1235 # fix malloc libs output
1239 # filter out the Electric Fence notice
1242 if (defined $o && /^\s+Electric Fence/) {
1248 print $o if (defined $o);
1252 print $o if (defined $o);
1257 # _df_device : get an IRIX style df line for a given device
1259 # - returns "" if not mounted
1260 # - returns fs type in field two (ala IRIX)
1261 # - joins line together if split by fancy df formatting
1262 # - strips header etc
1269 echo "Usage: _df_device device" 1>&2
1273 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1274 # IPv6 server as a regular expression.
1275 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1276 ($1==what) && (NF==1) {
1290 # _df_dir : get an IRIX style df line for device where a directory resides
1292 # - returns fs type in field two (ala IRIX)
1293 # - joins line together if split by fancy df formatting
1294 # - strips header etc
1301 echo "Usage: _df_dir device" 1>&2
1305 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1321 # return percentage used disk space for mounted device
1327 echo "Usage: _used device" 1>&2
1331 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1334 # return the FS type of a mounted device
1340 echo "Usage: _fs_type device" 1>&2
1345 # The Linux kernel shows NFSv4 filesystems in df output as
1346 # filesystem type nfs4, although we mounted it as nfs earlier.
1347 # Fix the filesystem type up here so that the callers don't
1348 # have to bother with this quirk.
1350 _df_device $1 | $AWK_PROG '{ print $2 }' | \
1351 sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
1354 # return the FS mount options of a mounted device
1356 # should write a version which just parses the output of mount for IRIX
1357 # compatibility, but since this isn't used at all, at the moment I'll leave
1364 echo "Usage: _fs_options device" 1>&2
1368 $AWK_PROG -v dev=$1 '
1369 match($1,dev) { print $4 }
1373 # returns device number if a file is a block device
1379 echo "Usage: _is_block_dev dev" 1>&2
1384 if [ -L "${_dev}" ]; then
1385 _dev=`readlink -f "${_dev}"`
1388 if [ -b "${_dev}" ]; then
1389 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1393 # returns device number if a file is a character device
1397 if [ $# -ne 1 ]; then
1398 echo "Usage: _is_char_dev dev" 1>&2
1403 if [ -L "${_dev}" ]; then
1404 _dev=`readlink -f "${_dev}"`
1407 if [ -c "${_dev}" ]; then
1408 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1412 # Do a command, log it to $seqres.full, optionally test return status
1413 # and die if command fails. If called with one argument _do executes the
1414 # command, logs it, and returns its exit status. With two arguments _do
1415 # first prints the message passed in the first argument, and then "done"
1416 # or "fail" depending on the return status of the command passed in the
1417 # second argument. If the command fails and the variable _do_die_on_error
1418 # is set to "always" or the two argument form is used and _do_die_on_error
1419 # is set to "message_only" _do will print an error message to
1420 # $seqres.out and exit.
1424 if [ $# -eq 1 ]; then
1426 elif [ $# -eq 2 ]; then
1429 echo -n "$_note... "
1431 echo "Usage: _do [note] cmd" 1>&2
1435 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1436 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1437 cat $tmp._out | _fix_malloc >>$seqres.full
1438 if [ $# -eq 2 ]; then
1439 if [ $ret -eq 0 ]; then
1446 && [ "$_do_die_on_error" = "always" \
1447 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1449 [ $# -ne 2 ] && echo
1450 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1457 # bail out, setting up .notrun file. Need to kill the filesystem check files
1458 # here, otherwise they are set incorrectly for the next test.
1462 echo "$*" > $seqres.notrun
1463 echo "$seq not run: $*"
1464 rm -f ${RESULT_DIR}/require_test*
1465 rm -f ${RESULT_DIR}/require_scratch*
1471 # just plain bail out
1475 echo "$*" | tee -a $seqres.full
1476 echo "(see $seqres.full for details)"
1481 # tests whether $FSTYP is one of the supported filesystems for a test
1487 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1493 _notrun "not suitable for this filesystem type: $FSTYP"
1497 # tests whether $FSTYP is one of the supported OSes for a test
1503 if [ "$h" = "$HOSTOS" ]
1509 _notrun "not suitable for this OS: $HOSTOS"
1512 # check if a FS on a device is mounted
1513 # if so, verify that it is mounted on mount point
1514 # if fstype is given as argument, verify that it is also
1515 # mounted with correct fs type
1525 # find $dev as the source, and print result in "$dev $mnt" format
1526 local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
1527 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1529 # if it's mounted, make sure its on $mnt
1530 if [ "$mount_rec" != "$dev $mnt" ]; then
1531 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1532 echo "Already mounted result:"
1534 return 2 # 2 = mounted on wrong mnt
1537 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
1538 echo "$devname=$dev is mounted but not a type $type filesystem"
1539 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1541 return 3 # 3 = mounted as wrong type
1543 return 0 # 0 = mounted as expected
1546 # this test needs a scratch partition - check we're ok & unmount it
1547 # No post-test check of the device is required. e.g. the test intentionally
1548 # finishes the test with the filesystem in a corrupt state
1549 _require_scratch_nocheck()
1553 echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
1554 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1555 _notrun "this test requires a valid \$SCRATCH_DEV"
1557 if [ ! -d "$SCRATCH_MNT" ]; then
1558 _notrun "this test requires a valid \$SCRATCH_MNT"
1562 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1563 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1564 _notrun "this test requires a valid \$SCRATCH_DEV"
1566 if [ ! -d "$SCRATCH_MNT" ]; then
1567 _notrun "this test requires a valid \$SCRATCH_MNT"
1571 echo $SCRATCH_DEV | grep -q "://" > /dev/null 2>&1
1572 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1573 _notrun "this test requires a valid \$SCRATCH_DEV"
1575 if [ ! -d "$SCRATCH_MNT" ]; then
1576 _notrun "this test requires a valid \$SCRATCH_MNT"
1580 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1581 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1582 _notrun "this test requires a valid \$SCRATCH_DEV"
1584 if [ ! -d "$SCRATCH_MNT" ]; then
1585 _notrun "this test requires a valid \$SCRATCH_MNT"
1589 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1590 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1592 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1593 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1594 # and we will create the mount point anyway on _overlay_mount
1595 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1596 _notrun "this test requires a valid \$SCRATCH_MNT"
1600 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1602 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1606 # ubifs needs an UBI volume. This will be a char device, not a block device.
1607 if [ ! -c "$SCRATCH_DEV" ]; then
1608 _notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
1610 if [ ! -d "$SCRATCH_MNT" ]; then
1611 _notrun "this test requires a valid \$SCRATCH_MNT"
1615 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1617 _notrun "this test requires a valid \$SCRATCH_DEV"
1619 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1621 _notrun "this test requires a valid \$SCRATCH_DEV"
1623 if [ ! -d "$SCRATCH_MNT" ]
1625 _notrun "this test requires a valid \$SCRATCH_MNT"
1630 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1632 [ $err -le 1 ] || exit 1
1635 # if it's mounted, unmount it
1636 if ! _scratch_unmount
1638 echo "failed to unmount $SCRATCH_DEV"
1642 rm -f ${RESULT_DIR}/require_scratch
1645 # we need the scratch device and it should be checked post test.
1648 _require_scratch_nocheck
1649 touch ${RESULT_DIR}/require_scratch
1653 # this test needs a test partition - check we're ok & mount it
1659 echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
1660 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1661 _notrun "this test requires a valid \$TEST_DEV"
1663 if [ ! -d "$TEST_DIR" ]; then
1664 _notrun "this test requires a valid \$TEST_DIR"
1668 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1669 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1670 _notrun "this test requires a valid \$TEST_DEV"
1672 if [ ! -d "$TEST_DIR" ]; then
1673 _notrun "this test requires a valid \$TEST_DIR"
1677 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1678 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1679 _notrun "this test requires a valid \$TEST_DEV"
1681 if [ ! -d "$TEST_DIR" ]; then
1682 _notrun "this test requires a valid \$TEST_DIR"
1686 echo $TEST_DEV | grep -q "://" > /dev/null 2>&1
1687 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1688 _notrun "this test requires a valid \$TEST_DIR"
1690 if [ ! -d "$TEST_DIR" ]; then
1691 _notrun "this test requires a valid \$TEST_DIR"
1695 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1696 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1698 if [ ! -d "$TEST_DIR" ]; then
1699 _notrun "this test requires a valid \$TEST_DIR"
1703 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1705 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1709 # ubifs needs an UBI volume. This will be a char device, not a block device.
1710 if [ ! -c "$TEST_DEV" ]; then
1711 _notrun "this test requires a valid UBI volume for \$TEST_DEV"
1713 if [ ! -d "$TEST_DIR" ]; then
1714 _notrun "this test requires a valid \$TEST_DIR"
1718 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1720 _notrun "this test requires a valid \$TEST_DEV"
1722 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1724 _notrun "this test requires a valid \$TEST_DEV"
1726 if [ ! -d "$TEST_DIR" ]
1728 _notrun "this test requires a valid \$TEST_DIR"
1733 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1735 [ $err -le 1 ] || exit 1
1740 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1744 touch ${RESULT_DIR}/require_test
1750 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
1751 [ "$USE_EXTERNAL" != yes ] && ret=1
1756 # this test needs a logdev
1760 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1761 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1762 [ "$USE_EXTERNAL" != yes ] && \
1763 _notrun "This test requires USE_EXTERNAL to be enabled"
1765 # ensure its not mounted
1766 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1769 # this test requires loopback device support
1773 if [ "$HOSTOS" != "Linux" ]
1775 _notrun "This test requires linux for loopback device support"
1778 modprobe loop >/dev/null 2>&1
1779 if grep loop /proc/devices >/dev/null 2>&1
1783 _notrun "This test requires loopback device support"
1787 # this test requires ext2 filesystem support
1791 if [ "$HOSTOS" != "Linux" ]
1793 _notrun "This test requires linux for ext2 filesystem support"
1796 modprobe ext2 >/dev/null 2>&1
1797 if grep ext2 /proc/filesystems >/dev/null 2>&1
1801 _notrun "This test requires ext2 filesystem support"
1805 # this test requires tmpfs filesystem support
1809 modprobe tmpfs >/dev/null 2>&1
1810 grep -q tmpfs /proc/filesystems ||
1811 _notrun "this test requires tmpfs support"
1814 # this test requires that (large) loopback device files are not in use
1816 _require_no_large_scratch_dev()
1818 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1819 _notrun "Large filesystem testing in progress, skipped this test"
1822 # this test requires that a realtime subvolume is in use, and
1823 # that the kernel supports realtime as well.
1827 [ "$USE_EXTERNAL" = yes ] || \
1828 _notrun "External volumes not in use, skipped this test"
1829 [ "$SCRATCH_RTDEV" = "" ] && \
1830 _notrun "Realtime device required, skipped this test"
1833 # this test requires that a specified command (executable) exists
1834 # $1 - command, $2 - name for error message
1836 # Note: the command string might have parameters, so strip them before checking
1837 # whether it is executable.
1840 if [ $# -eq 2 ]; then
1842 elif [ $# -eq 1 ]; then
1845 _fail "usage: _require_command <command> [<name>]"
1848 _command=`echo "$1" | awk '{ print $1 }'`
1849 if [ ! -x "$_command" ]; then
1850 _notrun "$_name utility required, skipped this test"
1854 # this test requires the device to be valid block device
1856 _require_block_device()
1858 if [ -z "$1" ]; then
1859 echo "Usage: _require_block_device <dev>" 1>&2
1862 if [ "`_is_block_dev "$1"`" == "" ]; then
1863 _notrun "require $1 to be valid block disk"
1867 # this test requires a path to refere to a local block or character device
1869 _require_local_device()
1871 if [ -z "$1" ]; then
1872 echo "Usage: _require_local_device <dev>" 1>&2
1875 if [ "`_is_block_dev "$1"`" != "" ]; then
1878 if [ "`_is_char_dev "$1"`" != "" ]; then
1881 _notrun "require $1 to be local device"
1884 # brd based ram disks erase the device when they receive a flush command when no
1885 # active references are present. This causes problems for DM devices sitting on
1886 # top of brd devices as DM doesn't hold active references to the brd device.
1887 _require_sane_bdev_flush()
1889 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1890 if [ $? -eq 0 ]; then
1891 _notrun "This test requires a sane block device flush"
1895 # this test requires a specific device mapper target
1896 _require_dm_target()
1900 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1902 _require_block_device $SCRATCH_DEV
1903 _require_sane_bdev_flush $SCRATCH_DEV
1904 _require_command "$DMSETUP_PROG" dmsetup
1906 modprobe dm-$_target >/dev/null 2>&1
1908 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1909 if [ $? -ne 0 ]; then
1910 _notrun "This test requires dm $_target support"
1914 # this test requires the ext4 kernel support crc feature on scratch device
1916 _require_scratch_ext4_crc()
1918 _scratch_mkfs_ext4 >/dev/null 2>&1
1919 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1920 _scratch_mount >/dev/null 2>&1 \
1921 || _notrun "Kernel doesn't support metadata_csum feature"
1925 # Check the specified feature whether it is available in mkfs.ext4 or not.
1926 _require_ext4_mkfs_feature()
1929 local testfile=/tmp/$$.ext4_mkfs
1931 if [ -z "$feature" ]; then
1932 echo "Usage: _require_ext4_mkfs_feature feature"
1937 local result=$($MKFS_EXT4_PROG -F -O $feature -n $testfile 512m 2>&1)
1939 echo $result | grep -q "Invalid filesystem option" && \
1940 _notrun "mkfs.ext4 doesn't support $feature feature"
1943 # this test requires the ext4 kernel support bigalloc feature
1945 _require_ext4_bigalloc()
1947 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1948 _scratch_mount >/dev/null 2>&1 \
1949 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1953 # this test requires that external log/realtime devices are not in use
1955 _require_nonexternal()
1957 [ "$USE_EXTERNAL" = yes ] && \
1958 _notrun "External device testing in progress, skipped this test"
1961 # this test requires that the kernel supports asynchronous I/O
1964 $here/src/feature -A
1969 _notrun "kernel does not support asynchronous I/O"
1972 _fail "unexpected error testing for asynchronous I/O support"
1977 # this test requires that a (specified) aio-dio executable exists
1978 # and that the kernel supports asynchronous I/O.
1979 # $1 - command (optional)
1985 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1986 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1988 AIO_TEST=src/aio-dio-regress/$1
1989 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1995 # this test requires that a test program exists under src/
1996 # $1 - command (require)
1998 _require_test_program()
2001 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
2004 # run an aio-dio program
2010 echo "usage: _run_aiodio command_name" 2>&1
2016 local testtemp=$TEST_DIR/aio-testfile
2018 $AIO_TEST $testtemp 2>&1
2025 # this test requires y2038 sysfs switch and filesystem
2026 # timestamp ranges support.
2029 local device=${1:-$TEST_DEV}
2030 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
2032 if [ ! -e $sysfsdir ]; then
2033 _notrun "no kernel support for y2038 sysfs switch"
2037 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
2038 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
2039 _notrun "filesystem $FSTYP timestamp bounds are unknown"
2043 _filesystem_timestamp_range()
2045 device=${1:-$TEST_DEV}
2048 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
2049 echo "-2147483648 15032385535"
2051 echo "-2147483648 2147483647"
2056 echo "-2147483648 2147483647"
2062 echo "-2147483648 2147483647"
2070 # indicate whether YP/NIS is active or not
2075 dn=$(domainname 2>/dev/null)
2076 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
2080 # cat the password file
2084 [ $(_yp_active) -eq 0 ] && ypcat passwd
2088 # cat the group file
2092 [ $(_yp_active) -eq 0 ] && ypcat group
2096 # check for a user on the machine, fsgqa as default
2104 _cat_passwd | grep -q $qa_user
2105 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
2106 echo /bin/true | su $qa_user
2107 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
2110 # check for a group on the machine, fsgqa as default
2118 _cat_group | grep -q $qa_group
2119 [ "$?" == "0" ] || _notrun "$qa_group group not defined."
2125 s,.*Permission\sdenied.*,Permission denied,;
2126 s,.*no\saccess\sto\stty.*,,;
2127 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2134 if [ "$HOSTOS" == "IRIX" ]
2136 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
2138 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
2142 _require_xfs_io_command()
2146 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2152 local param_checked=0
2154 testfile=$TEST_DIR/$$.xfs_io
2157 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
2160 testcopy=$TEST_DIR/$$.copy.xfs_io
2161 $XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
2162 testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
2163 rm -f $testcopy > /dev/null 2>&1
2166 testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
2169 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
2170 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2171 -c "$command 4k 8k" $testfile 2>&1`
2174 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2175 -c "fiemap -v $param" $testfile 2>&1`
2179 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2181 echo $testio | egrep -q "invalid option|Is a directory" && \
2182 _notrun "xfs_io $command support is missing"
2185 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
2186 echo $testio | egrep -q "Inappropriate ioctl" && \
2187 _notrun "xfs_io $command support is missing"
2190 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
2191 # a new -C flag was introduced to execute one shot commands.
2192 # Check for -C flag support as an indication for the bug fix.
2193 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
2194 echo $testio | egrep -q "invalid option" && \
2195 _notrun "xfs_io $command support is missing"
2198 testio=`$XFS_IO_PROG -x -c "$command dummy 0" $TEST_DIR 2>&1`
2199 echo $testio | egrep -q "Inappropriate ioctl" && \
2200 _notrun "xfs_io $command support is missing"
2203 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
2206 testio=`$XFS_IO_PROG -c "help $command" 2>&1`
2209 rm -f $testfile 2>&1 > /dev/null
2210 echo $testio | grep -q "not found" && \
2211 _notrun "xfs_io $command support is missing"
2212 echo $testio | grep -q "Operation not supported" && \
2213 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2214 echo $testio | grep -q "Invalid" && \
2215 _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
2216 echo $testio | grep -q "foreign file active" && \
2217 _notrun "xfs_io $command not supported on $FSTYP"
2218 echo $testio | egrep -q "Function not implemented" && \
2219 _notrun "xfs_io $command support is missing (missing syscall?)"
2221 if [ -n "$param" -a $param_checked -eq 0 ]; then
2222 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2223 _notrun "xfs_io $command doesn't support $param"
2227 # check that kernel and filesystem support direct I/O
2230 if [ $FSTYP = "ext4" ] ; then
2231 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2232 _notrun "ext4 encryption doesn't support O_DIRECT"
2235 testfile=$TEST_DIR/$$.direct
2236 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2237 if [ $? -ne 0 ]; then
2238 _notrun "O_DIRECT is not supported"
2240 rm -f $testfile 2>&1 > /dev/null
2243 # Check that the filesystem supports swapfiles
2244 _require_scratch_swapfile()
2248 _scratch_mkfs >/dev/null
2251 # Minimum size for mkswap is 10 pages
2252 local size=$(($(get_page_size) * 10))
2254 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
2255 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
2256 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
2258 _notrun "swapfiles are not supported"
2261 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
2265 # Check that a fs has enough free space (in 1024b blocks)
2270 BLOCKS=$2 # in units of 1024
2271 let GB=$BLOCKS/1024/1024
2273 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2274 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2275 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2279 # Check if the filesystem supports sparse files.
2281 # Unfortunately there is no better way to do this than a manual black list.
2283 _require_sparse_files()
2287 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2296 #boot_params always present in debugfs
2297 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2300 _require_fail_make_request()
2302 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2303 || _notrun "$DEBUGFS_MNT/fail_make_request \
2304 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2308 # Check if the file system supports seek_data/hole
2310 _require_seek_data_hole()
2312 testfile=$TEST_DIR/$$.seek
2313 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2314 rm -f $testfile &>/dev/null
2315 echo $testseek | grep -q "Kernel does not support" && \
2316 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2321 _require_test_program "runas"
2326 "$here/src/runas" "$@"
2329 _require_richacl_prog()
2331 _require_command "$GETRICHACL_PROG" getrichacl
2332 _require_command "$SETRICHACL_PROG" setrichacl
2335 _require_scratch_richacl_xfs()
2337 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2338 || _notrun "mkfs.xfs doesn't have richacl feature"
2339 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2340 _scratch_mount >/dev/null 2>&1 \
2341 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2345 _require_scratch_richacl_ext4()
2347 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2348 || _notrun "can't mkfs $FSTYP with option -O richacl"
2349 _scratch_mount >/dev/null 2>&1 \
2350 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2354 _require_scratch_richacl_support()
2357 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2358 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2362 _require_scratch_richacl()
2365 xfs) _require_scratch_richacl_xfs
2367 ext4) _require_scratch_richacl_ext4
2370 _require_scratch_richacl_support
2372 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2377 _scratch_mkfs_richacl()
2380 xfs) _scratch_mkfs_xfs -m richacl=1
2382 ext4) _scratch_mkfs -O richacl
2390 # check that a FS on a device is mounted
2391 # if so, return mount point
2397 echo "Usage: _is_mounted device" 1>&2
2403 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2404 pattern { print $3 ; exit 0 }
2408 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2413 # remount a FS to a new mode (ro or rw)
2419 echo "Usage: _remount device ro/rw" 1>&2
2425 if ! mount -o remount,$mode $device
2427 echo "_remount: failed to remount filesystem on $device as $mode"
2432 # Run the appropriate repair/check on a filesystem
2434 # if the filesystem is mounted, it's either remounted ro before being
2435 # checked or it's unmounted and then remounted
2438 # If set, we remount ro instead of unmounting for fsck
2441 _umount_or_remount_ro()
2445 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2450 mountpoint=`_is_mounted $device`
2452 if [ $USE_REMOUNT -eq 0 ]; then
2453 $UMOUNT_PROG $device
2460 _mount_or_remount_rw()
2462 if [ $# -ne 3 ]; then
2463 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2470 if [ $USE_REMOUNT -eq 0 ]; then
2471 if [ "$FSTYP" != "overlay" ]; then
2472 _mount -t $FSTYP $mount_opts $device $mountpoint
2474 _overlay_mount $device $mountpoint
2476 if [ $? -ne 0 ]; then
2477 _dump_err "!!! failed to remount $device on $mountpoint"
2487 # Check a generic filesystem in no-op mode; this assumes that the
2488 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2489 # and that it will still return an errno for corruption in this mode.
2491 # Filesystems which don't support this will need to define their
2492 # own check routine.
2494 _check_generic_filesystem()
2498 # If type is set, we're mounted
2499 type=`_fs_type $device`
2502 if [ "$type" = "$FSTYP" ]
2505 mountpoint=`_umount_or_remount_ro $device`
2508 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2511 _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
2512 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2513 cat $tmp.fsck >>$seqres.full
2514 echo "*** end fsck.$FSTYP output" >>$seqres.full
2522 echo "*** mount output ***" >>$seqres.full
2523 _mount >>$seqres.full
2524 echo "*** end mount output" >>$seqres.full
2525 elif [ "$type" = "$FSTYP" ]
2528 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2532 if [ $ok -eq 0 ]; then
2534 if [ "$iam" != "check" ]; then
2543 # Filter the knowen errors the UDF Verifier reports.
2544 _udf_test_known_error_filter()
2546 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."
2550 _check_udf_filesystem()
2552 [ "$DISABLE_UDF_TEST" == "1" ] && return
2554 if [ $# -ne 1 -a $# -ne 2 ]
2556 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2560 if [ ! -x $here/src/udf_test ]
2562 echo "udf_test not installed, please download and build the Philips"
2563 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2564 echo "Then copy the udf_test binary to $here/src/."
2565 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2573 LAST_BLOCK=`expr \( $2 - 1 \)`
2574 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2577 rm -f $seqres.checkfs
2578 sleep 1 # Due to a problem with time stamps in udf_test
2579 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2580 _udf_test_known_error_filter | \
2581 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2582 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2593 # no way to check consistency for nfs
2596 # no way to check consistency for cifs
2599 # no way to check consistency for CephFS
2602 # no way to check consistency for GlusterFS
2605 # no way to check consistency for overlay
2610 # do nothing for now
2613 _check_btrfs_filesystem $TEST_DEV
2616 # no way to check consistency for tmpfs
2619 # there is no fsck program for ubifs yet
2622 _check_generic_filesystem $TEST_DEV
2630 [ $# -eq 1 ] && device=$1
2636 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2637 SCRATCH_LOG="$SCRATCH_LOGDEV"
2639 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2640 SCRATCH_RT="$SCRATCH_RTDEV"
2642 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2645 _check_udf_filesystem $device $udf_fsize
2648 # Don't know how to check an NFS filesystem, yet.
2651 # Don't know how to check a CIFS filesystem, yet.
2654 # no way to check consistency for CephFS
2657 # no way to check consistency for GlusterFS
2660 # no way to check consistency for overlay
2665 _check_btrfs_filesystem $device
2668 # no way to check consistency for tmpfs
2671 # there is no fsck program for ubifs yet
2674 _check_generic_filesystem $device
2679 _full_fstyp_details()
2681 [ -z "$FSTYP" ] && FSTYP=xfs
2682 if [ $FSTYP = xfs ]; then
2683 if [ -d /proc/fs/xfs ]; then
2684 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2685 FSTYP="$FSTYP (non-debug)"
2686 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2687 FSTYP="$FSTYP (debug)"
2690 if uname -a | grep -qi 'debug'; then
2691 FSTYP="$FSTYP (debug)"
2693 FSTYP="$FSTYP (non-debug)"
2700 _full_platform_details()
2706 echo "$os/$platform $host $kernel"
2711 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2713 elif [ "`uname`" == "Linux" ]; then
2716 echo Unknown operating system: `uname`
2721 _link_out_file_named()
2726 my $feature, $result, $suffix, $opts;
2728 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2729 $feathash{$feature} = 1;
2731 $result = "default";
2736 ($opts, $suffix) = split(/ *: */);
2737 foreach my $opt (split(/,/, $opts)) {
2738 if (!exists($feathash{$opt})) {
2752 ln -fs $SRC.$SUFFIX $1
2757 if [ $# -eq 0 ]; then
2758 FEATURES="$(_get_os_name)"
2759 if [ -n "$MOUNT_OPTIONS" ]; then
2760 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2766 _link_out_file_named $seqfull.out "$FEATURES"
2775 # convert urandom incompressible data to compressible text data
2778 od /dev/urandom | dd iflag=fullblock ${*}
2781 #takes files, randomdata
2789 if [ $size -gt 0 ]; then
2790 if [ "$2" == "false" ]; then
2791 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2792 elif [ "$2" == "comp" ]; then
2793 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2795 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2802 # takes dirname, depth, randomdata
2805 dirname=$1; depth=$2; randomdata=$3
2806 mkdir $dirname || die "mkdir $dirname failed"
2809 _nfiles $files $randomdata # files for this dir and data type
2811 [ $depth -eq 0 ] && return
2812 let deep=$depth-1 # go 1 down
2814 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2817 while [ $d -lt $dirs ]
2819 _descend d$d $deep &
2825 # Populate a filesystem with inodes for performance experiments
2827 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2832 dirs=5 # ndirs in each subdir till leaves
2833 size=0 # sizeof files in K
2834 files=100 # num files in _each_ subdir
2835 depth=2 # depth of tree from root to leaves
2837 root=root # path of initial root of directory tree
2838 randomdata=false # -x data type urandom, zero or compressible
2841 while getopts "d:f:n:r:s:v:x:c" c
2850 x) randomdata=true;;
2851 c) randomdata=comp;;
2855 _descend $root $depth $randomdata
2860 [ $verbose = true ] && echo done
2863 # query whether the given file has the given inode flag set
2870 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2876 # query the given files extsize allocator hint in bytes (if any)
2883 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2884 awk '/^xattr.extsize =/ { print $3 }'`
2885 [ -z "$blocks" ] && blocks="0"
2889 # scratch_dev_pool should contain the disks pool for the btrfs raid
2890 _require_scratch_dev_pool()
2895 if [ -z "$SCRATCH_DEV_POOL" ]; then
2896 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2899 if [ -z "$1" ]; then
2905 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2909 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2910 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2914 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2918 for i in $SCRATCH_DEV_POOL; do
2919 if [ "`_is_block_dev "$i"`" = "" ]; then
2920 _notrun "this test requires valid block disk $i"
2922 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2923 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2925 if _mount | grep -q $i; then
2926 if ! $UMOUNT_PROG $i; then
2927 echo "failed to unmount $i - aborting"
2931 # to help better debug when something fails, we remove
2932 # traces of previous btrfs FS on the dev.
2933 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2937 # ensure devices in SCRATCH_DEV_POOL are of the same size
2938 # must be called after _require_scratch_dev_pool
2939 _require_scratch_dev_pool_equal_size()
2945 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2946 _size=`_get_device_size $SCRATCH_DEV`
2947 for _dev in $SCRATCH_DEV_POOL; do
2948 _newsize=`_get_device_size $_dev`
2949 if [ $_size -ne $_newsize ]; then
2950 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2955 # We will check if the device is deletable
2956 _require_deletable_scratch_dev_pool()
2960 for i in $SCRATCH_DEV_POOL; do
2961 x=`echo $i | cut -d"/" -f 3`
2962 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2963 _notrun "$i is a device which is not deletable"
2968 # Check that fio is present, and it is able to execute given jobfile
2973 _require_command "$FIO_PROG" fio
2974 if [ -z "$1" ]; then
2978 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2979 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2982 # Does freeze work on this fs?
2985 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2987 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2988 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2991 # Does NFS export work on this fs?
2994 _require_test_program "open_by_handle"
2995 mkdir -p "$TEST_DIR"/exportfs_test
2996 $here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
2997 || _notrun "$FSTYP does not support NFS export"
3001 # Does shutdown work on this fs?
3002 _require_scratch_shutdown()
3004 [ -x src/godown ] || _notrun "src/godown executable not found"
3006 _scratch_mkfs > /dev/null 2>&1
3008 src/godown -f $SCRATCH_MNT 2>&1 \
3009 || _notrun "$FSTYP does not support shutdown"
3013 # Does dax mount option work on this dev/fs?
3014 _require_scratch_dax()
3017 _scratch_mkfs > /dev/null 2>&1
3018 _scratch_mount -o dax
3019 # Check options to be sure. XFS ignores dax option
3020 # and goes on if dev underneath does not support dax.
3021 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
3022 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
3026 # Does norecovery support by this fs?
3027 _require_norecovery()
3029 _scratch_mount -o ro,norecovery || \
3030 _notrun "$FSTYP does not support norecovery"
3034 # Does this filesystem support metadata journaling?
3035 # We exclude ones here that don't; otherwise we assume that it does, so the
3036 # test will run, fail, and motivate someone to update this test for a new
3039 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
3040 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
3042 _require_metadata_journaling()
3051 ext2|vfat|msdos|udf)
3052 _notrun "$FSTYP does not support metadata journaling"
3055 # ext4 could be mkfs'd without a journal...
3057 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3058 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3059 # ext4 might not load a journal
3060 _exclude_scratch_mount_option "noload"
3063 # by default we pass; if you need to, add your fs above!
3070 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3075 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3078 _count_attr_extents()
3080 $XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
3083 # arg 1 is dev to remove and is output of the below eg.
3084 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3090 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3092 stat $disk > /dev/null 2>&1
3093 while [ $? -eq 0 ]; do
3095 stat $disk > /dev/null 2>&1
3099 # arg 1 is dev to add and is output of the below eg.
3100 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3105 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3106 h=`echo ${1} | cut -d":" -f 1`
3107 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3109 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3111 # ensure the device comes online
3113 for i in `seq 1 10`; do
3114 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3115 dev=`ls /sys/class/scsi_device/${1}/device/block`
3116 for j in `seq 1 10`;
3118 stat /dev/$dev > /dev/null 2>&1
3119 if [ $? -eq 0 ]; then
3130 if [ $dev_back_oneline -eq 0 ]; then
3131 echo "/dev/$dev online failed" >> $seqres.full
3133 echo "/dev/$dev is back online" >> $seqres.full
3139 if [ -z "$FSTRIM_PROG" ]; then
3140 _notrun "This test requires fstrim utility."
3144 _require_batched_discard()
3146 if [ $# -ne 1 ]; then
3147 echo "Usage: _require_batched_discard mnt_point" 1>&2
3151 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3156 if [ -z "$DUMPE2FS_PROG" ]; then
3157 _notrun "This test requires dumpe2fs utility."
3163 if [ ! -e /proc/self/uid_map ]; then
3164 _notrun "This test requires procfs uid_map support."
3166 if [ ! -e /proc/self/gid_map ]; then
3167 _notrun "This test requires procfs gid_map support."
3173 FSSUM_PROG=$here/src/fssum
3174 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3179 CLONER_PROG=$here/src/cloner
3180 [ -x $CLONER_PROG ] || \
3181 _notrun "cloner binary not present at $CLONER_PROG"
3184 # Normalize mount options from global $MOUNT_OPTIONS
3185 # Convert options like "-o opt1,opt2 -oopt3" to
3187 _normalize_mount_options()
3189 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
3192 # skip test if MOUNT_OPTIONS contains the given strings
3193 _exclude_scratch_mount_option()
3195 local mnt_opts=$(_normalize_mount_options)
3197 while [ $# -gt 0 ]; do
3198 if echo $mnt_opts | grep -qw "$1"; then
3199 _notrun "mount option \"$1\" not allowed in this test"
3207 _exclude_scratch_mount_option "noatime"
3208 if [ "$FSTYP" == "nfs" ]; then
3209 _notrun "atime related mount options have no effect on NFS"
3215 _scratch_mkfs > /dev/null 2>&1
3216 _scratch_mount -o relatime || \
3217 _notrun "relatime not supported by the current kernel"
3223 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3224 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3227 _create_loop_device()
3230 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3234 _destroy_loop_device()
3237 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3240 _scale_fsstress_args()
3243 while [ $# -gt 0 ]; do
3245 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3246 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3247 *) args="$args $1" ;;
3255 # Return the logical block size if running on a block device,
3256 # else substitute the page size.
3258 _min_dio_alignment()
3262 if [ -b "$dev" ]; then
3263 blockdev --getss $dev
3265 $here/src/feature -s
3271 echo "# $@" >> $seqres.full 2>&1
3272 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3275 _require_test_symlinks()
3277 # IRIX UDF does not support symlinks
3278 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3279 _notrun "Require symlinks support"
3280 target=`mktemp -p $TEST_DIR`
3281 link=`mktemp -p $TEST_DIR -u`
3282 ln -s `basename $target` $link
3283 if [ "$?" -ne 0 ]; then
3285 _notrun "Require symlinks support"
3290 _require_test_fcntl_advisory_locks()
3292 [ "$FSTYP" != "cifs" ] && return 0
3293 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3294 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3295 _notrun "Require fcntl advisory locks support"
3298 _require_test_lsattr()
3300 testio=$(lsattr -d $TEST_DIR 2>&1)
3301 echo $testio | grep -q "Operation not supported" && \
3302 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3303 echo $testio | grep -q "Inappropriate ioctl for device" && \
3304 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3309 if [ -z "$1" ]; then
3310 echo "Usage: _require_chattr <attr>"
3315 touch $TEST_DIR/syscalltest
3316 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3318 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3319 if [ "$status" -ne 0 ]; then
3320 _notrun "file system doesn't support chattr +$attribute"
3322 cat $TEST_DIR/syscalltest.out >> $seqres.full
3323 rm -f $TEST_DIR/syscalltest.out
3328 if [ -z "$1" ]; then
3329 echo "Usage: _get_total_inode <mnt>"
3333 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3339 if [ -z "$1" ]; then
3340 echo "Usage: _get_used_inode <mnt>"
3344 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3348 _get_used_inode_percent()
3350 if [ -z "$1" ]; then
3351 echo "Usage: _get_used_inode_percent <mnt>"
3355 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3362 if [ -z "$1" ]; then
3363 echo "Usage: _get_free_inode <mnt>"
3367 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3371 # get the available space in bytes
3373 _get_available_space()
3375 if [ -z "$1" ]; then
3376 echo "Usage: _get_available_space <mnt>"
3380 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3381 echo $((avail_kb * 1024))
3384 # return device size in kb
3387 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3390 # check dmesg log for WARNING/Oops/etc.
3393 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3396 rm -f ${RESULT_DIR}/check_dmesg
3398 # default filter is a simple cat command, caller could provide a
3399 # customized filter and pass the name through the first argument, to
3400 # filter out intentional WARNINGs or Oopses
3403 # search the dmesg log of last run of $seqnum for possible failures
3404 # use sed \cregexpc address type, since $seqnum contains "/"
3405 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3406 tac | $filter >$seqres.dmesg
3407 egrep -q -e "kernel BUG at" \
3411 -e "possible recursive locking detected" \
3412 -e "Internal error" \
3413 -e "(INFO|ERR): suspicious RCU usage" \
3414 -e "INFO: possible circular locking dependency detected" \
3415 -e "general protection fault:" \
3417 if [ $? -eq 0 ]; then
3418 _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3426 # don't check dmesg log after test
3427 _disable_dmesg_check()
3429 rm -f ${RESULT_DIR}/check_dmesg
3434 if [ "$iam" == new ]
3438 # make some further configuration checks here
3439 if [ "$TEST_DEV" = "" ]
3441 echo "common/rc: Error: \$TEST_DEV is not set"
3445 # if $TEST_DEV is not mounted, mount it now as XFS
3446 if [ -z "`_fs_type $TEST_DEV`" ]
3448 # $TEST_DEV is not mounted
3451 echo "common/rc: retrying test device mount with external set"
3452 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3455 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3461 # Sanity check that TEST partition is not mounted at another mount point
3462 # or as another fs type
3463 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3464 if [ -n "$SCRATCH_DEV" ]; then
3465 # Sanity check that SCRATCH partition is not mounted at another
3466 # mount point, because it is about to be unmounted and formatted.
3467 # Another fs type for scratch is fine (bye bye old fs type).
3468 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3469 [ $? -le 1 ] || exit 1
3472 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3473 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3474 export XFS_IO_PROG="$XFS_IO_PROG -F"
3476 # xfs_io -i option starts an idle thread for xfs_io.
3477 # With single threaded process, the file table is not shared
3478 # and file structs are not reference counted.
3479 # Spawning an idle thread can help detecting file struct
3480 # reference leaks, so we want to enable the option whenever
3482 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3483 export XFS_IO_PROG="$XFS_IO_PROG -i"
3485 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3486 # can change the UUID on v5 filesystems
3487 if [ "$FSTYP" == "xfs" ]; then
3489 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3490 # xfs_db will return 0 even if it can't generate a new uuid, so
3491 # check the output to make sure if it can change UUID of V5 xfs
3492 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3493 | grep -q "invalid UUID\|supported on V5 fs" \
3494 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3499 # get real device path name by following link
3503 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3504 _dev=`readlink -f "$_dev"`
3509 # basename of a device
3512 echo `basename $(_real_dev $1)`
3517 local _dev=`_real_dev $1`
3518 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3519 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3520 _maj=$(echo "ibase=16; $_maj" | bc)
3521 _min=$(echo "ibase=16; $_min" | bc)
3522 echo /sys/dev/block/$_maj:$_min
3525 # Get the minimum block size of a file. Usually this is the
3526 # minimum fs block size, but some filesystems (ocfs2) do block
3527 # mappings in larger units.
3528 _get_file_block_size()
3530 if [ -z $1 ] || [ ! -d $1 ]; then
3531 echo "Missing mount point argument for _get_file_block_size"
3534 if [ "$FSTYP" = "ocfs2" ]; then
3541 # Get the minimum block size of an fs.
3544 if [ -z $1 ] || [ ! -d $1 ]; then
3545 echo "Missing mount point argument for _get_block_size"
3553 echo $(getconf PAGE_SIZE)
3560 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3561 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3562 echo "$@" >>$seqres.full
3563 rm -f $TEST_DIR/junk
3564 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3565 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3571 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3573 # Only one argument is needed:
3574 # - attr: path name under /sys/fs/$FSTYP/DEV
3577 # _require_fs_sysfs error/fail_at_unmount
3581 local dname=$(_short_dev $TEST_DEV)
3583 if [ -z "$attr" -o -z "$dname" ];then
3584 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3587 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3588 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3594 $here/src/stat_test --check-statx ||
3595 _notrun "This test requires the statx system call"
3598 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3600 # All arguments are necessary, and in this order:
3601 # - dev: device name, e.g. $SCRATCH_DEV
3602 # - attr: path name under /sys/fs/$FSTYP/$dev
3603 # - content: the content of $attr
3606 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3607 _set_fs_sysfs_attr()
3615 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3616 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3619 local dname=$(_short_dev $dev)
3620 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3623 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3625 # All arguments are necessary, and in this order:
3626 # - dev: device name, e.g. $SCRATCH_DEV
3627 # - attr: path name under /sys/fs/$FSTYP/$dev
3630 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3631 _get_fs_sysfs_attr()
3636 if [ ! -b "$dev" -o -z "$attr" ];then
3637 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3640 local dname=$(_short_dev $dev)
3641 cat /sys/fs/${FSTYP}/${dname}/${attr}
3644 # Print the value of a filesystem module parameter
3645 # at /sys/module/$FSTYP/parameters/$PARAM
3647 # Usage example (FSTYP=overlay):
3648 # _get_fs_module_param index
3649 _get_fs_module_param()
3651 cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null
3654 # Generic test for specific filesystem feature.
3655 # Currently only implemented to test overlayfs features.
3656 _require_scratch_feature()
3662 # overalyfs features (e.g. redirect_dir, index) are
3663 # configurable from Kconfig (the build default), by module
3664 # parameter (the system default) and per mount by mount
3665 # option ${feature}=[on|off].
3667 # If the module parameter does not exist then there is no
3668 # point in checking the mount option.
3669 local default=`_get_fs_module_param ${feature}`
3670 [ "$default" = Y ] || [ "$default" = N ] || \
3671 _notrun "feature '${feature}' not supported by ${FSTYP}"
3673 _scratch_mkfs > /dev/null 2>&1
3674 _scratch_mount -o ${feature}=on || \
3675 _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
3676 # Check options to be sure. For example, Overlayfs will fallback to
3677 # index=off if underlying fs does not support file handles.
3678 # Overlayfs only displays mount option if it differs from the default.
3679 # Overlayfs may enable the feature, but fallback to read-only mount.
3680 ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \
3681 ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \
3682 touch $SCRATCH_MNT/foo 2>/dev/null ) || \
3683 _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
3687 _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
3695 ################################################################################
3696 # make sure this script returns success