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 # helper function to do the actual overlayfs mount operation
270 _overlay_mount_dirs()
277 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
278 -o workdir=$workdir $*
281 # Given a dir, set up 3 subdirectories and mount on the given mnt.
282 # The dir is used as the mount device so it can be seen from df or mount
289 local upper_fst=$(df --output=fstype $dir | tail -1)
292 if ! xfs_info $dir | grep -q "ftype=1" ; then
293 _notrun "upper fs needs to support d_type"
297 if ! tune2fs -l $(df --output=source $dir | tail -1) | \
298 grep -q filetype ; then
299 _notrun "upper fs needs to support d_type"
304 mkdir -p $dir/$OVERLAY_UPPER_DIR
305 mkdir -p $dir/$OVERLAY_LOWER_DIR
306 mkdir -p $dir/$OVERLAY_WORK_DIR
308 _overlay_mount_dirs $dir/$OVERLAY_LOWER_DIR $dir/$OVERLAY_UPPER_DIR \
309 $dir/$OVERLAY_WORK_DIR $OVERLAY_MOUNT_OPTIONS \
310 $SELINUX_MOUNT_OPTIONS $* $dir $mnt
313 _overlay_test_mount()
315 _overlay_mount $TEST_DEV $TEST_DIR $*
318 _overlay_scratch_mount()
320 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
323 _overlay_test_unmount()
325 $UMOUNT_PROG $TEST_DIR
328 _overlay_scratch_unmount()
330 $UMOUNT_PROG $SCRATCH_MNT
335 if [ "$FSTYP" == "overlay" ]; then
336 _overlay_scratch_mount $*
339 _mount -t $FSTYP `_scratch_mount_options $*`
346 _overlay_scratch_unmount
349 $UMOUNT_PROG $SCRATCH_MNT
352 $UMOUNT_PROG $SCRATCH_DEV
361 if test -n "$opts"; then
362 mount -o "remount,$opts" $SCRATCH_MNT
366 _scratch_cycle_mount()
370 if [ "$FSTYP" = tmpfs ]; then
371 _scratch_remount "$opts"
374 if test -n "$opts"; then
378 _scratch_mount "$opts"
383 if [ "$FSTYP" == "overlay" ]; then
384 _overlay_test_mount $*
388 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
393 if [ "$FSTYP" == "overlay" ]; then
394 _overlay_test_unmount
396 $UMOUNT_PROG $TEST_DEV
402 if [ "$FSTYP" = tmpfs ]; then
409 _scratch_mkfs_options()
411 _scratch_options mkfs
412 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
420 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
421 options="-l $SCRATCH_LOGDEV"
423 xfs_metadump $options $SCRATCH_DEV $dumpfile
426 _setup_large_xfs_fs()
431 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
432 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
433 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
435 # calculate the size of the file we need to allocate.
436 # Default free space in the FS is 50GB, but you can specify more via
437 # SCRATCH_DEV_EMPTY_SPACE
438 file_size=$(($fs_size - 50*1024*1024*1024))
439 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
441 # mount the filesystem, create the file, unmount it
442 _scratch_mount 2>&1 >$tmp_dir/mnt.err
444 if [ $status -ne 0 ]; then
446 cat $tmp_dir/mnt.err >&2
447 rm -f $tmp_dir/mnt.err
450 rm -f $tmp_dir/mnt.err
453 -c "truncate $file_size" \
454 -c "falloc -k 0 $file_size" \
456 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
457 export NUM_SPACE_FILES=1
460 if [ $status -ne 0 ]; then
461 echo "large file prealloc failed"
462 cat $tmp_dir/mnt.err >&2
468 _scratch_mkfs_xfs_opts()
472 # remove metadata related mkfs options if mkfs.xfs doesn't them
473 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
474 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
477 _scratch_options mkfs
479 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
483 _scratch_mkfs_xfs_supported()
487 _scratch_options mkfs
489 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
492 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
493 # $mkfs_opts, try again without $MKFS_OPTIONS
494 if [ $mkfs_status -ne 0 -a -n "$mkfs_opts" ]; then
495 $MKFS_XFS_PROG -N $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
503 # extra mkfs options can be added by tests
504 local extra_mkfs_options=$*
508 # save mkfs output in case conflict means we need to run again.
509 # only the output for the mkfs that applies should be shown
510 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
511 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
515 # a mkfs failure may be caused by conflicts between
516 # $MKFS_OPTIONS and $extra_mkfs_options
517 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
519 echo -n "** mkfs failed with extra mkfs options "
520 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
521 echo -n "** attempting to mkfs using only test $seq "
522 echo "options: $extra_mkfs_options **"
525 # running mkfs again. overwrite previous mkfs output files
526 _scratch_mkfs_xfs_opts $extra_mkfs_options \
527 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
531 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
532 # manually parse the mkfs output to get the fs size in bytes
534 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
535 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
537 print STDOUT "$size\n";
539 _setup_large_xfs_fs $fs_size
543 # output stored mkfs output, filtering unnecessary warnings from stderr
545 cat $tmp_dir.mkfserr | sed \
546 -e '/less than device physical sector/d' \
547 -e '/switching to logical sector/d' \
549 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
554 # xfs_check script is planned to be deprecated. But, we want to
555 # be able to invoke "xfs_check" behavior in xfstests in order to
556 # maintain the current verification levels.
561 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
563 while getopts "b:fi:l:stvV" c
569 i) OPTS=$OPTS"-i "$OPTARG" ";;
570 b) OPTS=$OPTS"-b "$OPTARG" ";;
571 f) DBOPTS=$DBOPTS" -f";;
572 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
573 V) $XFS_DB_PROG -p xfs_check -V
581 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
591 _setup_large_ext4_fs()
596 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
597 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
598 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
600 # Default free space in the FS is 50GB, but you can specify more via
601 # SCRATCH_DEV_EMPTY_SPACE
602 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
604 # mount the filesystem and create 16TB - 4KB files until we consume
605 # all the necessary space.
606 _scratch_mount 2>&1 >$tmp_dir/mnt.err
608 if [ $status -ne 0 ]; then
610 cat $tmp_dir/mnt.err >&2
611 rm -f $tmp_dir/mnt.err
614 rm -f $tmp_dir/mnt.err
616 file_size=$((16*1024*1024*1024*1024 - 4096))
618 while [ $space_to_consume -gt $file_size ]; do
621 -c "truncate $file_size" \
622 -c "falloc -k 0 $file_size" \
623 $SCRATCH_MNT/.use_space.$nfiles 2>&1
625 if [ $status -ne 0 ]; then
629 space_to_consume=$(( $space_to_consume - $file_size ))
630 nfiles=$(($nfiles + 1))
633 # consume the remaining space.
634 if [ $space_to_consume -gt 0 ]; then
636 -c "truncate $space_to_consume" \
637 -c "falloc -k 0 $space_to_consume" \
638 $SCRATCH_MNT/.use_space.$nfiles 2>&1
641 export NUM_SPACE_FILES=$nfiles
644 if [ $status -ne 0 ]; then
645 echo "large file prealloc failed"
646 cat $tmp_dir/mnt.err >&2
654 # extra mkfs options can be added by tests
655 local extra_mkfs_options=$*
659 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
660 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
663 # a mkfs failure may be caused by conflicts between
664 # $MKFS_OPTIONS and $extra_mkfs_options
665 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
667 echo -n "** mkfs failed with extra mkfs options "
668 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
669 echo -n "** attempting to mkfs using only test $seq "
670 echo "options: $extra_mkfs_options **"
673 # running mkfs again. overwrite previous mkfs output files
674 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
675 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
679 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
680 # manually parse the mkfs output to get the fs size in bytes
681 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
682 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
683 / inodes, / { blks = $3 } \
684 /reserved for the super user/ { resv = $1 } \
685 END { fssize = bs * blks - resv; print fssize }'`
687 _setup_large_ext4_fs $fs_size
691 # output stored mkfs output
692 grep -v -e ^Warning: -e "^mke2fs " $tmp_dir.mkfserr >&2
694 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
706 # do nothing for cifs
709 # do nothing for overlay
712 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
715 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
718 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
721 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
733 # do nothing for overlay
736 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
739 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
742 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
743 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
747 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
748 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
752 if [ $? -ne 0 ]; then
753 # output stored mkfs output
754 cat $tmp_dir.mkfserr >&2
759 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
762 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
763 _scratch_cleanup_files()
767 # $SCRATCH_DEV is a valid directory in overlay case
768 rm -rf $SCRATCH_DEV/*
772 rm -rf $SCRATCH_MNT/*
785 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
786 # avoid EEXIST caused by the leftover files created in previous runs
787 _scratch_cleanup_files
790 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
791 # avoid EEXIST caused by the leftover files created in previous runs
792 _scratch_cleanup_files
795 # unable to re-create overlay, remove all files in $SCRATCH_MNT to
796 # avoid EEXIST caused by the leftover files created in previous runs
797 _scratch_cleanup_files
800 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
803 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
806 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
809 _scratch_mkfs_ext4 $*
812 # do nothing for tmpfs
815 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
818 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
823 # Helper function to get a spare or replace-target device from
824 # configured SCRATCH_DEV_POLL, must call _scratch_dev_pool_get()
825 # before _spare_dev_get(). Replace-target-device/Spare-device will
826 # be assigned to SPARE_DEV.
827 # As of now only one replace-target-device/spare-device can be
831 # _scratch_dev_pool_get() <ndevs>
835 # _scratch_dev_pool_put()
839 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
840 if [ $? -ne 0 ]; then
841 _fail "Bug: unset val, must call _scratch_dev_pool_get before _spare_dev_get"
844 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
845 _fail "Bug: str empty, must call _scratch_dev_pool_get before _spare_dev_get"
848 # Check if the spare is already assigned
849 typeset -p SPARE_DEV >/dev/null 2>&1
850 if [ $? -eq 0 ]; then
851 if [ ! -z "$SPARE_DEV" ]; then
852 _fail "Bug: SPARE_DEV = $SPARE_DEV already assigned"
856 local ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
857 local config_ndevs=`echo $SCRATCH_DEV_POOL_SAVED| wc -w`
859 if [ $ndevs -eq $config_ndevs ]; then
860 _notrun "All devs used no spare"
862 # Get a dev that is not used
863 local devs[]="( $SCRATCH_DEV_POOL_SAVED )"
864 SPARE_DEV=${devs[@]:$ndevs:1}
870 typeset -p SPARE_DEV >/dev/null 2>&1
871 if [ $? -ne 0 ]; then
872 _fail "Bug: unset val, must call _spare_dev_get before its put"
875 if [ -z "$SPARE_DEV" ]; then
876 _fail "Bug: str empty, must call _spare_dev_get before its put"
883 # Generally test cases will have..
884 # _require_scratch_dev_pool X
885 # to make sure it has the enough scratch devices including
886 # replace-target and spare device. Now arg1 here is the
887 # required number of scratch devices by a-test-case excluding
888 # the replace-target and spare device. So this function will
889 # set SCRATCH_DEV_POOL to the specified number of devices.
892 # _scratch_dev_pool_get() <ndevs>
895 # _scratch_dev_pool_put()
897 _scratch_dev_pool_get()
899 if [ $# -ne 1 ]; then
900 _fail "Usage: _scratch_dev_pool_get ndevs"
904 local config_ndevs=`echo $SCRATCH_DEV_POOL| wc -w`
905 local devs[]="( $SCRATCH_DEV_POOL )"
907 typeset -p config_ndevs >/dev/null 2>&1
908 if [ $? -ne 0 ]; then
909 _fail "Bug: cant find SCRATCH_DEV_POOL ndevs"
912 if [ $config_ndevs -lt $test_ndevs ]; then
913 _notrun "Need at least test requested number of ndevs $test_ndevs"
916 SCRATCH_DEV_POOL_SAVED=${SCRATCH_DEV_POOL}
917 export SCRATCH_DEV_POOL_SAVED
918 SCRATCH_DEV_POOL=${devs[@]:0:$test_ndevs}
919 export SCRATCH_DEV_POOL
922 _scratch_dev_pool_put()
924 typeset -p SCRATCH_DEV_POOL_SAVED >/dev/null 2>&1
925 if [ $? -ne 0 ]; then
926 _fail "Bug: unset val, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
929 if [ -z "$SCRATCH_DEV_POOL_SAVED" ]; then
930 _fail "Bug: str empty, must call _scratch_dev_pool_get before _scratch_dev_pool_put"
933 export SCRATCH_DEV_POOL=$SCRATCH_DEV_POOL_SAVED
934 export SCRATCH_DEV_POOL_SAVED=""
941 # if dup profile is in mkfs options call _scratch_mkfs instead
942 # because dup profile only works with single device
943 if [[ "$*" =~ dup ]]; then
946 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
950 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
955 # Return the amount of free memory available on the system
958 free -b | grep ^Mem | awk '{print $4}'
961 # Create fs of certain size on scratch device
962 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
963 _scratch_mkfs_sized()
970 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
972 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
973 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
977 [ -n "$def_blksz" ] && blocksize=$def_blksz
978 [ -z "$blocksize" ] && blocksize=4096
982 if ! [[ $fssize =~ $re ]] ; then
983 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
985 if ! [[ $blocksize =~ $re ]] ; then
986 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
989 blocks=`expr $fssize / $blocksize`
991 if [ "$HOSTOS" == "Linux" -a -b "$SCRATCH_DEV" ]; then
992 devsize=`blockdev --getsize64 $SCRATCH_DEV`
993 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
998 # don't override MKFS_OPTIONS that set a block size.
999 echo $MKFS_OPTIONS |egrep -q "b?size="
1000 if [ $? -eq 0 ]; then
1001 _scratch_mkfs_xfs -d size=$fssize
1003 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
1006 ext2|ext3|ext4|ext4dev)
1007 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1010 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
1014 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
1015 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
1018 # mkfs.resier4 requires size in KB as input for creating filesystem
1019 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
1020 `expr $fssize / 1024`
1023 # mkfs.f2fs requires # of sectors as an input for the size
1024 sector_size=`blockdev --getss $SCRATCH_DEV`
1025 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
1028 free_mem=`_free_memory_bytes`
1029 if [ "$free_mem" -lt "$fssize" ] ; then
1030 _notrun "Not enough memory ($free_mem) for tmpfs with $fssize bytes"
1032 export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS"
1035 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
1040 # Emulate an N-data-disk stripe w/ various stripe units
1041 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
1042 _scratch_mkfs_geom()
1047 [ -z "$blocksize" ] && blocksize=4096
1049 let sunit_blocks=$sunit_bytes/$blocksize
1050 let swidth_blocks=$sunit_blocks*$swidth_mult
1054 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
1057 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
1060 _notrun "can't mkfs $FSTYP with geometry"
1066 # Create fs of certain blocksize on scratch device
1067 # _scratch_mkfs_blocksized blocksize
1068 _scratch_mkfs_blocksized()
1073 if ! [[ $blocksize =~ $re ]] ; then
1074 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
1079 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
1081 ext2|ext3|ext4|ocfs2)
1082 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
1085 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
1094 xfs_io -x -c "resblks $1" $SCRATCH_MNT
1101 _scratch_xfs_db_options()
1104 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1105 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1106 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
1109 _scratch_xfs_logprint()
1112 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1113 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1114 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
1117 _test_xfs_logprint()
1120 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1121 TEST_OPTIONS="-l$TEST_LOGDEV"
1122 $XFS_LOGPRINT_PROG $TEST_OPTIONS $* $TEST_DEV
1125 _scratch_xfs_check()
1128 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1129 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
1130 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1131 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
1132 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
1135 _scratch_xfs_repair()
1138 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
1139 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
1140 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
1141 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
1142 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
1143 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
1146 # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
1147 # errors found or errors were fixed) and nonzero otherwise; also spits out
1148 # a complaint on stderr if fsck didn't tell us that the FS is good to go.
1149 _repair_scratch_fs()
1153 _scratch_xfs_repair "$@" 2>&1
1155 if [ "$res" -eq 2 ]; then
1156 echo "xfs_repair returns $res; replay log?"
1159 if [ "$res" -gt 0 ]; then
1160 echo "mount returns $res; zap log?"
1161 _scratch_xfs_repair -L 2>&1
1162 echo "log zap returns $?"
1164 umount "$SCRATCH_MNT"
1166 _scratch_xfs_repair "$@" 2>&1
1169 test $res -ne 0 && >&2 echo "xfs_repair failed, err=$res"
1173 # Let's hope fsck -y suffices...
1174 fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
1181 >&2 echo "fsck.$FSTYP failed, err=$res"
1193 echo "Usage: _get_pids_by_name process-name" 1>&2
1197 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
1198 # HH:MM:SS before the psargs field, use this as the search anchor.
1200 # Matches with $1 (process-name) occur if the first psarg is $1
1201 # or ends in /$1 ... the matching uses sed's regular expressions,
1202 # so passing a regex into $1 will work.
1207 -e 's/[ ][ ]*/ /g' \
1210 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
1211 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
1214 # fix malloc libs output
1218 # filter out the Electric Fence notice
1221 if (defined $o && /^\s+Electric Fence/) {
1227 print $o if (defined $o);
1231 print $o if (defined $o);
1236 # _df_device : get an IRIX style df line for a given device
1238 # - returns "" if not mounted
1239 # - returns fs type in field two (ala IRIX)
1240 # - joins line together if split by fancy df formatting
1241 # - strips header etc
1248 echo "Usage: _df_device device" 1>&2
1252 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1253 # IPv6 server as a regular expression.
1254 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1255 ($1==what) && (NF==1) {
1269 # _df_dir : get an IRIX style df line for device where a directory resides
1271 # - returns fs type in field two (ala IRIX)
1272 # - joins line together if split by fancy df formatting
1273 # - strips header etc
1280 echo "Usage: _df_dir device" 1>&2
1284 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1300 # return percentage used disk space for mounted device
1306 echo "Usage: _used device" 1>&2
1310 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1313 # return the FS type of a mounted device
1319 echo "Usage: _fs_type device" 1>&2
1324 # The Linux kernel shows NFSv4 filesystems in df output as
1325 # filesystem type nfs4, although we mounted it as nfs earlier.
1326 # Fix the filesystem type up here so that the callers don't
1327 # have to bother with this quirk.
1329 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1332 # return the FS mount options of a mounted device
1334 # should write a version which just parses the output of mount for IRIX
1335 # compatibility, but since this isn't used at all, at the moment I'll leave
1342 echo "Usage: _fs_options device" 1>&2
1346 $AWK_PROG -v dev=$1 '
1347 match($1,dev) { print $4 }
1351 # returns device number if a file is a block device
1357 echo "Usage: _is_block_dev dev" 1>&2
1362 if [ -L "${_dev}" ]; then
1363 _dev=`readlink -f "${_dev}"`
1366 if [ -b "${_dev}" ]; then
1367 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1371 # Do a command, log it to $seqres.full, optionally test return status
1372 # and die if command fails. If called with one argument _do executes the
1373 # command, logs it, and returns its exit status. With two arguments _do
1374 # first prints the message passed in the first argument, and then "done"
1375 # or "fail" depending on the return status of the command passed in the
1376 # second argument. If the command fails and the variable _do_die_on_error
1377 # is set to "always" or the two argument form is used and _do_die_on_error
1378 # is set to "message_only" _do will print an error message to
1379 # $seqres.out and exit.
1383 if [ $# -eq 1 ]; then
1385 elif [ $# -eq 2 ]; then
1388 echo -n "$_note... "
1390 echo "Usage: _do [note] cmd" 1>&2
1394 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1395 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1396 cat $tmp._out | _fix_malloc >>$seqres.full
1397 if [ $# -eq 2 ]; then
1398 if [ $ret -eq 0 ]; then
1405 && [ "$_do_die_on_error" = "always" \
1406 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1408 [ $# -ne 2 ] && echo
1409 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1416 # bail out, setting up .notrun file. Need to kill the filesystem check files
1417 # here, otherwise they are set incorrectly for the next test.
1421 echo "$*" > $seqres.notrun
1422 echo "$seq not run: $*"
1423 rm -f ${RESULT_DIR}/require_test
1424 rm -f ${RESULT_DIR}/require_scratch
1429 # just plain bail out
1433 echo "$*" | tee -a $seqres.full
1434 echo "(see $seqres.full for details)"
1439 # tests whether $FSTYP is one of the supported filesystems for a test
1445 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1451 _notrun "not suitable for this filesystem type: $FSTYP"
1455 # tests whether $FSTYP is one of the supported OSes for a test
1461 if [ "$h" = "$HOSTOS" ]
1467 _notrun "not suitable for this OS: $HOSTOS"
1470 _require_btrfs_loadable()
1472 modprobe -r btrfs || _notrun "btrfs unloadable"
1473 modprobe btrfs || _notrun "Can't load btrfs"
1478 modprobe -r btrfs || _fail "btrfs unload failed"
1479 modprobe btrfs || _fail "btrfs load failed"
1482 # this test needs a scratch partition - check we're ok & unmount it
1483 # No post-test check of the device is required. e.g. the test intentionally
1484 # finishes the test with the filesystem in a corrupt state
1485 _require_scratch_nocheck()
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 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1499 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1500 _notrun "this test requires a valid \$SCRATCH_DEV"
1502 if [ ! -d "$SCRATCH_MNT" ]; then
1503 _notrun "this test requires a valid \$SCRATCH_MNT"
1507 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1508 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1510 if [ ! -d "$SCRATCH_MNT" ]; then
1511 _notrun "this test requires a valid \$SCRATCH_MNT"
1515 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1517 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1521 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1523 _notrun "this test requires a valid \$SCRATCH_DEV"
1525 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1527 _notrun "this test requires a valid \$SCRATCH_DEV"
1529 if [ ! -d "$SCRATCH_MNT" ]
1531 _notrun "this test requires a valid \$SCRATCH_MNT"
1537 # Note that we use -F here so grep doesn't try to interpret an NFS over
1538 # IPv6 server as a regular expression.
1539 mount_rec=`_mount | grep -F $SCRATCH_DEV`
1542 # if it's mounted, make sure its on $SCRATCH_MNT
1543 if ! echo $mount_rec | grep -q $SCRATCH_MNT
1545 echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
1546 echo "Already mounted result:"
1550 # and then unmount it
1551 if ! _scratch_unmount
1553 echo "failed to unmount $SCRATCH_DEV"
1557 rm -f ${RESULT_DIR}/require_scratch
1560 # we need the scratch device and it should be checked post test.
1563 _require_scratch_nocheck
1564 touch ${RESULT_DIR}/require_scratch
1568 # this test needs a test partition - check we're ok & mount it
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_DIR"
1578 if [ ! -d "$TEST_DIR" ]; then
1579 _notrun "this test requires a valid \$TEST_DIR"
1583 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1584 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1585 _notrun "this test requires a valid \$TEST_DEV"
1587 if [ ! -d "$TEST_DIR" ]; then
1588 _notrun "this test requires a valid \$TEST_DIR"
1592 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1593 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1595 if [ ! -d "$TEST_DIR" ]; then
1596 _notrun "this test requires a valid \$TEST_DIR"
1600 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1602 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1606 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1608 _notrun "this test requires a valid \$TEST_DEV"
1610 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1612 _notrun "this test requires a valid \$TEST_DEV"
1614 if [ ! -d "$TEST_DIR" ]
1616 _notrun "this test requires a valid \$TEST_DIR"
1622 # Note that we use -F here so grep doesn't try to interpret an NFS over
1623 # IPv6 server as a regular expression.
1624 mount_rec=`_mount | grep -F $TEST_DEV`
1627 # if it's mounted, make sure its on $TEST_DIR
1628 if ! echo $mount_rec | grep -q $TEST_DIR
1630 echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
1631 echo "Already mounted result:"
1636 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1637 if [ $? -ne 1 ]; then
1642 touch ${RESULT_DIR}/require_test
1645 # this test needs a logdev
1649 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1650 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1651 [ "$USE_EXTERNAL" != yes ] && \
1652 _notrun "This test requires USE_EXTERNAL to be enabled"
1654 # ensure its not mounted
1655 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1658 # this test requires loopback device support
1662 if [ "$HOSTOS" != "Linux" ]
1664 _notrun "This test requires linux for loopback device support"
1667 modprobe loop >/dev/null 2>&1
1668 if grep loop /proc/devices >/dev/null 2>&1
1672 _notrun "This test requires loopback device support"
1676 # this test requires ext2 filesystem support
1680 if [ "$HOSTOS" != "Linux" ]
1682 _notrun "This test requires linux for ext2 filesystem support"
1685 modprobe ext2 >/dev/null 2>&1
1686 if grep ext2 /proc/filesystems >/dev/null 2>&1
1690 _notrun "This test requires ext2 filesystem support"
1694 # this test requires that (large) loopback device files are not in use
1696 _require_no_large_scratch_dev()
1698 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1699 _notrun "Large filesystem testing in progress, skipped this test"
1702 # this test requires that a realtime subvolume is in use, and
1703 # that the kernel supports realtime as well.
1707 [ "$USE_EXTERNAL" = yes ] || \
1708 _notrun "External volumes not in use, skipped this test"
1709 [ "$SCRATCH_RTDEV" = "" ] && \
1710 _notrun "Realtime device required, skipped this test"
1713 # this test requires that a specified command (executable) exists
1714 # $1 - command, $2 - name for error message
1716 # Note: the command string might have parameters, so strip them before checking
1717 # whether it is executable.
1720 if [ $# -eq 2 ]; then
1722 elif [ $# -eq 1 ]; then
1725 _fail "usage: _require_command <command> [<name>]"
1728 _command=`echo "$1" | awk '{ print $1 }'`
1729 if [ ! -x "$_command" ]; then
1730 _notrun "$_name utility required, skipped this test"
1734 # this test requires the device to be valid block device
1736 _require_block_device()
1738 if [ -z "$1" ]; then
1739 echo "Usage: _require_block_device <dev>" 1>&2
1742 if [ "`_is_block_dev "$1"`" == "" ]; then
1743 _notrun "require $1 to be valid block disk"
1747 # brd based ram disks erase the device when they receive a flush command when no
1748 # active references are present. This causes problems for DM devices sitting on
1749 # top of brd devices as DM doesn't hold active references to the brd device.
1750 _require_sane_bdev_flush()
1752 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1753 if [ $? -eq 0 ]; then
1754 _notrun "This test requires a sane block device flush"
1758 # this test requires a specific device mapper target
1759 _require_dm_target()
1763 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1765 _require_block_device $SCRATCH_DEV
1766 _require_sane_bdev_flush $SCRATCH_DEV
1767 _require_command "$DMSETUP_PROG" dmsetup
1769 modprobe dm-$_target >/dev/null 2>&1
1771 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1772 if [ $? -ne 0 ]; then
1773 _notrun "This test requires dm $_target support"
1777 # this test requires the projid32bit feature to be available in mkfs.xfs.
1779 _require_projid32bit()
1781 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1782 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1785 _require_projid16bit()
1787 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1788 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1791 # this test requires the crc feature to be available in mkfs.xfs
1793 _require_xfs_mkfs_crc()
1795 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1796 || _notrun "mkfs.xfs doesn't have crc feature"
1799 # this test requires the xfs kernel support crc feature
1803 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1804 _scratch_mount >/dev/null 2>&1 \
1805 || _notrun "Kernel doesn't support crc feature"
1809 # this test requires the ext4 kernel support crc feature on scratch device
1811 _require_scratch_ext4_crc()
1813 _scratch_mkfs_ext4 >/dev/null 2>&1
1814 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1815 _scratch_mount >/dev/null 2>&1 \
1816 || _notrun "Kernel doesn't support metadata_csum feature"
1820 # this test requires the xfs kernel support crc feature on scratch device
1822 _require_scratch_xfs_crc()
1824 _scratch_mkfs_xfs >/dev/null 2>&1
1825 _scratch_mount >/dev/null 2>&1 \
1826 || _notrun "Kernel doesn't support crc feature"
1827 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1831 # this test requires the bigalloc feature to be available in mkfs.ext4
1833 _require_ext4_mkfs_bigalloc()
1835 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1836 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1839 # this test requires the ext4 kernel support bigalloc feature
1841 _require_ext4_bigalloc()
1843 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1844 _scratch_mount >/dev/null 2>&1 \
1845 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1849 # this test requires the finobt feature to be available in mkfs.xfs
1851 _require_xfs_mkfs_finobt()
1853 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1854 || _notrun "mkfs.xfs doesn't have finobt feature"
1857 # this test requires the xfs kernel support finobt feature
1859 _require_xfs_finobt()
1861 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1862 _scratch_mount >/dev/null 2>&1 \
1863 || _notrun "Kernel doesn't support finobt feature"
1867 # this test requires xfs sysfs attribute support
1869 _require_xfs_sysfs()
1872 sysfsdir=/sys/fs/xfs
1874 if [ ! -e $sysfsdir ]; then
1875 _notrun "no kernel support for XFS sysfs attributes"
1878 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1879 _notrun "sysfs attribute '$attr' is not supported"
1883 # this test requires the xfs sparse inode feature
1885 _require_xfs_sparse_inodes()
1887 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1888 || _notrun "mkfs.xfs does not support sparse inodes"
1889 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1890 _scratch_mount >/dev/null 2>&1 \
1891 || _notrun "kernel does not support sparse inodes"
1895 # this test requires that external log/realtime devices are not in use
1897 _require_nonexternal()
1899 [ "$USE_EXTERNAL" = yes ] && \
1900 _notrun "External device testing in progress, skipped this test"
1903 # this test requires that a (specified) aio-dio executable exists
1904 # $1 - command (optional)
1910 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1911 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1913 AIO_TEST=src/aio-dio-regress/$1
1914 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1919 # this test requires that a test program exists under src/
1920 # $1 - command (require)
1922 _require_test_program()
1925 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1928 # run an aio-dio program
1934 echo "usage: _run_aiodio command_name" 2>&1
1940 local testtemp=$TEST_DIR/aio-testfile
1942 $AIO_TEST $testtemp 2>&1
1949 # indicate whether YP/NIS is active or not
1954 dn=$(domainname 2>/dev/null)
1955 test -n "${dn}" -a "${dn}" != "(none)"
1959 # cat the password file
1963 [ $(_yp_active) -eq 0 ] && ypcat passwd
1967 # cat the group file
1971 [ $(_yp_active) -eq 0 ] && ypcat group
1975 # check for a user on the machine, fsgqa as default
1983 _cat_passwd | grep -q $qa_user
1984 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1985 echo /bin/true | su $qa_user
1986 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1989 # check for a group on the machine, fsgqa as default
1997 _cat_group | grep -q $qa_group
1998 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
2004 s,.*Permission\sdenied.*,Permission denied,;
2005 s,.*no\saccess\sto\stty.*,,;
2006 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
2013 if [ "$HOSTOS" == "IRIX" ]
2015 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
2017 echo $1 | su $qa_user 2>&1 | _filter_user_do
2021 _require_xfs_io_command()
2025 echo "Usage: _require_xfs_io_command command [switch]" 1>&2
2032 testfile=$TEST_DIR/$$.xfs_io
2035 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
2037 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
2038 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2039 -c "$command 4k 8k" $testfile 2>&1`
2042 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
2043 -c "fiemap -v" $testfile 2>&1`
2046 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
2048 echo $testio | egrep -q "invalid option|Is a directory" && \
2049 _notrun "xfs_io $command support is missing"
2052 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
2055 rm -f $testfile 2>&1 > /dev/null
2056 echo $testio | grep -q "not found" && \
2057 _notrun "xfs_io $command support is missing"
2058 echo $testio | grep -q "Operation not supported" && \
2059 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
2061 test -z "$param" && return
2062 $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
2063 _notrun "xfs_io $command doesn't support $param"
2066 # check that xfs_db supports a specific command
2067 _require_xfs_db_command()
2071 echo "Usage: _require_xfs_db_command command" 1>&2
2076 $XFS_DB_PROG -x -c "help" $SCRATCH_DEV | grep $command > /dev/null || \
2077 _notrun "xfs_db $command support is missing"
2080 # check that kernel and filesystem support direct I/O
2083 if [ $FSTYP = "ext4" ] ; then
2084 if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
2085 _notrun "ext4 encryption doesn't support O_DIRECT"
2088 testfile=$TEST_DIR/$$.direct
2089 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
2090 if [ $? -ne 0 ]; then
2091 _notrun "O_DIRECT is not supported"
2093 rm -f $testfile 2>&1 > /dev/null
2096 # Check that a fs has enough free space (in 1024b blocks)
2101 BLOCKS=$2 # in units of 1024
2102 let GB=$BLOCKS/1024/1024
2104 FREE_BLOCKS=`df -kP $MNT | grep -v Filesystem | awk '{print $4}'`
2105 [ $FREE_BLOCKS -lt $BLOCKS ] && \
2106 _notrun "This test requires at least ${GB}GB free on $MNT to run"
2110 # Check if the filesystem supports sparse files.
2112 # Unfortunately there is no better way to do this than a manual black list.
2114 _require_sparse_files()
2118 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
2127 #boot_params always present in debugfs
2128 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
2131 _require_fail_make_request()
2133 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
2134 || _notrun "$DEBUGFS_MNT/fail_make_request \
2135 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
2139 # Check if the file system supports seek_data/hole
2141 _require_seek_data_hole()
2143 testfile=$TEST_DIR/$$.seek
2144 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
2145 rm -f $testfile &>/dev/null
2146 echo $testseek | grep -q "Kernel does not support" && \
2147 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
2152 _require_test_program "runas"
2157 "$here/src/runas" "$@"
2160 _require_richacl_prog()
2162 _require_command "$GETRICHACL_PROG" getrichacl
2163 _require_command "$SETRICHACL_PROG" setrichacl
2166 _require_scratch_richacl_xfs()
2168 _scratch_mkfs_xfs_supported -m richacl=1 >/dev/null 2>&1 \
2169 || _notrun "mkfs.xfs doesn't have richacl feature"
2170 _scratch_mkfs_xfs -m richacl=1 >/dev/null 2>&1
2171 _scratch_mount >/dev/null 2>&1 \
2172 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2176 _require_scratch_richacl_ext4()
2178 _scratch_mkfs -O richacl >/dev/null 2>&1 \
2179 || _notrun "can't mkfs $FSTYP with option -O richacl"
2180 _scratch_mount >/dev/null 2>&1 \
2181 || _notrun "kernel doesn't support richacl feature on $FSTYP"
2185 _require_scratch_richacl_support()
2188 $GETFATTR_PROG -n system.richacl >/dev/null 2>&1 \
2189 || _notrun "this test requires richacl support on \$SCRATCH_DEV"
2193 _require_scratch_richacl()
2196 xfs) _require_scratch_richacl_xfs
2198 ext4) _require_scratch_richacl_ext4
2201 _require_scratch_richacl_support
2203 *) _notrun "this test requires richacl support on \$SCRATCH_DEV"
2208 _scratch_mkfs_richacl()
2211 xfs) _scratch_mkfs_xfs -m richacl=1
2213 ext4) _scratch_mkfs -O richacl
2221 # check that a FS on a device is mounted
2222 # if so, return mount point
2228 echo "Usage: _is_mounted device" 1>&2
2234 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
2235 pattern { print $3 ; exit 0 }
2239 echo "_is_mounted: $device is not a mounted $FSTYP FS"
2244 # remount a FS to a new mode (ro or rw)
2250 echo "Usage: _remount device ro/rw" 1>&2
2256 if ! mount -o remount,$mode $device
2258 echo "_remount: failed to remount filesystem on $device as $mode"
2263 # Run the appropriate repair/check on a filesystem
2265 # if the filesystem is mounted, it's either remounted ro before being
2266 # checked or it's unmounted and then remounted
2269 # If set, we remount ro instead of unmounting for fsck
2272 _umount_or_remount_ro()
2276 echo "Usage: _umount_or_remount_ro <device>" 1>&2
2281 mountpoint=`_is_mounted $device`
2283 if [ $USE_REMOUNT -eq 0 ]; then
2284 $UMOUNT_PROG $device
2291 _mount_or_remount_rw()
2293 if [ $# -ne 3 ]; then
2294 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
2301 if [ $USE_REMOUNT -eq 0 ]; then
2302 if [ "$FSTYP" != "overlay" ]; then
2303 _mount -t $FSTYP $mount_opts $device $mountpoint
2305 _overlay_mount $device $mountpoint
2307 if [ $? -ne 0 ]; then
2308 echo "!!! failed to remount $device on $mountpoint"
2318 # Check a generic filesystem in no-op mode; this assumes that the
2319 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2320 # and that it will still return an errno for corruption in this mode.
2322 # Filesystems which don't support this will need to define their
2323 # own check routine.
2325 _check_generic_filesystem()
2329 # If type is set, we're mounted
2330 type=`_fs_type $device`
2333 if [ "$type" = "$FSTYP" ]
2336 mountpoint=`_umount_or_remount_ro $device`
2339 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2342 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2344 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2345 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2346 cat $tmp.fsck >>$seqres.full
2347 echo "*** end fsck.$FSTYP output" >>$seqres.full
2355 echo "*** mount output ***" >>$seqres.full
2356 _mount >>$seqres.full
2357 echo "*** end mount output" >>$seqres.full
2358 elif [ "$type" = "$FSTYP" ]
2361 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2365 if [ $ok -eq 0 ]; then
2367 if [ "$iam" != "check" ]; then
2376 # run xfs_check and friends on a FS.
2378 _check_xfs_filesystem()
2382 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
2386 extra_mount_options=""
2387 extra_log_options=""
2390 if [ -f $device ];then
2394 if [ "$2" != "none" ]; then
2395 extra_log_options="-l$2"
2396 extra_mount_options="-ologdev=$2"
2399 if [ "$3" != "none" ]; then
2400 extra_rt_options="-r$3"
2401 extra_mount_options=$extra_mount_options" -ortdev=$3"
2403 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
2405 [ "$FSTYP" != xfs ] && return 0
2407 type=`_fs_type $device`
2410 if [ "$type" = "xfs" ]
2412 if [ -n "$TEST_XFS_SCRUB" ] && [ -x "$XFS_SCRUB_PROG" ]; then
2413 "$XFS_SCRUB_PROG" $scrubflag -vd $device >>$seqres.full
2414 if [ $? -ne 0 ]; then
2415 echo "filesystem on $device failed scrub (see $seqres.full)"
2420 mountpoint=`_umount_or_remount_ro $device`
2423 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
2424 | tee $tmp.logprint | grep -q "<CLEAN>"
2425 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
2427 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
2429 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
2430 echo "*** xfs_logprint -t output ***" >>$seqres.full
2431 cat $tmp.logprint >>$seqres.full
2432 echo "*** end xfs_logprint output" >>$seqres.full
2437 # xfs_check runs out of memory on large files, so even providing the test
2438 # option (-t) to avoid indexing the free space trees doesn't make it pass on
2439 # large filesystems. Avoid it.
2440 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
2441 _xfs_check $extra_log_options $device 2>&1 |\
2442 _fix_malloc >$tmp.fs_check
2444 if [ -s $tmp.fs_check ]
2446 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
2448 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2449 echo "*** xfs_check output ***" >>$seqres.full
2450 cat $tmp.fs_check >>$seqres.full
2451 echo "*** end xfs_check output" >>$seqres.full
2456 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2459 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
2461 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2462 echo "*** xfs_repair -n output ***" >>$seqres.full
2463 cat $tmp.repair | _fix_malloc >>$seqres.full
2464 echo "*** end xfs_repair output" >>$seqres.full
2468 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
2470 # Optionally test the index rebuilding behavior.
2471 if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then
2472 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2473 if [ $? -ne 0 ]; then
2474 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild) (see $seqres.full)"
2476 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)" >>$seqres.full
2477 echo "*** xfs_repair output ***" >>$seqres.full
2478 cat $tmp.repair | _fix_malloc >>$seqres.full
2479 echo "*** end xfs_repair output" >>$seqres.full
2485 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2486 if [ $? -ne 0 ]; then
2487 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify) (see $seqres.full)"
2489 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)" >>$seqres.full
2490 echo "*** xfs_repair -n output ***" >>$seqres.full
2491 cat $tmp.repair | _fix_malloc >>$seqres.full
2492 echo "*** end xfs_repair output" >>$seqres.full
2501 echo "*** mount output ***" >>$seqres.full
2502 _mount >>$seqres.full
2503 echo "*** end mount output" >>$seqres.full
2504 elif [ "$type" = "xfs" ]
2506 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
2509 if [ $ok -eq 0 ]; then
2511 if [ "$iam" != "check" ]; then
2520 # Filter the knowen errors the UDF Verifier reports.
2521 _udf_test_known_error_filter()
2523 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."
2527 _check_udf_filesystem()
2529 [ "$DISABLE_UDF_TEST" == "1" ] && return
2531 if [ $# -ne 1 -a $# -ne 2 ]
2533 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2537 if [ ! -x $here/src/udf_test ]
2539 echo "udf_test not installed, please download and build the Philips"
2540 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2541 echo "Then copy the udf_test binary to $here/src/."
2542 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2550 LAST_BLOCK=`expr \( $2 - 1 \)`
2551 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2554 rm -f $seqres.checkfs
2555 sleep 1 # Due to a problem with time stamps in udf_test
2556 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2557 _udf_test_known_error_filter | \
2558 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2559 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2563 _check_xfs_test_fs()
2567 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2568 TEST_LOG="$TEST_LOGDEV"
2570 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2571 TEST_RT="$TEST_RTDEV"
2573 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2575 # check for ipath consistency
2576 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2577 # errors go to stderr
2578 xfs_check_ipaths $TEST_DIR >/dev/null
2579 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2583 _check_btrfs_filesystem()
2587 # If type is set, we're mounted
2588 type=`_fs_type $device`
2591 if [ "$type" = "$FSTYP" ]
2594 mountpoint=`_umount_or_remount_ro $device`
2597 btrfsck $device >$tmp.fsck 2>&1
2600 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2602 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2603 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2604 cat $tmp.fsck >>$seqres.full
2605 echo "*** end fsck.$FSTYP output" >>$seqres.full
2613 echo "*** mount output ***" >>$seqres.full
2614 _mount >>$seqres.full
2615 echo "*** end mount output" >>$seqres.full
2616 elif [ "$type" = "$FSTYP" ]
2619 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2623 if [ $ok -eq 0 ]; then
2625 if [ "$iam" != "check" ]; then
2641 # no way to check consistency for nfs
2644 # no way to check consistency for cifs
2647 # no way to check consistency for overlay
2650 # do nothing for now
2653 _check_btrfs_filesystem $TEST_DEV
2656 # no way to check consistency for tmpfs
2659 _check_generic_filesystem $TEST_DEV
2667 [ $# -eq 1 ] && device=$1
2673 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2674 SCRATCH_LOG="$SCRATCH_LOGDEV"
2676 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2677 SCRATCH_RT="$SCRATCH_RTDEV"
2679 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2682 _check_udf_filesystem $device $udf_fsize
2685 # Don't know how to check an NFS filesystem, yet.
2688 # Don't know how to check a CIFS filesystem, yet.
2691 # no way to check consistency for overlay
2694 _check_btrfs_filesystem $device
2697 # no way to check consistency for tmpfs
2700 _check_generic_filesystem $device
2705 _full_fstyp_details()
2707 [ -z "$FSTYP" ] && FSTYP=xfs
2708 if [ $FSTYP = xfs ]; then
2709 if [ -d /proc/fs/xfs ]; then
2710 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2711 FSTYP="$FSTYP (non-debug)"
2712 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2713 FSTYP="$FSTYP (debug)"
2716 if uname -a | grep -qi 'debug'; then
2717 FSTYP="$FSTYP (debug)"
2719 FSTYP="$FSTYP (non-debug)"
2726 _full_platform_details()
2732 echo "$os/$platform $host $kernel"
2737 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2739 elif [ "`uname`" == "Linux" ]; then
2742 echo Unknown operating system: `uname`
2747 _link_out_file_named()
2752 my $feature, $result, $suffix, $opts;
2754 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2755 $feathash{$feature} = 1;
2757 $result = "default";
2762 ($opts, $suffix) = split(/ *: */);
2763 foreach my $opt (split(/,/, $opts)) {
2764 if (!exists($feathash{$opt})) {
2778 ln -fs $SRC.$SUFFIX $1
2783 if [ $# -eq 0 ]; then
2784 FEATURES="$(_get_os_name)"
2785 if [ -n "$MOUNT_OPTIONS" ]; then
2786 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2792 _link_out_file_named $seqfull.out "$FEATURES"
2801 #takes files, randomdata
2809 if [ $size -gt 0 ]; then
2810 if [ "$2" == "false" ]; then
2811 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2813 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2820 # takes dirname, depth, randomdata
2823 dirname=$1; depth=$2; randomdata=$3
2824 mkdir $dirname || die "mkdir $dirname failed"
2827 _nfiles $files $randomdata # files for this dir and data type
2829 [ $depth -eq 0 ] && return
2830 let deep=$depth-1 # go 1 down
2832 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2835 while [ $d -lt $dirs ]
2837 _descend d$d $deep &
2843 # Populate a filesystem with inodes for performance experiments
2845 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2850 dirs=5 # ndirs in each subdir till leaves
2851 size=0 # sizeof files in K
2852 files=100 # num files in _each_ subdir
2853 depth=2 # depth of tree from root to leaves
2855 root=root # path of initial root of directory tree
2856 randomdata=false # -x data type urandom or zero
2859 while getopts "d:f:n:r:s:v:x" c
2868 x) randomdata=true;;
2872 _descend $root $depth $randomdata
2877 [ $verbose = true ] && echo done
2880 # query whether the given file has the given inode flag set
2887 if which $XFS_IO_PROG >/dev/null; then
2888 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2895 # query the given files extsize allocator hint in bytes (if any)
2902 if which $XFS_IO_PROG >/dev/null; then
2903 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2904 awk '/^xattr.extsize =/ { print $3 }'`
2906 [ -z "$blocks" ] && blocks="0"
2910 # scratch_dev_pool should contain the disks pool for the btrfs raid
2911 _require_scratch_dev_pool()
2916 if [ -z "$SCRATCH_DEV_POOL" ]; then
2917 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2920 if [ -z "$1" ]; then
2926 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2930 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2931 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2935 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2939 for i in $SCRATCH_DEV_POOL; do
2940 if [ "`_is_block_dev "$i"`" = "" ]; then
2941 _notrun "this test requires valid block disk $i"
2943 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2944 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2946 if _mount | grep -q $i; then
2947 if ! $UMOUNT_PROG $i; then
2948 echo "failed to unmount $i - aborting"
2952 # to help better debug when something fails, we remove
2953 # traces of previous btrfs FS on the dev.
2954 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2958 # ensure devices in SCRATCH_DEV_POOL are of the same size
2959 # must be called after _require_scratch_dev_pool
2960 _require_scratch_dev_pool_equal_size()
2966 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2967 _size=`_get_device_size $SCRATCH_DEV`
2968 for _dev in $SCRATCH_DEV_POOL; do
2969 _newsize=`_get_device_size $_dev`
2970 if [ $_size -ne $_newsize ]; then
2971 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2976 # We will check if the device is deletable
2977 _require_deletable_scratch_dev_pool()
2981 for i in $SCRATCH_DEV_POOL; do
2982 x=`echo $i | cut -d"/" -f 3`
2983 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2984 _notrun "$i is a device which is not deletable"
2989 # We check for btrfs and (optionally) features of the btrfs command
2993 _require_command "$BTRFS_UTIL_PROG" btrfs
2994 if [ -z "$1" ]; then
2997 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2998 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
3001 # Check that fio is present, and it is able to execute given jobfile
3006 _require_command "$FIO_PROG" fio
3007 if [ -z "$1" ]; then
3011 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
3012 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
3015 # Does freeze work on this fs?
3018 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
3020 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
3021 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
3024 # Does shutdown work on this fs?
3025 _require_scratch_shutdown()
3027 [ -x src/godown ] || _notrun "src/godown executable not found"
3029 _scratch_mkfs > /dev/null 2>&1
3031 src/godown -f $SCRATCH_MNT 2>&1 \
3032 || _notrun "$FSTYP does not support shutdown"
3036 # Does norecovery support by this fs?
3037 _require_norecovery()
3039 _scratch_mount -o ro,norecovery || \
3040 _notrun "$FSTYP does not support norecovery"
3044 # Does this filesystem support metadata journaling?
3045 # We exclude ones here that don't; otherwise we assume that it does, so the
3046 # test will run, fail, and motivate someone to update this test for a new
3049 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
3050 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
3052 _require_metadata_journaling()
3062 _notrun "$FSTYP does not support metadata journaling"
3065 # ext4 could be mkfs'd without a journal...
3067 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
3068 _notrun "$FSTYP on $DEV not configured with metadata journaling"
3069 # ext4 might not load a journal
3070 _exclude_scratch_mount_option "noload"
3073 # by default we pass; if you need to, add your fs above!
3078 # Does fiemap support?
3081 _require_xfs_io_command "fiemap"
3086 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
3091 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
3094 # arg 1 is dev to remove and is output of the below eg.
3095 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3101 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
3103 stat $disk > /dev/null 2>&1
3104 while [ $? -eq 0 ]; do
3106 stat $disk > /dev/null 2>&1
3110 # arg 1 is dev to add and is output of the below eg.
3111 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
3116 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
3117 h=`echo ${1} | cut -d":" -f 1`
3118 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
3120 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
3122 # ensure the device comes online
3124 for i in `seq 1 10`; do
3125 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
3126 dev=`ls /sys/class/scsi_device/${1}/device/block`
3127 for j in `seq 1 10`;
3129 stat /dev/$dev > /dev/null 2>&1
3130 if [ $? -eq 0 ]; then
3141 if [ $dev_back_oneline -eq 0 ]; then
3142 echo "/dev/$dev online failed" >> $seqres.full
3144 echo "/dev/$dev is back online" >> $seqres.full
3150 if [ -z "$FSTRIM_PROG" ]; then
3151 _notrun "This test requires fstrim utility."
3155 _require_batched_discard()
3157 if [ $# -ne 1 ]; then
3158 echo "Usage: _require_batched_discard mnt_point" 1>&2
3162 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
3167 if [ -z "$DUMPE2FS_PROG" ]; then
3168 _notrun "This test requires dumpe2fs utility."
3174 if [ ! -e /proc/self/uid_map ]; then
3175 _notrun "This test requires procfs uid_map support."
3177 if [ ! -e /proc/self/gid_map ]; then
3178 _notrun "This test requires procfs gid_map support."
3184 FSSUM_PROG=$here/src/fssum
3185 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
3190 CLONER_PROG=$here/src/cloner
3191 [ -x $CLONER_PROG ] || \
3192 _notrun "cloner binary not present at $CLONER_PROG"
3195 # Normalize mount options from global $MOUNT_OPTIONS
3196 # Convert options like "-o opt1,opt2 -oopt3" to
3198 _normalize_mount_options()
3200 echo $MOUNT_OPTIONS | sed -n 's/-o\s*\(\S*\)/\1/gp'| sed 's/,/ /g'
3203 # skip test if MOUNT_OPTIONS contains the given strings
3204 _exclude_scratch_mount_option()
3206 local mnt_opts=$(_normalize_mount_options)
3208 while [ $# -gt 0 ]; do
3209 if echo $mnt_opts | grep -qw "$1"; then
3210 _notrun "mount option \"$1\" not allowed in this test"
3218 _exclude_scratch_mount_option "noatime"
3219 if [ "$FSTYP" == "nfs" ]; then
3220 _notrun "atime related mount options have no effect on NFS"
3226 _scratch_mkfs > /dev/null 2>&1
3227 _scratch_mount -o relatime || \
3228 _notrun "relatime not supported by the current kernel"
3234 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
3235 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
3238 _create_loop_device()
3241 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
3245 _destroy_loop_device()
3248 losetup -d $dev || _fail "Cannot destroy loop device $dev"
3251 _scale_fsstress_args()
3254 while [ $# -gt 0 ]; do
3256 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
3257 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
3258 *) args="$args $1" ;;
3266 # Return the logical block size if running on a block device,
3267 # else substitute the page size.
3269 _min_dio_alignment()
3273 if [ -b "$dev" ]; then
3274 blockdev --getss $dev
3276 $here/src/feature -s
3282 echo "# $@" >> $seqres.full 2>&1
3283 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
3286 _run_btrfs_util_prog()
3288 run_check $BTRFS_UTIL_PROG $*
3291 _require_btrfs_send_stream_version()
3293 $BTRFS_UTIL_PROG send 2>&1 | \
3294 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
3295 if [ $? -ne 0 ]; then
3296 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
3299 # test if btrfs kernel supports send stream version 2
3300 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
3301 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
3305 _require_btrfs_mkfs_feature()
3308 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
3312 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
3313 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
3315 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
3318 _require_btrfs_fs_feature()
3321 echo "Missing feature name argument for _require_btrfs_fs_feature"
3325 modprobe btrfs > /dev/null 2>&1
3326 [ -e /sys/fs/btrfs/features/$feat ] || \
3327 _notrun "Feature $feat not supported by the available btrfs version"
3330 _require_test_symlinks()
3332 # IRIX UDF does not support symlinks
3333 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
3334 _notrun "Require symlinks support"
3335 target=`mktemp -p $TEST_DIR`
3336 link=`mktemp -p $TEST_DIR -u`
3337 ln -s `basename $target` $link
3338 if [ "$?" -ne 0 ]; then
3340 _notrun "Require symlinks support"
3345 _require_test_fcntl_advisory_locks()
3347 [ "$FSTYP" != "cifs" ] && return 0
3348 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
3349 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
3350 _notrun "Require fcntl advisory locks support"
3353 # XFS ability to change UUIDs on V5/CRC filesystems
3355 _require_meta_uuid()
3357 # This will create a crc fs on $SCRATCH_DEV
3360 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
3361 | grep -q "invalid UUID\|supported on V5 fs" \
3362 && _notrun "Userspace doesn't support meta_uuid feature"
3364 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
3366 _scratch_mount >/dev/null 2>&1 \
3367 || _notrun "Kernel doesn't support meta_uuid feature"
3371 _require_btrfs_dev_del_by_devid()
3373 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
3374 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
3375 "(must support 'btrfs device delete <devid> /<mnt>')"
3378 _require_test_lsattr()
3380 testio=$(lsattr -d $TEST_DIR 2>&1)
3381 echo $testio | grep -q "Operation not supported" && \
3382 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3383 echo $testio | grep -q "Inappropriate ioctl for device" && \
3384 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3387 _require_xfs_test_rmapbt()
3391 if [ "$(xfs_info "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
3392 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
3396 _require_xfs_scratch_rmapbt()
3400 _scratch_mkfs > /dev/null
3402 if [ "$(xfs_info "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
3404 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
3425 "$XFS_IO_PROG" -c "bmap -${param}lpv" "$file" | grep -c "$@"
3432 touch $TEST_DIR/syscalltest
3433 chattr "+$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3435 chattr "-$attribute" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
3436 if [ "$status" -ne 0 ]; then
3437 _notrun "file system doesn't support chattr +$attribute"
3439 cat $TEST_DIR/syscalltest.out >> $seqres.full
3441 rm -f $TEST_DIR/syscalltest.out
3446 if [ -z "$1" ]; then
3447 echo "Usage: _get_total_inode <mnt>"
3451 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3457 if [ -z "$1" ]; then
3458 echo "Usage: _get_used_inode <mnt>"
3462 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3466 _get_used_inode_percent()
3468 if [ -z "$1" ]; then
3469 echo "Usage: _get_used_inode_percent <mnt>"
3473 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3480 if [ -z "$1" ]; then
3481 echo "Usage: _get_free_inode <mnt>"
3485 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3489 # get the available space in bytes
3491 _get_available_space()
3493 if [ -z "$1" ]; then
3494 echo "Usage: _get_available_space <mnt>"
3498 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3499 echo $((avail_kb * 1024))
3502 # get btrfs profile configs being tested
3504 # A set of pre-set profile configs are exported via _btrfs_profile_configs
3505 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
3506 # var in the format "metadata_profile:data_profile", multiple configs can be
3507 # seperated by space, e.g.
3508 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
3509 _btrfs_get_profile_configs()
3511 if [ "$FSTYP" != "btrfs" ]; then
3515 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3516 # Default configurations to test.
3528 # User-provided configurations.
3529 local configs=(${BTRFS_PROFILE_CONFIGS[@]})
3532 _btrfs_profile_configs=()
3533 for cfg in "${configs[@]}"; do
3534 local supported=true
3535 local profiles=(${cfg/:/ })
3536 if [ "$1" == "replace" ]; then
3537 # We can't do replace with these profiles because they
3538 # imply only one device ($SCRATCH_DEV), and we need to
3539 # keep $SCRATCH_DEV around for _scratch_mount
3540 # and _check_scratch_fs.
3544 elif [ "$1" == "replace-missing" ]; then
3545 # We can't replace missing devices with these profiles
3546 # because there isn't enough redundancy.
3553 local unsupported=()
3555 for unsupp in "${unsupported[@]}"; do
3556 if [ "${profiles[0]}" == "$unsupp" -o "${profiles[1]}" == "$unsupp" ]; then
3557 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3558 # For the default config, just omit it.
3561 # For user-provided config, don't run the test.
3562 _notrun "Profile $unsupp not supported for $1"
3566 if "$supported"; then
3567 _btrfs_profile_configs+=("-m ${profiles[0]} -d ${profiles[1]}")
3570 export _btrfs_profile_configs
3573 # stress btrfs by running balance operation in a loop
3574 _btrfs_stress_balance()
3578 $BTRFS_UTIL_PROG balance start $options
3582 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
3583 _btrfs_stress_subvolume()
3587 local subvol_name=$3
3591 mkdir -p $subvol_mnt
3592 while [ ! -e $stop_file ]; do
3593 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
3594 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
3595 $UMOUNT_PROG $subvol_mnt
3596 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
3600 # stress btrfs by running scrub in a loop
3601 _btrfs_stress_scrub()
3605 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
3609 # stress btrfs by defragmenting every file/dir in a loop and compress file
3610 # contents while defragmenting if second argument is not "nocompress"
3611 _btrfs_stress_defrag()
3617 if [ "$compress" == "nocompress" ]; then
3618 find $btrfs_mnt \( -type f -o -type d \) -exec \
3619 $BTRFS_UTIL_PROG filesystem defrag {} \;
3621 find $btrfs_mnt \( -type f -o -type d \) -exec \
3622 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
3623 find $btrfs_mnt \( -type f -o -type d \) -exec \
3624 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
3629 # stress btrfs by remounting it with different compression algorithms in a loop
3630 # run this with fsstress running at background could exercise the compression
3631 # code path and ensure no race when switching compression algorithm with constant
3633 _btrfs_stress_remount_compress()
3637 for algo in no zlib lzo; do
3638 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
3643 # stress btrfs by replacing devices in a loop
3644 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
3645 # device should be free(not used by btrfs)
3646 _btrfs_stress_replace()
3650 # The device number in SCRATCH_DEV_POOL should be at least 3,
3651 # one is SCRATCH_DEV, one is to be replaced, one is free device
3652 # we won't replace SCRATCH_DEV, see below for reason
3653 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
3654 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
3658 # take the last device as the first free_dev
3659 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
3661 # free_dev should be really free
3662 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
3663 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3667 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3668 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3669 # _scratch_mount and _check_scratch_fs etc.
3670 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3671 -e "s# *$free_dev *##"`
3673 # set the first device in dev_pool as the first src_dev to be replaced
3674 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3676 echo "dev_pool=$dev_pool"
3677 echo "free_dev=$free_dev, src_dev=$src_dev"
3679 echo "Replacing $src_dev with $free_dev"
3680 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3681 if [ $? -ne 0 ]; then
3682 # don't update src_dev and free_dev if replace failed
3685 dev_pool="$dev_pool $free_dev"
3686 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3688 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3692 # find the right option to force output in bytes, older versions of btrfs-progs
3693 # print that by default, newer print human readable numbers with unit suffix
3694 _btrfs_qgroup_units()
3696 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3699 # return device size in kb
3702 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3705 # check dmesg log for WARNING/Oops/etc.
3708 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3711 rm -f ${RESULT_DIR}/check_dmesg
3713 # default filter is a simple cat command, caller could provide a
3714 # customized filter and pass the name through the first argument, to
3715 # filter out intentional WARNINGs or Oopses
3718 # search the dmesg log of last run of $seqnum for possible failures
3719 # use sed \cregexpc address type, since $seqnum contains "/"
3720 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3721 tac | $filter >$seqres.dmesg
3722 grep -q -e "kernel BUG at" \
3726 -e "possible recursive locking detected" \
3727 -e "Internal error" \
3728 -e "INFO: suspicious RCU usage" \
3729 -e "INFO: possible circular locking dependency detected" \
3730 -e "general protection fault:" \
3732 if [ $? -eq 0 ]; then
3733 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3741 # don't check dmesg log after test
3742 _disable_dmesg_check()
3744 rm -f ${RESULT_DIR}/check_dmesg
3749 if [ "$iam" == new ]
3753 # make some further configuration checks here
3754 if [ "$TEST_DEV" = "" ]
3756 echo "common/rc: Error: \$TEST_DEV is not set"
3760 # if $TEST_DEV is not mounted, mount it now as XFS
3761 if [ -z "`_fs_type $TEST_DEV`" ]
3763 # $TEST_DEV is not mounted
3766 echo "common/rc: retrying test device mount with external set"
3767 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3770 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3776 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3778 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3779 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
3780 _df_device $TEST_DEV
3783 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3784 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3785 export XFS_IO_PROG="$XFS_IO_PROG -F"
3787 # xfs_copy doesn't work on v5 xfs yet without -d option
3788 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3789 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3793 # get real device path name by following link
3797 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3798 _dev=`readlink -f "$_dev"`
3803 # basename of a device
3806 echo `basename $(_real_dev $1)`
3812 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3813 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3814 _maj=$(echo "ibase=16; $_maj" | bc)
3815 _min=$(echo "ibase=16; $_min" | bc)
3816 echo /sys/dev/block/$_maj:$_min
3821 if [ -z $1 ] || [ ! -d $1 ]; then
3822 echo "Missing mount point argument for get_block_size"
3825 echo `stat -f -c %S $1`
3830 echo $(getconf PAGE_SIZE)
3837 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3838 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3839 echo "$@" >>$seqres.full
3840 rm -f $TEST_DIR/junk
3841 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3842 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3848 # Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
3850 # Only one argument is needed:
3851 # - attr: path name under /sys/fs/$FSTYP/DEV
3854 # _require_fs_sysfs error/fail_at_unmount
3858 local dname=$(_short_dev $TEST_DEV)
3860 if [ -z "$attr" -o -z "$dname" ];then
3861 _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
3864 if [ ! -e /sys/fs/${FSTYP}/${dname}/${attr} ];then
3865 _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
3869 # Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
3871 # All arguments are necessary, and in this order:
3872 # - dev: device name, e.g. $SCRATCH_DEV
3873 # - attr: path name under /sys/fs/$FSTYP/$dev
3874 # - content: the content of $attr
3877 # _set_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount 0
3878 _set_fs_sysfs_attr()
3886 if [ ! -b "$dev" -o -z "$attr" -o -z "$content" ];then
3887 _fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
3890 local dname=$(_short_dev $dev)
3891 echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
3894 # Print the content of /sys/fs/$FSTYP/$DEV/$ATTR
3896 # All arguments are necessary, and in this order:
3897 # - dev: device name, e.g. $SCRATCH_DEV
3898 # - attr: path name under /sys/fs/$FSTYP/$dev
3901 # _get_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
3902 _get_fs_sysfs_attr()
3907 if [ ! -b "$dev" -o -z "$attr" ];then
3908 _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
3911 local dname=$(_short_dev $dev)
3912 cat /sys/fs/${FSTYP}/${dname}/${attr}
3916 # Reset all xfs error handling attributes, set them to original
3919 # Only one argument, and it's mandatory:
3920 # - dev: device name, e.g. $SCRATCH_DEV
3922 # Note: this function only works for XFS
3923 _reset_xfs_sysfs_error_handling()
3927 if [ ! -b "$dev" -o "$FSTYP" != "xfs" ];then
3928 _fail "Usage: reset_xfs_sysfs_error_handling <device>"
3931 _set_fs_sysfs_attr $dev error/fail_at_unmount 1
3932 echo -n "error/fail_at_unmount="
3933 _get_fs_sysfs_attr $dev error/fail_at_unmount
3935 # Make sure all will be configured to retry forever by default, except
3936 # for ENODEV, which is an unrecoverable error, so it will be configured
3937 # to not retry on error by default.
3938 for e in default EIO ENOSPC; do
3939 _set_fs_sysfs_attr $dev \
3940 error/metadata/${e}/max_retries -1
3941 echo -n "error/metadata/${e}/max_retries="
3942 _get_fs_sysfs_attr $dev error/metadata/${e}/max_retries
3944 _set_fs_sysfs_attr $dev \
3945 error/metadata/${e}/retry_timeout_seconds 0
3946 echo -n "error/metadata/${e}/retry_timeout_seconds="
3947 _get_fs_sysfs_attr $dev \
3948 error/metadata/${e}/retry_timeout_seconds
3952 # Skip if we are running an older binary without the stricter input checks.
3953 # Make multiple checks to be sure that there is no regression on the one
3954 # selected feature check, which would skew the result.
3956 # At first, make a common function that runs the tests and returns
3957 # number of failed cases.
3958 _xfs_mkfs_validation_check()
3960 local tmpfile=`mktemp`
3961 local cmd="$MKFS_XFS_PROG -f -N -d file,name=$tmpfile,size=1g"
3963 $cmd -s size=2s >/dev/null 2>&1
3966 $cmd -l version=2,su=260k >/dev/null 2>&1
3967 sum=`expr $sum + $?`
3973 # Skip the test if all calls passed - mkfs accepts invalid input
3974 _require_xfs_mkfs_validation()
3976 _xfs_mkfs_validation_check
3977 if [ "$?" -eq 0 ]; then
3978 _notrun "Requires newer mkfs with stricter input checks: the oldest supported version of xfsprogs is 4.7."
3982 # The oposite of _require_xfs_mkfs_validation.
3983 _require_xfs_mkfs_without_validation()
3985 _xfs_mkfs_validation_check
3986 if [ "$?" -ne 0 ]; then
3987 _notrun "Requires older mkfs without strict input checks: the last supported version of xfsprogs is 4.5."
3993 ################################################################################
3994 # make sure this script returns success