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/$OVERLAY_LOWER_DIR,upperdir=$1/$OVERLAY_UPPER_DIR,workdir=$1/$OVERLAY_WORK_DIR"
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 $SCRATCH_DEV`
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 $*
339 # Given a dir, set up 3 subdirectories and mount on the given mnt.
340 # The dir is used as the mount device so it can be seen from df or mount
347 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
349 mkdir -p $dir/$OVERLAY_UPPER_DIR
350 mkdir -p $dir/$OVERLAY_LOWER_DIR
351 mkdir -p $dir/$OVERLAY_WORK_DIR
353 _overlay_mount_dirs $dir/$OVERLAY_LOWER_DIR $dir/$OVERLAY_UPPER_DIR \
354 $dir/$OVERLAY_WORK_DIR $OVERLAY_MOUNT_OPTIONS \
355 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
358 _overlay_test_mount()
360 _overlay_mount $TEST_DEV $TEST_DIR $*
363 _overlay_scratch_mount()
365 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
368 _overlay_test_unmount()
370 $UMOUNT_PROG $TEST_DIR
373 _overlay_scratch_unmount()
375 $UMOUNT_PROG $SCRATCH_MNT
380 if [ "$FSTYP" == "overlay" ]; then
381 _overlay_scratch_mount $*
384 _mount -t $FSTYP `_scratch_mount_options $*`
391 _overlay_scratch_unmount
394 $UMOUNT_PROG $SCRATCH_MNT
397 $UMOUNT_PROG $SCRATCH_DEV
406 if test -n "$opts"; then
407 mount -o "remount,$opts" $SCRATCH_MNT
411 _scratch_cycle_mount()
415 if [ "$FSTYP" = tmpfs ]; then
416 _scratch_remount "$opts"
419 if test -n "$opts"; then
423 _scratch_mount "$opts"
428 if [ "$FSTYP" == "overlay" ]; then
429 _overlay_test_mount $*
433 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
438 if [ "$FSTYP" == "overlay" ]; then
439 _overlay_test_unmount
441 $UMOUNT_PROG $TEST_DEV
447 if [ "$FSTYP" = tmpfs ]; then
454 _scratch_mkfs_options()
456 _scratch_options mkfs
457 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
460 # Do the actual mkfs work on SCRATCH_DEV. Firstly mkfs with both MKFS_OPTIONS
461 # and user specified mkfs options, if that fails (due to conflicts between mkfs
462 # options), do a second mkfs with only user provided mkfs options.
464 # First param is the mkfs command without any mkfs options and device.
465 # Second param is the filter to remove unnecessary messages from mkfs stderr.
466 # Other extra mkfs options are followed.
472 local extra_mkfs_options=$*
476 # save mkfs output in case conflict means we need to run again.
477 # only the output for the mkfs that applies should be shown
478 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
479 2>$tmp.mkfserr 1>$tmp.mkfsstd
482 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
483 # $extra_mkfs_options
484 if [ $mkfs_status -ne 0 -a -n "$extra_mkfs_options" ]; then
486 echo -n "** mkfs failed with extra mkfs options "
487 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
488 echo -n "** attempting to mkfs using only test $seq "
489 echo "options: $extra_mkfs_options **"
492 # running mkfs again. overwrite previous mkfs output files
493 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
494 2>$tmp.mkfserr 1>$tmp.mkfsstd
498 # output stored mkfs output, filtering unnecessary output from stderr
500 eval "cat $tmp.mkfserr | $mkfs_filter" >&2
512 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
513 options="-l $SCRATCH_LOGDEV"
515 xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
518 _setup_large_ext4_fs()
523 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
524 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
525 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
527 # Default free space in the FS is 50GB, but you can specify more via
528 # SCRATCH_DEV_EMPTY_SPACE
529 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
531 # mount the filesystem and create 16TB - 4KB files until we consume
532 # all the necessary space.
533 _scratch_mount 2>&1 >$tmp_dir/mnt.err
535 if [ $status -ne 0 ]; then
537 cat $tmp_dir/mnt.err >&2
538 rm -f $tmp_dir/mnt.err
541 rm -f $tmp_dir/mnt.err
543 file_size=$((16*1024*1024*1024*1024 - 4096))
545 while [ $space_to_consume -gt $file_size ]; do
548 -c "truncate $file_size" \
549 -c "falloc -k 0 $file_size" \
550 $SCRATCH_MNT/.use_space.$nfiles 2>&1
552 if [ $status -ne 0 ]; then
556 space_to_consume=$(( $space_to_consume - $file_size ))
557 nfiles=$(($nfiles + 1))
560 # consume the remaining space.
561 if [ $space_to_consume -gt 0 ]; then
563 -c "truncate $space_to_consume" \
564 -c "falloc -k 0 $space_to_consume" \
565 $SCRATCH_MNT/.use_space.$nfiles 2>&1
568 export NUM_SPACE_FILES=$nfiles
571 if [ $status -ne 0 ]; then
572 echo "large file prealloc failed"
573 cat $tmp_dir/mnt.err >&2
581 local mkfs_cmd="$MKFS_EXT4_PROG -F"
582 local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
587 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
590 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
591 # manually parse the mkfs output to get the fs size in bytes
592 fs_size=`cat $tmp.mkfsstd | awk ' \
593 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
594 / inodes, / { blks = $3 } \
595 /reserved for the super user/ { resv = $1 } \
596 END { fssize = bs * blks - resv; print fssize }'`
598 _setup_large_ext4_fs $fs_size
602 # output mkfs stdout and stderr
616 # do nothing for cifs
619 # do nothing for ceph
622 # do nothing for overlay
625 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
628 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
631 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
634 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
646 # do nothing for overlay
649 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
652 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
655 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
656 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
660 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
661 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
665 if [ $? -ne 0 ]; then
666 # output stored mkfs output
667 cat $tmp_dir.mkfserr >&2
672 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
675 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
676 _scratch_cleanup_files()
680 # $SCRATCH_DEV is a valid directory in overlay case
681 rm -rf $SCRATCH_DEV/*
685 rm -rf $SCRATCH_MNT/*
698 nfs*|cifs|ceph|overlay)
699 # unable to re-create this fstyp, just remove all files in
700 # $SCRATCH_MNT to avoid EEXIST caused by the leftover files
701 # created in previous runs
702 _scratch_cleanup_files
706 # do nothing for tmpfs
710 _scratch_mkfs_ext4 $*
718 mkfs_cmd="$MKFS_UDF_PROG"
722 mkfs_cmd="$MKFS_BTRFS_PROG"
726 mkfs_cmd="$MKFS_PROG -t $FSTYP -- -F"
727 mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
730 mkfs_cmd="$MKFS_F2FS_PROG"
734 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
735 mkfs_filter="grep -v -e ^mkfs\.ocfs2"
738 mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --"
743 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $*
747 # Helper function to get a spare or replace-target device from
748 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
749 # before _spare_dev_get(). Replace-target-device/Spare-device will
750 # be assigned to SPARE_DEV.
751 # As of now only one replace-target-device/spare-device can be
755 # _scratch_dev_pool_get() <ndevs>
759 # _scratch_dev_pool_put()
763 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
764 if [ $? -ne 0 ]; then
765 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
768 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
769 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
772 # Check if the spare is already assigned
773 typeset -p SPARE_DEV >/dev/null 2>&1
774 if [ $? -eq 0 ]; then
775 if [ ! -z "$SPARE_DEV" ]; then
776 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
780 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
781 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
783 if [ $ndevs -eq $config_ndevs ]; then
784 _notrun "All devs used no spare"
786 # Get a dev that is not used
787 local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
788 SPARE_DEV=${devs[@]:$ndevs:1}
794 typeset -p SPARE_DEV >/dev/null 2>&1
795 if [ $? -ne 0 ]; then
796 _fail "Bug: unset val, must call _spare_dev_get before its put"
799 if [ -z "$SPARE_DEV" ]; then
800 _fail "Bug: str empty, must call _spare_dev_get before its put"
807 # Generally test cases will have..
808 # _require_scratch_dev_pool X
809 # to make sure it has the enough scratch devices including
810 # replace-target and spare device. Now arg1 here is the
811 # required number of scratch devices by a-test-case excluding
812 # the replace-target and spare device. So this function will
813 # set SCRATCH_DEV_POOL to the specified number of devices.
816 # _scratch_dev_pool_get() <ndevs>
819 # _scratch_dev_pool_put()
821 _scratch_dev_pool_get()
823 if [ $# -ne 1 ]; then
824 _fail "Usage: _scratch_dev_pool_get ndevs"
828 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
829 local devs[]="( $SCRATCH_DEV_POOL )"
831 typeset -p config_ndevs >/dev/null 2>&1
832 if [ $? -ne 0 ]; then
833 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
836 if [ $config_ndevs -lt $test_ndevs ]; then
837 _notrun "Need at least test requested number of ndevs $test_ndevs"
840 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
841 export SCRATCH_DEV_POOL_SAVED
842 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
843 export SCRATCH_DEV_POOL
846 _scratch_dev_pool_put()
848 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
849 if [ $? -ne 0 ]; then
850 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
853 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
854 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
857 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
858 export SCRATCH_DEV_POOL_SAVED=""
865 # if dup profile is in mkfs options call _scratch_mkfs instead
866 # because dup profile only works with single device
867 if [[ "$*" =~ dup ]]; then
870 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
874 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
879 # Return the amount of free memory available on the system
882 free -b | grep ^Mem | awk '{print $4}'
885 # Create fs of certain size on scratch device
886 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
887 _scratch_mkfs_sized()
894 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
896 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4|ocfs2)
897 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
901 [ -n "$def_blksz" ] && blocksize=$def_blksz
902 [ -z "$blocksize" ] && blocksize=4096
906 if ! [[ $fssize =~ $re ]] ; then
907 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
909 if ! [[ $blocksize =~ $re ]] ; then
910 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
913 blocks=`expr $fssize / $blocksize`
915 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
916 devsize=`blockdev --getsize64 $SCRATCH_DEV`
917 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
922 # don't override MKFS_OPTIONS that set a block size.
923 echo $MKFS_OPTIONS |egrep -q "b?size="
924 if [ $? -eq 0 ]; then
925 _scratch_mkfs_xfs -d size=$fssize
927 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
930 ext2|ext3|ext4|ext4dev)
931 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
934 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
937 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
941 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
942 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
945 # mkfs.resier4 requires size in KB as input for creating filesystem
946 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
947 `expr $fssize / 1024`
950 # mkfs.f2fs requires # of sectors as an input for the size
951 sector_size=`blockdev --getss $SCRATCH_DEV`
952 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
955 free_mem=`_free_memory_bytes`
956 if [ "$free_mem" -lt "$fssize" ] ; then
957 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
959 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
962 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
967 # Emulate an N-data-disk stripe w/ various stripe units
968 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
974 [ -z "$blocksize" ] && blocksize=4096
976 let sunit_blocks=$sunit_bytes/$blocksize
977 let swidth_blocks=$sunit_blocks*$swidth_mult
981 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
984 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
987 _notrun "can't mkfs $FSTYP with geometry"
993 # Create fs of certain blocksize on scratch device
994 # _scratch_mkfs_blocksized blocksize
995 _scratch_mkfs_blocksized()
1000 if ! [[ $blocksize =~ $re ]] ; then
1001 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1006 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1009 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1012 yes | ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize -C $blocksize $SCRATCH_DEV
1015 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1024 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1032 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1033 # errors found or errors were fixed) and nonzero otherwise; also spits out
1034 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1035 _repair_scratch_fs()
1039 _scratch_xfs_repair "$@" 2>&1
1041 if [ "$res" -ne 0 ]; then
1042 echo "xfs_repair returns $res; replay log?"
1045 if [ "$res" -gt 0 ]; then
1046 echo "mount returns $res; zap log?"
1047 _scratch_xfs_repair -L 2>&1
1048 echo "log zap returns $?"
1050 umount "$SCRATCH_MNT"
1052 _scratch_xfs_repair "$@" 2>&1
1055 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1059 # Let's hope fsck -y suffices...
1060 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1067 >&2 echo "fsck.$FSTYP failed, err=$res"
1079 echo "Usage: _get_pids_by_name process-name" 1>&2
1083 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1084 # HH:MM:SS before the psargs field, use this as the search anchor.
1086 # Matches with $1 (process-name) occur if the first psarg is $1
1087 # or ends in /$1 ... the matching uses sed's regular expressions,
1088 # so passing a regex into $1 will work.
1093 -e 's/[ ][ ]*/ /g' \
1096 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1097 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1100 # fix malloc libs output
1104 # filter out the Electric Fence notice
1107 if (defined $o && /^\s+Electric Fence/) {
1113 print $o if (defined $o);
1117 print $o if (defined $o);
1122 # _df_device : get an IRIX style df line for a given device
1124 # - returns "" if not mounted
1125 # - returns fs type in field two (ala IRIX)
1126 # - joins line together if split by fancy df formatting
1127 # - strips header etc
1134 echo "Usage: _df_device device" 1>&2
1138 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1139 # IPv6 server as a regular expression.
1140 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1141 ($1==what) && (NF==1) {
1155 # _df_dir : get an IRIX style df line for device where a directory resides
1157 # - returns fs type in field two (ala IRIX)
1158 # - joins line together if split by fancy df formatting
1159 # - strips header etc
1166 echo "Usage: _df_dir device" 1>&2
1170 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1186 # return percentage used disk space for mounted device
1192 echo "Usage: _used device" 1>&2
1196 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1199 # return the FS type of a mounted device
1205 echo "Usage: _fs_type device" 1>&2
1210 # The Linux kernel shows NFSv4 filesystems in df output as
1211 # filesystem type nfs4, although we mounted it as nfs earlier.
1212 # Fix the filesystem type up here so that the callers don't
1213 # have to bother with this quirk.
1215 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1218 # return the FS mount options of a mounted device
1220 # should write a version which just parses the output of mount for IRIX
1221 # compatibility, but since this isn't used at all, at the moment I'll leave
1228 echo "Usage: _fs_options device" 1>&2
1232 $AWK_PROG -v dev=$1 '
1233 match($1,dev) { print $4 }
1237 # returns device number if a file is a block device
1243 echo "Usage: _is_block_dev dev" 1>&2
1248 if [ -L "${_dev}" ]; then
1249 _dev=`readlink -f "${_dev}"`
1252 if [ -b "${_dev}" ]; then
1253 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1257 # Do a command, log it to $seqres.full, optionally test return status
1258 # and die if command fails. If called with one argument _do executes the
1259 # command, logs it, and returns its exit status. With two arguments _do
1260 # first prints the message passed in the first argument, and then "done"
1261 # or "fail" depending on the return status of the command passed in the
1262 # second argument. If the command fails and the variable _do_die_on_error
1263 # is set to "always" or the two argument form is used and _do_die_on_error
1264 # is set to "message_only" _do will print an error message to
1265 # $seqres.out and exit.
1269 if [ $# -eq 1 ]; then
1271 elif [ $# -eq 2 ]; then
1274 echo -n "$_note... "
1276 echo "Usage: _do [note] cmd" 1>&2
1280 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1281 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1282 cat $tmp._out | _fix_malloc >>$seqres.full
1283 if [ $# -eq 2 ]; then
1284 if [ $ret -eq 0 ]; then
1291 && [ "$_do_die_on_error" = "always" \
1292 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1294 [ $# -ne 2 ] && echo
1295 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1302 # bail out, setting up .notrun file. Need to kill the filesystem check files
1303 # here, otherwise they are set incorrectly for the next test.
1307 echo "$*" > $seqres.notrun
1308 echo "$seq not run: $*"
1309 rm -f ${RESULT_DIR}/require_test*
1310 rm -f ${RESULT_DIR}/require_scratch*
1316 # just plain bail out
1320 echo "$*" | tee -a $seqres.full
1321 echo "(see $seqres.full for details)"
1326 # tests whether $FSTYP is one of the supported filesystems for a test
1332 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1338 _notrun "not suitable for this filesystem type: $FSTYP"
1342 # tests whether $FSTYP is one of the supported OSes for a test
1348 if [ "$h" = "$HOSTOS" ]
1354 _notrun "not suitable for this OS: $HOSTOS"
1357 # check if a FS on a device is mounted
1358 # if so, verify that it is mounted on mount point
1359 # if fstype is given as argument, verify that it is also
1360 # mounted with correct fs type
1370 # Note that we use -F here so grep doesn't try to interpret an NFS over
1371 # IPv6 server as a regular expression
1372 local mount_rec=`_mount | grep -F "$dev"`
1373 [ -n "$mount_rec" ] || return 1 # 1 = not mounted
1375 # if it's mounted, make sure its on $mnt
1376 if ! (echo $mount_rec | grep -q "$mnt")
1378 echo "$devname=$dev is mounted but not on $mntname=$mnt - aborting"
1379 echo "Already mounted result:"
1381 return 2 # 2 = mounted on wrong mnt
1384 if [ -n "$type" -a "`_fs_type $dev`" != "$type" ]
1386 echo "$devname=$dev is mounted but not a type $type filesystem"
1387 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
1389 return 3 # 3 = mounted as wrong type
1391 return 0 # 0 = mounted as expected
1394 # this test needs a scratch partition - check we're ok & unmount it
1395 # No post-test check of the device is required. e.g. the test intentionally
1396 # finishes the test with the filesystem in a corrupt state
1397 _require_scratch_nocheck()
1401 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1402 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1403 _notrun "this test requires a valid \$SCRATCH_DEV"
1405 if [ ! -d "$SCRATCH_MNT" ]; then
1406 _notrun "this test requires a valid \$SCRATCH_MNT"
1410 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1411 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1412 _notrun "this test requires a valid \$SCRATCH_DEV"
1414 if [ ! -d "$SCRATCH_MNT" ]; then
1415 _notrun "this test requires a valid \$SCRATCH_MNT"
1419 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1420 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1422 if [ ! -d "$SCRATCH_MNT" ]; then
1423 _notrun "this test requires a valid \$SCRATCH_MNT"
1427 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1429 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1433 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1435 _notrun "this test requires a valid \$SCRATCH_DEV"
1437 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1439 _notrun "this test requires a valid \$SCRATCH_DEV"
1441 if [ ! -d "$SCRATCH_MNT" ]
1443 _notrun "this test requires a valid \$SCRATCH_MNT"
1448 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
1450 [ $err -le 1 ] || exit 1
1453 # if it's mounted, unmount it
1454 if ! _scratch_unmount
1456 echo "failed to unmount $SCRATCH_DEV"
1460 rm -f ${RESULT_DIR}/require_scratch
1463 # we need the scratch device and it should be checked post test.
1466 _require_scratch_nocheck
1467 touch ${RESULT_DIR}/require_scratch
1471 # this test needs a test partition - check we're ok & mount it
1477 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1478 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1479 _notrun "this test requires a valid \$TEST_DEV"
1481 if [ ! -d "$TEST_DIR" ]; then
1482 _notrun "this test requires a valid \$TEST_DIR"
1486 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1487 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1488 _notrun "this test requires a valid \$TEST_DEV"
1490 if [ ! -d "$TEST_DIR" ]; then
1491 _notrun "this test requires a valid \$TEST_DIR"
1495 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1496 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1498 if [ ! -d "$TEST_DIR" ]; then
1499 _notrun "this test requires a valid \$TEST_DIR"
1503 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1505 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1509 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1511 _notrun "this test requires a valid \$TEST_DEV"
1513 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1515 _notrun "this test requires a valid \$TEST_DEV"
1517 if [ ! -d "$TEST_DIR" ]
1519 _notrun "this test requires a valid \$TEST_DIR"
1524 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
1526 [ $err -le 1 ] || exit 1
1529 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1530 if [ $? -ne 1 ]; then
1535 touch ${RESULT_DIR}/require_test
1538 # this test needs a logdev
1542 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1543 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1544 [ "$USE_EXTERNAL" != yes ] && \
1545 _notrun "This test requires USE_EXTERNAL to be enabled"
1547 # ensure its not mounted
1548 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1551 # this test requires loopback device support
1555 if [ "$HOSTOS" != "Linux" ]
1557 _notrun "This test requires linux for loopback device support"
1560 modprobe loop >/dev/null 2>&1
1561 if grep loop /proc/devices >/dev/null 2>&1
1565 _notrun "This test requires loopback device support"
1569 # this test requires ext2 filesystem support
1573 if [ "$HOSTOS" != "Linux" ]
1575 _notrun "This test requires linux for ext2 filesystem support"
1578 modprobe ext2 >/dev/null 2>&1
1579 if grep ext2 /proc/filesystems >/dev/null 2>&1
1583 _notrun "This test requires ext2 filesystem support"
1587 # this test requires tmpfs filesystem support
1591 modprobe tmpfs >/dev/null 2>&1
1592 grep -q tmpfs /proc/filesystems ||
1593 _notrun "this test requires tmpfs support"
1596 # this test requires that (large) loopback device files are not in use
1598 _require_no_large_scratch_dev()
1600 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1601 _notrun "Large filesystem testing in progress, skipped this test"
1604 # this test requires that a realtime subvolume is in use, and
1605 # that the kernel supports realtime as well.
1609 [ "$USE_EXTERNAL" = yes ] || \
1610 _notrun "External volumes not in use, skipped this test"
1611 [ "$SCRATCH_RTDEV" = "" ] && \
1612 _notrun "Realtime device required, skipped this test"
1615 # this test requires that a specified command (executable) exists
1616 # $1 - command, $2 - name for error message
1618 # Note: the command string might have parameters, so strip them before checking
1619 # whether it is executable.
1622 if [ $# -eq 2 ]; then
1624 elif [ $# -eq 1 ]; then
1627 _fail "usage: _require_command <command> [<name>]"
1630 _command=`echo "$1" | awk '{ print $1 }'`
1631 if [ ! -x "$_command" ]; then
1632 _notrun "$_name utility required, skipped this test"
1636 # this test requires the device to be valid block device
1638 _require_block_device()
1640 if [ -z "$1" ]; then
1641 echo "Usage: _require_block_device <dev>" 1>&2
1644 if [ "`_is_block_dev "$1"`" == "" ]; then
1645 _notrun "require $1 to be valid block disk"
1649 # brd based ram disks erase the device when they receive a flush command when no
1650 # active references are present. This causes problems for DM devices sitting on
1651 # top of brd devices as DM doesn't hold active references to the brd device.
1652 _require_sane_bdev_flush()
1654 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1655 if [ $? -eq 0 ]; then
1656 _notrun "This test requires a sane block device flush"
1660 # this test requires a specific device mapper target
1661 _require_dm_target()
1665 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1667 _require_block_device $SCRATCH_DEV
1668 _require_sane_bdev_flush $SCRATCH_DEV
1669 _require_command "$DMSETUP_PROG" dmsetup
1671 modprobe dm-$_target >/dev/null 2>&1
1673 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1674 if [ $? -ne 0 ]; then
1675 _notrun "This test requires dm $_target support"
1679 # this test requires the ext4 kernel support crc feature on scratch device
1681 _require_scratch_ext4_crc()
1683 _scratch_mkfs_ext4 >/dev/null 2>&1
1684 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1685 _scratch_mount >/dev/null 2>&1 \
1686 || _notrun "Kernel doesn't support metadata_csum feature"
1690 # this test requires the bigalloc feature to be available in mkfs.ext4
1692 _require_ext4_mkfs_bigalloc()
1694 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1695 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1698 # this test requires the ext4 kernel support bigalloc feature
1700 _require_ext4_bigalloc()
1702 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1703 _scratch_mount >/dev/null 2>&1 \
1704 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1708 # this test requires that external log/realtime devices are not in use
1710 _require_nonexternal()
1712 [ "$USE_EXTERNAL" = yes ] && \
1713 _notrun "External device testing in progress, skipped this test"
1716 # this test requires that a (specified) aio-dio executable exists
1717 # $1 - command (optional)
1723 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1724 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1726 AIO_TEST=src/aio-dio-regress/$1
1727 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1732 # this test requires that a test program exists under src/
1733 # $1 - command (require)
1735 _require_test_program()
1738 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1741 # run an aio-dio program
1747 echo "usage: _run_aiodio command_name" 2>&1
1753 local testtemp=$TEST_DIR/aio-testfile
1755 $AIO_TEST $testtemp 2>&1
1762 # this test requires y2038 sysfs switch and filesystem
1763 # timestamp ranges support.
1766 local device=${1:-$TEST_DEV}
1767 local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
1769 if [ ! -e $sysfsdir ]; then
1770 _notrun "no kernel support for y2038 sysfs switch"
1774 read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
1775 if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
1776 _notrun "filesystem $FSTYP timestamp bounds are unknown"
1780 _filesystem_timestamp_range()
1782 device=${1:-$TEST_DEV}
1785 if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
1786 echo "-2147483648 15032385535"
1788 echo "-2147483648 2147483647"
1793 echo "-2147483648 2147483647"
1799 echo "-2147483648 2147483647"
1807 # indicate whether YP/NIS is active or not
1812 dn=$(domainname 2>/dev/null)
1813 test -n "${dn}" -a "${dn}" != "(none)" -a "${dn}" != "localdomain"
1817 # cat the password file
1821 [ $(_yp_active) -eq 0 ] && ypcat passwd
1825 # cat the group file
1829 [ $(_yp_active) -eq 0 ] && ypcat group
1833 # check for a user on the machine, fsgqa as default
1841 _cat_passwd | grep -q $qa_user
1842 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1843 echo /bin/true | su $qa_user
1844 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1847 # check for a group on the machine, fsgqa as default
1855 _cat_group | grep -q $qa_group
1856 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1862 s,.*Permission\sdenied.*,Permission denied,;
1863 s,.*no\saccess\sto\stty.*,,;
1864 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1871 if [ "$HOSTOS" == "IRIX" ]
1873 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1875 echo $1 | su -s /bin/bash $qa_user 2>&1 | _filter_user_do
1879 _require_xfs_io_command()
1883 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
1890 testfile=$TEST_DIR/$$.xfs_io
1893 testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1`
1896 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1898 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare")
1899 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1900 -c "$command 4k 8k" $testfile 2>&1`
1903 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1904 -c "fiemap -v" $testfile 2>&1`
1907 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1909 echo $testio | egrep -q "invalid option|Is a directory" && \
1910 _notrun "xfs_io $command support is missing"
1913 testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
1914 echo $testio | egrep -q "Inappropriate ioctl" && \
1915 _notrun "xfs_io $command support is missing"
1918 # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
1919 # a new -C flag was introduced to execute one shot commands.
1920 # Check for -C flag support as an indication for the bug fix.
1921 testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
1922 echo $testio | egrep -q "invalid option" && \
1923 _notrun "xfs_io $command support is missing"
1926 testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
1929 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1932 rm -f $testfile 2>&1 > /dev/null
1933 echo $testio | grep -q "not found" && \
1934 _notrun "xfs_io $command support is missing"
1935 echo $testio | grep -q "Operation not supported" && \
1936 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1937 echo $testio | grep -q "foreign file active" && \
1938 _notrun "xfs_io $command not supported on $FSTYP"
1940 test -z "$param" && return
1941 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
1942 _notrun "xfs_io $command doesn't support $param"
1945 # check that kernel and filesystem support direct I/O
1948 if [ $FSTYP = "ext4" ] ; then
1949 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
1950 _notrun "ext4 encryption doesn't support O_DIRECT"
1953 testfile=$TEST_DIR/$$.direct
1954 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1955 if [ $? -ne 0 ]; then
1956 _notrun "O_DIRECT is not supported"
1958 rm -f $testfile 2>&1 > /dev/null
1961 # Check that the filesystem supports swapfiles
1962 _require_scratch_swapfile()
1966 _scratch_mkfs >/dev/null
1969 # Minimum size for mkswap is 10 pages
1970 local size=$(($(get_page_size) * 10))
1972 _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
1973 mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
1974 if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
1976 _notrun "swapfiles are not supported"
1979 swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
1983 # Check that a fs has enough free space (in 1024b blocks)
1988 BLOCKS=$2 # in units of 1024
1989 let GB=$BLOCKS/1024/1024
1991 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
1992 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1993 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1997 # Check if the filesystem supports sparse files.
1999 # Unfortunately there is no better way to do this than a manual black list.
2001 _require_sparse_files()
2005 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2014 #boot_params always present in debugfs
2015 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2018 _require_fail_make_request()
2020 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2021 || _notrun "$DEBUGFS_MNT/fail_make_request \
2022 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2026 # Check if the file system supports seek_data/hole
2028 _require_seek_data_hole()
2030 testfile=$TEST_DIR/$$.seek
2031 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2032 rm -f $testfile &>/dev/null
2033 echo $testseek | grep -q "Kernel does not support" && \
2034 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2039 _require_test_program "runas"
2044 "$here/src/runas" "$@"
2047 _require_richacl_prog()
2049 _require_command "$GETRICHACL_PROG" getrichacl
2050 _require_command "$SETRICHACL_PROG" setrichacl
2053 _require_scratch_richacl_xfs()
2055 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2056 || _notrun "mkfs.xfs doesn't have richacl feature"
2057 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2058 _scratch_mount >/dev/null 2>&1 \
2059 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2063 _require_scratch_richacl_ext4()
2065 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2066 || _notrun "can't mkfs $FSTYP with option -O richacl"
2067 _scratch_mount >/dev/null 2>&1 \
2068 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2072 _require_scratch_richacl_support()
2075 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2076 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2080 _require_scratch_richacl()
2083 xfs) _require_scratch_richacl_xfs
2085 ext4) _require_scratch_richacl_ext4
2088 _require_scratch_richacl_support
2090 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2095 _scratch_mkfs_richacl()
2098 xfs) _scratch_mkfs_xfs -m richacl=1
2100 ext4) _scratch_mkfs -O richacl
2108 # check that a FS on a device is mounted
2109 # if so, return mount point
2115 echo "Usage: _is_mounted device" 1>&2
2121 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2122 pattern { print $3 ; exit 0 }
2126 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2131 # remount a FS to a new mode (ro or rw)
2137 echo "Usage: _remount device ro/rw" 1>&2
2143 if ! mount -o remount,$mode $device
2145 echo "_remount: failed to remount filesystem on $device as $mode"
2150 # Run the appropriate repair/check on a filesystem
2152 # if the filesystem is mounted, it's either remounted ro before being
2153 # checked or it's unmounted and then remounted
2156 # If set, we remount ro instead of unmounting for fsck
2159 _umount_or_remount_ro()
2163 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2168 mountpoint=`_is_mounted $device`
2170 if [ $USE_REMOUNT -eq 0 ]; then
2171 $UMOUNT_PROG $device
2178 _mount_or_remount_rw()
2180 if [ $# -ne 3 ]; then
2181 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2188 if [ $USE_REMOUNT -eq 0 ]; then
2189 if [ "$FSTYP" != "overlay" ]; then
2190 _mount -t $FSTYP $mount_opts $device $mountpoint
2192 _overlay_mount $device $mountpoint
2194 if [ $? -ne 0 ]; then
2195 echo "!!! failed to remount $device on $mountpoint"
2205 # Check a generic filesystem in no-op mode; this assumes that the
2206 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2207 # and that it will still return an errno for corruption in this mode.
2209 # Filesystems which don't support this will need to define their
2210 # own check routine.
2212 _check_generic_filesystem()
2216 # If type is set, we're mounted
2217 type=`_fs_type $device`
2220 if [ "$type" = "$FSTYP" ]
2223 mountpoint=`_umount_or_remount_ro $device`
2226 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2229 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2231 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2232 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2233 cat $tmp.fsck >>$seqres.full
2234 echo "*** end fsck.$FSTYP output" >>$seqres.full
2242 echo "*** mount output ***" >>$seqres.full
2243 _mount >>$seqres.full
2244 echo "*** end mount output" >>$seqres.full
2245 elif [ "$type" = "$FSTYP" ]
2248 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2252 if [ $ok -eq 0 ]; then
2254 if [ "$iam" != "check" ]; then
2263 # Filter the knowen errors the UDF Verifier reports.
2264 _udf_test_known_error_filter()
2266 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."
2270 _check_udf_filesystem()
2272 [ "$DISABLE_UDF_TEST" == "1" ] && return
2274 if [ $# -ne 1 -a $# -ne 2 ]
2276 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2280 if [ ! -x $here/src/udf_test ]
2282 echo "udf_test not installed, please download and build the Philips"
2283 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2284 echo "Then copy the udf_test binary to $here/src/."
2285 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2293 LAST_BLOCK=`expr \( $2 - 1 \)`
2294 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2297 rm -f $seqres.checkfs
2298 sleep 1 # Due to a problem with time stamps in udf_test
2299 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2300 _udf_test_known_error_filter | \
2301 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2302 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2313 # no way to check consistency for nfs
2316 # no way to check consistency for cifs
2319 # no way to check consistency for CephFS
2322 # no way to check consistency for overlay
2325 # do nothing for now
2328 _check_btrfs_filesystem $TEST_DEV
2331 # no way to check consistency for tmpfs
2334 _check_generic_filesystem $TEST_DEV
2342 [ $# -eq 1 ] && device=$1
2348 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2349 SCRATCH_LOG="$SCRATCH_LOGDEV"
2351 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2352 SCRATCH_RT="$SCRATCH_RTDEV"
2354 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2357 _check_udf_filesystem $device $udf_fsize
2360 # Don't know how to check an NFS filesystem, yet.
2363 # Don't know how to check a CIFS filesystem, yet.
2366 # no way to check consistency for CephFS
2369 # no way to check consistency for overlay
2372 _check_btrfs_filesystem $device
2375 # no way to check consistency for tmpfs
2378 _check_generic_filesystem $device
2383 _full_fstyp_details()
2385 [ -z "$FSTYP" ] && FSTYP=xfs
2386 if [ $FSTYP = xfs ]; then
2387 if [ -d /proc/fs/xfs ]; then
2388 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2389 FSTYP="$FSTYP (non-debug)"
2390 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2391 FSTYP="$FSTYP (debug)"
2394 if uname -a | grep -qi 'debug'; then
2395 FSTYP="$FSTYP (debug)"
2397 FSTYP="$FSTYP (non-debug)"
2404 _full_platform_details()
2410 echo "$os/$platform $host $kernel"
2415 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2417 elif [ "`uname`" == "Linux" ]; then
2420 echo Unknown operating system: `uname`
2425 _link_out_file_named()
2430 my $feature, $result, $suffix, $opts;
2432 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2433 $feathash{$feature} = 1;
2435 $result = "default";
2440 ($opts, $suffix) = split(/ *: */);
2441 foreach my $opt (split(/,/, $opts)) {
2442 if (!exists($feathash{$opt})) {
2456 ln -fs $SRC.$SUFFIX $1
2461 if [ $# -eq 0 ]; then
2462 FEATURES="$(_get_os_name)"
2463 if [ -n "$MOUNT_OPTIONS" ]; then
2464 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2470 _link_out_file_named $seqfull.out "$FEATURES"
2479 # convert urandom incompressible data to compressible text data
2482 od /dev/urandom | dd iflag=fullblock ${*}
2485 #takes files, randomdata
2493 if [ $size -gt 0 ]; then
2494 if [ "$2" == "false" ]; then
2495 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2496 elif [ "$2" == "comp" ]; then
2497 _ddt of=$file bs=1024 count=$size 2>&1 | _filter_dd
2499 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2506 # takes dirname, depth, randomdata
2509 dirname=$1; depth=$2; randomdata=$3
2510 mkdir $dirname || die "mkdir $dirname failed"
2513 _nfiles $files $randomdata # files for this dir and data type
2515 [ $depth -eq 0 ] && return
2516 let deep=$depth-1 # go 1 down
2518 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2521 while [ $d -lt $dirs ]
2523 _descend d$d $deep &
2529 # Populate a filesystem with inodes for performance experiments
2531 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2536 dirs=5 # ndirs in each subdir till leaves
2537 size=0 # sizeof files in K
2538 files=100 # num files in _each_ subdir
2539 depth=2 # depth of tree from root to leaves
2541 root=root # path of initial root of directory tree
2542 randomdata=false # -x data type urandom, zero or compressible
2545 while getopts "d:f:n:r:s:v:x:c" c
2554 x) randomdata=true;;
2555 c) randomdata=comp;;
2559 _descend $root $depth $randomdata
2564 [ $verbose = true ] && echo done
2567 # query whether the given file has the given inode flag set
2574 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2580 # query the given files extsize allocator hint in bytes (if any)
2587 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2588 awk '/^xattr.extsize =/ { print $3 }'`
2589 [ -z "$blocks" ] && blocks="0"
2593 # scratch_dev_pool should contain the disks pool for the btrfs raid
2594 _require_scratch_dev_pool()
2599 if [ -z "$SCRATCH_DEV_POOL" ]; then
2600 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2603 if [ -z "$1" ]; then
2609 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2613 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2614 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2618 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2622 for i in $SCRATCH_DEV_POOL; do
2623 if [ "`_is_block_dev "$i"`" = "" ]; then
2624 _notrun "this test requires valid block disk $i"
2626 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2627 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2629 if _mount | grep -q $i; then
2630 if ! $UMOUNT_PROG $i; then
2631 echo "failed to unmount $i - aborting"
2635 # to help better debug when something fails, we remove
2636 # traces of previous btrfs FS on the dev.
2637 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2641 # ensure devices in SCRATCH_DEV_POOL are of the same size
2642 # must be called after _require_scratch_dev_pool
2643 _require_scratch_dev_pool_equal_size()
2649 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2650 _size=`_get_device_size $SCRATCH_DEV`
2651 for _dev in $SCRATCH_DEV_POOL; do
2652 _newsize=`_get_device_size $_dev`
2653 if [ $_size -ne $_newsize ]; then
2654 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2659 # We will check if the device is deletable
2660 _require_deletable_scratch_dev_pool()
2664 for i in $SCRATCH_DEV_POOL; do
2665 x=`echo $i | cut -d"/" -f 3`
2666 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2667 _notrun "$i is a device which is not deletable"
2672 # Check that fio is present, and it is able to execute given jobfile
2677 _require_command "$FIO_PROG" fio
2678 if [ -z "$1" ]; then
2682 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2683 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2686 # Does freeze work on this fs?
2689 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2691 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2692 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2695 # Does shutdown work on this fs?
2696 _require_scratch_shutdown()
2698 [ -x src/godown ] || _notrun "src/godown executable not found"
2700 _scratch_mkfs > /dev/null 2>&1
2702 src/godown -f $SCRATCH_MNT 2>&1 \
2703 || _notrun "$FSTYP does not support shutdown"
2707 # Does dax mount option work on this dev/fs?
2708 _require_scratch_dax()
2711 _scratch_mkfs > /dev/null 2>&1
2712 _scratch_mount -o dax
2713 # Check options to be sure. XFS ignores dax option
2714 # and goes on if dev underneath does not support dax.
2715 _fs_options $SCRATCH_DEV | grep -qw "dax" || \
2716 _notrun "$SCRATCH_DEV $FSTYP does not support -o dax"
2720 # Does norecovery support by this fs?
2721 _require_norecovery()
2723 _scratch_mount -o ro,norecovery || \
2724 _notrun "$FSTYP does not support norecovery"
2728 # Does this filesystem support metadata journaling?
2729 # We exclude ones here that don't; otherwise we assume that it does, so the
2730 # test will run, fail, and motivate someone to update this test for a new
2733 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2734 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2736 _require_metadata_journaling()
2746 _notrun "$FSTYP does not support metadata journaling"
2749 # ext4 could be mkfs'd without a journal...
2751 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2752 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2753 # ext4 might not load a journal
2754 _exclude_scratch_mount_option "noload"
2757 # by default we pass; if you need to, add your fs above!
2762 # Does fiemap support?
2765 _require_xfs_io_command "fiemap"
2770 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2775 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2778 # arg 1 is dev to remove and is output of the below eg.
2779 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2785 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2787 stat $disk > /dev/null 2>&1
2788 while [ $? -eq 0 ]; do
2790 stat $disk > /dev/null 2>&1
2794 # arg 1 is dev to add and is output of the below eg.
2795 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2800 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2801 h=`echo ${1} | cut -d":" -f 1`
2802 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2804 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2806 # ensure the device comes online
2808 for i in `seq 1 10`; do
2809 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2810 dev=`ls /sys/class/scsi_device/${1}/device/block`
2811 for j in `seq 1 10`;
2813 stat /dev/$dev > /dev/null 2>&1
2814 if [ $? -eq 0 ]; then
2825 if [ $dev_back_oneline -eq 0 ]; then
2826 echo "/dev/$dev online failed" >> $seqres.full
2828 echo "/dev/$dev is back online" >> $seqres.full
2834 if [ -z "$FSTRIM_PROG" ]; then
2835 _notrun "This test requires fstrim utility."
2839 _require_batched_discard()
2841 if [ $# -ne 1 ]; then
2842 echo "Usage: _require_batched_discard mnt_point" 1>&2
2846 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2851 if [ -z "$DUMPE2FS_PROG" ]; then
2852 _notrun "This test requires dumpe2fs utility."
2858 if [ ! -e /proc/self/uid_map ]; then
2859 _notrun "This test requires procfs uid_map support."
2861 if [ ! -e /proc/self/gid_map ]; then
2862 _notrun "This test requires procfs gid_map support."
2868 FSSUM_PROG=$here/src/fssum
2869 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2874 CLONER_PROG=$here/src/cloner
2875 [ -x $CLONER_PROG ] || \
2876 _notrun "cloner binary not present at $CLONER_PROG"
2879 # Normalize mount options from global $MOUNT_OPTIONS
2880 # Convert options like "-o opt1,opt2 -oopt3" to
2882 _normalize_mount_options()
2884 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
2887 # skip test if MOUNT_OPTIONS contains the given strings
2888 _exclude_scratch_mount_option()
2890 local mnt_opts=$(_normalize_mount_options)
2892 while [ $# -gt 0 ]; do
2893 if echo $mnt_opts | grep -qw "$1"; then
2894 _notrun "mount option \"$1\" not allowed in this test"
2902 _exclude_scratch_mount_option "noatime"
2903 if [ "$FSTYP" == "nfs" ]; then
2904 _notrun "atime related mount options have no effect on NFS"
2910 _scratch_mkfs > /dev/null 2>&1
2911 _scratch_mount -o relatime || \
2912 _notrun "relatime not supported by the current kernel"
2918 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2919 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2922 _create_loop_device()
2925 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2929 _destroy_loop_device()
2932 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2935 _scale_fsstress_args()
2938 while [ $# -gt 0 ]; do
2940 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2941 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2942 *) args="$args $1" ;;
2950 # Return the logical block size if running on a block device,
2951 # else substitute the page size.
2953 _min_dio_alignment()
2957 if [ -b "$dev" ]; then
2958 blockdev --getss $dev
2960 $here/src/feature -s
2966 echo "# $@" >> $seqres.full 2>&1
2967 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2970 _require_test_symlinks()
2972 # IRIX UDF does not support symlinks
2973 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2974 _notrun "Require symlinks support"
2975 target=`mktemp -p $TEST_DIR`
2976 link=`mktemp -p $TEST_DIR -u`
2977 ln -s `basename $target` $link
2978 if [ "$?" -ne 0 ]; then
2980 _notrun "Require symlinks support"
2985 _require_test_fcntl_advisory_locks()
2987 [ "$FSTYP" != "cifs" ] && return 0
2988 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2989 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2990 _notrun "Require fcntl advisory locks support"
2993 _require_test_lsattr()
2995 testio=$(lsattr -d $TEST_DIR 2>&1)
2996 echo $testio | grep -q "Operation not supported" && \
2997 _notrun "lsattr not supported by test filesystem type: $FSTYP"
2998 echo $testio | grep -q "Inappropriate ioctl for device" && \
2999 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3006 touch $TEST_DIR/syscalltest
3007 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3009 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3010 if [ "$status" -ne 0 ]; then
3011 _notrun "file system doesn't support chattr +$attribute"
3013 cat $TEST_DIR/syscalltest.out >> $seqres.full
3015 rm -f $TEST_DIR/syscalltest.out
3020 if [ -z "$1" ]; then
3021 echo "Usage: _get_total_inode <mnt>"
3025 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3031 if [ -z "$1" ]; then
3032 echo "Usage: _get_used_inode <mnt>"
3036 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3040 _get_used_inode_percent()
3042 if [ -z "$1" ]; then
3043 echo "Usage: _get_used_inode_percent <mnt>"
3047 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3054 if [ -z "$1" ]; then
3055 echo "Usage: _get_free_inode <mnt>"
3059 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3063 # get the available space in bytes
3065 _get_available_space()
3067 if [ -z "$1" ]; then
3068 echo "Usage: _get_available_space <mnt>"
3072 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3073 echo $((avail_kb * 1024))
3076 # return device size in kb
3079 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3082 # check dmesg log for WARNING/Oops/etc.
3085 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3088 rm -f ${RESULT_DIR}/check_dmesg
3090 # default filter is a simple cat command, caller could provide a
3091 # customized filter and pass the name through the first argument, to
3092 # filter out intentional WARNINGs or Oopses
3095 # search the dmesg log of last run of $seqnum for possible failures
3096 # use sed \cregexpc address type, since $seqnum contains "/"
3097 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3098 tac | $filter >$seqres.dmesg
3099 grep -q -e "kernel BUG at" \
3103 -e "possible recursive locking detected" \
3104 -e "Internal error" \
3105 -e "INFO: suspicious RCU usage" \
3106 -e "INFO: possible circular locking dependency detected" \
3107 -e "general protection fault:" \
3109 if [ $? -eq 0 ]; then
3110 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3118 # don't check dmesg log after test
3119 _disable_dmesg_check()
3121 rm -f ${RESULT_DIR}/check_dmesg
3126 if [ "$iam" == new ]
3130 # make some further configuration checks here
3131 if [ "$TEST_DEV" = "" ]
3133 echo "common/rc: Error: \$TEST_DEV is not set"
3137 # if $TEST_DEV is not mounted, mount it now as XFS
3138 if [ -z "`_fs_type $TEST_DEV`" ]
3140 # $TEST_DEV is not mounted
3143 echo "common/rc: retrying test device mount with external set"
3144 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3147 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3153 # Sanity check that TEST partition is not mounted at another mount point
3154 # or as another fs type
3155 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR $FSTYP || exit 1
3156 if [ -n "$SCRATCH_DEV" ]; then
3157 # Sanity check that SCRATCH partition is not mounted at another
3158 # mount point, because it is about to be unmounted and formatted.
3159 # Another fs type for scratch is fine (bye bye old fs type).
3160 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT
3161 [ $? -le 1 ] || exit 1
3164 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3165 $XFS_IO_PROG -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3166 export XFS_IO_PROG="$XFS_IO_PROG -F"
3168 # xfs_io -i option starts an idle thread for xfs_io.
3169 # With single threaded process, the file table is not shared
3170 # and file structs are not reference counted.
3171 # Spawning an idle thread can help detecting file struct
3172 # reference leaks, so we want to enable the option whenever
3174 $XFS_IO_PROG -i -c quit 2>/dev/null && \
3175 export XFS_IO_PROG="$XFS_IO_PROG -i"
3177 # xfs_copy on v5 filesystems do not require the "-d" option if xfs_db
3178 # can change the UUID on v5 filesystems
3179 if [ "$FSTYP" == "xfs" ]; then
3181 $MKFS_XFS_PROG -d file,name=/tmp/$$.img,size=512m >/dev/null 2>&1
3182 # xfs_db will return 0 even if it can't generate a new uuid, so
3183 # check the output to make sure if it can change UUID of V5 xfs
3184 $XFS_DB_PROG -x -c "uuid generate" /tmp/$$.img \
3185 | grep -q "invalid UUID\|supported on V5 fs" \
3186 && export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3191 # get real device path name by following link
3195 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3196 _dev=`readlink -f "$_dev"`
3201 # basename of a device
3204 echo `basename $(_real_dev $1)`
3209 local _dev=`_real_dev $1`
3210 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3211 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3212 _maj=$(echo "ibase=16; $_maj" | bc)
3213 _min=$(echo "ibase=16; $_min" | bc)
3214 echo /sys/dev/block/$_maj:$_min
3217 # Get the minimum block size of a file. Usually this is the
3218 # minimum fs block size, but some filesystems (ocfs2) do block
3219 # mappings in larger units.
3220 _get_file_block_size()
3222 if [ -z $1 ] || [ ! -d $1 ]; then
3223 echo "Missing mount point argument for _get_file_block_size"
3226 if [ "$FSTYP" = "ocfs2" ]; then
3233 # Get the minimum block size of an fs.
3236 if [ -z $1 ] || [ ! -d $1 ]; then
3237 echo "Missing mount point argument for _get_block_size"
3245 echo $(getconf PAGE_SIZE)
3252 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3253 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3254 echo "$@" >>$seqres.full
3255 rm -f $TEST_DIR/junk
3256 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3257 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3263 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3265 # Only one argument is needed:
3266 # - attr: path name under /sys/fs/$FSTYP/DEV
3269 # _require_fs_sysfs error/fail_at_unmount
3273 local dname=$(_short_dev $TEST_DEV)
3275 if [ -z "$attr" -o -z "$dname" ];then
3276 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3279 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3280 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3284 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3286 # All arguments are necessary, and in this order:
3287 # - dev: device name, e.g. $SCRATCH_DEV
3288 # - attr: path name under /sys/fs/$FSTYP/$dev
3289 # - content: the content of $attr
3292 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3293 _set_fs_sysfs_attr()
3301 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3302 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3305 local dname=$(_short_dev $dev)
3306 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3309 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3311 # All arguments are necessary, and in this order:
3312 # - dev: device name, e.g. $SCRATCH_DEV
3313 # - attr: path name under /sys/fs/$FSTYP/$dev
3316 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3317 _get_fs_sysfs_attr()
3322 if [ ! -b "$dev" -o -z "$attr" ];then
3323 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3326 local dname=$(_short_dev $dev)
3327 cat /sys/fs/${FSTYP}/${dname}/${attr}
3334 ################################################################################
3335 # make sure this script returns success