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"
173 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
177 if [ ! -z "$REPORT_LIST" ]; then
184 $MOUNT_PROG `_mount_ops_filter $*`
187 # Call _mount to do mount operation but also save mountpoint to
188 # MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
191 local mnt_point=${!#}
194 if [ $? -eq 0 ]; then
195 MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
201 # Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
202 # and return it to caller
205 local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
207 if [ -n "$last_mnt" ]; then
208 $UMOUNT_PROG $last_mnt
210 MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
213 # Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
216 if [ -n "$MOUNTED_POINT_STACK" ]; then
217 $UMOUNT_PROG $MOUNTED_POINT_STACK
219 MOUNTED_POINT_STACK=""
227 if [ "$FSTYP" != "xfs" ]; then
233 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
242 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
243 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
244 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
245 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
253 if [ "$FSTYP" != "xfs" ]; then
267 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
268 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
269 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
270 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
277 #get mount point to handle dmapi mtpt option correctly
279 [ $last_index -gt 0 ] && shift $last_index
282 # irix is fussy about how it is fed its mount options
283 # - multiple -o's are not allowed
284 # - no spaces between comma delimitered options
285 # the sed script replaces all -o's (except the first) with a comma
286 # not required for linux, but won't hurt
288 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
289 | sed -e 's/dmapi/dmi/' \
290 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
294 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
295 # with the safe set of scratch mount options (e.g. loop image may be
296 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
297 _common_dev_mount_options()
299 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
302 _overlay_basic_mount_options()
304 echo "-o lowerdir=$1/$OVL_LOWER,upperdir=$1/$OVL_UPPER,workdir=$1/$OVL_WORK"
307 _overlay_mount_options()
309 echo `_common_dev_mount_options` \
310 `_overlay_basic_mount_options $1` \
311 $OVERLAY_MOUNT_OPTIONS
314 _scratch_mount_options()
316 _scratch_options mount
318 if [ "$FSTYP" == "overlay" ]; then
319 echo `_overlay_mount_options $OVL_BASE_SCRATCH_MNT`
322 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
323 $SCRATCH_DEV $SCRATCH_MNT
330 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
333 xfs_info $dir | grep -q "ftype=1"
336 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
337 tune2fs -l $dev | grep -q filetype
340 local testfile=$dir/$$.ftype
342 # look for DT_UNKNOWN files
343 local unknowns=$(src/t_dir_type $dir u | wc -l)
345 # 0 unknowns is success
351 # helper function to do the actual overlayfs mount operation
352 _overlay_mount_dirs()
359 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
360 -o workdir=$workdir $*
367 mkdir -p $dir/$OVL_UPPER
368 mkdir -p $dir/$OVL_LOWER
369 mkdir -p $dir/$OVL_WORK
370 mkdir -p $dir/$OVL_MNT
373 # Given a base fs dir, set up overlay directories and mount on the given mnt.
374 # The dir is used as the mount device so it can be seen from df or mount
381 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
385 _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER \
386 $dir/$OVL_WORK $OVERLAY_MOUNT_OPTIONS \
387 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
390 _overlay_base_test_mount()
392 if [ -z "$OVL_BASE_TEST_DEV" -o -z "$OVL_BASE_TEST_DIR" ] || \
393 _check_mounted_on OVL_BASE_TEST_DEV $OVL_BASE_TEST_DEV \
394 OVL_BASE_TEST_DIR $OVL_BASE_TEST_DIR
396 # no base fs or already mounted
400 # base fs mounted but not on mount point
404 _mount $TEST_FS_MOUNT_OPTS \
405 $SELINUX_MOUNT_OPTIONS \
406 $OVL_BASE_TEST_DEV $OVL_BASE_TEST_DIR
409 _overlay_test_mount()
411 _overlay_base_test_mount && \
412 _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
415 _overlay_base_scratch_mount()
417 if [ -z "$OVL_BASE_SCRATCH_DEV" -o -z "$OVL_BASE_SCRATCH_MNT" ] || \
418 _check_mounted_on OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_DEV \
419 OVL_BASE_SCRATCH_MNT $OVL_BASE_SCRATCH_MNT
421 # no base fs or already mounted
425 # base fs mounted but not on mount point
429 _mount $OVL_BASE_MOUNT_OPTIONS \
430 $SELINUX_MOUNT_OPTIONS \
431 $OVL_BASE_SCRATCH_DEV $OVL_BASE_SCRATCH_MNT
434 _overlay_base_scratch_unmount()
436 [ -n "$OVL_BASE_SCRATCH_DEV" -a -n "$OVL_BASE_SCRATCH_MNT" ] || return 0
438 $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
441 _overlay_scratch_mount()
443 _overlay_base_scratch_mount && \
444 _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
447 _overlay_base_test_unmount()
449 [ -n "$OVL_BASE_TEST_DEV" -a -n "$OVL_BASE_TEST_DIR" ] || return 0
451 $UMOUNT_PROG $OVL_BASE_TEST_DIR
454 _overlay_test_unmount()
456 $UMOUNT_PROG $TEST_DIR
457 _overlay_base_test_unmount
460 _overlay_scratch_unmount()
462 $UMOUNT_PROG $SCRATCH_MNT
463 _overlay_base_scratch_unmount
468 if [ "$FSTYP" == "overlay" ]; then
469 _overlay_scratch_mount $*
472 _mount -t $FSTYP `_scratch_mount_options $*`
479 _overlay_scratch_unmount
482 $UMOUNT_PROG $SCRATCH_MNT
485 $UMOUNT_PROG $SCRATCH_DEV
494 if test -n "$opts"; then
495 mount -o "remount,$opts" $SCRATCH_MNT
499 _scratch_cycle_mount()
503 if [ "$FSTYP" = tmpfs ]; then
504 _scratch_remount "$opts"
507 if test -n "$opts"; then
511 _scratch_mount "$opts"
516 if [ "$FSTYP" == "overlay" ]; then
517 _overlay_test_mount $*
521 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
526 if [ "$FSTYP" == "overlay" ]; then
527 _overlay_test_unmount
529 $UMOUNT_PROG $TEST_DEV
535 if [ "$FSTYP" = tmpfs ]; then
542 _scratch_mkfs_options()
544 _scratch_options mkfs
545 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
548 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
549 # and user specified mkfs options, if that fails (due to conflicts between mkfs
550 # options), do a second mkfs with only user provided mkfs options.
552 # First param is the mkfs command without any mkfs options and device.
553 # Second param is the filter to remove unnecessary messages from mkfs stderr.
554 # Other extra mkfs options are followed.
560 local extra_mkfs_options=$*
564 # save mkfs output in case conflict means we need to run again.
565 # only the output for the mkfs that applies should be shown
566 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
567 2>$tmp.mkfserr 1>$tmp.mkfsstd
570 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
571 # $extra_mkfs_options
572 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
574 echo -n "** mkfs failed with extra mkfs options "
575 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
576 echo -n "** attempting to mkfs using only test $seq "
577 echo "options: $extra_mkfs_options **"
580 # running mkfs again. overwrite previous mkfs output files
581 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
582 2>$tmp.mkfserr 1>$tmp.mkfsstd
586 # output stored mkfs output, filtering unnecessary output from stderr
588 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
600 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
601 options="-l $SCRATCH_LOGDEV"
603 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
606 _setup_large_ext4_fs()
611 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
612 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
613 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
615 # Default free space in the FS is 50GB, but you can specify more via
616 # SCRATCH_DEV_EMPTY_SPACE
617 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
619 # mount the filesystem and create 16TB - 4KB files until we consume
620 # all the necessary space.
621 _scratch_mount 2>&1 >$tmp_dir/mnt.err
623 if [ $status -ne 0 ]; then
625 cat $tmp_dir/mnt.err >&2
626 rm -f $tmp_dir/mnt.err
629 rm -f $tmp_dir/mnt.err
631 file_size=$((16*1024*1024*1024*1024 - 4096))
633 while [ $space_to_consume -gt $file_size ]; do
636 -c "truncate $file_size" \
637 -c "falloc -k 0 $file_size" \
638 $SCRATCH_MNT/.use_space.$nfiles 2>&1
640 if [ $status -ne 0 ]; then
644 space_to_consume=$(( $space_to_consume - $file_size ))
645 nfiles=$(($nfiles + 1))
648 # consume the remaining space.
649 if [ $space_to_consume -gt 0 ]; then
651 -c "truncate $space_to_consume" \
652 -c "falloc -k 0 $space_to_consume" \
653 $SCRATCH_MNT/.use_space.$nfiles 2>&1
656 export NUM_SPACE_FILES=$nfiles
659 if [ $status -ne 0 ]; then
660 echo "large file prealloc failed"
661 cat $tmp_dir/mnt.err >&2
669 local mkfs_cmd="$MKFS_EXT4_PROG -F"
670 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
675 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
678 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
679 # manually parse the mkfs output to get the fs size in bytes
680 fs_size=`cat $tmp.mkfsstd | awk ' \
681 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
682 / inodes, / { blks = $3 } \
683 /reserved for the super user/ { resv = $1 } \
684 END { fssize = bs * blks - resv; print fssize }'`
686 _setup_large_ext4_fs $fs_size
690 # output mkfs stdout and stderr
704 # do nothing for cifs
707 # do nothing for ceph
710 # do nothing for overlay
713 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
716 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
719 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
722 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
734 # do nothing for overlay
737 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
740 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
743 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
744 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
748 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
749 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
753 if [ $? -ne 0 ]; then
754 # output stored mkfs output
755 cat $tmp_dir.mkfserr >&2
760 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
763 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
764 _scratch_cleanup_files()
768 # Avoid rm -rf /* if we messed up
769 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
770 _overlay_base_scratch_mount || return 1
771 rm -rf $OVL_BASE_SCRATCH_MNT/* || return 1
772 _overlay_mkdirs $OVL_BASE_SCRATCH_MNT
773 # leave base fs mouted so tests can setup lower/upper dir files
776 [ -n "$SCRATCH_MNT" ] || return 1
778 rm -rf $SCRATCH_MNT/*
791 nfs*|cifs|ceph|overlay)
792 # unable to re-create this fstyp, just remove all files in
793 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
794 # created in previous runs
795 _scratch_cleanup_files
799 # do nothing for tmpfs
803 _scratch_mkfs_ext4 $*
811 mkfs_cmd="$MKFS_UDF_PROG"
815 mkfs_cmd="$MKFS_BTRFS_PROG"
819 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
820 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
823 mkfs_cmd="$MKFS_F2FS_PROG"
827 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
828 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
831 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
836 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
840 # Helper function to get a spare or replace-target device from
841 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
842 # before _spare_dev_get(). Replace-target-device/Spare-device will
843 # be assigned to SPARE_DEV.
844 # As of now only one replace-target-device/spare-device can be
848 # _scratch_dev_pool_get() <ndevs>
852 # _scratch_dev_pool_put()
856 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
857 if [ $? -ne 0 ]; then
858 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
861 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
862 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
865 # Check if the spare is already assigned
866 typeset -p SPARE_DEV >/dev/null 2>&1
867 if [ $? -eq 0 ]; then
868 if [ ! -z "$SPARE_DEV" ]; then
869 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
873 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
874 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
876 if [ $ndevs -eq $config_ndevs ]; then
877 _notrun "All devs used no spare"
879 # Get a dev that is not used
880 local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
881 SPARE_DEV=${devs[@]:$ndevs:1}
887 typeset -p SPARE_DEV >/dev/null 2>&1
888 if [ $? -ne 0 ]; then
889 _fail "Bug: unset val, must call _spare_dev_get before its put"
892 if [ -z "$SPARE_DEV" ]; then
893 _fail "Bug: str empty, must call _spare_dev_get before its put"
900 # Generally test cases will have..
901 # _require_scratch_dev_pool X
902 # to make sure it has the enough scratch devices including
903 # replace-target and spare device. Now arg1 here is the
904 # required number of scratch devices by a-test-case excluding
905 # the replace-target and spare device. So this function will
906 # set SCRATCH_DEV_POOL to the specified number of devices.
909 # _scratch_dev_pool_get() <ndevs>
912 # _scratch_dev_pool_put()
914 _scratch_dev_pool_get()
916 if [ $# -ne 1 ]; then
917 _fail "Usage: _scratch_dev_pool_get ndevs"
921 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
922 local devs[]="( $SCRATCH_DEV_POOL )"
924 typeset -p config_ndevs >/dev/null 2>&1
925 if [ $? -ne 0 ]; then
926 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
929 if [ $config_ndevs -lt $test_ndevs ]; then
930 _notrun "Need at least test requested number of ndevs $test_ndevs"
933 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
934 export SCRATCH_DEV_POOL_SAVED
935 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
936 export SCRATCH_DEV_POOL
939 _scratch_dev_pool_put()
941 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
942 if [ $? -ne 0 ]; then
943 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
946 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
947 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
950 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
951 export SCRATCH_DEV_POOL_SAVED=""
958 # if dup profile is in mkfs options call _scratch_mkfs instead
959 # because dup profile only works with single device
960 if [[ "$*" =~ dup ]]; then
963 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
967 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
972 # Return the amount of free memory available on the system
975 free -b | grep ^Mem | awk '{print $4}'
978 # Create fs of certain size on scratch device
979 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
980 _scratch_mkfs_sized()
987 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
989 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
990 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
994 [ -n "$def_blksz" ] && blocksize=$def_blksz
995 [ -z "$blocksize" ] && blocksize=4096
999 if ! [[ $fssize =~ $re ]] ; then
1000 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
1002 if ! [[ $blocksize =~ $re ]] ; then
1003 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1006 blocks=`expr $fssize / $blocksize`
1008 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
1009 devsize=`blockdev --getsize64 $SCRATCH_DEV`
1010 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
1015 # don't override MKFS_OPTIONS that set a block size.
1016 echo $MKFS_OPTIONS |egrep -q "b?size="
1017 if [ $? -eq 0 ]; then
1018 _scratch_mkfs_xfs -d size=$fssize
1020 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
1023 ext2|ext3|ext4|ext4dev)
1024 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1027 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1030 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1034 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1035 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1038 # mkfs.resier4 requires size in KB as input for creating filesystem
1039 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1040 `expr $fssize / 1024`
1043 # mkfs.f2fs requires # of sectors as an input for the size
1044 sector_size=`blockdev --getss $SCRATCH_DEV`
1045 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1048 free_mem=`_free_memory_bytes`
1049 if [ "$free_mem" -lt "$fssize" ] ; then
1050 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1052 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1055 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1060 # Emulate an N-data-disk stripe w/ various stripe units
1061 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1062 _scratch_mkfs_geom()
1067 [ -z "$blocksize" ] && blocksize=4096
1069 let sunit_blocks=$sunit_bytes/$blocksize
1070 let swidth_blocks=$sunit_blocks*$swidth_mult
1074 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1077 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1080 _notrun "can't mkfs $FSTYP with geometry"
1086 # Create fs of certain blocksize on scratch device
1087 # _scratch_mkfs_blocksized blocksize
1088 _scratch_mkfs_blocksized()
1093 if ! [[ $blocksize =~ $re ]] ; then
1094 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1099 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1102 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1105 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1108 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1117 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1125 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1126 # errors found or errors were fixed) and nonzero otherwise; also spits out
1127 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1128 _repair_scratch_fs()
1132 _scratch_xfs_repair "$@" 2>&1
1134 if [ "$res" -ne 0 ]; then
1135 echo "xfs_repair returns $res; replay log?"
1138 if [ "$res" -gt 0 ]; then
1139 echo "mount returns $res; zap log?"
1140 _scratch_xfs_repair -L 2>&1
1141 echo "log zap returns $?"
1143 umount "$SCRATCH_MNT"
1145 _scratch_xfs_repair "$@" 2>&1
1148 if [ $res -ne 0 ]; then
1149 _dump_err2 "xfs_repair failed, err=$res"
1154 # Let's hope fsck -y suffices...
1155 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1162 _dump_err2 "fsck.$FSTYP failed, err=$res"
1174 echo "Usage: _get_pids_by_name process-name" 1>&2
1178 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1179 # HH:MM:SS before the psargs field, use this as the search anchor.
1181 # Matches with $1 (process-name) occur if the first psarg is $1
1182 # or ends in /$1 ... the matching uses sed's regular expressions,
1183 # so passing a regex into $1 will work.
1188 -e 's/[ ][ ]*/ /g' \
1191 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1192 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1195 # fix malloc libs output
1199 # filter out the Electric Fence notice
1202 if (defined $o && /^\s+Electric Fence/) {
1208 print $o if (defined $o);
1212 print $o if (defined $o);
1217 # _df_device : get an IRIX style df line for a given device
1219 # - returns "" if not mounted
1220 # - returns fs type in field two (ala IRIX)
1221 # - joins line together if split by fancy df formatting
1222 # - strips header etc
1229 echo "Usage: _df_device device" 1>&2
1233 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1234 # IPv6 server as a regular expression.
1235 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1236 ($1==what) && (NF==1) {
1250 # _df_dir : get an IRIX style df line for device where a directory resides
1252 # - returns fs type in field two (ala IRIX)
1253 # - joins line together if split by fancy df formatting
1254 # - strips header etc
1261 echo "Usage: _df_dir device" 1>&2
1265 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1281 # return percentage used disk space for mounted device
1287 echo "Usage: _used device" 1>&2
1291 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1294 # return the FS type of a mounted device
1300 echo "Usage: _fs_type device" 1>&2
1305 # The Linux kernel shows NFSv4 filesystems in df output as
1306 # filesystem type nfs4, although we mounted it as nfs earlier.
1307 # Fix the filesystem type up here so that the callers don't
1308 # have to bother with this quirk.
1310 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1313 # return the FS mount options of a mounted device
1315 # should write a version which just parses the output of mount for IRIX
1316 # compatibility, but since this isn't used at all, at the moment I'll leave
1323 echo "Usage: _fs_options device" 1>&2
1327 $AWK_PROG -v dev=$1 '
1328 match($1,dev) { print $4 }
1332 # returns device number if a file is a block device
1338 echo "Usage: _is_block_dev dev" 1>&2
1343 if [ -L "${_dev}" ]; then
1344 _dev=`readlink -f "${_dev}"`
1347 if [ -b "${_dev}" ]; then
1348 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1352 # Do a command, log it to $seqres.full, optionally test return status
1353 # and die if command fails. If called with one argument _do executes the
1354 # command, logs it, and returns its exit status. With two arguments _do
1355 # first prints the message passed in the first argument, and then "done"
1356 # or "fail" depending on the return status of the command passed in the
1357 # second argument. If the command fails and the variable _do_die_on_error
1358 # is set to "always" or the two argument form is used and _do_die_on_error
1359 # is set to "message_only" _do will print an error message to
1360 # $seqres.out and exit.
1364 if [ $# -eq 1 ]; then
1366 elif [ $# -eq 2 ]; then
1369 echo -n "$_note... "
1371 echo "Usage: _do [note] cmd" 1>&2
1375 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1376 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1377 cat $tmp._out | _fix_malloc >>$seqres.full
1378 if [ $# -eq 2 ]; then
1379 if [ $ret -eq 0 ]; then
1386 && [ "$_do_die_on_error" = "always" \
1387 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1389 [ $# -ne 2 ] && echo
1390 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1397 # bail out, setting up .notrun file. Need to kill the filesystem check files
1398 # here, otherwise they are set incorrectly for the next test.
1402 echo "$*" > $seqres.notrun
1403 echo "$seq not run: $*"
1404 rm -f ${RESULT_DIR}/require_test*
1405 rm -f ${RESULT_DIR}/require_scratch*
1411 # just plain bail out
1415 echo "$*" | tee -a $seqres.full
1416 echo "(see $seqres.full for details)"
1421 # tests whether $FSTYP is one of the supported filesystems for a test
1427 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1433 _notrun "not suitable for this filesystem type: $FSTYP"
1437 # tests whether $FSTYP is one of the supported OSes for a test
1443 if [ "$h" = "$HOSTOS" ]
1449 _notrun "not suitable for this OS: $HOSTOS"
1452 # check if a FS on a device is mounted
1453 # if so, verify that it is mounted on mount point
1454 # if fstype is given as argument, verify that it is also
1455 # mounted with correct fs type
1465 # find $dev as the source, and print result in "$dev $mnt" format
1466 local mount_rec=`findmnt -rnc -S $dev -o SOURCE,TARGET`
1467 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1469 # if it's mounted, make sure its on $mnt
1470 if [ "$mount_rec" != "$dev $mnt" ]; then
1471 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1472 echo "Already mounted result:"
1474 return 2 # 2 = mounted on wrong mnt
1477 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]; then
1478 echo "$devname=$dev is mounted but not a type $type filesystem"
1479 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1481 return 3 # 3 = mounted as wrong type
1483 return 0 # 0 = mounted as expected
1486 # this test needs a scratch partition - check we're ok & unmount it
1487 # No post-test check of the device is required. e.g. the test intentionally
1488 # finishes the test with the filesystem in a corrupt state
1489 _require_scratch_nocheck()
1493 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1494 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1495 _notrun "this test requires a valid \$SCRATCH_DEV"
1497 if [ ! -d "$SCRATCH_MNT" ]; then
1498 _notrun "this test requires a valid \$SCRATCH_MNT"
1502 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1503 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1504 _notrun "this test requires a valid \$SCRATCH_DEV"
1506 if [ ! -d "$SCRATCH_MNT" ]; then
1507 _notrun "this test requires a valid \$SCRATCH_MNT"
1511 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1512 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1514 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1515 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1516 # and we will create the mount point anyway on _overlay_mount
1517 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1518 _notrun "this test requires a valid \$SCRATCH_MNT"
1522 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1524 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1528 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1530 _notrun "this test requires a valid \$SCRATCH_DEV"
1532 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1534 _notrun "this test requires a valid \$SCRATCH_DEV"
1536 if [ ! -d "$SCRATCH_MNT" ]
1538 _notrun "this test requires a valid \$SCRATCH_MNT"
1543 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1545 [ $err -le 1 ] || exit 1
1548 # if it's mounted, unmount it
1549 if ! _scratch_unmount
1551 echo "failed to unmount $SCRATCH_DEV"
1555 rm -f ${RESULT_DIR}/require_scratch
1558 # we need the scratch device and it should be checked post test.
1561 _require_scratch_nocheck
1562 touch ${RESULT_DIR}/require_scratch
1566 # this test needs a test partition - check we're ok & mount it
1572 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1573 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1574 _notrun "this test requires a valid \$TEST_DEV"
1576 if [ ! -d "$TEST_DIR" ]; then
1577 _notrun "this test requires a valid \$TEST_DIR"
1581 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1582 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1583 _notrun "this test requires a valid \$TEST_DEV"
1585 if [ ! -d "$TEST_DIR" ]; then
1586 _notrun "this test requires a valid \$TEST_DIR"
1590 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1591 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1593 if [ ! -d "$TEST_DIR" ]; then
1594 _notrun "this test requires a valid \$TEST_DIR"
1598 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1600 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1604 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1606 _notrun "this test requires a valid \$TEST_DEV"
1608 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1610 _notrun "this test requires a valid \$TEST_DEV"
1612 if [ ! -d "$TEST_DIR" ]
1614 _notrun "this test requires a valid \$TEST_DIR"
1619 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1621 [ $err -le 1 ] || exit 1
1626 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1630 touch ${RESULT_DIR}/require_test
1633 # this test needs a logdev
1637 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1638 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1639 [ "$USE_EXTERNAL" != yes ] && \
1640 _notrun "This test requires USE_EXTERNAL to be enabled"
1642 # ensure its not mounted
1643 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1646 # this test requires loopback device support
1650 if [ "$HOSTOS" != "Linux" ]
1652 _notrun "This test requires linux for loopback device support"
1655 modprobe loop >/dev/null 2>&1
1656 if grep loop /proc/devices >/dev/null 2>&1
1660 _notrun "This test requires loopback device support"
1664 # this test requires ext2 filesystem support
1668 if [ "$HOSTOS" != "Linux" ]
1670 _notrun "This test requires linux for ext2 filesystem support"
1673 modprobe ext2 >/dev/null 2>&1
1674 if grep ext2 /proc/filesystems >/dev/null 2>&1
1678 _notrun "This test requires ext2 filesystem support"
1682 # this test requires tmpfs filesystem support
1686 modprobe tmpfs >/dev/null 2>&1
1687 grep -q tmpfs /proc/filesystems ||
1688 _notrun "this test requires tmpfs support"
1691 # this test requires that (large) loopback device files are not in use
1693 _require_no_large_scratch_dev()
1695 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1696 _notrun "Large filesystem testing in progress, skipped this test"
1699 # this test requires that a realtime subvolume is in use, and
1700 # that the kernel supports realtime as well.
1704 [ "$USE_EXTERNAL" = yes ] || \
1705 _notrun "External volumes not in use, skipped this test"
1706 [ "$SCRATCH_RTDEV" = "" ] && \
1707 _notrun "Realtime device required, skipped this test"
1710 # this test requires that a specified command (executable) exists
1711 # $1 - command, $2 - name for error message
1713 # Note: the command string might have parameters, so strip them before checking
1714 # whether it is executable.
1717 if [ $# -eq 2 ]; then
1719 elif [ $# -eq 1 ]; then
1722 _fail "usage: _require_command <command> [<name>]"
1725 _command=`echo "$1" | awk '{ print $1 }'`
1726 if [ ! -x "$_command" ]; then
1727 _notrun "$_name utility required, skipped this test"
1731 # this test requires the device to be valid block device
1733 _require_block_device()
1735 if [ -z "$1" ]; then
1736 echo "Usage: _require_block_device <dev>" 1>&2
1739 if [ "`_is_block_dev "$1"`" == "" ]; then
1740 _notrun "require $1 to be valid block disk"
1744 # brd based ram disks erase the device when they receive a flush command when no
1745 # active references are present. This causes problems for DM devices sitting on
1746 # top of brd devices as DM doesn't hold active references to the brd device.
1747 _require_sane_bdev_flush()
1749 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1750 if [ $? -eq 0 ]; then
1751 _notrun "This test requires a sane block device flush"
1755 # this test requires a specific device mapper target
1756 _require_dm_target()
1760 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1762 _require_block_device $SCRATCH_DEV
1763 _require_sane_bdev_flush $SCRATCH_DEV
1764 _require_command "$DMSETUP_PROG" dmsetup
1766 modprobe dm-$_target >/dev/null 2>&1
1768 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1769 if [ $? -ne 0 ]; then
1770 _notrun "This test requires dm $_target support"
1774 # this test requires the ext4 kernel support crc feature on scratch device
1776 _require_scratch_ext4_crc()
1778 _scratch_mkfs_ext4 >/dev/null 2>&1
1779 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1780 _scratch_mount >/dev/null 2>&1 \
1781 || _notrun "Kernel doesn't support metadata_csum feature"
1785 # Check the specified feature whether it is available in mkfs.ext4 or not.
1786 _require_ext4_mkfs_feature()
1789 local testfile=/tmp/$$.ext4_mkfs
1791 if [ -z "$feature" ]; then
1792 echo "Usage: _require_ext4_mkfs_feature feature"
1797 local result=$($MKFS_EXT4_PROG -F -O $feature -n $testfile 512m 2>&1)
1799 echo $result | grep -q "Invalid filesystem option" && \
1800 _notrun "mkfs.ext4 doesn't support $feature feature"
1803 # this test requires the ext4 kernel support bigalloc feature
1805 _require_ext4_bigalloc()
1807 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1808 _scratch_mount >/dev/null 2>&1 \
1809 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1813 # this test requires that external log/realtime devices are not in use
1815 _require_nonexternal()
1817 [ "$USE_EXTERNAL" = yes ] && \
1818 _notrun "External device testing in progress, skipped this test"
1821 # this test requires that a (specified) aio-dio executable exists
1822 # $1 - command (optional)
1828 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1829 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1831 AIO_TEST=src/aio-dio-regress/$1
1832 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1837 # this test requires that a test program exists under src/
1838 # $1 - command (require)
1840 _require_test_program()
1843 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1846 # run an aio-dio program
1852 echo "usage: _run_aiodio command_name" 2>&1
1858 local testtemp=$TEST_DIR/aio-testfile
1860 $AIO_TEST $testtemp 2>&1
1867 # this test requires y2038 sysfs switch and filesystem
1868 # timestamp ranges support.
1871 local device=${1:-$TEST_DEV}
1872 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
1874 if [ ! -e $sysfsdir ]; then
1875 _notrun "no kernel support for y2038 sysfs switch"
1879 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
1880 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
1881 _notrun "filesystem $FSTYP timestamp bounds are unknown"
1885 _filesystem_timestamp_range()
1887 device=${1:-$TEST_DEV}
1890 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
1891 echo "-2147483648 15032385535"
1893 echo "-2147483648 2147483647"
1898 echo "-2147483648 2147483647"
1904 echo "-2147483648 2147483647"
1912 # indicate whether YP/NIS is active or not
1917 dn=$(domainname 2>/dev/null)
1918 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
1922 # cat the password file
1926 [ $(_yp_active) -eq 0 ] && ypcat passwd
1930 # cat the group file
1934 [ $(_yp_active) -eq 0 ] && ypcat group
1938 # check for a user on the machine, fsgqa as default
1946 _cat_passwd | grep -q $qa_user
1947 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1948 echo /bin/true | su $qa_user
1949 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1952 # check for a group on the machine, fsgqa as default
1960 _cat_group | grep -q $qa_group
1961 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1967 s,.*Permission\sdenied.*,Permission denied,;
1968 s,.*no\saccess\sto\stty.*,,;
1969 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1976 if [ "$HOSTOS" == "IRIX" ]
1978 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1980 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
1984 _require_xfs_io_command()
1988 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
1995 testfile=$TEST_DIR/$$.xfs_io
1998 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
2001 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
2003 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
2004 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2005 -c "$command 4k 8k" $testfile 2>&1`
2008 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2009 -c "fiemap -v" $testfile 2>&1`
2012 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2014 echo $testio | egrep -q "invalid option|Is a directory" && \
2015 _notrun "xfs_io $command support is missing"
2018 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
2019 echo $testio | egrep -q "Inappropriate ioctl" && \
2020 _notrun "xfs_io $command support is missing"
2023 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
2024 # a new -C flag was introduced to execute one shot commands.
2025 # Check for -C flag support as an indication for the bug fix.
2026 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
2027 echo $testio | egrep -q "invalid option" && \
2028 _notrun "xfs_io $command support is missing"
2031 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
2034 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
2037 rm -f $testfile 2>&1 > /dev/null
2038 echo $testio | grep -q "not found" && \
2039 _notrun "xfs_io $command support is missing"
2040 echo $testio | grep -q "Operation not supported" && \
2041 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2042 echo $testio | grep -q "foreign file active" && \
2043 _notrun "xfs_io $command not supported on $FSTYP"
2045 test -z "$param" && return
2046 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2047 _notrun "xfs_io $command doesn't support $param"
2050 # check that kernel and filesystem support direct I/O
2053 if [ $FSTYP = "ext4" ] ; then
2054 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2055 _notrun "ext4 encryption doesn't support O_DIRECT"
2058 testfile=$TEST_DIR/$$.direct
2059 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2060 if [ $? -ne 0 ]; then
2061 _notrun "O_DIRECT is not supported"
2063 rm -f $testfile 2>&1 > /dev/null
2066 # Check that the filesystem supports swapfiles
2067 _require_scratch_swapfile()
2071 _scratch_mkfs >/dev/null
2074 # Minimum size for mkswap is 10 pages
2075 local size=$(($(get_page_size) * 10))
2077 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
2078 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
2079 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
2081 _notrun "swapfiles are not supported"
2084 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
2088 # Check that a fs has enough free space (in 1024b blocks)
2093 BLOCKS=$2 # in units of 1024
2094 let GB=$BLOCKS/1024/1024
2096 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2097 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2098 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2102 # Check if the filesystem supports sparse files.
2104 # Unfortunately there is no better way to do this than a manual black list.
2106 _require_sparse_files()
2110 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2119 #boot_params always present in debugfs
2120 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2123 _require_fail_make_request()
2125 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2126 || _notrun "$DEBUGFS_MNT/fail_make_request \
2127 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2131 # Check if the file system supports seek_data/hole
2133 _require_seek_data_hole()
2135 testfile=$TEST_DIR/$$.seek
2136 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2137 rm -f $testfile &>/dev/null
2138 echo $testseek | grep -q "Kernel does not support" && \
2139 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2144 _require_test_program "runas"
2149 "$here/src/runas" "$@"
2152 _require_richacl_prog()
2154 _require_command "$GETRICHACL_PROG" getrichacl
2155 _require_command "$SETRICHACL_PROG" setrichacl
2158 _require_scratch_richacl_xfs()
2160 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2161 || _notrun "mkfs.xfs doesn't have richacl feature"
2162 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2163 _scratch_mount >/dev/null 2>&1 \
2164 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2168 _require_scratch_richacl_ext4()
2170 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2171 || _notrun "can't mkfs $FSTYP with option -O richacl"
2172 _scratch_mount >/dev/null 2>&1 \
2173 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2177 _require_scratch_richacl_support()
2180 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2181 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2185 _require_scratch_richacl()
2188 xfs) _require_scratch_richacl_xfs
2190 ext4) _require_scratch_richacl_ext4
2193 _require_scratch_richacl_support
2195 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2200 _scratch_mkfs_richacl()
2203 xfs) _scratch_mkfs_xfs -m richacl=1
2205 ext4) _scratch_mkfs -O richacl
2213 # check that a FS on a device is mounted
2214 # if so, return mount point
2220 echo "Usage: _is_mounted device" 1>&2
2226 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2227 pattern { print $3 ; exit 0 }
2231 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2236 # remount a FS to a new mode (ro or rw)
2242 echo "Usage: _remount device ro/rw" 1>&2
2248 if ! mount -o remount,$mode $device
2250 echo "_remount: failed to remount filesystem on $device as $mode"
2255 # Run the appropriate repair/check on a filesystem
2257 # if the filesystem is mounted, it's either remounted ro before being
2258 # checked or it's unmounted and then remounted
2261 # If set, we remount ro instead of unmounting for fsck
2264 _umount_or_remount_ro()
2268 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2273 mountpoint=`_is_mounted $device`
2275 if [ $USE_REMOUNT -eq 0 ]; then
2276 $UMOUNT_PROG $device
2283 _mount_or_remount_rw()
2285 if [ $# -ne 3 ]; then
2286 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2293 if [ $USE_REMOUNT -eq 0 ]; then
2294 if [ "$FSTYP" != "overlay" ]; then
2295 _mount -t $FSTYP $mount_opts $device $mountpoint
2297 _overlay_mount $device $mountpoint
2299 if [ $? -ne 0 ]; then
2300 _dump_err "!!! failed to remount $device on $mountpoint"
2310 # Check a generic filesystem in no-op mode; this assumes that the
2311 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2312 # and that it will still return an errno for corruption in this mode.
2314 # Filesystems which don't support this will need to define their
2315 # own check routine.
2317 _check_generic_filesystem()
2321 # If type is set, we're mounted
2322 type=`_fs_type $device`
2325 if [ "$type" = "$FSTYP" ]
2328 mountpoint=`_umount_or_remount_ro $device`
2331 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2334 _log_err "_check_generic_filesystem: filesystem on $device is inconsistent"
2335 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2336 cat $tmp.fsck >>$seqres.full
2337 echo "*** end fsck.$FSTYP output" >>$seqres.full
2345 echo "*** mount output ***" >>$seqres.full
2346 _mount >>$seqres.full
2347 echo "*** end mount output" >>$seqres.full
2348 elif [ "$type" = "$FSTYP" ]
2351 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2355 if [ $ok -eq 0 ]; then
2357 if [ "$iam" != "check" ]; then
2366 # Filter the knowen errors the UDF Verifier reports.
2367 _udf_test_known_error_filter()
2369 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."
2373 _check_udf_filesystem()
2375 [ "$DISABLE_UDF_TEST" == "1" ] && return
2377 if [ $# -ne 1 -a $# -ne 2 ]
2379 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2383 if [ ! -x $here/src/udf_test ]
2385 echo "udf_test not installed, please download and build the Philips"
2386 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2387 echo "Then copy the udf_test binary to $here/src/."
2388 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2396 LAST_BLOCK=`expr \( $2 - 1 \)`
2397 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2400 rm -f $seqres.checkfs
2401 sleep 1 # Due to a problem with time stamps in udf_test
2402 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2403 _udf_test_known_error_filter | \
2404 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2405 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2416 # no way to check consistency for nfs
2419 # no way to check consistency for cifs
2422 # no way to check consistency for CephFS
2425 # no way to check consistency for overlay
2428 # do nothing for now
2431 _check_btrfs_filesystem $TEST_DEV
2434 # no way to check consistency for tmpfs
2437 _check_generic_filesystem $TEST_DEV
2445 [ $# -eq 1 ] && device=$1
2451 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2452 SCRATCH_LOG="$SCRATCH_LOGDEV"
2454 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2455 SCRATCH_RT="$SCRATCH_RTDEV"
2457 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2460 _check_udf_filesystem $device $udf_fsize
2463 # Don't know how to check an NFS filesystem, yet.
2466 # Don't know how to check a CIFS filesystem, yet.
2469 # no way to check consistency for CephFS
2472 # no way to check consistency for overlay
2475 _check_btrfs_filesystem $device
2478 # no way to check consistency for tmpfs
2481 _check_generic_filesystem $device
2486 _full_fstyp_details()
2488 [ -z "$FSTYP" ] && FSTYP=xfs
2489 if [ $FSTYP = xfs ]; then
2490 if [ -d /proc/fs/xfs ]; then
2491 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2492 FSTYP="$FSTYP (non-debug)"
2493 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2494 FSTYP="$FSTYP (debug)"
2497 if uname -a | grep -qi 'debug'; then
2498 FSTYP="$FSTYP (debug)"
2500 FSTYP="$FSTYP (non-debug)"
2507 _full_platform_details()
2513 echo "$os/$platform $host $kernel"
2518 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2520 elif [ "`uname`" == "Linux" ]; then
2523 echo Unknown operating system: `uname`
2528 _link_out_file_named()
2533 my $feature, $result, $suffix, $opts;
2535 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2536 $feathash{$feature} = 1;
2538 $result = "default";
2543 ($opts, $suffix) = split(/ *: */);
2544 foreach my $opt (split(/,/, $opts)) {
2545 if (!exists($feathash{$opt})) {
2559 ln -fs $SRC.$SUFFIX $1
2564 if [ $# -eq 0 ]; then
2565 FEATURES="$(_get_os_name)"
2566 if [ -n "$MOUNT_OPTIONS" ]; then
2567 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2573 _link_out_file_named $seqfull.out "$FEATURES"
2582 # convert urandom incompressible data to compressible text data
2585 od /dev/urandom | dd iflag=fullblock ${*}
2588 #takes files, randomdata
2596 if [ $size -gt 0 ]; then
2597 if [ "$2" == "false" ]; then
2598 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2599 elif [ "$2" == "comp" ]; then
2600 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2602 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2609 # takes dirname, depth, randomdata
2612 dirname=$1; depth=$2; randomdata=$3
2613 mkdir $dirname || die "mkdir $dirname failed"
2616 _nfiles $files $randomdata # files for this dir and data type
2618 [ $depth -eq 0 ] && return
2619 let deep=$depth-1 # go 1 down
2621 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2624 while [ $d -lt $dirs ]
2626 _descend d$d $deep &
2632 # Populate a filesystem with inodes for performance experiments
2634 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2639 dirs=5 # ndirs in each subdir till leaves
2640 size=0 # sizeof files in K
2641 files=100 # num files in _each_ subdir
2642 depth=2 # depth of tree from root to leaves
2644 root=root # path of initial root of directory tree
2645 randomdata=false # -x data type urandom, zero or compressible
2648 while getopts "d:f:n:r:s:v:x:c" c
2657 x) randomdata=true;;
2658 c) randomdata=comp;;
2662 _descend $root $depth $randomdata
2667 [ $verbose = true ] && echo done
2670 # query whether the given file has the given inode flag set
2677 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2683 # query the given files extsize allocator hint in bytes (if any)
2690 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2691 awk '/^xattr.extsize =/ { print $3 }'`
2692 [ -z "$blocks" ] && blocks="0"
2696 # scratch_dev_pool should contain the disks pool for the btrfs raid
2697 _require_scratch_dev_pool()
2702 if [ -z "$SCRATCH_DEV_POOL" ]; then
2703 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2706 if [ -z "$1" ]; then
2712 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2716 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2717 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2721 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2725 for i in $SCRATCH_DEV_POOL; do
2726 if [ "`_is_block_dev "$i"`" = "" ]; then
2727 _notrun "this test requires valid block disk $i"
2729 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2730 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2732 if _mount | grep -q $i; then
2733 if ! $UMOUNT_PROG $i; then
2734 echo "failed to unmount $i - aborting"
2738 # to help better debug when something fails, we remove
2739 # traces of previous btrfs FS on the dev.
2740 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2744 # ensure devices in SCRATCH_DEV_POOL are of the same size
2745 # must be called after _require_scratch_dev_pool
2746 _require_scratch_dev_pool_equal_size()
2752 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2753 _size=`_get_device_size $SCRATCH_DEV`
2754 for _dev in $SCRATCH_DEV_POOL; do
2755 _newsize=`_get_device_size $_dev`
2756 if [ $_size -ne $_newsize ]; then
2757 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2762 # We will check if the device is deletable
2763 _require_deletable_scratch_dev_pool()
2767 for i in $SCRATCH_DEV_POOL; do
2768 x=`echo $i | cut -d"/" -f 3`
2769 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2770 _notrun "$i is a device which is not deletable"
2775 # Check that fio is present, and it is able to execute given jobfile
2780 _require_command "$FIO_PROG" fio
2781 if [ -z "$1" ]; then
2785 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2786 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2789 # Does freeze work on this fs?
2792 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2794 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2795 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2798 # Does shutdown work on this fs?
2799 _require_scratch_shutdown()
2801 [ -x src/godown ] || _notrun "src/godown executable not found"
2803 _scratch_mkfs > /dev/null 2>&1
2805 src/godown -f $SCRATCH_MNT 2>&1 \
2806 || _notrun "$FSTYP does not support shutdown"
2810 # Does dax mount option work on this dev/fs?
2811 _require_scratch_dax()
2814 _scratch_mkfs > /dev/null 2>&1
2815 _scratch_mount -o dax
2816 # Check options to be sure. XFS ignores dax option
2817 # and goes on if dev underneath does not support dax.
2818 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
2819 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
2823 # Does norecovery support by this fs?
2824 _require_norecovery()
2826 _scratch_mount -o ro,norecovery || \
2827 _notrun "$FSTYP does not support norecovery"
2831 # Does this filesystem support metadata journaling?
2832 # We exclude ones here that don't; otherwise we assume that it does, so the
2833 # test will run, fail, and motivate someone to update this test for a new
2836 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2837 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2839 _require_metadata_journaling()
2849 _notrun "$FSTYP does not support metadata journaling"
2852 # ext4 could be mkfs'd without a journal...
2854 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2855 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2856 # ext4 might not load a journal
2857 _exclude_scratch_mount_option "noload"
2860 # by default we pass; if you need to, add your fs above!
2865 # Does fiemap support?
2868 _require_xfs_io_command "fiemap"
2873 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2878 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2881 # arg 1 is dev to remove and is output of the below eg.
2882 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2888 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2890 stat $disk > /dev/null 2>&1
2891 while [ $? -eq 0 ]; do
2893 stat $disk > /dev/null 2>&1
2897 # arg 1 is dev to add and is output of the below eg.
2898 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2903 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2904 h=`echo ${1} | cut -d":" -f 1`
2905 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2907 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2909 # ensure the device comes online
2911 for i in `seq 1 10`; do
2912 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2913 dev=`ls /sys/class/scsi_device/${1}/device/block`
2914 for j in `seq 1 10`;
2916 stat /dev/$dev > /dev/null 2>&1
2917 if [ $? -eq 0 ]; then
2928 if [ $dev_back_oneline -eq 0 ]; then
2929 echo "/dev/$dev online failed" >> $seqres.full
2931 echo "/dev/$dev is back online" >> $seqres.full
2937 if [ -z "$FSTRIM_PROG" ]; then
2938 _notrun "This test requires fstrim utility."
2942 _require_batched_discard()
2944 if [ $# -ne 1 ]; then
2945 echo "Usage: _require_batched_discard mnt_point" 1>&2
2949 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2954 if [ -z "$DUMPE2FS_PROG" ]; then
2955 _notrun "This test requires dumpe2fs utility."
2961 if [ ! -e /proc/self/uid_map ]; then
2962 _notrun "This test requires procfs uid_map support."
2964 if [ ! -e /proc/self/gid_map ]; then
2965 _notrun "This test requires procfs gid_map support."
2971 FSSUM_PROG=$here/src/fssum
2972 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2977 CLONER_PROG=$here/src/cloner
2978 [ -x $CLONER_PROG ] || \
2979 _notrun "cloner binary not present at $CLONER_PROG"
2982 # Normalize mount options from global $MOUNT_OPTIONS
2983 # Convert options like "-o opt1,opt2 -oopt3" to
2985 _normalize_mount_options()
2987 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
2990 # skip test if MOUNT_OPTIONS contains the given strings
2991 _exclude_scratch_mount_option()
2993 local mnt_opts=$(_normalize_mount_options)
2995 while [ $# -gt 0 ]; do
2996 if echo $mnt_opts | grep -qw "$1"; then
2997 _notrun "mount option \"$1\" not allowed in this test"
3005 _exclude_scratch_mount_option "noatime"
3006 if [ "$FSTYP" == "nfs" ]; then
3007 _notrun "atime related mount options have no effect on NFS"
3013 _scratch_mkfs > /dev/null 2>&1
3014 _scratch_mount -o relatime || \
3015 _notrun "relatime not supported by the current kernel"
3021 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3022 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3025 _create_loop_device()
3028 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3032 _destroy_loop_device()
3035 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3038 _scale_fsstress_args()
3041 while [ $# -gt 0 ]; do
3043 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3044 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3045 *) args="$args $1" ;;
3053 # Return the logical block size if running on a block device,
3054 # else substitute the page size.
3056 _min_dio_alignment()
3060 if [ -b "$dev" ]; then
3061 blockdev --getss $dev
3063 $here/src/feature -s
3069 echo "# $@" >> $seqres.full 2>&1
3070 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3073 _require_test_symlinks()
3075 # IRIX UDF does not support symlinks
3076 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3077 _notrun "Require symlinks support"
3078 target=`mktemp -p $TEST_DIR`
3079 link=`mktemp -p $TEST_DIR -u`
3080 ln -s `basename $target` $link
3081 if [ "$?" -ne 0 ]; then
3083 _notrun "Require symlinks support"
3088 _require_test_fcntl_advisory_locks()
3090 [ "$FSTYP" != "cifs" ] && return 0
3091 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3092 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3093 _notrun "Require fcntl advisory locks support"
3096 _require_test_lsattr()
3098 testio=$(lsattr -d $TEST_DIR 2>&1)
3099 echo $testio | grep -q "Operation not supported" && \
3100 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3101 echo $testio | grep -q "Inappropriate ioctl for device" && \
3102 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3109 touch $TEST_DIR/syscalltest
3110 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3112 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3113 if [ "$status" -ne 0 ]; then
3114 _notrun "file system doesn't support chattr +$attribute"
3116 cat $TEST_DIR/syscalltest.out >> $seqres.full
3118 rm -f $TEST_DIR/syscalltest.out
3123 if [ -z "$1" ]; then
3124 echo "Usage: _get_total_inode <mnt>"
3128 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3134 if [ -z "$1" ]; then
3135 echo "Usage: _get_used_inode <mnt>"
3139 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3143 _get_used_inode_percent()
3145 if [ -z "$1" ]; then
3146 echo "Usage: _get_used_inode_percent <mnt>"
3150 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3157 if [ -z "$1" ]; then
3158 echo "Usage: _get_free_inode <mnt>"
3162 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3166 # get the available space in bytes
3168 _get_available_space()
3170 if [ -z "$1" ]; then
3171 echo "Usage: _get_available_space <mnt>"
3175 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3176 echo $((avail_kb * 1024))
3179 # return device size in kb
3182 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3185 # check dmesg log for WARNING/Oops/etc.
3188 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3191 rm -f ${RESULT_DIR}/check_dmesg
3193 # default filter is a simple cat command, caller could provide a
3194 # customized filter and pass the name through the first argument, to
3195 # filter out intentional WARNINGs or Oopses
3198 # search the dmesg log of last run of $seqnum for possible failures
3199 # use sed \cregexpc address type, since $seqnum contains "/"
3200 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3201 tac | $filter >$seqres.dmesg
3202 grep -q -e "kernel BUG at" \
3206 -e "possible recursive locking detected" \
3207 -e "Internal error" \
3208 -e "INFO: suspicious RCU usage" \
3209 -e "INFO: possible circular locking dependency detected" \
3210 -e "general protection fault:" \
3212 if [ $? -eq 0 ]; then
3213 _dump_err "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3221 # don't check dmesg log after test
3222 _disable_dmesg_check()
3224 rm -f ${RESULT_DIR}/check_dmesg
3229 if [ "$iam" == new ]
3233 # make some further configuration checks here
3234 if [ "$TEST_DEV" = "" ]
3236 echo "common/rc: Error: \$TEST_DEV is not set"
3240 # if $TEST_DEV is not mounted, mount it now as XFS
3241 if [ -z "`_fs_type $TEST_DEV`" ]
3243 # $TEST_DEV is not mounted
3246 echo "common/rc: retrying test device mount with external set"
3247 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3250 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3256 # Sanity check that TEST partition is not mounted at another mount point
3257 # or as another fs type
3258 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3259 if [ -n "$SCRATCH_DEV" ]; then
3260 # Sanity check that SCRATCH partition is not mounted at another
3261 # mount point, because it is about to be unmounted and formatted.
3262 # Another fs type for scratch is fine (bye bye old fs type).
3263 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3264 [ $? -le 1 ] || exit 1
3267 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3268 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3269 export XFS_IO_PROG="$XFS_IO_PROG -F"
3271 # xfs_io -i option starts an idle thread for xfs_io.
3272 # With single threaded process, the file table is not shared
3273 # and file structs are not reference counted.
3274 # Spawning an idle thread can help detecting file struct
3275 # reference leaks, so we want to enable the option whenever
3277 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3278 export XFS_IO_PROG="$XFS_IO_PROG -i"
3280 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3281 # can change the UUID on v5 filesystems
3282 if [ "$FSTYP" == "xfs" ]; then
3284 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3285 # xfs_db will return 0 even if it can't generate a new uuid, so
3286 # check the output to make sure if it can change UUID of V5 xfs
3287 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3288 | grep -q "invalid UUID\|supported on V5 fs" \
3289 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3294 # get real device path name by following link
3298 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3299 _dev=`readlink -f "$_dev"`
3304 # basename of a device
3307 echo `basename $(_real_dev $1)`
3312 local _dev=`_real_dev $1`
3313 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3314 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3315 _maj=$(echo "ibase=16; $_maj" | bc)
3316 _min=$(echo "ibase=16; $_min" | bc)
3317 echo /sys/dev/block/$_maj:$_min
3320 # Get the minimum block size of a file. Usually this is the
3321 # minimum fs block size, but some filesystems (ocfs2) do block
3322 # mappings in larger units.
3323 _get_file_block_size()
3325 if [ -z $1 ] || [ ! -d $1 ]; then
3326 echo "Missing mount point argument for _get_file_block_size"
3329 if [ "$FSTYP" = "ocfs2" ]; then
3336 # Get the minimum block size of an fs.
3339 if [ -z $1 ] || [ ! -d $1 ]; then
3340 echo "Missing mount point argument for _get_block_size"
3348 echo $(getconf PAGE_SIZE)
3355 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3356 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3357 echo "$@" >>$seqres.full
3358 rm -f $TEST_DIR/junk
3359 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3360 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3366 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3368 # Only one argument is needed:
3369 # - attr: path name under /sys/fs/$FSTYP/DEV
3372 # _require_fs_sysfs error/fail_at_unmount
3376 local dname=$(_short_dev $TEST_DEV)
3378 if [ -z "$attr" -o -z "$dname" ];then
3379 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3382 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3383 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3387 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3389 # All arguments are necessary, and in this order:
3390 # - dev: device name, e.g. $SCRATCH_DEV
3391 # - attr: path name under /sys/fs/$FSTYP/$dev
3392 # - content: the content of $attr
3395 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3396 _set_fs_sysfs_attr()
3404 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3405 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3408 local dname=$(_short_dev $dev)
3409 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3412 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3414 # All arguments are necessary, and in this order:
3415 # - dev: device name, e.g. $SCRATCH_DEV
3416 # - attr: path name under /sys/fs/$FSTYP/$dev
3419 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3420 _get_fs_sysfs_attr()
3425 if [ ! -b "$dev" -o -z "$attr" ];then
3426 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3429 local dname=$(_short_dev $dev)
3430 cat /sys/fs/${FSTYP}/${dname}/${attr}
3436 ################################################################################
3437 # make sure this script returns success