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"
118 # make sure we have a standard umask
121 # check for correct setup and source the $FSTYP specific functions now
124 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
125 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
126 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
127 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
132 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
135 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
140 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
143 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
154 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
160 $MOUNT_PROG `_mount_ops_filter $*`
163 # Call _mount to do mount operation but also save mountpoint to
164 # MOUNTED_POINT_STACK. Note that the mount point must be the last parameter
167 local mnt_point=${!#}
170 if [ $? -eq 0 ]; then
171 MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
177 # Unmount the last mounted mountpoint in MOUNTED_POINT_STACK
178 # and return it to caller
181 local last_mnt=`echo $MOUNTED_POINT_STACK | awk '{print $1}'`
183 if [ -n "$last_mnt" ]; then
184 $UMOUNT_PROG $last_mnt
186 MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | cut -d\ -f2-`
189 # Unmount all mountpoints in MOUNTED_POINT_STACK and clear the stack
192 if [ -n "$MOUNTED_POINT_STACK" ]; then
193 $UMOUNT_PROG $MOUNTED_POINT_STACK
195 MOUNTED_POINT_STACK=""
203 if [ "$FSTYP" != "xfs" ]; then
209 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
218 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
219 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
220 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
221 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
229 if [ "$FSTYP" != "xfs" ]; then
243 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
244 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
245 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
246 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
253 #get mount point to handle dmapi mtpt option correctly
255 [ $last_index -gt 0 ] && shift $last_index
258 # irix is fussy about how it is fed its mount options
259 # - multiple -o's are not allowed
260 # - no spaces between comma delimitered options
261 # the sed script replaces all -o's (except the first) with a comma
262 # not required for linux, but won't hurt
264 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
265 | sed -e 's/dmapi/dmi/' \
266 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
270 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
271 # with the safe set of scratch mount options (e.g. loop image may be
272 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
273 _common_dev_mount_options()
275 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
278 _overlay_basic_mount_options()
280 echo "-o lowerdir=$1/$OVL_LOWER,upperdir=$1/$OVL_UPPER,workdir=$1/$OVL_WORK"
283 _overlay_mount_options()
285 echo `_common_dev_mount_options` \
286 `_overlay_basic_mount_options $1` \
287 $OVERLAY_MOUNT_OPTIONS
290 _scratch_mount_options()
292 _scratch_options mount
294 if [ "$FSTYP" == "overlay" ]; then
295 echo `_overlay_mount_options $OVL_BASE_SCRATCH_MNT`
298 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
299 $SCRATCH_DEV $SCRATCH_MNT
306 local fstyp=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $2}'`
309 xfs_info $dir | grep -q "ftype=1"
312 local dev=`$DF_PROG $dir | tail -1 | $AWK_PROG '{print $1}'`
313 tune2fs -l $dev | grep -q filetype
316 local testfile=$dir/$$.ftype
318 # look for DT_UNKNOWN files
319 local unknowns=$(src/t_dir_type $dir u | wc -l)
321 # 0 unknowns is success
327 # helper function to do the actual overlayfs mount operation
328 _overlay_mount_dirs()
335 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
336 -o workdir=$workdir $*
343 mkdir -p $dir/$OVL_UPPER
344 mkdir -p $dir/$OVL_LOWER
345 mkdir -p $dir/$OVL_WORK
346 mkdir -p $dir/$OVL_MNT
349 # Given a base fs dir, set up overlay directories and mount on the given mnt.
350 # The dir is used as the mount device so it can be seen from df or mount
357 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
361 _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER \
362 $dir/$OVL_WORK $OVERLAY_MOUNT_OPTIONS \
363 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
366 _overlay_test_mount()
368 _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
371 _overlay_scratch_mount()
373 _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
376 _overlay_test_unmount()
378 $UMOUNT_PROG $TEST_DIR
381 _overlay_scratch_unmount()
383 $UMOUNT_PROG $SCRATCH_MNT
388 if [ "$FSTYP" == "overlay" ]; then
389 _overlay_scratch_mount $*
392 _mount -t $FSTYP `_scratch_mount_options $*`
399 _overlay_scratch_unmount
402 $UMOUNT_PROG $SCRATCH_MNT
405 $UMOUNT_PROG $SCRATCH_DEV
414 if test -n "$opts"; then
415 mount -o "remount,$opts" $SCRATCH_MNT
419 _scratch_cycle_mount()
423 if [ "$FSTYP" = tmpfs ]; then
424 _scratch_remount "$opts"
427 if test -n "$opts"; then
431 _scratch_mount "$opts"
436 if [ "$FSTYP" == "overlay" ]; then
437 _overlay_test_mount $*
441 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
446 if [ "$FSTYP" == "overlay" ]; then
447 _overlay_test_unmount
449 $UMOUNT_PROG $TEST_DEV
455 if [ "$FSTYP" = tmpfs ]; then
462 _scratch_mkfs_options()
464 _scratch_options mkfs
465 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
468 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
469 # and user specified mkfs options, if that fails (due to conflicts between mkfs
470 # options), do a second mkfs with only user provided mkfs options.
472 # First param is the mkfs command without any mkfs options and device.
473 # Second param is the filter to remove unnecessary messages from mkfs stderr.
474 # Other extra mkfs options are followed.
480 local extra_mkfs_options=$*
484 # save mkfs output in case conflict means we need to run again.
485 # only the output for the mkfs that applies should be shown
486 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
487 2>$tmp.mkfserr 1>$tmp.mkfsstd
490 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
491 # $extra_mkfs_options
492 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
494 echo -n "** mkfs failed with extra mkfs options "
495 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
496 echo -n "** attempting to mkfs using only test $seq "
497 echo "options: $extra_mkfs_options **"
500 # running mkfs again. overwrite previous mkfs output files
501 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
502 2>$tmp.mkfserr 1>$tmp.mkfsstd
506 # output stored mkfs output, filtering unnecessary output from stderr
508 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
520 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
521 options="-l $SCRATCH_LOGDEV"
523 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
526 _setup_large_ext4_fs()
531 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
532 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
533 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
535 # Default free space in the FS is 50GB, but you can specify more via
536 # SCRATCH_DEV_EMPTY_SPACE
537 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
539 # mount the filesystem and create 16TB - 4KB files until we consume
540 # all the necessary space.
541 _scratch_mount 2>&1 >$tmp_dir/mnt.err
543 if [ $status -ne 0 ]; then
545 cat $tmp_dir/mnt.err >&2
546 rm -f $tmp_dir/mnt.err
549 rm -f $tmp_dir/mnt.err
551 file_size=$((16*1024*1024*1024*1024 - 4096))
553 while [ $space_to_consume -gt $file_size ]; do
556 -c "truncate $file_size" \
557 -c "falloc -k 0 $file_size" \
558 $SCRATCH_MNT/.use_space.$nfiles 2>&1
560 if [ $status -ne 0 ]; then
564 space_to_consume=$(( $space_to_consume - $file_size ))
565 nfiles=$(($nfiles + 1))
568 # consume the remaining space.
569 if [ $space_to_consume -gt 0 ]; then
571 -c "truncate $space_to_consume" \
572 -c "falloc -k 0 $space_to_consume" \
573 $SCRATCH_MNT/.use_space.$nfiles 2>&1
576 export NUM_SPACE_FILES=$nfiles
579 if [ $status -ne 0 ]; then
580 echo "large file prealloc failed"
581 cat $tmp_dir/mnt.err >&2
589 local mkfs_cmd="$MKFS_EXT4_PROG -F"
590 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
595 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
598 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
599 # manually parse the mkfs output to get the fs size in bytes
600 fs_size=`cat $tmp.mkfsstd | awk ' \
601 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
602 / inodes, / { blks = $3 } \
603 /reserved for the super user/ { resv = $1 } \
604 END { fssize = bs * blks - resv; print fssize }'`
606 _setup_large_ext4_fs $fs_size
610 # output mkfs stdout and stderr
624 # do nothing for cifs
627 # do nothing for ceph
630 # do nothing for overlay
633 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
636 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
639 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
642 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
654 # do nothing for overlay
657 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
660 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
663 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
664 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
668 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
669 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
673 if [ $? -ne 0 ]; then
674 # output stored mkfs output
675 cat $tmp_dir.mkfserr >&2
680 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
683 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
684 _scratch_cleanup_files()
688 # Avoid rm -rf /* if we messed up
689 [ -n "$OVL_BASE_SCRATCH_MNT" ] || return 1
690 rm -rf $OVL_BASE_SCRATCH_MNT/*
693 [ -n "$SCRATCH_MNT" ] || return 1
695 rm -rf $SCRATCH_MNT/*
708 nfs*|cifs|ceph|overlay)
709 # unable to re-create this fstyp, just remove all files in
710 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
711 # created in previous runs
712 _scratch_cleanup_files
716 # do nothing for tmpfs
720 _scratch_mkfs_ext4 $*
728 mkfs_cmd="$MKFS_UDF_PROG"
732 mkfs_cmd="$MKFS_BTRFS_PROG"
736 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
737 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
740 mkfs_cmd="$MKFS_F2FS_PROG"
744 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
745 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
748 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
753 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
757 # Helper function to get a spare or replace-target device from
758 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
759 # before _spare_dev_get(). Replace-target-device/Spare-device will
760 # be assigned to SPARE_DEV.
761 # As of now only one replace-target-device/spare-device can be
765 # _scratch_dev_pool_get() <ndevs>
769 # _scratch_dev_pool_put()
773 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
774 if [ $? -ne 0 ]; then
775 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
778 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
779 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
782 # Check if the spare is already assigned
783 typeset -p SPARE_DEV >/dev/null 2>&1
784 if [ $? -eq 0 ]; then
785 if [ ! -z "$SPARE_DEV" ]; then
786 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
790 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
791 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
793 if [ $ndevs -eq $config_ndevs ]; then
794 _notrun "All devs used no spare"
796 # Get a dev that is not used
797 local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
798 SPARE_DEV=${devs[@]:$ndevs:1}
804 typeset -p SPARE_DEV >/dev/null 2>&1
805 if [ $? -ne 0 ]; then
806 _fail "Bug: unset val, must call _spare_dev_get before its put"
809 if [ -z "$SPARE_DEV" ]; then
810 _fail "Bug: str empty, must call _spare_dev_get before its put"
817 # Generally test cases will have..
818 # _require_scratch_dev_pool X
819 # to make sure it has the enough scratch devices including
820 # replace-target and spare device. Now arg1 here is the
821 # required number of scratch devices by a-test-case excluding
822 # the replace-target and spare device. So this function will
823 # set SCRATCH_DEV_POOL to the specified number of devices.
826 # _scratch_dev_pool_get() <ndevs>
829 # _scratch_dev_pool_put()
831 _scratch_dev_pool_get()
833 if [ $# -ne 1 ]; then
834 _fail "Usage: _scratch_dev_pool_get ndevs"
838 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
839 local devs[]="( $SCRATCH_DEV_POOL )"
841 typeset -p config_ndevs >/dev/null 2>&1
842 if [ $? -ne 0 ]; then
843 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
846 if [ $config_ndevs -lt $test_ndevs ]; then
847 _notrun "Need at least test requested number of ndevs $test_ndevs"
850 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
851 export SCRATCH_DEV_POOL_SAVED
852 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
853 export SCRATCH_DEV_POOL
856 _scratch_dev_pool_put()
858 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
859 if [ $? -ne 0 ]; then
860 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
863 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
864 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
867 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
868 export SCRATCH_DEV_POOL_SAVED=""
875 # if dup profile is in mkfs options call _scratch_mkfs instead
876 # because dup profile only works with single device
877 if [[ "$*" =~ dup ]]; then
880 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
884 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
889 # Return the amount of free memory available on the system
892 free -b | grep ^Mem | awk '{print $4}'
895 # Create fs of certain size on scratch device
896 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
897 _scratch_mkfs_sized()
904 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
906 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
907 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
911 [ -n "$def_blksz" ] && blocksize=$def_blksz
912 [ -z "$blocksize" ] && blocksize=4096
916 if ! [[ $fssize =~ $re ]] ; then
917 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
919 if ! [[ $blocksize =~ $re ]] ; then
920 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
923 blocks=`expr $fssize / $blocksize`
925 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
926 devsize=`blockdev --getsize64 $SCRATCH_DEV`
927 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
932 # don't override MKFS_OPTIONS that set a block size.
933 echo $MKFS_OPTIONS |egrep -q "b?size="
934 if [ $? -eq 0 ]; then
935 _scratch_mkfs_xfs -d size=$fssize
937 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
940 ext2|ext3|ext4|ext4dev)
941 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
944 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
947 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
951 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
952 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
955 # mkfs.resier4 requires size in KB as input for creating filesystem
956 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
957 `expr $fssize / 1024`
960 # mkfs.f2fs requires # of sectors as an input for the size
961 sector_size=`blockdev --getss $SCRATCH_DEV`
962 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
965 free_mem=`_free_memory_bytes`
966 if [ "$free_mem" -lt "$fssize" ] ; then
967 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
969 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
972 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
977 # Emulate an N-data-disk stripe w/ various stripe units
978 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
984 [ -z "$blocksize" ] && blocksize=4096
986 let sunit_blocks=$sunit_bytes/$blocksize
987 let swidth_blocks=$sunit_blocks*$swidth_mult
991 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
994 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
997 _notrun "can't mkfs $FSTYP with geometry"
1003 # Create fs of certain blocksize on scratch device
1004 # _scratch_mkfs_blocksized blocksize
1005 _scratch_mkfs_blocksized()
1010 if ! [[ $blocksize =~ $re ]] ; then
1011 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1016 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1019 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1022 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1025 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1034 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1042 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1043 # errors found or errors were fixed) and nonzero otherwise; also spits out
1044 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1045 _repair_scratch_fs()
1049 _scratch_xfs_repair "$@" 2>&1
1051 if [ "$res" -ne 0 ]; then
1052 echo "xfs_repair returns $res; replay log?"
1055 if [ "$res" -gt 0 ]; then
1056 echo "mount returns $res; zap log?"
1057 _scratch_xfs_repair -L 2>&1
1058 echo "log zap returns $?"
1060 umount "$SCRATCH_MNT"
1062 _scratch_xfs_repair "$@" 2>&1
1065 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1069 # Let's hope fsck -y suffices...
1070 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1077 >&2 echo "fsck.$FSTYP failed, err=$res"
1089 echo "Usage: _get_pids_by_name process-name" 1>&2
1093 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1094 # HH:MM:SS before the psargs field, use this as the search anchor.
1096 # Matches with $1 (process-name) occur if the first psarg is $1
1097 # or ends in /$1 ... the matching uses sed's regular expressions,
1098 # so passing a regex into $1 will work.
1103 -e 's/[ ][ ]*/ /g' \
1106 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1107 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1110 # fix malloc libs output
1114 # filter out the Electric Fence notice
1117 if (defined $o && /^\s+Electric Fence/) {
1123 print $o if (defined $o);
1127 print $o if (defined $o);
1132 # _df_device : get an IRIX style df line for a given device
1134 # - returns "" if not mounted
1135 # - returns fs type in field two (ala IRIX)
1136 # - joins line together if split by fancy df formatting
1137 # - strips header etc
1144 echo "Usage: _df_device device" 1>&2
1148 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1149 # IPv6 server as a regular expression.
1150 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1151 ($1==what) && (NF==1) {
1165 # _df_dir : get an IRIX style df line for device where a directory resides
1167 # - returns fs type in field two (ala IRIX)
1168 # - joins line together if split by fancy df formatting
1169 # - strips header etc
1176 echo "Usage: _df_dir device" 1>&2
1180 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1196 # return percentage used disk space for mounted device
1202 echo "Usage: _used device" 1>&2
1206 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1209 # return the FS type of a mounted device
1215 echo "Usage: _fs_type device" 1>&2
1220 # The Linux kernel shows NFSv4 filesystems in df output as
1221 # filesystem type nfs4, although we mounted it as nfs earlier.
1222 # Fix the filesystem type up here so that the callers don't
1223 # have to bother with this quirk.
1225 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1228 # return the FS mount options of a mounted device
1230 # should write a version which just parses the output of mount for IRIX
1231 # compatibility, but since this isn't used at all, at the moment I'll leave
1238 echo "Usage: _fs_options device" 1>&2
1242 $AWK_PROG -v dev=$1 '
1243 match($1,dev) { print $4 }
1247 # returns device number if a file is a block device
1253 echo "Usage: _is_block_dev dev" 1>&2
1258 if [ -L "${_dev}" ]; then
1259 _dev=`readlink -f "${_dev}"`
1262 if [ -b "${_dev}" ]; then
1263 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1267 # Do a command, log it to $seqres.full, optionally test return status
1268 # and die if command fails. If called with one argument _do executes the
1269 # command, logs it, and returns its exit status. With two arguments _do
1270 # first prints the message passed in the first argument, and then "done"
1271 # or "fail" depending on the return status of the command passed in the
1272 # second argument. If the command fails and the variable _do_die_on_error
1273 # is set to "always" or the two argument form is used and _do_die_on_error
1274 # is set to "message_only" _do will print an error message to
1275 # $seqres.out and exit.
1279 if [ $# -eq 1 ]; then
1281 elif [ $# -eq 2 ]; then
1284 echo -n "$_note... "
1286 echo "Usage: _do [note] cmd" 1>&2
1290 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1291 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1292 cat $tmp._out | _fix_malloc >>$seqres.full
1293 if [ $# -eq 2 ]; then
1294 if [ $ret -eq 0 ]; then
1301 && [ "$_do_die_on_error" = "always" \
1302 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1304 [ $# -ne 2 ] && echo
1305 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1312 # bail out, setting up .notrun file. Need to kill the filesystem check files
1313 # here, otherwise they are set incorrectly for the next test.
1317 echo "$*" > $seqres.notrun
1318 echo "$seq not run: $*"
1319 rm -f ${RESULT_DIR}/require_test*
1320 rm -f ${RESULT_DIR}/require_scratch*
1326 # just plain bail out
1330 echo "$*" | tee -a $seqres.full
1331 echo "(see $seqres.full for details)"
1336 # tests whether $FSTYP is one of the supported filesystems for a test
1342 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1348 _notrun "not suitable for this filesystem type: $FSTYP"
1352 # tests whether $FSTYP is one of the supported OSes for a test
1358 if [ "$h" = "$HOSTOS" ]
1364 _notrun "not suitable for this OS: $HOSTOS"
1367 # check if a FS on a device is mounted
1368 # if so, verify that it is mounted on mount point
1369 # if fstype is given as argument, verify that it is also
1370 # mounted with correct fs type
1380 # Note that we use -F here so grep doesn't try to interpret an NFS over
1381 # IPv6 server as a regular expression. Because of that, we cannot use
1382 # ^$dev so we use "$dev on " to avoid matching $dev to mount point field
1383 # for overlay case, where $dev is a directory.
1384 local mount_rec=`_mount | grep -F "$dev on "`
1385 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1387 # if it's mounted, make sure its on $mnt
1388 if ! (echo $mount_rec | grep -q "$dev on $mnt")
1390 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1391 echo "Already mounted result:"
1393 return 2 # 2 = mounted on wrong mnt
1396 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]
1398 echo "$devname=$dev is mounted but not a type $type filesystem"
1399 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1401 return 3 # 3 = mounted as wrong type
1403 return 0 # 0 = mounted as expected
1406 # this test needs a scratch partition - check we're ok & unmount it
1407 # No post-test check of the device is required. e.g. the test intentionally
1408 # finishes the test with the filesystem in a corrupt state
1409 _require_scratch_nocheck()
1413 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1414 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1415 _notrun "this test requires a valid \$SCRATCH_DEV"
1417 if [ ! -d "$SCRATCH_MNT" ]; then
1418 _notrun "this test requires a valid \$SCRATCH_MNT"
1422 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1423 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1424 _notrun "this test requires a valid \$SCRATCH_DEV"
1426 if [ ! -d "$SCRATCH_MNT" ]; then
1427 _notrun "this test requires a valid \$SCRATCH_MNT"
1431 if [ -z "$OVL_BASE_SCRATCH_MNT" -o ! -d "$OVL_BASE_SCRATCH_MNT" ]; then
1432 _notrun "this test requires a valid \$OVL_BASE_SCRATCH_MNT as ovl base dir"
1434 # if $SCRATCH_MNT is derived from $OVL_BASE_SCRATCH_MNT then
1435 # don't check $SCRATCH_MNT dir here because base fs may not be mounted
1436 # and we will create the mount point anyway on _overlay_mount
1437 if [ "$SCRATCH_MNT" != "$OVL_BASE_SCRATCH_MNT/$OVL_MNT" -a ! -d "$SCRATCH_MNT" ]; then
1438 _notrun "this test requires a valid \$SCRATCH_MNT"
1442 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1444 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1448 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1450 _notrun "this test requires a valid \$SCRATCH_DEV"
1452 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1454 _notrun "this test requires a valid \$SCRATCH_DEV"
1456 if [ ! -d "$SCRATCH_MNT" ]
1458 _notrun "this test requires a valid \$SCRATCH_MNT"
1463 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1465 [ $err -le 1 ] || exit 1
1468 # if it's mounted, unmount it
1469 if ! _scratch_unmount
1471 echo "failed to unmount $SCRATCH_DEV"
1475 rm -f ${RESULT_DIR}/require_scratch
1478 # we need the scratch device and it should be checked post test.
1481 _require_scratch_nocheck
1482 touch ${RESULT_DIR}/require_scratch
1486 # this test needs a test partition - check we're ok & mount it
1492 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1493 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1494 _notrun "this test requires a valid \$TEST_DEV"
1496 if [ ! -d "$TEST_DIR" ]; then
1497 _notrun "this test requires a valid \$TEST_DIR"
1501 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1502 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1503 _notrun "this test requires a valid \$TEST_DEV"
1505 if [ ! -d "$TEST_DIR" ]; then
1506 _notrun "this test requires a valid \$TEST_DIR"
1510 if [ -z "$OVL_BASE_TEST_DIR" -o ! -d "$OVL_BASE_TEST_DIR" ]; then
1511 _notrun "this test requires a valid \$TEST_DIR as ovl base dir"
1513 if [ ! -d "$TEST_DIR" ]; then
1514 _notrun "this test requires a valid \$TEST_DIR"
1518 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1520 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1524 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1526 _notrun "this test requires a valid \$TEST_DEV"
1528 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1530 _notrun "this test requires a valid \$TEST_DEV"
1532 if [ ! -d "$TEST_DIR" ]
1534 _notrun "this test requires a valid \$TEST_DIR"
1539 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1541 [ $err -le 1 ] || exit 1
1546 echo "!!! failed to mount $TEST_DEV on $TEST_DIR"
1550 touch ${RESULT_DIR}/require_test
1553 # this test needs a logdev
1557 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1558 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1559 [ "$USE_EXTERNAL" != yes ] && \
1560 _notrun "This test requires USE_EXTERNAL to be enabled"
1562 # ensure its not mounted
1563 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1566 # this test requires loopback device support
1570 if [ "$HOSTOS" != "Linux" ]
1572 _notrun "This test requires linux for loopback device support"
1575 modprobe loop >/dev/null 2>&1
1576 if grep loop /proc/devices >/dev/null 2>&1
1580 _notrun "This test requires loopback device support"
1584 # this test requires ext2 filesystem support
1588 if [ "$HOSTOS" != "Linux" ]
1590 _notrun "This test requires linux for ext2 filesystem support"
1593 modprobe ext2 >/dev/null 2>&1
1594 if grep ext2 /proc/filesystems >/dev/null 2>&1
1598 _notrun "This test requires ext2 filesystem support"
1602 # this test requires tmpfs filesystem support
1606 modprobe tmpfs >/dev/null 2>&1
1607 grep -q tmpfs /proc/filesystems ||
1608 _notrun "this test requires tmpfs support"
1611 # this test requires that (large) loopback device files are not in use
1613 _require_no_large_scratch_dev()
1615 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1616 _notrun "Large filesystem testing in progress, skipped this test"
1619 # this test requires that a realtime subvolume is in use, and
1620 # that the kernel supports realtime as well.
1624 [ "$USE_EXTERNAL" = yes ] || \
1625 _notrun "External volumes not in use, skipped this test"
1626 [ "$SCRATCH_RTDEV" = "" ] && \
1627 _notrun "Realtime device required, skipped this test"
1630 # this test requires that a specified command (executable) exists
1631 # $1 - command, $2 - name for error message
1633 # Note: the command string might have parameters, so strip them before checking
1634 # whether it is executable.
1637 if [ $# -eq 2 ]; then
1639 elif [ $# -eq 1 ]; then
1642 _fail "usage: _require_command <command> [<name>]"
1645 _command=`echo "$1" | awk '{ print $1 }'`
1646 if [ ! -x "$_command" ]; then
1647 _notrun "$_name utility required, skipped this test"
1651 # this test requires the device to be valid block device
1653 _require_block_device()
1655 if [ -z "$1" ]; then
1656 echo "Usage: _require_block_device <dev>" 1>&2
1659 if [ "`_is_block_dev "$1"`" == "" ]; then
1660 _notrun "require $1 to be valid block disk"
1664 # brd based ram disks erase the device when they receive a flush command when no
1665 # active references are present. This causes problems for DM devices sitting on
1666 # top of brd devices as DM doesn't hold active references to the brd device.
1667 _require_sane_bdev_flush()
1669 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1670 if [ $? -eq 0 ]; then
1671 _notrun "This test requires a sane block device flush"
1675 # this test requires a specific device mapper target
1676 _require_dm_target()
1680 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1682 _require_block_device $SCRATCH_DEV
1683 _require_sane_bdev_flush $SCRATCH_DEV
1684 _require_command "$DMSETUP_PROG" dmsetup
1686 modprobe dm-$_target >/dev/null 2>&1
1688 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1689 if [ $? -ne 0 ]; then
1690 _notrun "This test requires dm $_target support"
1694 # this test requires the ext4 kernel support crc feature on scratch device
1696 _require_scratch_ext4_crc()
1698 _scratch_mkfs_ext4 >/dev/null 2>&1
1699 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1700 _scratch_mount >/dev/null 2>&1 \
1701 || _notrun "Kernel doesn't support metadata_csum feature"
1705 # this test requires the bigalloc feature to be available in mkfs.ext4
1707 _require_ext4_mkfs_bigalloc()
1709 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1710 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1713 # this test requires the ext4 kernel support bigalloc feature
1715 _require_ext4_bigalloc()
1717 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1718 _scratch_mount >/dev/null 2>&1 \
1719 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1723 # this test requires that external log/realtime devices are not in use
1725 _require_nonexternal()
1727 [ "$USE_EXTERNAL" = yes ] && \
1728 _notrun "External device testing in progress, skipped this test"
1731 # this test requires that a (specified) aio-dio executable exists
1732 # $1 - command (optional)
1738 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1739 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1741 AIO_TEST=src/aio-dio-regress/$1
1742 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1747 # this test requires that a test program exists under src/
1748 # $1 - command (require)
1750 _require_test_program()
1753 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1756 # run an aio-dio program
1762 echo "usage: _run_aiodio command_name" 2>&1
1768 local testtemp=$TEST_DIR/aio-testfile
1770 $AIO_TEST $testtemp 2>&1
1777 # this test requires y2038 sysfs switch and filesystem
1778 # timestamp ranges support.
1781 local device=${1:-$TEST_DEV}
1782 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
1784 if [ ! -e $sysfsdir ]; then
1785 _notrun "no kernel support for y2038 sysfs switch"
1789 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
1790 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
1791 _notrun "filesystem $FSTYP timestamp bounds are unknown"
1795 _filesystem_timestamp_range()
1797 device=${1:-$TEST_DEV}
1800 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
1801 echo "-2147483648 15032385535"
1803 echo "-2147483648 2147483647"
1808 echo "-2147483648 2147483647"
1814 echo "-2147483648 2147483647"
1822 # indicate whether YP/NIS is active or not
1827 dn=$(domainname 2>/dev/null)
1828 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
1832 # cat the password file
1836 [ $(_yp_active) -eq 0 ] && ypcat passwd
1840 # cat the group file
1844 [ $(_yp_active) -eq 0 ] && ypcat group
1848 # check for a user on the machine, fsgqa as default
1856 _cat_passwd | grep -q $qa_user
1857 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1858 echo /bin/true | su $qa_user
1859 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1862 # check for a group on the machine, fsgqa as default
1870 _cat_group | grep -q $qa_group
1871 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1877 s,.*Permission\sdenied.*,Permission denied,;
1878 s,.*no\saccess\sto\stty.*,,;
1879 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1886 if [ "$HOSTOS" == "IRIX" ]
1888 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1890 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
1894 _require_xfs_io_command()
1898 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
1905 testfile=$TEST_DIR/$$.xfs_io
1908 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
1911 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1913 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
1914 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1915 -c "$command 4k 8k" $testfile 2>&1`
1918 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1919 -c "fiemap -v" $testfile 2>&1`
1922 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1924 echo $testio | egrep -q "invalid option|Is a directory" && \
1925 _notrun "xfs_io $command support is missing"
1928 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
1929 echo $testio | egrep -q "Inappropriate ioctl" && \
1930 _notrun "xfs_io $command support is missing"
1933 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
1934 # a new -C flag was introduced to execute one shot commands.
1935 # Check for -C flag support as an indication for the bug fix.
1936 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
1937 echo $testio | egrep -q "invalid option" && \
1938 _notrun "xfs_io $command support is missing"
1941 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
1944 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1947 rm -f $testfile 2>&1 > /dev/null
1948 echo $testio | grep -q "not found" && \
1949 _notrun "xfs_io $command support is missing"
1950 echo $testio | grep -q "Operation not supported" && \
1951 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1952 echo $testio | grep -q "foreign file active" && \
1953 _notrun "xfs_io $command not supported on $FSTYP"
1955 test -z "$param" && return
1956 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
1957 _notrun "xfs_io $command doesn't support $param"
1960 # check that kernel and filesystem support direct I/O
1963 if [ $FSTYP = "ext4" ] ; then
1964 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
1965 _notrun "ext4 encryption doesn't support O_DIRECT"
1968 testfile=$TEST_DIR/$$.direct
1969 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1970 if [ $? -ne 0 ]; then
1971 _notrun "O_DIRECT is not supported"
1973 rm -f $testfile 2>&1 > /dev/null
1976 # Check that the filesystem supports swapfiles
1977 _require_scratch_swapfile()
1981 _scratch_mkfs >/dev/null
1984 # Minimum size for mkswap is 10 pages
1985 local size=$(($(get_page_size) * 10))
1987 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
1988 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
1989 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
1991 _notrun "swapfiles are not supported"
1994 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
1998 # Check that a fs has enough free space (in 1024b blocks)
2003 BLOCKS=$2 # in units of 1024
2004 let GB=$BLOCKS/1024/1024
2006 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2007 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2008 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2012 # Check if the filesystem supports sparse files.
2014 # Unfortunately there is no better way to do this than a manual black list.
2016 _require_sparse_files()
2020 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2029 #boot_params always present in debugfs
2030 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2033 _require_fail_make_request()
2035 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2036 || _notrun "$DEBUGFS_MNT/fail_make_request \
2037 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2041 # Check if the file system supports seek_data/hole
2043 _require_seek_data_hole()
2045 testfile=$TEST_DIR/$$.seek
2046 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2047 rm -f $testfile &>/dev/null
2048 echo $testseek | grep -q "Kernel does not support" && \
2049 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2054 _require_test_program "runas"
2059 "$here/src/runas" "$@"
2062 _require_richacl_prog()
2064 _require_command "$GETRICHACL_PROG" getrichacl
2065 _require_command "$SETRICHACL_PROG" setrichacl
2068 _require_scratch_richacl_xfs()
2070 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2071 || _notrun "mkfs.xfs doesn't have richacl feature"
2072 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2073 _scratch_mount >/dev/null 2>&1 \
2074 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2078 _require_scratch_richacl_ext4()
2080 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2081 || _notrun "can't mkfs $FSTYP with option -O richacl"
2082 _scratch_mount >/dev/null 2>&1 \
2083 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2087 _require_scratch_richacl_support()
2090 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2091 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2095 _require_scratch_richacl()
2098 xfs) _require_scratch_richacl_xfs
2100 ext4) _require_scratch_richacl_ext4
2103 _require_scratch_richacl_support
2105 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2110 _scratch_mkfs_richacl()
2113 xfs) _scratch_mkfs_xfs -m richacl=1
2115 ext4) _scratch_mkfs -O richacl
2123 # check that a FS on a device is mounted
2124 # if so, return mount point
2130 echo "Usage: _is_mounted device" 1>&2
2136 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2137 pattern { print $3 ; exit 0 }
2141 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2146 # remount a FS to a new mode (ro or rw)
2152 echo "Usage: _remount device ro/rw" 1>&2
2158 if ! mount -o remount,$mode $device
2160 echo "_remount: failed to remount filesystem on $device as $mode"
2165 # Run the appropriate repair/check on a filesystem
2167 # if the filesystem is mounted, it's either remounted ro before being
2168 # checked or it's unmounted and then remounted
2171 # If set, we remount ro instead of unmounting for fsck
2174 _umount_or_remount_ro()
2178 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2183 mountpoint=`_is_mounted $device`
2185 if [ $USE_REMOUNT -eq 0 ]; then
2186 $UMOUNT_PROG $device
2193 _mount_or_remount_rw()
2195 if [ $# -ne 3 ]; then
2196 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2203 if [ $USE_REMOUNT -eq 0 ]; then
2204 if [ "$FSTYP" != "overlay" ]; then
2205 _mount -t $FSTYP $mount_opts $device $mountpoint
2207 _overlay_mount $device $mountpoint
2209 if [ $? -ne 0 ]; then
2210 echo "!!! failed to remount $device on $mountpoint"
2220 # Check a generic filesystem in no-op mode; this assumes that the
2221 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2222 # and that it will still return an errno for corruption in this mode.
2224 # Filesystems which don't support this will need to define their
2225 # own check routine.
2227 _check_generic_filesystem()
2231 # If type is set, we're mounted
2232 type=`_fs_type $device`
2235 if [ "$type" = "$FSTYP" ]
2238 mountpoint=`_umount_or_remount_ro $device`
2241 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2244 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2246 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2247 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2248 cat $tmp.fsck >>$seqres.full
2249 echo "*** end fsck.$FSTYP output" >>$seqres.full
2257 echo "*** mount output ***" >>$seqres.full
2258 _mount >>$seqres.full
2259 echo "*** end mount output" >>$seqres.full
2260 elif [ "$type" = "$FSTYP" ]
2263 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2267 if [ $ok -eq 0 ]; then
2269 if [ "$iam" != "check" ]; then
2278 # Filter the knowen errors the UDF Verifier reports.
2279 _udf_test_known_error_filter()
2281 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."
2285 _check_udf_filesystem()
2287 [ "$DISABLE_UDF_TEST" == "1" ] && return
2289 if [ $# -ne 1 -a $# -ne 2 ]
2291 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2295 if [ ! -x $here/src/udf_test ]
2297 echo "udf_test not installed, please download and build the Philips"
2298 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2299 echo "Then copy the udf_test binary to $here/src/."
2300 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2308 LAST_BLOCK=`expr \( $2 - 1 \)`
2309 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2312 rm -f $seqres.checkfs
2313 sleep 1 # Due to a problem with time stamps in udf_test
2314 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2315 _udf_test_known_error_filter | \
2316 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2317 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2328 # no way to check consistency for nfs
2331 # no way to check consistency for cifs
2334 # no way to check consistency for CephFS
2337 # no way to check consistency for overlay
2340 # do nothing for now
2343 _check_btrfs_filesystem $TEST_DEV
2346 # no way to check consistency for tmpfs
2349 _check_generic_filesystem $TEST_DEV
2357 [ $# -eq 1 ] && device=$1
2363 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2364 SCRATCH_LOG="$SCRATCH_LOGDEV"
2366 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2367 SCRATCH_RT="$SCRATCH_RTDEV"
2369 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2372 _check_udf_filesystem $device $udf_fsize
2375 # Don't know how to check an NFS filesystem, yet.
2378 # Don't know how to check a CIFS filesystem, yet.
2381 # no way to check consistency for CephFS
2384 # no way to check consistency for overlay
2387 _check_btrfs_filesystem $device
2390 # no way to check consistency for tmpfs
2393 _check_generic_filesystem $device
2398 _full_fstyp_details()
2400 [ -z "$FSTYP" ] && FSTYP=xfs
2401 if [ $FSTYP = xfs ]; then
2402 if [ -d /proc/fs/xfs ]; then
2403 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2404 FSTYP="$FSTYP (non-debug)"
2405 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2406 FSTYP="$FSTYP (debug)"
2409 if uname -a | grep -qi 'debug'; then
2410 FSTYP="$FSTYP (debug)"
2412 FSTYP="$FSTYP (non-debug)"
2419 _full_platform_details()
2425 echo "$os/$platform $host $kernel"
2430 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2432 elif [ "`uname`" == "Linux" ]; then
2435 echo Unknown operating system: `uname`
2440 _link_out_file_named()
2445 my $feature, $result, $suffix, $opts;
2447 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2448 $feathash{$feature} = 1;
2450 $result = "default";
2455 ($opts, $suffix) = split(/ *: */);
2456 foreach my $opt (split(/,/, $opts)) {
2457 if (!exists($feathash{$opt})) {
2471 ln -fs $SRC.$SUFFIX $1
2476 if [ $# -eq 0 ]; then
2477 FEATURES="$(_get_os_name)"
2478 if [ -n "$MOUNT_OPTIONS" ]; then
2479 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2485 _link_out_file_named $seqfull.out "$FEATURES"
2494 # convert urandom incompressible data to compressible text data
2497 od /dev/urandom | dd iflag=fullblock ${*}
2500 #takes files, randomdata
2508 if [ $size -gt 0 ]; then
2509 if [ "$2" == "false" ]; then
2510 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2511 elif [ "$2" == "comp" ]; then
2512 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2514 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2521 # takes dirname, depth, randomdata
2524 dirname=$1; depth=$2; randomdata=$3
2525 mkdir $dirname || die "mkdir $dirname failed"
2528 _nfiles $files $randomdata # files for this dir and data type
2530 [ $depth -eq 0 ] && return
2531 let deep=$depth-1 # go 1 down
2533 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2536 while [ $d -lt $dirs ]
2538 _descend d$d $deep &
2544 # Populate a filesystem with inodes for performance experiments
2546 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2551 dirs=5 # ndirs in each subdir till leaves
2552 size=0 # sizeof files in K
2553 files=100 # num files in _each_ subdir
2554 depth=2 # depth of tree from root to leaves
2556 root=root # path of initial root of directory tree
2557 randomdata=false # -x data type urandom, zero or compressible
2560 while getopts "d:f:n:r:s:v:x:c" c
2569 x) randomdata=true;;
2570 c) randomdata=comp;;
2574 _descend $root $depth $randomdata
2579 [ $verbose = true ] && echo done
2582 # query whether the given file has the given inode flag set
2589 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2595 # query the given files extsize allocator hint in bytes (if any)
2602 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2603 awk '/^xattr.extsize =/ { print $3 }'`
2604 [ -z "$blocks" ] && blocks="0"
2608 # scratch_dev_pool should contain the disks pool for the btrfs raid
2609 _require_scratch_dev_pool()
2614 if [ -z "$SCRATCH_DEV_POOL" ]; then
2615 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2618 if [ -z "$1" ]; then
2624 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2628 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2629 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2633 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2637 for i in $SCRATCH_DEV_POOL; do
2638 if [ "`_is_block_dev "$i"`" = "" ]; then
2639 _notrun "this test requires valid block disk $i"
2641 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2642 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2644 if _mount | grep -q $i; then
2645 if ! $UMOUNT_PROG $i; then
2646 echo "failed to unmount $i - aborting"
2650 # to help better debug when something fails, we remove
2651 # traces of previous btrfs FS on the dev.
2652 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2656 # ensure devices in SCRATCH_DEV_POOL are of the same size
2657 # must be called after _require_scratch_dev_pool
2658 _require_scratch_dev_pool_equal_size()
2664 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2665 _size=`_get_device_size $SCRATCH_DEV`
2666 for _dev in $SCRATCH_DEV_POOL; do
2667 _newsize=`_get_device_size $_dev`
2668 if [ $_size -ne $_newsize ]; then
2669 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2674 # We will check if the device is deletable
2675 _require_deletable_scratch_dev_pool()
2679 for i in $SCRATCH_DEV_POOL; do
2680 x=`echo $i | cut -d"/" -f 3`
2681 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2682 _notrun "$i is a device which is not deletable"
2687 # Check that fio is present, and it is able to execute given jobfile
2692 _require_command "$FIO_PROG" fio
2693 if [ -z "$1" ]; then
2697 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2698 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2701 # Does freeze work on this fs?
2704 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2706 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2707 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2710 # Does shutdown work on this fs?
2711 _require_scratch_shutdown()
2713 [ -x src/godown ] || _notrun "src/godown executable not found"
2715 _scratch_mkfs > /dev/null 2>&1
2717 src/godown -f $SCRATCH_MNT 2>&1 \
2718 || _notrun "$FSTYP does not support shutdown"
2722 # Does dax mount option work on this dev/fs?
2723 _require_scratch_dax()
2726 _scratch_mkfs > /dev/null 2>&1
2727 _scratch_mount -o dax
2728 # Check options to be sure. XFS ignores dax option
2729 # and goes on if dev underneath does not support dax.
2730 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
2731 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
2735 # Does norecovery support by this fs?
2736 _require_norecovery()
2738 _scratch_mount -o ro,norecovery || \
2739 _notrun "$FSTYP does not support norecovery"
2743 # Does this filesystem support metadata journaling?
2744 # We exclude ones here that don't; otherwise we assume that it does, so the
2745 # test will run, fail, and motivate someone to update this test for a new
2748 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2749 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2751 _require_metadata_journaling()
2761 _notrun "$FSTYP does not support metadata journaling"
2764 # ext4 could be mkfs'd without a journal...
2766 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2767 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2768 # ext4 might not load a journal
2769 _exclude_scratch_mount_option "noload"
2772 # by default we pass; if you need to, add your fs above!
2777 # Does fiemap support?
2780 _require_xfs_io_command "fiemap"
2785 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2790 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2793 # arg 1 is dev to remove and is output of the below eg.
2794 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2800 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2802 stat $disk > /dev/null 2>&1
2803 while [ $? -eq 0 ]; do
2805 stat $disk > /dev/null 2>&1
2809 # arg 1 is dev to add and is output of the below eg.
2810 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2815 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2816 h=`echo ${1} | cut -d":" -f 1`
2817 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2819 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2821 # ensure the device comes online
2823 for i in `seq 1 10`; do
2824 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2825 dev=`ls /sys/class/scsi_device/${1}/device/block`
2826 for j in `seq 1 10`;
2828 stat /dev/$dev > /dev/null 2>&1
2829 if [ $? -eq 0 ]; then
2840 if [ $dev_back_oneline -eq 0 ]; then
2841 echo "/dev/$dev online failed" >> $seqres.full
2843 echo "/dev/$dev is back online" >> $seqres.full
2849 if [ -z "$FSTRIM_PROG" ]; then
2850 _notrun "This test requires fstrim utility."
2854 _require_batched_discard()
2856 if [ $# -ne 1 ]; then
2857 echo "Usage: _require_batched_discard mnt_point" 1>&2
2861 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2866 if [ -z "$DUMPE2FS_PROG" ]; then
2867 _notrun "This test requires dumpe2fs utility."
2873 if [ ! -e /proc/self/uid_map ]; then
2874 _notrun "This test requires procfs uid_map support."
2876 if [ ! -e /proc/self/gid_map ]; then
2877 _notrun "This test requires procfs gid_map support."
2883 FSSUM_PROG=$here/src/fssum
2884 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2889 CLONER_PROG=$here/src/cloner
2890 [ -x $CLONER_PROG ] || \
2891 _notrun "cloner binary not present at $CLONER_PROG"
2894 # Normalize mount options from global $MOUNT_OPTIONS
2895 # Convert options like "-o opt1,opt2 -oopt3" to
2897 _normalize_mount_options()
2899 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
2902 # skip test if MOUNT_OPTIONS contains the given strings
2903 _exclude_scratch_mount_option()
2905 local mnt_opts=$(_normalize_mount_options)
2907 while [ $# -gt 0 ]; do
2908 if echo $mnt_opts | grep -qw "$1"; then
2909 _notrun "mount option \"$1\" not allowed in this test"
2917 _exclude_scratch_mount_option "noatime"
2918 if [ "$FSTYP" == "nfs" ]; then
2919 _notrun "atime related mount options have no effect on NFS"
2925 _scratch_mkfs > /dev/null 2>&1
2926 _scratch_mount -o relatime || \
2927 _notrun "relatime not supported by the current kernel"
2933 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2934 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2937 _create_loop_device()
2940 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2944 _destroy_loop_device()
2947 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2950 _scale_fsstress_args()
2953 while [ $# -gt 0 ]; do
2955 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2956 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2957 *) args="$args $1" ;;
2965 # Return the logical block size if running on a block device,
2966 # else substitute the page size.
2968 _min_dio_alignment()
2972 if [ -b "$dev" ]; then
2973 blockdev --getss $dev
2975 $here/src/feature -s
2981 echo "# $@" >> $seqres.full 2>&1
2982 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2985 _require_test_symlinks()
2987 # IRIX UDF does not support symlinks
2988 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2989 _notrun "Require symlinks support"
2990 target=`mktemp -p $TEST_DIR`
2991 link=`mktemp -p $TEST_DIR -u`
2992 ln -s `basename $target` $link
2993 if [ "$?" -ne 0 ]; then
2995 _notrun "Require symlinks support"
3000 _require_test_fcntl_advisory_locks()
3002 [ "$FSTYP" != "cifs" ] && return 0
3003 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3004 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3005 _notrun "Require fcntl advisory locks support"
3008 _require_test_lsattr()
3010 testio=$(lsattr -d $TEST_DIR 2>&1)
3011 echo $testio | grep -q "Operation not supported" && \
3012 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3013 echo $testio | grep -q "Inappropriate ioctl for device" && \
3014 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3021 touch $TEST_DIR/syscalltest
3022 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3024 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3025 if [ "$status" -ne 0 ]; then
3026 _notrun "file system doesn't support chattr +$attribute"
3028 cat $TEST_DIR/syscalltest.out >> $seqres.full
3030 rm -f $TEST_DIR/syscalltest.out
3035 if [ -z "$1" ]; then
3036 echo "Usage: _get_total_inode <mnt>"
3040 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3046 if [ -z "$1" ]; then
3047 echo "Usage: _get_used_inode <mnt>"
3051 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3055 _get_used_inode_percent()
3057 if [ -z "$1" ]; then
3058 echo "Usage: _get_used_inode_percent <mnt>"
3062 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3069 if [ -z "$1" ]; then
3070 echo "Usage: _get_free_inode <mnt>"
3074 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3078 # get the available space in bytes
3080 _get_available_space()
3082 if [ -z "$1" ]; then
3083 echo "Usage: _get_available_space <mnt>"
3087 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3088 echo $((avail_kb * 1024))
3091 # return device size in kb
3094 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3097 # check dmesg log for WARNING/Oops/etc.
3100 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3103 rm -f ${RESULT_DIR}/check_dmesg
3105 # default filter is a simple cat command, caller could provide a
3106 # customized filter and pass the name through the first argument, to
3107 # filter out intentional WARNINGs or Oopses
3110 # search the dmesg log of last run of $seqnum for possible failures
3111 # use sed \cregexpc address type, since $seqnum contains "/"
3112 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3113 tac | $filter >$seqres.dmesg
3114 grep -q -e "kernel BUG at" \
3118 -e "possible recursive locking detected" \
3119 -e "Internal error" \
3120 -e "INFO: suspicious RCU usage" \
3121 -e "INFO: possible circular locking dependency detected" \
3122 -e "general protection fault:" \
3124 if [ $? -eq 0 ]; then
3125 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3133 # don't check dmesg log after test
3134 _disable_dmesg_check()
3136 rm -f ${RESULT_DIR}/check_dmesg
3141 if [ "$iam" == new ]
3145 # make some further configuration checks here
3146 if [ "$TEST_DEV" = "" ]
3148 echo "common/rc: Error: \$TEST_DEV is not set"
3152 # if $TEST_DEV is not mounted, mount it now as XFS
3153 if [ -z "`_fs_type $TEST_DEV`" ]
3155 # $TEST_DEV is not mounted
3158 echo "common/rc: retrying test device mount with external set"
3159 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3162 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3168 # Sanity check that TEST partition is not mounted at another mount point
3169 # or as another fs type
3170 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3171 if [ -n "$SCRATCH_DEV" ]; then
3172 # Sanity check that SCRATCH partition is not mounted at another
3173 # mount point, because it is about to be unmounted and formatted.
3174 # Another fs type for scratch is fine (bye bye old fs type).
3175 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3176 [ $? -le 1 ] || exit 1
3179 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3180 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3181 export XFS_IO_PROG="$XFS_IO_PROG -F"
3183 # xfs_io -i option starts an idle thread for xfs_io.
3184 # With single threaded process, the file table is not shared
3185 # and file structs are not reference counted.
3186 # Spawning an idle thread can help detecting file struct
3187 # reference leaks, so we want to enable the option whenever
3189 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3190 export XFS_IO_PROG="$XFS_IO_PROG -i"
3192 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3193 # can change the UUID on v5 filesystems
3194 if [ "$FSTYP" == "xfs" ]; then
3196 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3197 # xfs_db will return 0 even if it can't generate a new uuid, so
3198 # check the output to make sure if it can change UUID of V5 xfs
3199 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3200 | grep -q "invalid UUID\|supported on V5 fs" \
3201 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3206 # get real device path name by following link
3210 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3211 _dev=`readlink -f "$_dev"`
3216 # basename of a device
3219 echo `basename $(_real_dev $1)`
3224 local _dev=`_real_dev $1`
3225 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3226 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3227 _maj=$(echo "ibase=16; $_maj" | bc)
3228 _min=$(echo "ibase=16; $_min" | bc)
3229 echo /sys/dev/block/$_maj:$_min
3232 # Get the minimum block size of a file. Usually this is the
3233 # minimum fs block size, but some filesystems (ocfs2) do block
3234 # mappings in larger units.
3235 _get_file_block_size()
3237 if [ -z $1 ] || [ ! -d $1 ]; then
3238 echo "Missing mount point argument for _get_file_block_size"
3241 if [ "$FSTYP" = "ocfs2" ]; then
3248 # Get the minimum block size of an fs.
3251 if [ -z $1 ] || [ ! -d $1 ]; then
3252 echo "Missing mount point argument for _get_block_size"
3260 echo $(getconf PAGE_SIZE)
3267 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3268 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3269 echo "$@" >>$seqres.full
3270 rm -f $TEST_DIR/junk
3271 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3272 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3278 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3280 # Only one argument is needed:
3281 # - attr: path name under /sys/fs/$FSTYP/DEV
3284 # _require_fs_sysfs error/fail_at_unmount
3288 local dname=$(_short_dev $TEST_DEV)
3290 if [ -z "$attr" -o -z "$dname" ];then
3291 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3294 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3295 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3299 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3301 # All arguments are necessary, and in this order:
3302 # - dev: device name, e.g. $SCRATCH_DEV
3303 # - attr: path name under /sys/fs/$FSTYP/$dev
3304 # - content: the content of $attr
3307 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3308 _set_fs_sysfs_attr()
3316 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3317 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3320 local dname=$(_short_dev $dev)
3321 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3324 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3326 # All arguments are necessary, and in this order:
3327 # - dev: device name, e.g. $SCRATCH_DEV
3328 # - attr: path name under /sys/fs/$FSTYP/$dev
3331 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3332 _get_fs_sysfs_attr()
3337 if [ ! -b "$dev" -o -z "$attr" ];then
3338 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3341 local dname=$(_short_dev $dev)
3342 cat /sys/fs/${FSTYP}/${dname}/${attr}
3349 ################################################################################
3350 # make sure this script returns success