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"
177 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
182 [ "$UBIUPDATEVOL_PROG" = "" ] && _fatal "ubiupdatevol not found"
186 if [ ! -z "$REPORT_LIST" ]; then
193 $MOUNT_PROG `_mount_ops_filter $*`
196 # Call _mount to do mount operation but also save mountpoint to
197 # MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
200 local mnt_point=${!#}
203 if [ $? -eq 0 ]; then
204 MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
210 # Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
211 # and return it to caller
214 local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
216 if [ -n "$last_mnt" ]; then
217 $UMOUNT_PROG $last_mnt
219 MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
222 # Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
225 if [ -n "$MOUNTED_POINT_STACK" ]; then
226 $UMOUNT_PROG $MOUNTED_POINT_STACK
228 MOUNTED_POINT_STACK=""
236 if [ "$FSTYP" != "xfs" ]; then
242 SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
251 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
252 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
253 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
254 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
262 if [ "$FSTYP" != "xfs" ]; then
276 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
277 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
278 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
279 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
286 #get mount point to handle dmapi mtpt option correctly
288 [ $last_index -gt 0 ] && shift $last_index
291 echo $params | sed -e 's/dmapi/dmi/' \
292 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
296 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
297 # with the safe set of scratch mount options (e.g. loop image may be
298 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
299 _common_dev_mount_options()
301 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
304 _scratch_mount_options()
306 _scratch_options mount
308 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
309 $SCRATCH_DEV $SCRATCH_MNT
316 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
319 xfs_info $dir | grep -q "ftype=1"
322 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
323 tune2fs -l $dev | grep -q filetype
326 local testfile=$dir/$$.ftype
328 # look for DT_UNKNOWN files
329 local unknowns=$(src/t_dir_type $dir u | wc -l)
331 # 0 unknowns is success
339 if [ "$FSTYP" == "overlay" ]; then
340 _overlay_scratch_mount $*
343 _mount -t $FSTYP `_scratch_mount_options $*`
350 _overlay_scratch_unmount
353 $UMOUNT_PROG $SCRATCH_MNT
356 $UMOUNT_PROG $SCRATCH_DEV
365 if test -n "$opts"; then
366 mount -o "remount,$opts" $SCRATCH_MNT
370 _scratch_cycle_mount()
374 if [ "$FSTYP" = tmpfs ]; then
375 _scratch_remount "$opts"
378 if test -n "$opts"; then
382 _scratch_mount "$opts"
387 if [ $FSTYP = "overlay" ]; then
388 # In lagacy overlay usage, it may specify directory as
389 # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
390 # will be null, so check OVL_BASE_SCRATCH_DEV before
391 # running shutdown to avoid shutting down base fs accidently.
392 if [ -z $OVL_BASE_SCRATCH_DEV ]; then
393 _fail "_scratch_shutdown: call _require_scratch_shutdown first in test"
395 src/godown $* $OVL_BASE_SCRATCH_MNT
398 src/godown $* $SCRATCH_MNT
404 if [ "$FSTYP" == "overlay" ]; then
405 _overlay_test_mount $*
409 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
414 if [ "$FSTYP" == "overlay" ]; then
415 _overlay_test_unmount
417 $UMOUNT_PROG $TEST_DEV
423 if [ "$FSTYP" = tmpfs ]; then
430 _scratch_mkfs_options()
432 _scratch_options mkfs
433 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
436 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
437 # and user specified mkfs options, if that fails (due to conflicts between mkfs
438 # options), do a second mkfs with only user provided mkfs options.
440 # First param is the mkfs command without any mkfs options and device.
441 # Second param is the filter to remove unnecessary messages from mkfs stderr.
442 # Other extra mkfs options are followed.
448 local extra_mkfs_options=$*
450 local tmp=`mktemp -u`
452 # save mkfs output in case conflict means we need to run again.
453 # only the output for the mkfs that applies should be shown
454 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
455 2>$tmp.mkfserr 1>$tmp.mkfsstd
458 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
459 # $extra_mkfs_options
460 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
462 echo -n "** mkfs failed with extra mkfs options "
463 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
464 echo -n "** attempting to mkfs using only test $seq "
465 echo "options: $extra_mkfs_options **"
468 # running mkfs again. overwrite previous mkfs output files
469 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
470 2>$tmp.mkfserr 1>$tmp.mkfsstd
474 # output stored mkfs output, filtering unnecessary output from stderr
476 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
478 rm -f $tmp.mkfserr $tmp.mkfsstd
488 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
489 options="-l $SCRATCH_LOGDEV"
491 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
494 _setup_large_ext4_fs()
499 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
500 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
501 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
503 # Default free space in the FS is 50GB, but you can specify more via
504 # SCRATCH_DEV_EMPTY_SPACE
505 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
507 # mount the filesystem and create 16TB - 4KB files until we consume
508 # all the necessary space.
509 _scratch_mount 2>&1 >$tmp_dir/mnt.err
511 if [ $status -ne 0 ]; then
513 cat $tmp_dir/mnt.err >&2
514 rm -f $tmp_dir/mnt.err
517 rm -f $tmp_dir/mnt.err
519 file_size=$((16*1024*1024*1024*1024 - 4096))
521 while [ $space_to_consume -gt $file_size ]; do
524 -c "truncate $file_size" \
525 -c "falloc -k 0 $file_size" \
526 $SCRATCH_MNT/.use_space.$nfiles 2>&1
528 if [ $status -ne 0 ]; then
532 space_to_consume=$(( $space_to_consume - $file_size ))
533 nfiles=$(($nfiles + 1))
536 # consume the remaining space.
537 if [ $space_to_consume -gt 0 ]; then
539 -c "truncate $space_to_consume" \
540 -c "falloc -k 0 $space_to_consume" \
541 $SCRATCH_MNT/.use_space.$nfiles 2>&1
544 export NUM_SPACE_FILES=$nfiles
547 if [ $status -ne 0 ]; then
548 echo "large file prealloc failed"
549 cat $tmp_dir/mnt.err >&2
557 local mkfs_cmd="$MKFS_EXT4_PROG -F"
558 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
559 local tmp=`mktemp -u`
562 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
563 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
564 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
566 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
569 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
570 # manually parse the mkfs output to get the fs size in bytes
571 fs_size=`cat $tmp.mkfsstd | awk ' \
572 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
573 / inodes, / { blks = $3 } \
574 /reserved for the super user/ { resv = $1 } \
575 END { fssize = bs * blks - resv; print fssize }'`
577 _setup_large_ext4_fs $fs_size
581 # output mkfs stdout and stderr
584 rm -f $tmp.mkfserr $tmp.mkfsstd
596 # do nothing for cifs
599 # do nothing for ceph
602 # do nothing for glusterfs
605 # do nothing for overlay
608 # do nothing for pvfs2
611 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
614 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
617 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
620 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
627 local tmp=`mktemp -u`
633 # do nothing for overlay
636 # do nothing for pvfs2
639 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
642 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
645 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
646 2>$tmp.mkfserr 1>$tmp.mkfsstd
649 $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* \
650 2>$tmp.mkfserr 1>$tmp.mkfsstd
653 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
654 2>$tmp.mkfserr 1>$tmp.mkfsstd
658 if [ $? -ne 0 ]; then
659 # output stored mkfs output
665 rm -f $tmp.mkfserr $tmp.mkfsstd
668 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
669 _scratch_cleanup_files()
673 # Avoid rm -rf /* if we messed up
674 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
675 _overlay_base_scratch_mount || return 1
676 rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
677 _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
678 # leave base fs mouted so tests can setup lower/upper dir files
681 [ -n "$SCRATCH_MNT" ] || return 1
683 rm -rf $SCRATCH_MNT/*
696 nfs*|cifs|ceph|overlay|glusterfs|pvfs2)
697 # unable to re-create this fstyp, just remove all files in
698 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
699 # created in previous runs
700 _scratch_cleanup_files
704 # do nothing for tmpfs
708 # erase the UBI volume; reformated automatically on next mount
709 $UBIUPDATEVOL_PROG ${SCRATCH_DEV} -t
713 _scratch_mkfs_ext4 $*
721 mkfs_cmd="$MKFS_UDF_PROG"
725 mkfs_cmd="$MKFS_BTRFS_PROG"
729 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
730 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
732 # put journal on separate device?
733 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
734 $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
735 mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
738 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
739 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
742 mkfs_cmd="$MKFS_F2FS_PROG"
746 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
747 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
750 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
755 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
759 # Helper function to get a spare or replace-target device from
760 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
761 # before _spare_dev_get(). Replace-target-device/Spare-device will
762 # be assigned to SPARE_DEV.
763 # As of now only one replace-target-device/spare-device can be
767 # _scratch_dev_pool_get() <ndevs>
771 # _scratch_dev_pool_put()
775 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
776 if [ $? -ne 0 ]; then
777 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
780 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
781 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
784 # Check if the spare is already assigned
785 typeset -p SPARE_DEV >/dev/null 2>&1
786 if [ $? -eq 0 ]; then
787 if [ ! -z "$SPARE_DEV" ]; then
788 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
792 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
793 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
795 if [ $ndevs -eq $config_ndevs ]; then
796 _notrun "All devs used no spare"
798 # Get a dev that is not used
799 local -a devs="( $SCRATCH_DEV_POOL_SAVED )"
800 SPARE_DEV=${devs[@]:$ndevs:1}
806 typeset -p SPARE_DEV >/dev/null 2>&1
807 if [ $? -ne 0 ]; then
808 _fail "Bug: unset val, must call _spare_dev_get before its put"
811 if [ -z "$SPARE_DEV" ]; then
812 _fail "Bug: str empty, must call _spare_dev_get before its put"
819 # Generally test cases will have..
820 # _require_scratch_dev_pool X
821 # to make sure it has the enough scratch devices including
822 # replace-target and spare device. Now arg1 here is the
823 # required number of scratch devices by a-test-case excluding
824 # the replace-target and spare device. So this function will
825 # set SCRATCH_DEV_POOL to the specified number of devices.
828 # _scratch_dev_pool_get() <ndevs>
831 # _scratch_dev_pool_put()
833 _scratch_dev_pool_get()
835 if [ $# -ne 1 ]; then
836 _fail "Usage: _scratch_dev_pool_get ndevs"
840 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
841 local -a devs="( $SCRATCH_DEV_POOL )"
843 typeset -p config_ndevs >/dev/null 2>&1
844 if [ $? -ne 0 ]; then
845 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
848 if [ $config_ndevs -lt $test_ndevs ]; then
849 _notrun "Need at least test requested number of ndevs $test_ndevs"
852 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
853 export SCRATCH_DEV_POOL_SAVED
854 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
855 export SCRATCH_DEV_POOL
858 _scratch_dev_pool_put()
860 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
861 if [ $? -ne 0 ]; then
862 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
865 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
866 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
869 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
870 export SCRATCH_DEV_POOL_SAVED=""
877 # if dup profile is in mkfs options call _scratch_mkfs instead
878 # because dup profile only works with single device
879 if [[ "$*" =~ dup ]]; then
882 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
886 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
891 # Return the amount of free memory available on the system
894 free -b | grep ^Mem | awk '{print $4}'
897 # Create fs of certain size on scratch device
898 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
899 _scratch_mkfs_sized()
906 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
908 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2|reiserfs)
909 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
916 [ -n "$def_blksz" ] && blocksize=$def_blksz
917 [ -z "$blocksize" ] && blocksize=4096
921 if ! [[ $fssize =~ $re ]] ; then
922 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
924 if ! [[ $blocksize =~ $re ]] ; then
925 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
928 blocks=`expr $fssize / $blocksize`
930 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
931 devsize=`blockdev --getsize64 $SCRATCH_DEV`
932 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
937 # don't override MKFS_OPTIONS that set a block size.
938 echo $MKFS_OPTIONS |egrep -q "b?size="
939 if [ $? -eq 0 ]; then
940 _scratch_mkfs_xfs -d size=$fssize
942 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
945 ext2|ext3|ext4|ext4dev)
946 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
949 # mkfs.gfs2 doesn't automatically shrink journal files on small
950 # filesystems, so the journal files may end up being bigger than the
951 # filesystem, which will cause mkfs.gfs2 to fail. Until that's fixed,
952 # shrink the journal size to at most one eigth of the filesystem and at
953 # least 8 MiB, the minimum size allowed.
955 DEFAULT_JOURNAL_SIZE=128
956 if (( fssize/8 / (1024*1024) < DEFAULT_JOURNAL_SIZE )); then
957 (( JOURNAL_SIZE = fssize/8 / (1024*1024) ))
958 (( JOURNAL_SIZE >= MIN_JOURNAL_SIZE )) || JOURNAL_SIZE=$MIN_JOURNAL_SIZE
959 MKFS_OPTIONS="-J $JOURNAL_SIZE $MKFS_OPTIONS"
961 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV $blocks
964 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
967 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
971 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
972 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
975 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV $blocks
978 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
981 # mkfs.resier4 requires size in KB as input for creating filesystem
982 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
983 `expr $fssize / 1024`
986 # mkfs.f2fs requires # of sectors as an input for the size
987 sector_size=`blockdev --getss $SCRATCH_DEV`
988 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
991 free_mem=`_free_memory_bytes`
992 if [ "$free_mem" -lt "$fssize" ] ; then
993 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
995 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
998 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1003 # Emulate an N-data-disk stripe w/ various stripe units
1004 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1005 _scratch_mkfs_geom()
1010 [ -z "$blocksize" ] && blocksize=4096
1012 let sunit_blocks=$sunit_bytes/$blocksize
1013 let swidth_blocks=$sunit_blocks*$swidth_mult
1017 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1020 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1023 _notrun "can't mkfs $FSTYP with geometry"
1029 # Create fs of certain blocksize on scratch device
1030 # _scratch_mkfs_blocksized blocksize
1031 _scratch_mkfs_blocksized()
1036 if ! [[ $blocksize =~ $re ]] ; then
1037 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1042 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1045 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1048 ${MKFS_PROG}.$FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV
1051 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1054 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1063 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1071 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1072 # errors found or errors were fixed) and nonzero otherwise; also spits out
1073 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1074 _repair_scratch_fs()
1078 _scratch_xfs_repair "$@" 2>&1
1080 if [ "$res" -ne 0 ]; then
1081 echo "xfs_repair returns $res; replay log?"
1084 if [ "$res" -gt 0 ]; then
1085 echo "mount returns $res; zap log?"
1086 _scratch_xfs_repair -L 2>&1
1087 echo "log zap returns $?"
1089 umount "$SCRATCH_MNT"
1091 _scratch_xfs_repair "$@" 2>&1
1094 if [ $res -ne 0 ]; then
1095 _dump_err2 "xfs_repair failed, err=$res"
1100 # Let's hope fsck -y suffices...
1101 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1108 _dump_err2 "fsck.$FSTYP failed, err=$res"
1120 echo "Usage: _get_pids_by_name process-name" 1>&2
1124 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1125 # HH:MM:SS before the psargs field, use this as the search anchor.
1127 # Matches with $1 (process-name) occur if the first psarg is $1
1128 # or ends in /$1 ... the matching uses sed's regular expressions,
1129 # so passing a regex into $1 will work.
1134 -e 's/[ ][ ]*/ /g' \
1137 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1138 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1141 # fix malloc libs output
1145 # filter out the Electric Fence notice
1148 if (defined $o && /^\s+Electric Fence/) {
1154 print $o if (defined $o);
1158 print $o if (defined $o);
1163 # _df_device : get an IRIX style df line for a given device
1165 # - returns "" if not mounted
1166 # - returns fs type in field two (ala IRIX)
1167 # - joins line together if split by fancy df formatting
1168 # - strips header etc
1175 echo "Usage: _df_device device" 1>&2
1179 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1180 # IPv6 server as a regular expression.
1181 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1182 ($1==what) && (NF==1) {
1196 # _df_dir : get an IRIX style df line for device where a directory resides
1198 # - returns fs type in field two (ala IRIX)
1199 # - joins line together if split by fancy df formatting
1200 # - strips header etc
1207 echo "Usage: _df_dir device" 1>&2
1211 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1227 # return percentage used disk space for mounted device
1233 echo "Usage: _used device" 1>&2
1237 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1240 # return the FS type of a mounted device
1246 echo "Usage: _fs_type device" 1>&2
1251 # The Linux kernel shows NFSv4 filesystems in df output as
1252 # filesystem type nfs4, although we mounted it as nfs earlier.
1253 # Fix the filesystem type up here so that the callers don't
1254 # have to bother with this quirk.
1256 _df_device $1 | $AWK_PROG '{ print $2 }' | \
1257 sed -e 's/nfs4/nfs/' -e 's/fuse.glusterfs/glusterfs/'
1260 # return the FS mount options of a mounted device
1262 # should write a version which just parses the output of mount for IRIX
1263 # compatibility, but since this isn't used at all, at the moment I'll leave
1270 echo "Usage: _fs_options device" 1>&2
1274 $AWK_PROG -v dev=$1 '
1275 match($1,dev) { print $4 }
1279 # returns device number if a file is a block device
1285 echo "Usage: _is_block_dev dev" 1>&2
1290 if [ -L "${_dev}" ]; then
1291 _dev=`readlink -f "${_dev}"`
1294 if [ -b "${_dev}" ]; then
1295 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1299 # returns device number if a file is a character device
1303 if [ $# -ne 1 ]; then
1304 echo "Usage: _is_char_dev dev" 1>&2
1309 if [ -L "${_dev}" ]; then
1310 _dev=`readlink -f "${_dev}"`
1313 if [ -c "${_dev}" ]; then
1314 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1318 # Do a command, log it to $seqres.full, optionally test return status
1319 # and die if command fails. If called with one argument _do executes the
1320 # command, logs it, and returns its exit status. With two arguments _do
1321 # first prints the message passed in the first argument, and then "done"
1322 # or "fail" depending on the return status of the command passed in the
1323 # second argument. If the command fails and the variable _do_die_on_error
1324 # is set to "always" or the two argument form is used and _do_die_on_error
1325 # is set to "message_only" _do will print an error message to
1326 # $seqres.out and exit.
1330 if [ $# -eq 1 ]; then
1332 elif [ $# -eq 2 ]; then
1335 echo -n "$_note... "
1337 echo "Usage: _do [note] cmd" 1>&2
1341 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1342 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1343 cat $tmp._out | _fix_malloc >>$seqres.full
1345 if [ $# -eq 2 ]; then
1346 if [ $ret -eq 0 ]; then
1353 && [ "$_do_die_on_error" = "always" \
1354 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1356 [ $# -ne 2 ] && echo
1357 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1364 # bail out, setting up .notrun file. Need to kill the filesystem check files
1365 # here, otherwise they are set incorrectly for the next test.
1369 echo "$*" > $seqres.notrun
1370 echo "$seq not run: $*"
1371 rm -f ${RESULT_DIR}/require_test*
1372 rm -f ${RESULT_DIR}/require_scratch*
1378 # just plain bail out
1382 echo "$*" | tee -a $seqres.full
1383 echo "(see $seqres.full for details)"
1388 # tests whether $FSTYP is one of the supported filesystems for a test
1394 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1400 _notrun "not suitable for this filesystem type: $FSTYP"
1404 # tests whether $FSTYP is one of the supported OSes for a test
1410 if [ "$h" = "$HOSTOS" ]
1416 _notrun "not suitable for this OS: $HOSTOS"
1419 # check if a FS on a device is mounted
1420 # if so, verify that it is mounted on mount point
1421 # if fstype is given as argument, verify that it is also
1422 # mounted with correct fs type
1432 # find $dev as the source, and print result in "$dev $mnt" format
1433 local mount_rec=`findmnt -rncv -S $dev -o SOURCE,TARGET`
1434 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1436 # if it's mounted, make sure its on $mnt
1437 if [ "$mount_rec" != "$dev $mnt" ]; then
1438 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1439 echo "Already mounted result:"
1441 return 2 # 2 = mounted on wrong mnt
1444 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
1445 echo "$devname=$dev is mounted but not a type $type filesystem"
1446 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1448 return 3 # 3 = mounted as wrong type
1450 return 0 # 0 = mounted as expected
1453 # this test needs a scratch partition - check we're ok & unmount it
1454 # No post-test check of the device is required. e.g. the test intentionally
1455 # finishes the test with the filesystem in a corrupt state
1456 _require_scratch_nocheck()
1460 echo $SCRATCH_DEV | egrep -q ":/?" > /dev/null 2>&1
1461 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1462 _notrun "this test requires a valid \$SCRATCH_DEV"
1464 if [ ! -d "$SCRATCH_MNT" ]; then
1465 _notrun "this test requires a valid \$SCRATCH_MNT"
1469 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1470 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1471 _notrun "this test requires a valid \$SCRATCH_DEV"
1473 if [ ! -d "$SCRATCH_MNT" ]; then
1474 _notrun "this test requires a valid \$SCRATCH_MNT"
1478 echo $SCRATCH_DEV | grep -q "://" > /dev/null 2>&1
1479 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1480 _notrun "this test requires a valid \$SCRATCH_DEV"
1482 if [ ! -d "$SCRATCH_MNT" ]; then
1483 _notrun "this test requires a valid \$SCRATCH_MNT"
1487 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1488 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1489 _notrun "this test requires a valid \$SCRATCH_DEV"
1491 if [ ! -d "$SCRATCH_MNT" ]; then
1492 _notrun "this test requires a valid \$SCRATCH_MNT"
1496 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1497 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1499 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1500 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1501 # and we will create the mount point anyway on _overlay_mount
1502 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1503 _notrun "this test requires a valid \$SCRATCH_MNT"
1507 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1509 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1513 # ubifs needs an UBI volume. This will be a char device, not a block device.
1514 if [ ! -c "$SCRATCH_DEV" ]; then
1515 _notrun "this test requires a valid UBI volume for \$SCRATCH_DEV"
1517 if [ ! -d "$SCRATCH_MNT" ]; then
1518 _notrun "this test requires a valid \$SCRATCH_MNT"
1522 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1524 _notrun "this test requires a valid \$SCRATCH_DEV"
1526 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1528 _notrun "this test requires a valid \$SCRATCH_DEV"
1530 if [ ! -d "$SCRATCH_MNT" ]
1532 _notrun "this test requires a valid \$SCRATCH_MNT"
1537 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1539 [ $err -le 1 ] || exit 1
1542 # if it's mounted, unmount it
1543 if ! _scratch_unmount
1545 echo "failed to unmount $SCRATCH_DEV"
1549 rm -f ${RESULT_DIR}/require_scratch
1552 # we need the scratch device and it should be checked post test.
1555 _require_scratch_nocheck
1556 touch ${RESULT_DIR}/require_scratch
1560 # this test needs a test partition - check we're ok & mount it
1566 echo $TEST_DEV | egrep -q ":/?" > /dev/null 2>&1
1567 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1568 _notrun "this test requires a valid \$TEST_DEV"
1570 if [ ! -d "$TEST_DIR" ]; then
1571 _notrun "this test requires a valid \$TEST_DIR"
1575 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1576 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1577 _notrun "this test requires a valid \$TEST_DEV"
1579 if [ ! -d "$TEST_DIR" ]; then
1580 _notrun "this test requires a valid \$TEST_DIR"
1584 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1585 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1586 _notrun "this test requires a valid \$TEST_DEV"
1588 if [ ! -d "$TEST_DIR" ]; then
1589 _notrun "this test requires a valid \$TEST_DIR"
1593 echo $TEST_DEV | grep -q "://" > /dev/null 2>&1
1594 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1595 _notrun "this test requires a valid \$TEST_DIR"
1597 if [ ! -d "$TEST_DIR" ]; then
1598 _notrun "this test requires a valid \$TEST_DIR"
1602 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1603 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1605 if [ ! -d "$TEST_DIR" ]; then
1606 _notrun "this test requires a valid \$TEST_DIR"
1610 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1612 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1616 # ubifs needs an UBI volume. This will be a char device, not a block device.
1617 if [ ! -c "$TEST_DEV" ]; then
1618 _notrun "this test requires a valid UBI volume for \$TEST_DEV"
1620 if [ ! -d "$TEST_DIR" ]; then
1621 _notrun "this test requires a valid \$TEST_DIR"
1625 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1627 _notrun "this test requires a valid \$TEST_DEV"
1629 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1631 _notrun "this test requires a valid \$TEST_DEV"
1633 if [ ! -d "$TEST_DIR" ]
1635 _notrun "this test requires a valid \$TEST_DIR"
1640 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1642 [ $err -le 1 ] || exit 1
1647 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1651 touch ${RESULT_DIR}/require_test
1657 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && ret=1
1658 [ "$USE_EXTERNAL" != yes ] && ret=1
1663 # this test needs a logdev
1667 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1668 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1669 [ "$USE_EXTERNAL" != yes ] && \
1670 _notrun "This test requires USE_EXTERNAL to be enabled"
1672 # ensure its not mounted
1673 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1676 # this test requires loopback device support
1680 if [ "$HOSTOS" != "Linux" ]
1682 _notrun "This test requires linux for loopback device support"
1685 modprobe loop >/dev/null 2>&1
1686 if grep loop /proc/devices >/dev/null 2>&1
1690 _notrun "This test requires loopback device support"
1694 # this test requires ext2 filesystem support
1698 if [ "$HOSTOS" != "Linux" ]
1700 _notrun "This test requires linux for ext2 filesystem support"
1703 modprobe ext2 >/dev/null 2>&1
1704 if grep ext2 /proc/filesystems >/dev/null 2>&1
1708 _notrun "This test requires ext2 filesystem support"
1712 # this test requires tmpfs filesystem support
1716 modprobe tmpfs >/dev/null 2>&1
1717 grep -q tmpfs /proc/filesystems ||
1718 _notrun "this test requires tmpfs support"
1721 # this test requires that (large) loopback device files are not in use
1723 _require_no_large_scratch_dev()
1725 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1726 _notrun "Large filesystem testing in progress, skipped this test"
1729 # this test requires that a realtime subvolume is in use, and
1730 # that the kernel supports realtime as well.
1734 [ "$USE_EXTERNAL" = yes ] || \
1735 _notrun "External volumes not in use, skipped this test"
1736 [ "$SCRATCH_RTDEV" = "" ] && \
1737 _notrun "Realtime device required, skipped this test"
1740 # this test requires that a specified command (executable) exists
1741 # $1 - command, $2 - name for error message
1743 # Note: the command string might have parameters, so strip them before checking
1744 # whether it is executable.
1747 if [ $# -eq 2 ]; then
1749 elif [ $# -eq 1 ]; then
1752 _fail "usage: _require_command <command> [<name>]"
1755 _command=`echo "$1" | awk '{ print $1 }'`
1756 if [ ! -x "$_command" ]; then
1757 _notrun "$_name utility required, skipped this test"
1761 # this test requires the device to be valid block device
1763 _require_block_device()
1765 if [ -z "$1" ]; then
1766 echo "Usage: _require_block_device <dev>" 1>&2
1769 if [ "`_is_block_dev "$1"`" == "" ]; then
1770 _notrun "require $1 to be valid block disk"
1774 # this test requires a path to refere to a local block or character device
1776 _require_local_device()
1778 if [ -z "$1" ]; then
1779 echo "Usage: _require_local_device <dev>" 1>&2
1782 if [ "`_is_block_dev "$1"`" != "" ]; then
1785 if [ "`_is_char_dev "$1"`" != "" ]; then
1788 _notrun "require $1 to be local device"
1791 # brd based ram disks erase the device when they receive a flush command when no
1792 # active references are present. This causes problems for DM devices sitting on
1793 # top of brd devices as DM doesn't hold active references to the brd device.
1794 _require_sane_bdev_flush()
1796 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1797 if [ $? -eq 0 ]; then
1798 _notrun "This test requires a sane block device flush"
1802 # this test requires a specific device mapper target
1803 _require_dm_target()
1807 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1809 _require_block_device $SCRATCH_DEV
1810 _require_sane_bdev_flush $SCRATCH_DEV
1811 _require_command "$DMSETUP_PROG" dmsetup
1813 modprobe dm-$_target >/dev/null 2>&1
1815 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1816 if [ $? -ne 0 ]; then
1817 _notrun "This test requires dm $_target support"
1821 # this test requires the ext4 kernel support crc feature on scratch device
1823 _require_scratch_ext4_crc()
1825 _scratch_mkfs_ext4 >/dev/null 2>&1
1826 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1827 _scratch_mount >/dev/null 2>&1 \
1828 || _notrun "Kernel doesn't support metadata_csum feature"
1832 # Check whether the specified feature whether it is supported by
1833 # mkfs.ext4 and the kernel.
1834 _require_scratch_ext4_feature()
1836 if [ -z "$1" ]; then
1837 echo "Usage: _require_scratch_ext4_feature feature"
1840 $MKFS_EXT4_PROG -F $MKFS_OPTIONS -O "$1" \
1841 $SCRATCH_DEV 512m >/dev/null 2>&1 \
1842 || _notrun "mkfs.ext4 doesn't support $1 feature"
1843 _scratch_mount >/dev/null 2>&1 \
1844 || _notrun "Kernel doesn't support the ext4 feature(s): $1"
1848 # this test requires that external log/realtime devices are not in use
1850 _require_nonexternal()
1852 [ "$USE_EXTERNAL" = yes ] && \
1853 _notrun "External device testing in progress, skipped this test"
1856 # this test requires that the kernel supports asynchronous I/O
1859 $here/src/feature -A
1864 _notrun "kernel does not support asynchronous I/O"
1867 _fail "unexpected error testing for asynchronous I/O support"
1872 # this test requires that a (specified) aio-dio executable exists
1873 # and that the kernel supports asynchronous I/O.
1874 # $1 - command (optional)
1880 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1881 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1883 AIO_TEST=src/aio-dio-regress/$1
1884 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1890 # this test requires that a test program exists under src/
1891 # $1 - command (require)
1893 _require_test_program()
1896 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1899 # run an aio-dio program
1905 echo "usage: _run_aiodio command_name" 2>&1
1911 local testtemp=$TEST_DIR/aio-testfile
1913 $AIO_TEST $testtemp 2>&1
1920 # this test requires y2038 sysfs switch and filesystem
1921 # timestamp ranges support.
1924 local device=${1:-$TEST_DEV}
1925 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
1927 if [ ! -e $sysfsdir ]; then
1928 _notrun "no kernel support for y2038 sysfs switch"
1932 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
1933 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
1934 _notrun "filesystem $FSTYP timestamp bounds are unknown"
1938 _filesystem_timestamp_range()
1940 device=${1:-$TEST_DEV}
1943 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
1944 echo "-2147483648 15032385535"
1946 echo "-2147483648 2147483647"
1951 echo "-2147483648 2147483647"
1957 echo "-2147483648 2147483647"
1965 # indicate whether YP/NIS is active or not
1970 dn=$(domainname 2>/dev/null)
1971 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
1975 # cat the password file
1979 [ $(_yp_active) -eq 0 ] && ypcat passwd
1983 # cat the group file
1987 [ $(_yp_active) -eq 0 ] && ypcat group
1991 # check for a user on the machine, fsgqa as default
1999 _cat_passwd | grep -q $qa_user
2000 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
2001 echo /bin/true | su $qa_user
2002 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
2005 # check for a group on the machine, fsgqa as default
2013 _cat_group | grep -q $qa_group
2014 [ "$?" == "0" ] || _notrun "$qa_group group not defined."
2020 s,.*Permission\sdenied.*,Permission denied,;
2021 s,.*no\saccess\sto\stty.*,,;
2022 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2029 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
2032 _require_xfs_io_command()
2036 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2042 local param_checked=0
2045 testfile=$TEST_DIR/$$.xfs_io
2048 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
2051 testcopy=$TEST_DIR/$$.copy.xfs_io
2052 $XFS_IO_PROG -F -f -c "pwrite 0 4k" $testfile > /dev/null 2>&1
2053 testio=`$XFS_IO_PROG -F -f -c "copy_range $testfile" $testcopy 2>&1`
2054 rm -f $testcopy > /dev/null 2>&1
2057 testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1`
2060 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
2061 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2062 -c "$command 4k 8k" $testfile 2>&1`
2065 # If 'ranged' is passed as argument then we check to see if fiemap supports
2066 # ranged query params
2067 if echo "$param" | grep -q "ranged"; then
2068 param=$(echo "$param" | sed "s/ranged//")
2069 $XFS_IO_PROG -c "help fiemap" | grep -q "\[offset \[len\]\]"
2070 [ $? -eq 0 ] || _notrun "xfs_io $command ranged support is missing"
2072 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2073 -c "fiemap -v $param" $testfile 2>&1`
2077 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2079 echo $testio | egrep -q "invalid option|Is a directory" && \
2080 _notrun "xfs_io $command support is missing"
2083 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
2084 echo $testio | grep -q "Inappropriate ioctl" && \
2085 _notrun "xfs_io $command support is missing"
2088 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
2089 # a new -C flag was introduced to execute one shot commands.
2090 # Check for -C flag support as an indication for the bug fix.
2091 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
2092 echo $testio | grep -q "invalid option" && \
2093 _notrun "xfs_io $command support is missing"
2096 # -N (RWF_NOWAIT) only works with direct vectored I/O writes
2097 local pwrite_opts=" "
2098 if [ "$param" == "-N" ]; then
2100 pwrite_opts+="-V 1 -b 4k"
2102 testio=`$XFS_IO_PROG -f $opts -c \
2103 "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1`
2107 testio=`$XFS_IO_PROG -x -c "$command probe 0" $TEST_DIR 2>&1`
2108 echo $testio | grep -q "Inappropriate ioctl" && \
2109 _notrun "xfs_io $command support is missing"
2112 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
2116 testio=`$XFS_IO_PROG -c "syncfs" $testfile 2>&1`
2119 testio=`$XFS_IO_PROG -c "help $command" 2>&1`
2122 rm -f $testfile 2>&1 > /dev/null
2123 echo $testio | grep -q "not found" && \
2124 _notrun "xfs_io $command support is missing"
2125 echo $testio | grep -q "Operation not supported" && \
2126 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2127 echo $testio | grep -q "Invalid" && \
2128 _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
2129 echo $testio | grep -q "foreign file active" && \
2130 _notrun "xfs_io $command not supported on $FSTYP"
2131 echo $testio | grep -q "Function not implemented" && \
2132 _notrun "xfs_io $command support is missing (missing syscall?)"
2134 [ -n "$param" ] || return
2136 if [ $param_checked -eq 0 ]; then
2137 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2138 _notrun "xfs_io $command doesn't support $param"
2140 # xfs_io could result in "command %c not supported" if it was
2141 # built on kernels not supporting pwritev2() calls
2142 echo $testio | grep -q "\(invalid option\|not supported\)" && \
2143 _notrun "xfs_io $command doesn't support $param"
2147 # check that kernel and filesystem support direct I/O
2150 if [ $FSTYP = "ext4" ] ; then
2151 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2152 _notrun "ext4 encryption doesn't support O_DIRECT"
2153 elif echo "$MOUNT_OPTIONS" | grep -q "data=journal"; then
2154 _notrun "ext4 data journaling doesn't support O_DIRECT"
2157 testfile=$TEST_DIR/$$.direct
2158 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2159 if [ $? -ne 0 ]; then
2160 _notrun "O_DIRECT is not supported"
2162 rm -f $testfile 2>&1 > /dev/null
2165 # Check that the filesystem supports swapfiles
2166 _require_scratch_swapfile()
2170 _scratch_mkfs >/dev/null
2173 # Minimum size for mkswap is 10 pages
2174 local size=$(($(get_page_size) * 10))
2176 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
2177 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
2178 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
2180 _notrun "swapfiles are not supported"
2183 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
2187 # Check that a fs has enough free space (in 1024b blocks)
2192 BLOCKS=$2 # in units of 1024
2193 let GB=$BLOCKS/1024/1024
2195 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2196 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2197 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2201 # Check if the filesystem supports sparse files.
2203 # Unfortunately there is no better way to do this than a manual black list.
2205 _require_sparse_files()
2209 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2218 #boot_params always present in debugfs
2219 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2222 _require_fail_make_request()
2224 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2225 || _notrun "$DEBUGFS_MNT/fail_make_request \
2226 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2229 # Disable extent zeroing for ext4 on the given device
2230 _ext4_disable_extent_zeroout()
2232 local dev=${1:-$TEST_DEV}
2233 local sdev=`_short_dev $dev`
2235 [ -f /sys/fs/ext4/$sdev/extent_max_zeroout_kb ] && \
2236 echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
2239 # Check if the file system supports seek_data/hole
2240 _require_seek_data_hole()
2242 local dev=${1:-$TEST_DEV}
2243 local testfile=$TEST_DIR/$$.seek
2244 local testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2246 rm -f $testfile &>/dev/null
2247 echo $testseek | grep -q "Kernel does not support" && \
2248 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2249 # Disable extent zeroing for ext4 as that change where holes are
2251 if [ "$FSTYP" = "ext4" ]; then
2252 _ext4_disable_extent_zeroout $dev
2258 _require_test_program "runas"
2263 "$here/src/runas" "$@"
2266 _require_richacl_prog()
2268 _require_command "$GETRICHACL_PROG" getrichacl
2269 _require_command "$SETRICHACL_PROG" setrichacl
2272 _require_scratch_richacl_xfs()
2274 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2275 || _notrun "mkfs.xfs doesn't have richacl feature"
2276 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2277 _scratch_mount >/dev/null 2>&1 \
2278 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2282 _require_scratch_richacl_ext4()
2284 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2285 || _notrun "can't mkfs $FSTYP with option -O richacl"
2286 _scratch_mount >/dev/null 2>&1 \
2287 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2291 _require_scratch_richacl_support()
2294 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2295 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2299 _require_scratch_richacl()
2302 xfs) _require_scratch_richacl_xfs
2304 ext4) _require_scratch_richacl_ext4
2307 _require_scratch_richacl_support
2309 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2314 _scratch_mkfs_richacl()
2317 xfs) _scratch_mkfs_xfs -m richacl=1
2319 ext4) _scratch_mkfs -O richacl
2327 # check that a FS on a device is mounted
2328 # if so, return mount point
2334 echo "Usage: _is_mounted device" 1>&2
2340 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2341 pattern { print $3 ; exit 0 }
2345 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2350 # remount a FS to a new mode (ro or rw)
2356 echo "Usage: _remount device ro/rw" 1>&2
2362 if ! mount -o remount,$mode $device
2364 echo "_remount: failed to remount filesystem on $device as $mode"
2369 # Run the appropriate repair/check on a filesystem
2371 # if the filesystem is mounted, it's either remounted ro before being
2372 # checked or it's unmounted and then remounted
2375 # If set, we remount ro instead of unmounting for fsck
2378 _umount_or_remount_ro()
2382 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2387 mountpoint=`_is_mounted $device`
2389 if [ $USE_REMOUNT -eq 0 ]; then
2390 $UMOUNT_PROG $device
2397 _mount_or_remount_rw()
2399 if [ $# -ne 3 ]; then
2400 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2407 if [ $USE_REMOUNT -eq 0 ]; then
2408 if [ "$FSTYP" != "overlay" ]; then
2409 _mount -t $FSTYP $mount_opts $device $mountpoint
2411 _overlay_mount $device $mountpoint
2413 if [ $? -ne 0 ]; then
2414 _dump_err "!!! failed to remount $device on $mountpoint"
2424 # Check a generic filesystem in no-op mode; this assumes that the
2425 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2426 # and that it will still return an errno for corruption in this mode.
2428 # Filesystems which don't support this will need to define their
2429 # own check routine.
2431 _check_generic_filesystem()
2435 # If type is set, we're mounted
2436 type=`_fs_type $device`
2439 if [ "$type" = "$FSTYP" ]
2442 mountpoint=`_umount_or_remount_ro $device`
2445 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2448 _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
2449 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2450 cat $tmp.fsck >>$seqres.full
2451 echo "*** end fsck.$FSTYP output" >>$seqres.full
2459 echo "*** mount output ***" >>$seqres.full
2460 _mount >>$seqres.full
2461 echo "*** end mount output" >>$seqres.full
2462 elif [ "$type" = "$FSTYP" ]
2465 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2469 if [ $ok -eq 0 ]; then
2471 if [ "$iam" != "check" ]; then
2480 # Filter the knowen errors the UDF Verifier reports.
2481 _udf_test_known_error_filter()
2483 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."
2487 _check_udf_filesystem()
2489 [ "$DISABLE_UDF_TEST" == "1" ] && return
2491 if [ $# -ne 1 -a $# -ne 2 ]
2493 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2497 if [ ! -x $here/src/udf_test ]
2499 echo "udf_test not installed, please download and build the Philips"
2500 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2501 echo "Then copy the udf_test binary to $here/src/."
2502 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2510 LAST_BLOCK=`expr \( $2 - 1 \)`
2511 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2514 rm -f $seqres.checkfs
2515 sleep 1 # Due to a problem with time stamps in udf_test
2516 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2517 _udf_test_known_error_filter | \
2518 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2519 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2530 # no way to check consistency for nfs
2533 # no way to check consistency for cifs
2536 # no way to check consistency for CephFS
2539 # no way to check consistency for GlusterFS
2542 # no way to check consistency for overlay
2547 # do nothing for now
2550 _check_btrfs_filesystem $TEST_DEV
2553 # no way to check consistency for tmpfs
2556 # there is no fsck program for ubifs yet
2559 _check_generic_filesystem $TEST_DEV
2567 [ $# -eq 1 ] && device=$1
2573 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2574 SCRATCH_LOG="$SCRATCH_LOGDEV"
2576 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2577 SCRATCH_RT="$SCRATCH_RTDEV"
2579 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2582 _check_udf_filesystem $device $udf_fsize
2585 # Don't know how to check an NFS filesystem, yet.
2588 # Don't know how to check a CIFS filesystem, yet.
2591 # no way to check consistency for CephFS
2594 # no way to check consistency for GlusterFS
2597 # no way to check consistency for overlay
2602 _check_btrfs_filesystem $device
2605 # no way to check consistency for tmpfs
2608 # there is no fsck program for ubifs yet
2611 _check_generic_filesystem $device
2616 _full_fstyp_details()
2618 [ -z "$FSTYP" ] && FSTYP=xfs
2619 if [ $FSTYP = xfs ]; then
2620 if [ -d /proc/fs/xfs ]; then
2621 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2622 FSTYP="$FSTYP (non-debug)"
2623 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2624 FSTYP="$FSTYP (debug)"
2627 if uname -a | grep -qi 'debug'; then
2628 FSTYP="$FSTYP (debug)"
2630 FSTYP="$FSTYP (non-debug)"
2637 _full_platform_details()
2643 echo "$os/$platform $host $kernel"
2648 if [ "`uname`" == "Linux" ]; then
2651 echo Unknown operating system: `uname`
2656 _link_out_file_named()
2661 my $feature, $result, $suffix, $opts;
2663 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2664 $feathash{$feature} = 1;
2666 $result = "default";
2671 ($opts, $suffix) = split(/ *: */);
2672 foreach my $opt (split(/,/, $opts)) {
2673 if (!exists($feathash{$opt})) {
2687 ln -fs $SRC.$SUFFIX $1
2692 if [ $# -eq 0 ]; then
2693 FEATURES="$(_get_os_name)"
2694 if [ -n "$MOUNT_OPTIONS" ]; then
2695 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2701 _link_out_file_named $seqfull.out "$FEATURES"
2710 # convert urandom incompressible data to compressible text data
2713 od /dev/urandom | dd iflag=fullblock ${*}
2716 #takes files, randomdata
2724 if [ $size -gt 0 ]; then
2725 if [ "$2" == "false" ]; then
2726 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2727 elif [ "$2" == "comp" ]; then
2728 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2730 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2737 # takes dirname, depth, randomdata
2740 dirname=$1; depth=$2; randomdata=$3
2741 mkdir $dirname || die "mkdir $dirname failed"
2744 _nfiles $files $randomdata # files for this dir and data type
2746 [ $depth -eq 0 ] && return
2747 let deep=$depth-1 # go 1 down
2749 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2752 while [ $d -lt $dirs ]
2754 _descend d$d $deep &
2760 # Populate a filesystem with inodes for performance experiments
2762 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2767 dirs=5 # ndirs in each subdir till leaves
2768 size=0 # sizeof files in K
2769 files=100 # num files in _each_ subdir
2770 depth=2 # depth of tree from root to leaves
2772 root=root # path of initial root of directory tree
2773 randomdata=false # -x data type urandom, zero or compressible
2776 while getopts "d:f:n:r:s:v:x:c" c
2785 x) randomdata=true;;
2786 c) randomdata=comp;;
2790 _descend $root $depth $randomdata
2795 [ $verbose = true ] && echo done
2798 # query whether the given file has the given inode flag set
2805 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2811 # query the given files extsize allocator hint in bytes (if any)
2818 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2819 awk '/^xattr.extsize =/ { print $3 }'`
2820 [ -z "$blocks" ] && blocks="0"
2824 # scratch_dev_pool should contain the disks pool for the btrfs raid
2825 _require_scratch_dev_pool()
2830 if [ -z "$SCRATCH_DEV_POOL" ]; then
2831 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2834 if [ -z "$1" ]; then
2840 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2844 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2845 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2849 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2853 for i in $SCRATCH_DEV_POOL; do
2854 if [ "`_is_block_dev "$i"`" = "" ]; then
2855 _notrun "this test requires valid block disk $i"
2857 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2858 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2860 if _mount | grep -q $i; then
2861 if ! $UMOUNT_PROG $i; then
2862 echo "failed to unmount $i - aborting"
2866 # to help better debug when something fails, we remove
2867 # traces of previous btrfs FS on the dev.
2868 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2872 # ensure devices in SCRATCH_DEV_POOL are of the same size
2873 # must be called after _require_scratch_dev_pool
2874 _require_scratch_dev_pool_equal_size()
2880 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2881 _size=`_get_device_size $SCRATCH_DEV`
2882 for _dev in $SCRATCH_DEV_POOL; do
2883 _newsize=`_get_device_size $_dev`
2884 if [ $_size -ne $_newsize ]; then
2885 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2890 # We will check if the device is deletable
2891 _require_deletable_scratch_dev_pool()
2895 for i in $SCRATCH_DEV_POOL; do
2896 x=`echo $i | cut -d"/" -f 3`
2897 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2898 _notrun "$i is a device which is not deletable"
2903 # Check that fio is present, and it is able to execute given jobfile
2908 _require_command "$FIO_PROG" fio
2909 if [ -z "$1" ]; then
2913 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2914 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2917 # Does freeze work on this fs?
2920 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2922 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2923 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2926 # Does NFS export work on this fs?
2929 _require_test_program "open_by_handle"
2930 mkdir -p "$TEST_DIR"/exportfs_test
2931 $here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
2932 || _notrun "$FSTYP does not support NFS export"
2936 # Does shutdown work on this fs?
2937 _require_scratch_shutdown()
2939 [ -x src/godown ] || _notrun "src/godown executable not found"
2941 _scratch_mkfs > /dev/null 2>&1 || _notrun "_scratch_mkfs failed on $SCRATCH_DEV"
2942 _scratch_mount || _notrun "_scratch_mount failed on $SCRATCH_MNT"
2944 if [ $FSTYP = "overlay" ]; then
2945 if [ -z $OVL_BASE_SCRATCH_DEV ]; then
2946 # In lagacy overlay usage, it may specify directory as
2947 # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
2948 # will be null, so check OVL_BASE_SCRATCH_DEV before
2949 # running shutdown to avoid shutting down base fs accidently.
2950 _notrun "$SCRATCH_DEV is not a block device"
2952 src/godown -f $OVL_BASE_SCRATCH_MNT 2>&1 \
2953 || _notrun "Underlying filesystem does not support shutdown"
2956 src/godown -f $SCRATCH_MNT 2>&1 \
2957 || _notrun "$FSTYP does not support shutdown"
2963 # Does dax mount option work on this dev/fs?
2964 _require_scratch_dax()
2967 _scratch_mkfs > /dev/null 2>&1
2968 _scratch_mount -o dax
2969 # Check options to be sure. XFS ignores dax option
2970 # and goes on if dev underneath does not support dax.
2971 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
2972 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
2976 # Does norecovery support by this fs?
2977 _require_norecovery()
2979 _scratch_mount -o ro,norecovery || \
2980 _notrun "$FSTYP does not support norecovery"
2984 # Does this filesystem support metadata journaling?
2985 # We exclude ones here that don't; otherwise we assume that it does, so the
2986 # test will run, fail, and motivate someone to update this test for a new
2989 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2990 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2992 _require_metadata_journaling()
3001 ext2|vfat|msdos|udf)
3002 _notrun "$FSTYP does not support metadata journaling"
3005 # ext4 could be mkfs'd without a journal...
3007 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3008 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3009 # ext4 might not load a journal
3010 _exclude_scratch_mount_option "noload"
3013 # metadata journaling check is based on base filesystem configurations
3014 # and because -overlay option saves those configurations to OVL_BASE_*,
3015 # adding restore/override the configurations before/after the check.
3016 if [ ! -z $OVL_BASE_FSTYP -a $OVL_BASE_FSTYP != "overlay" ]; then
3017 _overlay_config_restore
3018 _require_metadata_journaling
3019 _overlay_config_override
3021 _notrun "No metadata journaling support for legacy overlay setup"
3025 # by default we pass; if you need to, add your fs above!
3032 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3037 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3040 _count_attr_extents()
3042 $XFS_IO_PROG -c "fiemap -a" $1 | tail -n +2 | grep -v hole | wc -l
3045 # arg 1 is dev to remove and is output of the below eg.
3046 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3052 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3054 stat $disk > /dev/null 2>&1
3055 while [ $? -eq 0 ]; do
3057 stat $disk > /dev/null 2>&1
3061 # arg 1 is dev to add and is output of the below eg.
3062 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3067 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3068 h=`echo ${1} | cut -d":" -f 1`
3069 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3071 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3073 # ensure the device comes online
3075 for i in `seq 1 10`; do
3076 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3077 dev=`ls /sys/class/scsi_device/${1}/device/block`
3078 for j in `seq 1 10`;
3080 stat /dev/$dev > /dev/null 2>&1
3081 if [ $? -eq 0 ]; then
3092 if [ $dev_back_oneline -eq 0 ]; then
3093 echo "/dev/$dev online failed" >> $seqres.full
3095 echo "/dev/$dev is back online" >> $seqres.full
3101 if [ -z "$FSTRIM_PROG" ]; then
3102 _notrun "This test requires fstrim utility."
3106 _require_batched_discard()
3108 if [ $# -ne 1 ]; then
3109 echo "Usage: _require_batched_discard mnt_point" 1>&2
3113 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3118 if [ -z "$DUMPE2FS_PROG" ]; then
3119 _notrun "This test requires dumpe2fs utility."
3125 if [ ! -e /proc/self/uid_map ]; then
3126 _notrun "This test requires procfs uid_map support."
3128 if [ ! -e /proc/self/gid_map ]; then
3129 _notrun "This test requires procfs gid_map support."
3135 FSSUM_PROG=$here/src/fssum
3136 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3141 CLONER_PROG=$here/src/cloner
3142 [ -x $CLONER_PROG ] || \
3143 _notrun "cloner binary not present at $CLONER_PROG"
3146 # Normalize mount options from global $MOUNT_OPTIONS
3147 # Convert options like "-o opt1,opt2 -oopt3" to
3149 _normalize_mount_options()
3151 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
3154 # skip test if MOUNT_OPTIONS contains the given strings
3155 _exclude_scratch_mount_option()
3157 local mnt_opts=$(_normalize_mount_options)
3159 while [ $# -gt 0 ]; do
3160 if echo $mnt_opts | grep -qw "$1"; then
3161 _notrun "mount option \"$1\" not allowed in this test"
3169 _exclude_scratch_mount_option "noatime"
3170 if [ "$FSTYP" == "nfs" ]; then
3171 _notrun "atime related mount options have no effect on NFS"
3177 _scratch_mkfs > /dev/null 2>&1
3178 _scratch_mount -o relatime || \
3179 _notrun "relatime not supported by the current kernel"
3185 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3186 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3189 _create_loop_device()
3192 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3196 _destroy_loop_device()
3199 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3202 _scale_fsstress_args()
3205 while [ $# -gt 0 ]; do
3207 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3208 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3209 *) args="$args $1" ;;
3217 # Return the logical block size if running on a block device,
3218 # else substitute the page size.
3220 _min_dio_alignment()
3224 if [ -b "$dev" ]; then
3225 blockdev --getss $dev
3227 $here/src/feature -s
3233 echo "# $@" >> $seqres.full 2>&1
3234 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3237 _require_test_symlinks()
3239 target=`mktemp -p $TEST_DIR`
3240 link=`mktemp -p $TEST_DIR -u`
3241 ln -s `basename $target` $link
3242 if [ "$?" -ne 0 ]; then
3244 _notrun "Require symlinks support"
3249 _require_test_fcntl_advisory_locks()
3251 [ "$FSTYP" != "cifs" ] && return 0
3252 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3253 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3254 _notrun "Require fcntl advisory locks support"
3257 _require_test_lsattr()
3259 testio=$(lsattr -d $TEST_DIR 2>&1)
3260 echo $testio | grep -q "Operation not supported" && \
3261 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3262 echo $testio | grep -q "Inappropriate ioctl for device" && \
3263 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3268 if [ -z "$1" ]; then
3269 echo "Usage: _require_chattr <attr>"
3274 touch $TEST_DIR/syscalltest
3275 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3277 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3278 if [ "$status" -ne 0 ]; then
3279 _notrun "file system doesn't support chattr +$attribute"
3281 cat $TEST_DIR/syscalltest.out >> $seqres.full
3282 rm -f $TEST_DIR/syscalltest.out
3287 if [ -z "$1" ]; then
3288 echo "Usage: _get_total_inode <mnt>"
3292 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3298 if [ -z "$1" ]; then
3299 echo "Usage: _get_used_inode <mnt>"
3303 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3307 _get_used_inode_percent()
3309 if [ -z "$1" ]; then
3310 echo "Usage: _get_used_inode_percent <mnt>"
3314 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3321 if [ -z "$1" ]; then
3322 echo "Usage: _get_free_inode <mnt>"
3326 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3330 # get the available space in bytes
3332 _get_available_space()
3334 if [ -z "$1" ]; then
3335 echo "Usage: _get_available_space <mnt>"
3339 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3340 echo $((avail_kb * 1024))
3343 # return device size in kb
3346 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3349 # check dmesg log for WARNING/Oops/etc.
3352 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3355 rm -f ${RESULT_DIR}/check_dmesg
3357 # default filter is a simple cat command, caller could provide a
3358 # customized filter and pass the name through the first argument, to
3359 # filter out intentional WARNINGs or Oopses
3362 # search the dmesg log of last run of $seqnum for possible failures
3363 # use sed \cregexpc address type, since $seqnum contains "/"
3364 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3365 tac | $filter >$seqres.dmesg
3366 egrep -q -e "kernel BUG at" \
3370 -e "possible recursive locking detected" \
3371 -e "Internal error" \
3372 -e "(INFO|ERR): suspicious RCU usage" \
3373 -e "INFO: possible circular locking dependency detected" \
3374 -e "general protection fault:" \
3375 -e "BUG .* remaining" \
3378 if [ $? -eq 0 ]; then
3379 _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3387 # don't check dmesg log after test
3388 _disable_dmesg_check()
3390 rm -f ${RESULT_DIR}/check_dmesg
3395 if [ "$iam" == new ]
3399 # make some further configuration checks here
3400 if [ "$TEST_DEV" = "" ]
3402 echo "common/rc: Error: \$TEST_DEV is not set"
3406 # if $TEST_DEV is not mounted, mount it now as XFS
3407 if [ -z "`_fs_type $TEST_DEV`" ]
3409 # $TEST_DEV is not mounted
3412 echo "common/rc: retrying test device mount with external set"
3413 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3416 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3422 # Sanity check that TEST partition is not mounted at another mount point
3423 # or as another fs type
3424 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3425 if [ -n "$SCRATCH_DEV" ]; then
3426 # Sanity check that SCRATCH partition is not mounted at another
3427 # mount point, because it is about to be unmounted and formatted.
3428 # Another fs type for scratch is fine (bye bye old fs type).
3429 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3430 [ $? -le 1 ] || exit 1
3433 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3434 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3435 export XFS_IO_PROG="$XFS_IO_PROG -F"
3437 # xfs_io -i option starts an idle thread for xfs_io.
3438 # With single threaded process, the file table is not shared
3439 # and file structs are not reference counted.
3440 # Spawning an idle thread can help detecting file struct
3441 # reference leaks, so we want to enable the option whenever
3443 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3444 export XFS_IO_PROG="$XFS_IO_PROG -i"
3446 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3447 # can change the UUID on v5 filesystems
3448 if [ "$FSTYP" == "xfs" ]; then
3450 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3451 # xfs_db will return 0 even if it can't generate a new uuid, so
3452 # check the output to make sure if it can change UUID of V5 xfs
3453 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3454 | grep -q "invalid UUID\|supported on V5 fs" \
3455 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3460 # get real device path name by following link
3464 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3465 _dev=`readlink -f "$_dev"`
3470 # basename of a device
3473 echo `basename $(_real_dev $1)`
3478 local _dev=`_real_dev $1`
3479 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3480 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3481 _maj=$(echo "ibase=16; $_maj" | bc)
3482 _min=$(echo "ibase=16; $_min" | bc)
3483 echo /sys/dev/block/$_maj:$_min
3486 # Get the minimum block size of a file. Usually this is the
3487 # minimum fs block size, but some filesystems (ocfs2) do block
3488 # mappings in larger units.
3489 _get_file_block_size()
3491 if [ -z $1 ] || [ ! -d $1 ]; then
3492 echo "Missing mount point argument for _get_file_block_size"
3495 if [ "$FSTYP" = "ocfs2" ]; then
3502 # Get the minimum block size of an fs.
3505 if [ -z $1 ] || [ ! -d $1 ]; then
3506 echo "Missing mount point argument for _get_block_size"
3514 echo $(getconf PAGE_SIZE)
3521 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3522 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3523 echo "$@" >>$seqres.full
3524 rm -f $TEST_DIR/junk
3525 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3526 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3534 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3536 # Only one argument is needed:
3537 # - attr: path name under /sys/fs/$FSTYP/DEV
3540 # _require_fs_sysfs error/fail_at_unmount
3544 local dname=$(_short_dev $TEST_DEV)
3546 if [ -z "$attr" -o -z "$dname" ];then
3547 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3550 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3551 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3557 $here/src/stat_test --check-statx ||
3558 _notrun "This test requires the statx system call"
3561 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3563 # All arguments are necessary, and in this order:
3564 # - dev: device name, e.g. $SCRATCH_DEV
3565 # - attr: path name under /sys/fs/$FSTYP/$dev
3566 # - content: the content of $attr
3569 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3570 _set_fs_sysfs_attr()
3578 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3579 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3582 local dname=$(_short_dev $dev)
3583 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3586 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3588 # All arguments are necessary, and in this order:
3589 # - dev: device name, e.g. $SCRATCH_DEV
3590 # - attr: path name under /sys/fs/$FSTYP/$dev
3593 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3594 _get_fs_sysfs_attr()
3599 if [ ! -b "$dev" -o -z "$attr" ];then
3600 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3603 local dname=$(_short_dev $dev)
3604 cat /sys/fs/${FSTYP}/${dname}/${attr}
3607 # Generic test for specific filesystem feature.
3608 # Currently only implemented to test overlayfs features.
3609 _require_scratch_feature()
3615 _require_scratch_overlay_feature ${feature}
3618 _fail "Test for feature '${feature}' of ${FSTYP} is not implemented"
3625 ################################################################################
3626 # make sure this script returns success