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 $@
76 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
79 # Prints the md5 checksum of a given file
82 md5sum $1 | cut -d ' ' -f1
85 # Write a byte into a range of a file
93 "$XFS_IO_PROG" $xfs_io_args -f -c "pwrite -S $pattern $offset $len" "$file"
96 # mmap-write a byte into a range of a file
104 "$XFS_IO_PROG" -f -c "mmap -rw 0 $mmap_len" -c "mwrite -S $pattern $offset $len" "$file"
107 # ls -l w/ selinux sometimes puts a dot at the end:
108 # -rwxrw-r--. id1 id2 file1
109 # Also filter out lost+found directory on extN file system if present
113 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
116 # we need common/config
117 if [ "$iam" != "check" ]
119 if ! . ./common/config
121 echo "$iam: failed to source common/config"
126 # check for correct setup
129 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
130 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
131 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
132 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
135 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
138 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
141 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
144 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
153 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
157 # make sure we have a standard umask
162 $MOUNT_PROG `_mount_ops_filter $*`
170 if [ "$FSTYP" != "xfs" ]; then
176 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
185 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
186 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
187 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
188 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
196 if [ "$FSTYP" != "xfs" ]; then
210 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
211 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
212 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
213 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
220 #get mount point to handle dmapi mtpt option correctly
222 [ $last_index -gt 0 ] && shift $last_index
225 # irix is fussy about how it is fed its mount options
226 # - multiple -o's are not allowed
227 # - no spaces between comma delimitered options
228 # the sed script replaces all -o's (except the first) with a comma
229 # not required for linux, but won't hurt
231 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
232 | sed -e 's/dmapi/dmi/' \
233 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
237 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
238 # with the safe set of scratch mount options (e.g. loop image may be
239 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
240 _common_dev_mount_options()
242 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
245 _overlay_basic_mount_options()
247 echo "-o lowerdir=$1/$OVERLAY_LOWER_DIR,upperdir=$1/$OVERLAY_UPPER_DIR,workdir=$1/$OVERLAY_WORK_DIR"
250 _overlay_mount_options()
252 echo `_common_dev_mount_options` \
253 `_overlay_basic_mount_options $1` \
254 $OVERLAY_MOUNT_OPTIONS
257 _scratch_mount_options()
259 _scratch_options mount
261 if [ "$FSTYP" == "overlay" ]; then
262 echo `_overlay_mount_options $SCRATCH_DEV`
265 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
266 $SCRATCH_DEV $SCRATCH_MNT
269 # Given a dir, set up 3 subdirectories and mount on the given mnt.
270 # The dir is used as the mount device so it can be seen from df or mount
277 local upper_fst=$(df --output=fstype $dir | tail -1)
280 if ! xfs_info $dir | grep -q "ftype=1" ; then
281 _notrun "upper fs needs to support d_type"
285 if ! tune2fs -l $(df --output=source $dir | tail -1) | \
286 grep -q filetype ; then
287 _notrun "upper fs needs to support d_type"
292 mkdir -p $dir/$OVERLAY_UPPER_DIR
293 mkdir -p $dir/$OVERLAY_LOWER_DIR
294 mkdir -p $dir/$OVERLAY_WORK_DIR
296 $MOUNT_PROG -t overlay $SELINUX_MOUNT_OPTIONS \
297 -o lowerdir=$dir/$OVERLAY_LOWER_DIR \
298 -o upperdir=$dir/$OVERLAY_UPPER_DIR \
299 -o workdir=$dir/$OVERLAY_WORK_DIR \
300 $OVERLAY_MOUNT_OPTIONS $* \
304 _overlay_test_mount()
306 _overlay_mount $TEST_DEV $TEST_DIR $*
309 _overlay_scratch_mount()
311 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
314 _overlay_test_unmount()
316 $UMOUNT_PROG $TEST_DIR
319 _overlay_scratch_unmount()
321 $UMOUNT_PROG $SCRATCH_MNT
326 if [ "$FSTYP" == "overlay" ]; then
327 _overlay_scratch_mount $*
330 _mount -t $FSTYP `_scratch_mount_options $*`
337 _overlay_scratch_unmount
340 $UMOUNT_PROG $SCRATCH_MNT
343 $UMOUNT_PROG $SCRATCH_DEV
352 if test -n "$opts"; then
353 mount -o "remount,$opts" $SCRATCH_MNT
357 _scratch_cycle_mount()
361 if [ "$FSTYP" = tmpfs ]; then
362 _scratch_remount "$opts"
365 if test -n "$opts"; then
369 _scratch_mount "$opts"
374 if [ "$FSTYP" == "overlay" ]; then
375 _overlay_test_mount $*
379 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
384 if [ "$FSTYP" == "overlay" ]; then
385 _overlay_test_unmount
387 $UMOUNT_PROG $TEST_DEV
393 if [ "$FSTYP" = tmpfs ]; then
400 _scratch_mkfs_options()
402 _scratch_options mkfs
403 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
411 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
412 options="-l $SCRATCH_LOGDEV"
414 xfs_metadump $options $SCRATCH_DEV $dumpfile
417 _setup_large_xfs_fs()
422 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
423 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
424 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
426 # calculate the size of the file we need to allocate.
427 # Default free space in the FS is 50GB, but you can specify more via
428 # SCRATCH_DEV_EMPTY_SPACE
429 file_size=$(($fs_size - 50*1024*1024*1024))
430 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
432 # mount the filesystem, create the file, unmount it
433 _scratch_mount 2>&1 >$tmp_dir/mnt.err
435 if [ $status -ne 0 ]; then
437 cat $tmp_dir/mnt.err >&2
438 rm -f $tmp_dir/mnt.err
441 rm -f $tmp_dir/mnt.err
444 -c "truncate $file_size" \
445 -c "falloc -k 0 $file_size" \
447 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
448 export NUM_SPACE_FILES=1
451 if [ $status -ne 0 ]; then
452 echo "large file prealloc failed"
453 cat $tmp_dir/mnt.err >&2
459 _scratch_mkfs_xfs_opts()
463 # remove metadata related mkfs options if mkfs.xfs doesn't them
464 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
465 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
468 _scratch_options mkfs
470 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
474 _scratch_mkfs_xfs_supported()
478 _scratch_options mkfs
480 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
483 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
484 # $mkfs_opts, try again without $MKFS_OPTIONS
485 if [ $mkfs_status -ne 0 -a -n "$mkfs_opts" ]; then
486 $MKFS_XFS_PROG -N $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
494 # extra mkfs options can be added by tests
495 local extra_mkfs_options=$*
499 # save mkfs output in case conflict means we need to run again.
500 # only the output for the mkfs that applies should be shown
501 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
502 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
506 # a mkfs failure may be caused by conflicts between
507 # $MKFS_OPTIONS and $extra_mkfs_options
508 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
510 echo -n "** mkfs failed with extra mkfs options "
511 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
512 echo -n "** attempting to mkfs using only test $seq "
513 echo "options: $extra_mkfs_options **"
516 # running mkfs again. overwrite previous mkfs output files
517 _scratch_mkfs_xfs_opts $extra_mkfs_options \
518 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
522 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
523 # manually parse the mkfs output to get the fs size in bytes
525 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
526 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
528 print STDOUT "$size\n";
530 _setup_large_xfs_fs $fs_size
534 # output stored mkfs output, filtering unnecessary warnings from stderr
536 cat $tmp_dir.mkfserr | sed \
537 -e '/less than device physical sector/d' \
538 -e '/switching to logical sector/d' \
540 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
545 # xfs_check script is planned to be deprecated. But, we want to
546 # be able to invoke "xfs_check" behavior in xfstests in order to
547 # maintain the current verification levels.
552 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
554 while getopts "b:fi:l:stvV" c
560 i) OPTS=$OPTS"-i "$OPTARG" ";;
561 b) OPTS=$OPTS"-b "$OPTARG" ";;
562 f) DBOPTS=$DBOPTS" -f";;
563 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
564 V) $XFS_DB_PROG -p xfs_check -V
572 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
582 _setup_large_ext4_fs()
587 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
588 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
589 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
591 # Default free space in the FS is 50GB, but you can specify more via
592 # SCRATCH_DEV_EMPTY_SPACE
593 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
595 # mount the filesystem and create 16TB - 4KB files until we consume
596 # all the necessary space.
597 _scratch_mount 2>&1 >$tmp_dir/mnt.err
599 if [ $status -ne 0 ]; then
601 cat $tmp_dir/mnt.err >&2
602 rm -f $tmp_dir/mnt.err
605 rm -f $tmp_dir/mnt.err
607 file_size=$((16*1024*1024*1024*1024 - 4096))
609 while [ $space_to_consume -gt $file_size ]; do
612 -c "truncate $file_size" \
613 -c "falloc -k 0 $file_size" \
614 $SCRATCH_MNT/.use_space.$nfiles 2>&1
616 if [ $status -ne 0 ]; then
620 space_to_consume=$(( $space_to_consume - $file_size ))
621 nfiles=$(($nfiles + 1))
624 # consume the remaining space.
625 if [ $space_to_consume -gt 0 ]; then
627 -c "truncate $space_to_consume" \
628 -c "falloc -k 0 $space_to_consume" \
629 $SCRATCH_MNT/.use_space.$nfiles 2>&1
632 export NUM_SPACE_FILES=$nfiles
635 if [ $status -ne 0 ]; then
636 echo "large file prealloc failed"
637 cat $tmp_dir/mnt.err >&2
645 # extra mkfs options can be added by tests
646 local extra_mkfs_options=$*
650 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
651 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
654 # a mkfs failure may be caused by conflicts between
655 # $MKFS_OPTIONS and $extra_mkfs_options
656 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
658 echo -n "** mkfs failed with extra mkfs options "
659 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
660 echo -n "** attempting to mkfs using only test $seq "
661 echo "options: $extra_mkfs_options **"
664 # running mkfs again. overwrite previous mkfs output files
665 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
666 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
670 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
671 # manually parse the mkfs output to get the fs size in bytes
672 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
673 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
674 / inodes, / { blks = $3 } \
675 /reserved for the super user/ { resv = $1 } \
676 END { fssize = bs * blks - resv; print fssize }'`
678 _setup_large_ext4_fs $fs_size
682 # output stored mkfs output
683 grep -v -e ^Warning: -e "^mke2fs " $tmp_dir.mkfserr >&2
685 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
697 # do nothing for cifs
700 # do nothing for overlay
703 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
706 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
709 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
712 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
724 # do nothing for overlay
727 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
730 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
733 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
734 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
738 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
739 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
743 if [ $? -ne 0 ]; then
744 # output stored mkfs output
745 cat $tmp_dir.mkfserr >&2
750 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
753 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
754 _scratch_cleanup_files()
758 # $SCRATCH_DEV is a valid directory in overlay case
759 rm -rf $SCRATCH_DEV/*
763 rm -rf $SCRATCH_MNT/*
776 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
777 # avoid EEXIST caused by the leftover files created in previous runs
778 _scratch_cleanup_files
781 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
782 # avoid EEXIST caused by the leftover files created in previous runs
783 _scratch_cleanup_files
786 # unable to re-create overlay, remove all files in $SCRATCH_MNT to
787 # avoid EEXIST caused by the leftover files created in previous runs
788 _scratch_cleanup_files
791 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
794 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
797 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
800 _scratch_mkfs_ext4 $*
803 # do nothing for tmpfs
806 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
809 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
814 # Helper function to get a spare or replace-target device from
815 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
816 # before _spare_dev_get(). Replace-target-device/Spare-device will
817 # be assigned to SPARE_DEV.
818 # As of now only one replace-target-device/spare-device can be
822 # _scratch_dev_pool_get() <ndevs>
826 # _scratch_dev_pool_put()
830 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
831 if [ $? -ne 0 ]; then
832 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
835 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
836 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
839 # Check if the spare is already assigned
840 typeset -p SPARE_DEV >/dev/null 2>&1
841 if [ $? -eq 0 ]; then
842 if [ ! -z "$SPARE_DEV" ]; then
843 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
847 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
848 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
850 if [ $ndevs -eq $config_ndevs ]; then
851 _notrun "All devs used no spare"
853 # Get a dev that is not used
854 local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
855 SPARE_DEV=${devs[@]:$ndevs:1}
861 typeset -p SPARE_DEV >/dev/null 2>&1
862 if [ $? -ne 0 ]; then
863 _fail "Bug: unset val, must call _spare_dev_get before its put"
866 if [ -z "$SPARE_DEV" ]; then
867 _fail "Bug: str empty, must call _spare_dev_get before its put"
874 # Generally test cases will have..
875 # _require_scratch_dev_pool X
876 # to make sure it has the enough scratch devices including
877 # replace-target and spare device. Now arg1 here is the
878 # required number of scratch devices by a-test-case excluding
879 # the replace-target and spare device. So this function will
880 # set SCRATCH_DEV_POOL to the specified number of devices.
883 # _scratch_dev_pool_get() <ndevs>
886 # _scratch_dev_pool_put()
888 _scratch_dev_pool_get()
890 if [ $# -ne 1 ]; then
891 _fail "Usage: _scratch_dev_pool_get ndevs"
895 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
896 local devs[]="( $SCRATCH_DEV_POOL )"
898 typeset -p config_ndevs >/dev/null 2>&1
899 if [ $? -ne 0 ]; then
900 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
903 if [ $config_ndevs -lt $test_ndevs ]; then
904 _notrun "Need at least test requested number of ndevs $test_ndevs"
907 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
908 export SCRATCH_DEV_POOL_SAVED
909 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
910 export SCRATCH_DEV_POOL
913 _scratch_dev_pool_put()
915 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
916 if [ $? -ne 0 ]; then
917 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
920 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
921 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
924 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
925 export SCRATCH_DEV_POOL_SAVED=""
932 # if dup profile is in mkfs options call _scratch_mkfs instead
933 # because dup profile only works with single device
934 if [[ "$*" =~ dup ]]; then
937 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
941 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
946 # Return the amount of free memory available on the system
949 free -b | grep ^Mem | awk '{print $4}'
952 # Create fs of certain size on scratch device
953 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
954 _scratch_mkfs_sized()
961 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
963 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
964 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
968 [ -n "$def_blksz" ] && blocksize=$def_blksz
969 [ -z "$blocksize" ] && blocksize=4096
973 if ! [[ $fssize =~ $re ]] ; then
974 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
976 if ! [[ $blocksize =~ $re ]] ; then
977 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
980 blocks=`expr $fssize / $blocksize`
982 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
983 devsize=`blockdev --getsize64 $SCRATCH_DEV`
984 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
989 # don't override MKFS_OPTIONS that set a block size.
990 echo $MKFS_OPTIONS |egrep -q "b?size="
991 if [ $? -eq 0 ]; then
992 _scratch_mkfs_xfs -d size=$fssize
994 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
997 ext2|ext3|ext4|ext4dev)
998 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1001 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1005 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1006 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1009 # mkfs.resier4 requires size in KB as input for creating filesystem
1010 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1011 `expr $fssize / 1024`
1014 # mkfs.f2fs requires # of sectors as an input for the size
1015 sector_size=`blockdev --getss $SCRATCH_DEV`
1016 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1019 free_mem=`_free_memory_bytes`
1020 if [ "$free_mem" -lt "$fssize" ] ; then
1021 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1023 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1026 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1031 # Emulate an N-data-disk stripe w/ various stripe units
1032 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1033 _scratch_mkfs_geom()
1038 [ -z "$blocksize" ] && blocksize=4096
1040 let sunit_blocks=$sunit_bytes/$blocksize
1041 let swidth_blocks=$sunit_blocks*$swidth_mult
1045 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1048 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1051 _notrun "can't mkfs $FSTYP with geometry"
1057 # Create fs of certain blocksize on scratch device
1058 # _scratch_mkfs_blocksized blocksize
1059 _scratch_mkfs_blocksized()
1064 if ! [[ $blocksize =~ $re ]] ; then
1065 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1070 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1072 ext2|ext3|ext4|ocfs2)
1073 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1076 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1085 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1092 _scratch_xfs_db_options()
1095 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1096 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1097 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
1100 _scratch_xfs_logprint()
1103 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1104 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1105 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
1108 _test_xfs_logprint()
1111 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1112 TEST_OPTIONS="-l$TEST_LOGDEV"
1113 $XFS_LOGPRINT_PROG $TEST_OPTIONS $* $TEST_DEV
1116 _scratch_xfs_check()
1119 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1120 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
1121 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1122 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
1123 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
1126 _scratch_xfs_repair()
1129 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1130 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1131 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1132 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
1133 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
1134 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
1137 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1138 # errors found or errors were fixed) and nonzero otherwise; also spits out
1139 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1140 _repair_scratch_fs()
1144 _scratch_xfs_repair "$@" 2>&1
1146 if [ "$res" -eq 2 ]; then
1147 echo "xfs_repair returns $res; replay log?"
1150 if [ "$res" -gt 0 ]; then
1151 echo "mount returns $res; zap log?"
1152 _scratch_xfs_repair -L 2>&1
1153 echo "log zap returns $?"
1155 umount "$SCRATCH_MNT"
1157 _scratch_xfs_repair "$@" 2>&1
1160 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1164 # Let's hope fsck -y suffices...
1165 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1172 >&2 echo "fsck.$FSTYP failed, err=$res"
1184 echo "Usage: _get_pids_by_name process-name" 1>&2
1188 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1189 # HH:MM:SS before the psargs field, use this as the search anchor.
1191 # Matches with $1 (process-name) occur if the first psarg is $1
1192 # or ends in /$1 ... the matching uses sed's regular expressions,
1193 # so passing a regex into $1 will work.
1198 -e 's/[ ][ ]*/ /g' \
1201 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1202 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1205 # fix malloc libs output
1209 # filter out the Electric Fence notice
1212 if (defined $o && /^\s+Electric Fence/) {
1218 print $o if (defined $o);
1222 print $o if (defined $o);
1227 # _df_device : get an IRIX style df line for a given device
1229 # - returns "" if not mounted
1230 # - returns fs type in field two (ala IRIX)
1231 # - joins line together if split by fancy df formatting
1232 # - strips header etc
1239 echo "Usage: _df_device device" 1>&2
1243 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1244 # IPv6 server as a regular expression.
1245 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1246 ($1==what) && (NF==1) {
1260 # _df_dir : get an IRIX style df line for device where a directory resides
1262 # - returns fs type in field two (ala IRIX)
1263 # - joins line together if split by fancy df formatting
1264 # - strips header etc
1271 echo "Usage: _df_dir device" 1>&2
1275 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1291 # return percentage used disk space for mounted device
1297 echo "Usage: _used device" 1>&2
1301 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1304 # return the FS type of a mounted device
1310 echo "Usage: _fs_type device" 1>&2
1315 # The Linux kernel shows NFSv4 filesystems in df output as
1316 # filesystem type nfs4, although we mounted it as nfs earlier.
1317 # Fix the filesystem type up here so that the callers don't
1318 # have to bother with this quirk.
1320 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1323 # return the FS mount options of a mounted device
1325 # should write a version which just parses the output of mount for IRIX
1326 # compatibility, but since this isn't used at all, at the moment I'll leave
1333 echo "Usage: _fs_options device" 1>&2
1337 $AWK_PROG -v dev=$1 '
1338 match($1,dev) { print $4 }
1342 # returns device number if a file is a block device
1348 echo "Usage: _is_block_dev dev" 1>&2
1353 if [ -L "${_dev}" ]; then
1354 _dev=`readlink -f "${_dev}"`
1357 if [ -b "${_dev}" ]; then
1358 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1362 # Do a command, log it to $seqres.full, optionally test return status
1363 # and die if command fails. If called with one argument _do executes the
1364 # command, logs it, and returns its exit status. With two arguments _do
1365 # first prints the message passed in the first argument, and then "done"
1366 # or "fail" depending on the return status of the command passed in the
1367 # second argument. If the command fails and the variable _do_die_on_error
1368 # is set to "always" or the two argument form is used and _do_die_on_error
1369 # is set to "message_only" _do will print an error message to
1370 # $seqres.out and exit.
1374 if [ $# -eq 1 ]; then
1376 elif [ $# -eq 2 ]; then
1379 echo -n "$_note... "
1381 echo "Usage: _do [note] cmd" 1>&2
1385 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1386 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1387 cat $tmp._out | _fix_malloc >>$seqres.full
1388 if [ $# -eq 2 ]; then
1389 if [ $ret -eq 0 ]; then
1396 && [ "$_do_die_on_error" = "always" \
1397 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1399 [ $# -ne 2 ] && echo
1400 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1407 # bail out, setting up .notrun file. Need to kill the filesystem check files
1408 # here, otherwise they are set incorrectly for the next test.
1412 echo "$*" > $seqres.notrun
1413 echo "$seq not run: $*"
1414 rm -f ${RESULT_DIR}/require_test
1415 rm -f ${RESULT_DIR}/require_scratch
1420 # just plain bail out
1424 echo "$*" | tee -a $seqres.full
1425 echo "(see $seqres.full for details)"
1430 # tests whether $FSTYP is one of the supported filesystems for a test
1436 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1442 _notrun "not suitable for this filesystem type: $FSTYP"
1446 # tests whether $FSTYP is one of the supported OSes for a test
1452 if [ "$h" = "$HOSTOS" ]
1458 _notrun "not suitable for this OS: $HOSTOS"
1461 _require_btrfs_loadable()
1463 modprobe -r btrfs || _notrun "btrfs unloadable"
1464 modprobe btrfs || _notrun "Can't load btrfs"
1469 modprobe -r btrfs || _fail "btrfs unload failed"
1470 modprobe btrfs || _fail "btrfs load failed"
1473 # this test needs a scratch partition - check we're ok & unmount it
1474 # No post-test check of the device is required. e.g. the test intentionally
1475 # finishes the test with the filesystem in a corrupt state
1476 _require_scratch_nocheck()
1480 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1481 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1482 _notrun "this test requires a valid \$SCRATCH_DEV"
1484 if [ ! -d "$SCRATCH_MNT" ]; then
1485 _notrun "this test requires a valid \$SCRATCH_MNT"
1489 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1490 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1491 _notrun "this test requires a valid \$SCRATCH_DEV"
1493 if [ ! -d "$SCRATCH_MNT" ]; then
1494 _notrun "this test requires a valid \$SCRATCH_MNT"
1498 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1499 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1501 if [ ! -d "$SCRATCH_MNT" ]; then
1502 _notrun "this test requires a valid \$SCRATCH_MNT"
1506 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1508 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1512 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1514 _notrun "this test requires a valid \$SCRATCH_DEV"
1516 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1518 _notrun "this test requires a valid \$SCRATCH_DEV"
1520 if [ ! -d "$SCRATCH_MNT" ]
1522 _notrun "this test requires a valid \$SCRATCH_MNT"
1528 # Note that we use -F here so grep doesn't try to interpret an NFS over
1529 # IPv6 server as a regular expression.
1530 mount_rec=`_mount | grep -F $SCRATCH_DEV`
1533 # if it's mounted, make sure its on $SCRATCH_MNT
1534 if ! echo $mount_rec | grep -q $SCRATCH_MNT
1536 echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
1537 echo "Already mounted result:"
1541 # and then unmount it
1542 if ! _scratch_unmount
1544 echo "failed to unmount $SCRATCH_DEV"
1548 rm -f ${RESULT_DIR}/require_scratch
1551 # we need the scratch device and it should be checked post test.
1554 _require_scratch_nocheck
1555 touch ${RESULT_DIR}/require_scratch
1559 # this test needs a test partition - check we're ok & mount it
1565 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1566 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1567 _notrun "this test requires a valid \$TEST_DIR"
1569 if [ ! -d "$TEST_DIR" ]; then
1570 _notrun "this test requires a valid \$TEST_DIR"
1574 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1575 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1576 _notrun "this test requires a valid \$TEST_DEV"
1578 if [ ! -d "$TEST_DIR" ]; then
1579 _notrun "this test requires a valid \$TEST_DIR"
1583 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1584 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1586 if [ ! -d "$TEST_DIR" ]; then
1587 _notrun "this test requires a valid \$TEST_DIR"
1591 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1593 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1597 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1599 _notrun "this test requires a valid \$TEST_DEV"
1601 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1603 _notrun "this test requires a valid \$TEST_DEV"
1605 if [ ! -d "$TEST_DIR" ]
1607 _notrun "this test requires a valid \$TEST_DIR"
1613 # Note that we use -F here so grep doesn't try to interpret an NFS over
1614 # IPv6 server as a regular expression.
1615 mount_rec=`_mount | grep -F $TEST_DEV`
1618 # if it's mounted, make sure its on $TEST_DIR
1619 if ! echo $mount_rec | grep -q $TEST_DIR
1621 echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
1622 echo "Already mounted result:"
1627 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1628 if [ $? -ne 1 ]; then
1633 touch ${RESULT_DIR}/require_test
1636 # this test needs a logdev
1640 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1641 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1642 [ "$USE_EXTERNAL" != yes ] && \
1643 _notrun "This test requires USE_EXTERNAL to be enabled"
1645 # ensure its not mounted
1646 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1649 # this test requires loopback device support
1653 if [ "$HOSTOS" != "Linux" ]
1655 _notrun "This test requires linux for loopback device support"
1658 modprobe loop >/dev/null 2>&1
1659 if grep loop /proc/devices >/dev/null 2>&1
1663 _notrun "This test requires loopback device support"
1667 # this test requires ext2 filesystem support
1671 if [ "$HOSTOS" != "Linux" ]
1673 _notrun "This test requires linux for ext2 filesystem support"
1676 modprobe ext2 >/dev/null 2>&1
1677 if grep ext2 /proc/filesystems >/dev/null 2>&1
1681 _notrun "This test requires ext2 filesystem support"
1685 # this test requires that (large) loopback device files are not in use
1687 _require_no_large_scratch_dev()
1689 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1690 _notrun "Large filesystem testing in progress, skipped this test"
1693 # this test requires that a realtime subvolume is in use, and
1694 # that the kernel supports realtime as well.
1698 [ "$USE_EXTERNAL" = yes ] || \
1699 _notrun "External volumes not in use, skipped this test"
1700 [ "$SCRATCH_RTDEV" = "" ] && \
1701 _notrun "Realtime device required, skipped this test"
1704 # this test requires that a specified command (executable) exists
1705 # $1 - command, $2 - name for error message
1707 # Note: the command string might have parameters, so strip them before checking
1708 # whether it is executable.
1711 if [ $# -eq 2 ]; then
1713 elif [ $# -eq 1 ]; then
1716 _fail "usage: _require_command <command> [<name>]"
1719 _command=`echo "$1" | awk '{ print $1 }'`
1720 if [ ! -x "$_command" ]; then
1721 _notrun "$_name utility required, skipped this test"
1725 # this test requires the device to be valid block device
1727 _require_block_device()
1729 if [ -z "$1" ]; then
1730 echo "Usage: _require_block_device <dev>" 1>&2
1733 if [ "`_is_block_dev "$1"`" == "" ]; then
1734 _notrun "require $1 to be valid block disk"
1738 # brd based ram disks erase the device when they receive a flush command when no
1739 # active references are present. This causes problems for DM devices sitting on
1740 # top of brd devices as DM doesn't hold active references to the brd device.
1741 _require_sane_bdev_flush()
1743 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1744 if [ $? -eq 0 ]; then
1745 _notrun "This test requires a sane block device flush"
1749 # this test requires a specific device mapper target
1750 _require_dm_target()
1754 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1756 _require_block_device $SCRATCH_DEV
1757 _require_sane_bdev_flush $SCRATCH_DEV
1758 _require_command "$DMSETUP_PROG" dmsetup
1760 modprobe dm-$_target >/dev/null 2>&1
1762 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1763 if [ $? -ne 0 ]; then
1764 _notrun "This test requires dm $_target support"
1768 # this test requires the projid32bit feature to be available in mkfs.xfs.
1770 _require_projid32bit()
1772 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1773 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1776 _require_projid16bit()
1778 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1779 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1782 # this test requires the crc feature to be available in mkfs.xfs
1784 _require_xfs_mkfs_crc()
1786 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1787 || _notrun "mkfs.xfs doesn't have crc feature"
1790 # this test requires the xfs kernel support crc feature
1794 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1795 _scratch_mount >/dev/null 2>&1 \
1796 || _notrun "Kernel doesn't support crc feature"
1800 # this test requires the ext4 kernel support crc feature on scratch device
1802 _require_scratch_ext4_crc()
1804 _scratch_mkfs_ext4 >/dev/null 2>&1
1805 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1806 _scratch_mount >/dev/null 2>&1 \
1807 || _notrun "Kernel doesn't support metadata_csum feature"
1811 # this test requires the xfs kernel support crc feature on scratch device
1813 _require_scratch_xfs_crc()
1815 _scratch_mkfs_xfs >/dev/null 2>&1
1816 _scratch_mount >/dev/null 2>&1 \
1817 || _notrun "Kernel doesn't support crc feature"
1818 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1822 # this test requires the bigalloc feature to be available in mkfs.ext4
1824 _require_ext4_mkfs_bigalloc()
1826 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1827 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1830 # this test requires the ext4 kernel support bigalloc feature
1832 _require_ext4_bigalloc()
1834 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1835 _scratch_mount >/dev/null 2>&1 \
1836 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1840 # this test requires the finobt feature to be available in mkfs.xfs
1842 _require_xfs_mkfs_finobt()
1844 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1845 || _notrun "mkfs.xfs doesn't have finobt feature"
1848 # this test requires the xfs kernel support finobt feature
1850 _require_xfs_finobt()
1852 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1853 _scratch_mount >/dev/null 2>&1 \
1854 || _notrun "Kernel doesn't support finobt feature"
1858 # this test requires xfs sysfs attribute support
1860 _require_xfs_sysfs()
1863 sysfsdir=/sys/fs/xfs
1865 if [ ! -e $sysfsdir ]; then
1866 _notrun "no kernel support for XFS sysfs attributes"
1869 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1870 _notrun "sysfs attribute '$attr' is not supported"
1874 # this test requires the xfs sparse inode feature
1876 _require_xfs_sparse_inodes()
1878 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1879 || _notrun "mkfs.xfs does not support sparse inodes"
1880 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1881 _scratch_mount >/dev/null 2>&1 \
1882 || _notrun "kernel does not support sparse inodes"
1886 # this test requires that external log/realtime devices are not in use
1888 _require_nonexternal()
1890 [ "$USE_EXTERNAL" = yes ] && \
1891 _notrun "External device testing in progress, skipped this test"
1894 # this test requires that a (specified) aio-dio executable exists
1895 # $1 - command (optional)
1901 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1902 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1904 AIO_TEST=src/aio-dio-regress/$1
1905 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1910 # this test requires that a test program exists under src/
1911 # $1 - command (require)
1913 _require_test_program()
1916 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1919 # run an aio-dio program
1925 echo "usage: _run_aiodio command_name" 2>&1
1931 local testtemp=$TEST_DIR/aio-testfile
1933 $AIO_TEST $testtemp 2>&1
1940 # indicate whether YP/NIS is active or not
1945 dn=$(domainname 2>/dev/null)
1946 test -n "${dn}" -a "${dn}" != "(none)"
1950 # cat the password file
1954 [ $(_yp_active) -eq 0 ] && ypcat passwd
1958 # cat the group file
1962 [ $(_yp_active) -eq 0 ] && ypcat group
1966 # check for a user on the machine, fsgqa as default
1974 _cat_passwd | grep -q $qa_user
1975 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1976 echo /bin/true | su $qa_user
1977 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1980 # check for a group on the machine, fsgqa as default
1988 _cat_group | grep -q $qa_group
1989 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1995 s,.*Permission\sdenied.*,Permission denied,;
1996 s,.*no\saccess\sto\stty.*,,;
1997 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2004 if [ "$HOSTOS" == "IRIX" ]
2006 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
2008 echo $1 | su $qa_user 2>&1 | _filter_user_do
2012 _require_xfs_io_command()
2016 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2023 testfile=$TEST_DIR/$$.xfs_io
2026 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
2028 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
2029 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2030 -c "$command 4k 8k" $testfile 2>&1`
2033 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2034 -c "fiemap -v" $testfile 2>&1`
2037 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2039 echo $testio | egrep -q "invalid option|Is a directory" && \
2040 _notrun "xfs_io $command support is missing"
2043 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
2046 rm -f $testfile 2>&1 > /dev/null
2047 echo $testio | grep -q "not found" && \
2048 _notrun "xfs_io $command support is missing"
2049 echo $testio | grep -q "Operation not supported" && \
2050 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2052 test -z "$param" && return
2053 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2054 _notrun "xfs_io $command doesn't support $param"
2057 # check that xfs_db supports a specific command
2058 _require_xfs_db_command()
2062 echo "Usage: _require_xfs_db_command command" 1>&2
2067 $XFS_DB_PROG -x -c "help" $SCRATCH_DEV | grep $command > /dev/null || \
2068 _notrun "xfs_db $command support is missing"
2071 # check that kernel and filesystem support direct I/O
2074 if [ $FSTYP = "ext4" ] ; then
2075 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2076 _notrun "ext4 encryption doesn't support O_DIRECT"
2079 testfile=$TEST_DIR/$$.direct
2080 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2081 if [ $? -ne 0 ]; then
2082 _notrun "O_DIRECT is not supported"
2084 rm -f $testfile 2>&1 > /dev/null
2087 # Check that a fs has enough free space (in 1024b blocks)
2092 BLOCKS=$2 # in units of 1024
2093 let GB=$BLOCKS/1024/1024
2095 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2096 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2097 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2101 # Check if the filesystem supports sparse files.
2103 # Unfortunately there is no better way to do this than a manual black list.
2105 _require_sparse_files()
2109 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2118 #boot_params always present in debugfs
2119 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2122 _require_fail_make_request()
2124 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2125 || _notrun "$DEBUGFS_MNT/fail_make_request \
2126 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2130 # Check if the file system supports seek_data/hole
2132 _require_seek_data_hole()
2134 testfile=$TEST_DIR/$$.seek
2135 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2136 rm -f $testfile &>/dev/null
2137 echo $testseek | grep -q "Kernel does not support" && \
2138 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2143 _require_test_program "runas"
2148 "$here/src/runas" "$@"
2151 _require_richacl_prog()
2153 _require_command "$GETRICHACL_PROG" getrichacl
2154 _require_command "$SETRICHACL_PROG" setrichacl
2157 _require_scratch_richacl_xfs()
2159 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2160 || _notrun "mkfs.xfs doesn't have richacl feature"
2161 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2162 _scratch_mount >/dev/null 2>&1 \
2163 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2167 _require_scratch_richacl_ext4()
2169 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2170 || _notrun "can't mkfs $FSTYP with option -O richacl"
2171 _scratch_mount >/dev/null 2>&1 \
2172 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2176 _require_scratch_richacl_support()
2179 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2180 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2184 _require_scratch_richacl()
2187 xfs) _require_scratch_richacl_xfs
2189 ext4) _require_scratch_richacl_ext4
2192 _require_scratch_richacl_support
2194 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2199 _scratch_mkfs_richacl()
2202 xfs) _scratch_mkfs_xfs -m richacl=1
2204 ext4) _scratch_mkfs -O richacl
2212 # check that a FS on a device is mounted
2213 # if so, return mount point
2219 echo "Usage: _is_mounted device" 1>&2
2225 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2226 pattern { print $3 ; exit 0 }
2230 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2235 # remount a FS to a new mode (ro or rw)
2241 echo "Usage: _remount device ro/rw" 1>&2
2247 if ! mount -o remount,$mode $device
2249 echo "_remount: failed to remount filesystem on $device as $mode"
2254 # Run the appropriate repair/check on a filesystem
2256 # if the filesystem is mounted, it's either remounted ro before being
2257 # checked or it's unmounted and then remounted
2260 # If set, we remount ro instead of unmounting for fsck
2263 _umount_or_remount_ro()
2267 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2272 mountpoint=`_is_mounted $device`
2274 if [ $USE_REMOUNT -eq 0 ]; then
2275 $UMOUNT_PROG $device
2282 _mount_or_remount_rw()
2284 if [ $# -ne 3 ]; then
2285 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2292 if [ $USE_REMOUNT -eq 0 ]; then
2293 if [ "$FSTYP" != "overlay" ]; then
2294 _mount -t $FSTYP $mount_opts $device $mountpoint
2296 _overlay_mount $device $mountpoint
2298 if [ $? -ne 0 ]; then
2299 echo "!!! failed to remount $device on $mountpoint"
2309 # Check a generic filesystem in no-op mode; this assumes that the
2310 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2311 # and that it will still return an errno for corruption in this mode.
2313 # Filesystems which don't support this will need to define their
2314 # own check routine.
2316 _check_generic_filesystem()
2320 # If type is set, we're mounted
2321 type=`_fs_type $device`
2324 if [ "$type" = "$FSTYP" ]
2327 mountpoint=`_umount_or_remount_ro $device`
2330 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2333 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2335 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2336 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2337 cat $tmp.fsck >>$seqres.full
2338 echo "*** end fsck.$FSTYP output" >>$seqres.full
2346 echo "*** mount output ***" >>$seqres.full
2347 _mount >>$seqres.full
2348 echo "*** end mount output" >>$seqres.full
2349 elif [ "$type" = "$FSTYP" ]
2352 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2356 if [ $ok -eq 0 ]; then
2358 if [ "$iam" != "check" ]; then
2367 # run xfs_check and friends on a FS.
2369 _check_xfs_filesystem()
2373 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
2377 extra_mount_options=""
2378 extra_log_options=""
2381 if [ -f $device ];then
2385 if [ "$2" != "none" ]; then
2386 extra_log_options="-l$2"
2387 extra_mount_options="-ologdev=$2"
2390 if [ "$3" != "none" ]; then
2391 extra_rt_options="-r$3"
2392 extra_mount_options=$extra_mount_options" -ortdev=$3"
2394 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
2396 [ "$FSTYP" != xfs ] && return 0
2398 type=`_fs_type $device`
2401 if [ "$type" = "xfs" ]
2403 if [ -n "$TEST_XFS_SCRUB" ] && [ -x "$XFS_SCRUB_PROG" ]; then
2404 "$XFS_SCRUB_PROG" $scrubflag -vd $device >>$seqres.full
2405 if [ $? -ne 0 ]; then
2406 echo "filesystem on $device failed scrub (see $seqres.full)"
2411 mountpoint=`_umount_or_remount_ro $device`
2414 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
2415 | tee $tmp.logprint | grep -q "<CLEAN>"
2416 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
2418 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
2420 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
2421 echo "*** xfs_logprint -t output ***" >>$seqres.full
2422 cat $tmp.logprint >>$seqres.full
2423 echo "*** end xfs_logprint output" >>$seqres.full
2428 # xfs_check runs out of memory on large files, so even providing the test
2429 # option (-t) to avoid indexing the free space trees doesn't make it pass on
2430 # large filesystems. Avoid it.
2431 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
2432 _xfs_check $extra_log_options $device 2>&1 |\
2433 _fix_malloc >$tmp.fs_check
2435 if [ -s $tmp.fs_check ]
2437 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
2439 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2440 echo "*** xfs_check output ***" >>$seqres.full
2441 cat $tmp.fs_check >>$seqres.full
2442 echo "*** end xfs_check output" >>$seqres.full
2447 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2450 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
2452 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2453 echo "*** xfs_repair -n output ***" >>$seqres.full
2454 cat $tmp.repair | _fix_malloc >>$seqres.full
2455 echo "*** end xfs_repair output" >>$seqres.full
2459 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
2461 # Optionally test the index rebuilding behavior.
2462 if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then
2463 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2464 if [ $? -ne 0 ]; then
2465 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild) (see $seqres.full)"
2467 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)" >>$seqres.full
2468 echo "*** xfs_repair output ***" >>$seqres.full
2469 cat $tmp.repair | _fix_malloc >>$seqres.full
2470 echo "*** end xfs_repair output" >>$seqres.full
2476 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2477 if [ $? -ne 0 ]; then
2478 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify) (see $seqres.full)"
2480 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)" >>$seqres.full
2481 echo "*** xfs_repair -n output ***" >>$seqres.full
2482 cat $tmp.repair | _fix_malloc >>$seqres.full
2483 echo "*** end xfs_repair output" >>$seqres.full
2492 echo "*** mount output ***" >>$seqres.full
2493 _mount >>$seqres.full
2494 echo "*** end mount output" >>$seqres.full
2495 elif [ "$type" = "xfs" ]
2497 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
2500 if [ $ok -eq 0 ]; then
2502 if [ "$iam" != "check" ]; then
2511 # Filter the knowen errors the UDF Verifier reports.
2512 _udf_test_known_error_filter()
2514 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."
2518 _check_udf_filesystem()
2520 [ "$DISABLE_UDF_TEST" == "1" ] && return
2522 if [ $# -ne 1 -a $# -ne 2 ]
2524 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2528 if [ ! -x $here/src/udf_test ]
2530 echo "udf_test not installed, please download and build the Philips"
2531 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2532 echo "Then copy the udf_test binary to $here/src/."
2533 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2541 LAST_BLOCK=`expr \( $2 - 1 \)`
2542 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2545 rm -f $seqres.checkfs
2546 sleep 1 # Due to a problem with time stamps in udf_test
2547 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2548 _udf_test_known_error_filter | \
2549 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2550 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2554 _check_xfs_test_fs()
2558 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2559 TEST_LOG="$TEST_LOGDEV"
2561 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2562 TEST_RT="$TEST_RTDEV"
2564 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2566 # check for ipath consistency
2567 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2568 # errors go to stderr
2569 xfs_check_ipaths $TEST_DIR >/dev/null
2570 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2574 _check_btrfs_filesystem()
2578 # If type is set, we're mounted
2579 type=`_fs_type $device`
2582 if [ "$type" = "$FSTYP" ]
2585 mountpoint=`_umount_or_remount_ro $device`
2588 btrfsck $device >$tmp.fsck 2>&1
2591 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2593 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2594 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2595 cat $tmp.fsck >>$seqres.full
2596 echo "*** end fsck.$FSTYP output" >>$seqres.full
2604 echo "*** mount output ***" >>$seqres.full
2605 _mount >>$seqres.full
2606 echo "*** end mount output" >>$seqres.full
2607 elif [ "$type" = "$FSTYP" ]
2610 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2614 if [ $ok -eq 0 ]; then
2616 if [ "$iam" != "check" ]; then
2632 # no way to check consistency for nfs
2635 # no way to check consistency for cifs
2638 # no way to check consistency for overlay
2641 # do nothing for now
2644 _check_btrfs_filesystem $TEST_DEV
2647 # no way to check consistency for tmpfs
2650 _check_generic_filesystem $TEST_DEV
2658 [ $# -eq 1 ] && device=$1
2664 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2665 SCRATCH_LOG="$SCRATCH_LOGDEV"
2667 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2668 SCRATCH_RT="$SCRATCH_RTDEV"
2670 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2673 _check_udf_filesystem $device $udf_fsize
2676 # Don't know how to check an NFS filesystem, yet.
2679 # Don't know how to check a CIFS filesystem, yet.
2682 # no way to check consistency for overlay
2685 _check_btrfs_filesystem $device
2688 # no way to check consistency for tmpfs
2691 _check_generic_filesystem $device
2696 _full_fstyp_details()
2698 [ -z "$FSTYP" ] && FSTYP=xfs
2699 if [ $FSTYP = xfs ]; then
2700 if [ -d /proc/fs/xfs ]; then
2701 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2702 FSTYP="$FSTYP (non-debug)"
2703 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2704 FSTYP="$FSTYP (debug)"
2707 if uname -a | grep -qi 'debug'; then
2708 FSTYP="$FSTYP (debug)"
2710 FSTYP="$FSTYP (non-debug)"
2717 _full_platform_details()
2723 echo "$os/$platform $host $kernel"
2728 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2730 elif [ "`uname`" == "Linux" ]; then
2733 echo Unknown operating system: `uname`
2738 _link_out_file_named()
2743 my $feature, $result, $suffix, $opts;
2745 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2746 $feathash{$feature} = 1;
2748 $result = "default";
2753 ($opts, $suffix) = split(/ *: */);
2754 foreach my $opt (split(/,/, $opts)) {
2755 if (!exists($feathash{$opt})) {
2769 ln -fs $SRC.$SUFFIX $1
2774 if [ $# -eq 0 ]; then
2775 FEATURES="$(_get_os_name)"
2776 if [ -n "$MOUNT_OPTIONS" ]; then
2777 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2783 _link_out_file_named $seqfull.out "$FEATURES"
2792 #takes files, randomdata
2800 if [ $size -gt 0 ]; then
2801 if [ "$2" == "false" ]; then
2802 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2804 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2811 # takes dirname, depth, randomdata
2814 dirname=$1; depth=$2; randomdata=$3
2815 mkdir $dirname || die "mkdir $dirname failed"
2818 _nfiles $files $randomdata # files for this dir and data type
2820 [ $depth -eq 0 ] && return
2821 let deep=$depth-1 # go 1 down
2823 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2826 while [ $d -lt $dirs ]
2828 _descend d$d $deep &
2834 # Populate a filesystem with inodes for performance experiments
2836 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2841 dirs=5 # ndirs in each subdir till leaves
2842 size=0 # sizeof files in K
2843 files=100 # num files in _each_ subdir
2844 depth=2 # depth of tree from root to leaves
2846 root=root # path of initial root of directory tree
2847 randomdata=false # -x data type urandom or zero
2850 while getopts "d:f:n:r:s:v:x" c
2859 x) randomdata=true;;
2863 _descend $root $depth $randomdata
2868 [ $verbose = true ] && echo done
2871 # query whether the given file has the given inode flag set
2878 if which $XFS_IO_PROG >/dev/null; then
2879 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2886 # query the given files extsize allocator hint in bytes (if any)
2893 if which $XFS_IO_PROG >/dev/null; then
2894 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2895 awk '/^xattr.extsize =/ { print $3 }'`
2897 [ -z "$blocks" ] && blocks="0"
2901 # scratch_dev_pool should contain the disks pool for the btrfs raid
2902 _require_scratch_dev_pool()
2907 if [ -z "$SCRATCH_DEV_POOL" ]; then
2908 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2911 if [ -z "$1" ]; then
2917 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2921 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2922 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2926 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2930 for i in $SCRATCH_DEV_POOL; do
2931 if [ "`_is_block_dev "$i"`" = "" ]; then
2932 _notrun "this test requires valid block disk $i"
2934 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2935 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2937 if _mount | grep -q $i; then
2938 if ! $UMOUNT_PROG $i; then
2939 echo "failed to unmount $i - aborting"
2943 # to help better debug when something fails, we remove
2944 # traces of previous btrfs FS on the dev.
2945 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2949 # ensure devices in SCRATCH_DEV_POOL are of the same size
2950 # must be called after _require_scratch_dev_pool
2951 _require_scratch_dev_pool_equal_size()
2957 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2958 _size=`_get_device_size $SCRATCH_DEV`
2959 for _dev in $SCRATCH_DEV_POOL; do
2960 _newsize=`_get_device_size $_dev`
2961 if [ $_size -ne $_newsize ]; then
2962 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2967 # We will check if the device is deletable
2968 _require_deletable_scratch_dev_pool()
2972 for i in $SCRATCH_DEV_POOL; do
2973 x=`echo $i | cut -d"/" -f 3`
2974 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2975 _notrun "$i is a device which is not deletable"
2980 # We check for btrfs and (optionally) features of the btrfs command
2984 _require_command "$BTRFS_UTIL_PROG" btrfs
2985 if [ -z "$1" ]; then
2988 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2989 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2992 # Check that fio is present, and it is able to execute given jobfile
2997 _require_command "$FIO_PROG" fio
2998 if [ -z "$1" ]; then
3002 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
3003 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
3006 # Does freeze work on this fs?
3009 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
3011 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
3012 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
3015 # Does shutdown work on this fs?
3016 _require_scratch_shutdown()
3018 [ -x src/godown ] || _notrun "src/godown executable not found"
3020 _scratch_mkfs > /dev/null 2>&1
3022 src/godown -f $SCRATCH_MNT 2>&1 \
3023 || _notrun "$FSTYP does not support shutdown"
3027 # Does norecovery support by this fs?
3028 _require_norecovery()
3030 _scratch_mount -o ro,norecovery || \
3031 _notrun "$FSTYP does not support norecovery"
3035 # Does this filesystem support metadata journaling?
3036 # We exclude ones here that don't; otherwise we assume that it does, so the
3037 # test will run, fail, and motivate someone to update this test for a new
3040 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
3041 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
3043 _require_metadata_journaling()
3053 _notrun "$FSTYP does not support metadata journaling"
3056 # ext4 could be mkfs'd without a journal...
3058 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3059 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3062 # by default we pass; if you need to, add your fs above!
3067 # Does fiemap support?
3070 _require_xfs_io_command "fiemap"
3075 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3080 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3083 # arg 1 is dev to remove and is output of the below eg.
3084 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3090 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3092 stat $disk > /dev/null 2>&1
3093 while [ $? -eq 0 ]; do
3095 stat $disk > /dev/null 2>&1
3099 # arg 1 is dev to add and is output of the below eg.
3100 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3105 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3106 h=`echo ${1} | cut -d":" -f 1`
3107 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3109 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3111 # ensure the device comes online
3113 for i in `seq 1 10`; do
3114 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3115 dev=`ls /sys/class/scsi_device/${1}/device/block`
3116 for j in `seq 1 10`;
3118 stat /dev/$dev > /dev/null 2>&1
3119 if [ $? -eq 0 ]; then
3130 if [ $dev_back_oneline -eq 0 ]; then
3131 echo "/dev/$dev online failed" >> $seqres.full
3133 echo "/dev/$dev is back online" >> $seqres.full
3139 if [ -z "$FSTRIM_PROG" ]; then
3140 _notrun "This test requires fstrim utility."
3144 _require_batched_discard()
3146 if [ $# -ne 1 ]; then
3147 echo "Usage: _require_batched_discard mnt_point" 1>&2
3151 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3156 if [ -z "$DUMPE2FS_PROG" ]; then
3157 _notrun "This test requires dumpe2fs utility."
3163 if [ ! -e /proc/self/uid_map ]; then
3164 _notrun "This test requires procfs uid_map support."
3166 if [ ! -e /proc/self/gid_map ]; then
3167 _notrun "This test requires procfs gid_map support."
3173 FSSUM_PROG=$here/src/fssum
3174 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3179 CLONER_PROG=$here/src/cloner
3180 [ -x $CLONER_PROG ] || \
3181 _notrun "cloner binary not present at $CLONER_PROG"
3184 # skip test if MKFS_OPTIONS contains the given string
3185 _exclude_scratch_mount_option()
3187 if echo $MOUNT_OPTIONS | grep -q "$1"; then
3188 _notrun "mount option \"$1\" not allowed in this test"
3194 _exclude_scratch_mount_option "noatime"
3195 if [ "$FSTYP" == "nfs" ]; then
3196 _notrun "atime related mount options have no effect on NFS"
3202 _scratch_mkfs > /dev/null 2>&1
3203 _scratch_mount -o relatime || \
3204 _notrun "relatime not supported by the current kernel"
3210 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3211 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3214 _create_loop_device()
3217 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3221 _destroy_loop_device()
3224 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3227 _scale_fsstress_args()
3230 while [ $# -gt 0 ]; do
3232 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3233 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3234 *) args="$args $1" ;;
3242 # Return the logical block size if running on a block device,
3243 # else substitute the page size.
3245 _min_dio_alignment()
3249 if [ -b "$dev" ]; then
3250 blockdev --getss $dev
3252 $here/src/feature -s
3258 echo "# $@" >> $seqres.full 2>&1
3259 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3262 _run_btrfs_util_prog()
3264 run_check $BTRFS_UTIL_PROG $*
3267 _require_btrfs_send_stream_version()
3269 $BTRFS_UTIL_PROG send 2>&1 | \
3270 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
3271 if [ $? -ne 0 ]; then
3272 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
3275 # test if btrfs kernel supports send stream version 2
3276 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
3277 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
3281 _require_btrfs_mkfs_feature()
3284 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
3288 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
3289 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
3291 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
3294 _require_btrfs_fs_feature()
3297 echo "Missing feature name argument for _require_btrfs_fs_feature"
3301 modprobe btrfs > /dev/null 2>&1
3302 [ -e /sys/fs/btrfs/features/$feat ] || \
3303 _notrun "Feature $feat not supported by the available btrfs version"
3306 _require_test_symlinks()
3308 # IRIX UDF does not support symlinks
3309 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3310 _notrun "Require symlinks support"
3311 target=`mktemp -p $TEST_DIR`
3312 link=`mktemp -p $TEST_DIR -u`
3313 ln -s `basename $target` $link
3314 if [ "$?" -ne 0 ]; then
3316 _notrun "Require symlinks support"
3321 _require_test_fcntl_advisory_locks()
3323 [ "$FSTYP" != "cifs" ] && return 0
3324 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3325 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3326 _notrun "Require fcntl advisory locks support"
3329 # XFS ability to change UUIDs on V5/CRC filesystems
3331 _require_meta_uuid()
3333 # This will create a crc fs on $SCRATCH_DEV
3336 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
3337 | grep -q "invalid UUID\|supported on V5 fs" \
3338 && _notrun "Userspace doesn't support meta_uuid feature"
3340 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
3342 _scratch_mount >/dev/null 2>&1 \
3343 || _notrun "Kernel doesn't support meta_uuid feature"
3347 _require_btrfs_dev_del_by_devid()
3349 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
3350 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
3351 "(must support 'btrfs device delete <devid> /<mnt>')"
3354 _require_test_lsattr()
3356 testio=$(lsattr -d $TEST_DIR 2>&1)
3357 echo $testio | grep -q "Operation not supported" && \
3358 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3359 echo $testio | grep -q "Inappropriate ioctl for device" && \
3360 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3363 _require_xfs_test_rmapbt()
3367 if [ "$(xfs_info "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
3368 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
3372 _require_xfs_scratch_rmapbt()
3376 _scratch_mkfs > /dev/null
3378 if [ "$(xfs_info "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
3380 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
3401 "$XFS_IO_PROG" -c "bmap -${param}lpv" "$file" | grep -c "$@"
3408 touch $TEST_DIR/syscalltest
3409 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3411 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3412 if [ "$status" -ne 0 ]; then
3413 _notrun "file system doesn't support chattr +$attribute"
3415 cat $TEST_DIR/syscalltest.out >> $seqres.full
3417 rm -f $TEST_DIR/syscalltest.out
3422 if [ -z "$1" ]; then
3423 echo "Usage: _get_total_inode <mnt>"
3427 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3433 if [ -z "$1" ]; then
3434 echo "Usage: _get_used_inode <mnt>"
3438 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3442 _get_used_inode_percent()
3444 if [ -z "$1" ]; then
3445 echo "Usage: _get_used_inode_percent <mnt>"
3449 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3456 if [ -z "$1" ]; then
3457 echo "Usage: _get_free_inode <mnt>"
3461 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3465 # get the available space in bytes
3467 _get_available_space()
3469 if [ -z "$1" ]; then
3470 echo "Usage: _get_available_space <mnt>"
3474 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3475 echo $((avail_kb * 1024))
3478 # get btrfs profile configs being tested
3480 # A set of pre-set profile configs are exported via _btrfs_profile_configs
3481 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
3482 # var in the format "metadata_profile:data_profile", multiple configs can be
3483 # seperated by space, e.g.
3484 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
3485 _btrfs_get_profile_configs()
3487 if [ "$FSTYP" != "btrfs" ]; then
3491 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3492 # Default configurations to test.
3504 # User-provided configurations.
3505 local configs=(${BTRFS_PROFILE_CONFIGS[@]})
3508 _btrfs_profile_configs=()
3509 for cfg in "${configs[@]}"; do
3510 local supported=true
3511 local profiles=(${cfg/:/ })
3512 if [ "$1" == "replace" ]; then
3513 # We can't do replace with these profiles because they
3514 # imply only one device ($SCRATCH_DEV), and we need to
3515 # keep $SCRATCH_DEV around for _scratch_mount
3516 # and _check_scratch_fs.
3520 elif [ "$1" == "replace-missing" ]; then
3521 # We can't replace missing devices with these profiles
3522 # because there isn't enough redundancy.
3529 local unsupported=()
3531 for unsupp in "${unsupported[@]}"; do
3532 if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then
3533 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3534 # For the default config, just omit it.
3537 # For user-provided config, don't run the test.
3538 _notrun "Profile $unsupp not supported for $1"
3542 if "$supported"; then
3543 _btrfs_profile_configs+=("-m ${profiles[0]} -d ${profiles[1]}")
3546 export _btrfs_profile_configs
3549 # stress btrfs by running balance operation in a loop
3550 _btrfs_stress_balance()
3554 $BTRFS_UTIL_PROG balance start $options
3558 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
3559 _btrfs_stress_subvolume()
3563 local subvol_name=$3
3567 mkdir -p $subvol_mnt
3568 while [ ! -e $stop_file ]; do
3569 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
3570 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
3571 $UMOUNT_PROG $subvol_mnt
3572 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
3576 # stress btrfs by running scrub in a loop
3577 _btrfs_stress_scrub()
3581 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
3585 # stress btrfs by defragmenting every file/dir in a loop and compress file
3586 # contents while defragmenting if second argument is not "nocompress"
3587 _btrfs_stress_defrag()
3593 if [ "$compress" == "nocompress" ]; then
3594 find $btrfs_mnt \( -type f -o -type d \) -exec \
3595 $BTRFS_UTIL_PROG filesystem defrag {} \;
3597 find $btrfs_mnt \( -type f -o -type d \) -exec \
3598 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
3599 find $btrfs_mnt \( -type f -o -type d \) -exec \
3600 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
3605 # stress btrfs by remounting it with different compression algorithms in a loop
3606 # run this with fsstress running at background could exercise the compression
3607 # code path and ensure no race when switching compression algorithm with constant
3609 _btrfs_stress_remount_compress()
3613 for algo in no zlib lzo; do
3614 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
3619 # stress btrfs by replacing devices in a loop
3620 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
3621 # device should be free(not used by btrfs)
3622 _btrfs_stress_replace()
3626 # The device number in SCRATCH_DEV_POOL should be at least 3,
3627 # one is SCRATCH_DEV, one is to be replaced, one is free device
3628 # we won't replace SCRATCH_DEV, see below for reason
3629 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
3630 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
3634 # take the last device as the first free_dev
3635 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
3637 # free_dev should be really free
3638 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
3639 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3643 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3644 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3645 # _scratch_mount and _check_scratch_fs etc.
3646 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3647 -e "s# *$free_dev *##"`
3649 # set the first device in dev_pool as the first src_dev to be replaced
3650 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3652 echo "dev_pool=$dev_pool"
3653 echo "free_dev=$free_dev, src_dev=$src_dev"
3655 echo "Replacing $src_dev with $free_dev"
3656 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3657 if [ $? -ne 0 ]; then
3658 # don't update src_dev and free_dev if replace failed
3661 dev_pool="$dev_pool $free_dev"
3662 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3664 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3668 # find the right option to force output in bytes, older versions of btrfs-progs
3669 # print that by default, newer print human readable numbers with unit suffix
3670 _btrfs_qgroup_units()
3672 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3675 # return device size in kb
3678 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3681 # check dmesg log for WARNING/Oops/etc.
3684 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3687 rm -f ${RESULT_DIR}/check_dmesg
3689 # default filter is a simple cat command, caller could provide a
3690 # customized filter and pass the name through the first argument, to
3691 # filter out intentional WARNINGs or Oopses
3694 # search the dmesg log of last run of $seqnum for possible failures
3695 # use sed \cregexpc address type, since $seqnum contains "/"
3696 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3697 tac | $filter >$seqres.dmesg
3698 grep -q -e "kernel BUG at" \
3702 -e "possible recursive locking detected" \
3703 -e "Internal error" \
3704 -e "INFO: suspicious RCU usage" \
3705 -e "INFO: possible circular locking dependency detected" \
3706 -e "general protection fault:" \
3708 if [ $? -eq 0 ]; then
3709 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3717 # don't check dmesg log after test
3718 _disable_dmesg_check()
3720 rm -f ${RESULT_DIR}/check_dmesg
3725 if [ "$iam" == new ]
3729 # make some further configuration checks here
3730 if [ "$TEST_DEV" = "" ]
3732 echo "common/rc: Error: \$TEST_DEV is not set"
3736 # if $TEST_DEV is not mounted, mount it now as XFS
3737 if [ -z "`_fs_type $TEST_DEV`" ]
3739 # $TEST_DEV is not mounted
3742 echo "common/rc: retrying test device mount with external set"
3743 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3746 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3752 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3754 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3755 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
3756 _df_device $TEST_DEV
3759 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3760 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3761 export XFS_IO_PROG="$XFS_IO_PROG -F"
3763 # xfs_copy doesn't work on v5 xfs yet without -d option
3764 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3765 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3769 # get real device path name by following link
3773 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3774 _dev=`readlink -f "$_dev"`
3779 # basename of a device
3782 echo `basename $(_real_dev $1)`
3788 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3789 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3790 _maj=$(echo "ibase=16; $_maj" | bc)
3791 _min=$(echo "ibase=16; $_min" | bc)
3792 echo /sys/dev/block/$_maj:$_min
3797 if [ -z $1 ] || [ ! -d $1 ]; then
3798 echo "Missing mount point argument for get_block_size"
3801 echo `stat -f -c %S $1`
3806 echo $(getconf PAGE_SIZE)
3813 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3814 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3815 echo "$@" >>$seqres.full
3816 rm -f $TEST_DIR/junk
3817 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3818 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3824 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3826 # Only one argument is needed:
3827 # - attr: path name under /sys/fs/$FSTYP/DEV
3830 # _require_fs_sysfs error/fail_at_unmount
3834 local dname=$(_short_dev $TEST_DEV)
3836 if [ -z "$attr" -o -z "$dname" ];then
3837 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3840 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3841 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3845 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3847 # All arguments are necessary, and in this order:
3848 # - dev: device name, e.g. $SCRATCH_DEV
3849 # - attr: path name under /sys/fs/$FSTYP/$dev
3850 # - content: the content of $attr
3853 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3854 _set_fs_sysfs_attr()
3862 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3863 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3866 local dname=$(_short_dev $dev)
3867 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3870 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3872 # All arguments are necessary, and in this order:
3873 # - dev: device name, e.g. $SCRATCH_DEV
3874 # - attr: path name under /sys/fs/$FSTYP/$dev
3877 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3878 _get_fs_sysfs_attr()
3883 if [ ! -b "$dev" -o -z "$attr" ];then
3884 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3887 local dname=$(_short_dev $dev)
3888 cat /sys/fs/${FSTYP}/${dname}/${attr}
3891 # Skip if we are running an older binary without the stricter input checks.
3892 # Make multiple checks to be sure that there is no regression on the one
3893 # selected feature check, which would skew the result.
3895 # At first, make a common function that runs the tests and returns
3896 # number of failed cases.
3897 _xfs_mkfs_validation_check()
3899 local tmpfile=`mktemp`
3900 local cmd="$MKFS_XFS_PROG -f -N -d file,name=$tmpfile,size=1g"
3902 $cmd -s size=2s >/dev/null 2>&1
3905 $cmd -l version=2,su=260k >/dev/null 2>&1
3906 sum=`expr $sum + $?`
3912 # Skip the test if all calls passed - mkfs accepts invalid input
3913 _require_xfs_mkfs_validation()
3915 _xfs_mkfs_validation_check
3916 if [ "$?" -eq 0 ]; then
3917 _notrun "Requires newer mkfs with stricter input checks: the oldest supported version of xfsprogs is 4.7."
3921 # The oposite of _require_xfs_mkfs_validation.
3922 _require_xfs_mkfs_without_validation()
3924 _xfs_mkfs_validation_check
3925 if [ "$?" -ne 0 ]; then
3926 _notrun "Requires older mkfs without strict input checks: the last supported version of xfsprogs is 4.5."
3932 ################################################################################
3933 # make sure this script returns success