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
276 mkdir -p $dir/$OVERLAY_UPPER_DIR
277 mkdir -p $dir/$OVERLAY_LOWER_DIR
278 mkdir -p $dir/$OVERLAY_WORK_DIR
280 $MOUNT_PROG -t overlay $SELINUX_MOUNT_OPTIONS \
281 -o lowerdir=$dir/$OVERLAY_LOWER_DIR \
282 -o upperdir=$dir/$OVERLAY_UPPER_DIR \
283 -o workdir=$dir/$OVERLAY_WORK_DIR \
284 $OVERLAY_MOUNT_OPTIONS $* \
288 _overlay_test_mount()
290 _overlay_mount $TEST_DEV $TEST_DIR $*
293 _overlay_scratch_mount()
295 _overlay_mount $SCRATCH_DEV $SCRATCH_MNT $*
298 _overlay_test_unmount()
300 $UMOUNT_PROG $TEST_DIR
303 _overlay_scratch_unmount()
305 $UMOUNT_PROG $SCRATCH_MNT
310 if [ "$FSTYP" == "overlay" ]; then
311 _overlay_scratch_mount $*
314 _mount -t $FSTYP `_scratch_mount_options $*`
321 _overlay_scratch_unmount
324 $UMOUNT_PROG $SCRATCH_MNT
327 $UMOUNT_PROG $SCRATCH_DEV
340 if [ "$FSTYP" == "overlay" ]; then
341 _overlay_test_mount $*
345 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
350 if [ "$FSTYP" == "overlay" ]; then
351 _overlay_test_unmount
353 $UMOUNT_PROG $TEST_DEV
363 _scratch_mkfs_options()
365 _scratch_options mkfs
366 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
374 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
375 options="-l $SCRATCH_LOGDEV"
377 xfs_metadump $options $SCRATCH_DEV $dumpfile
380 _setup_large_xfs_fs()
385 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
386 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
387 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
389 # calculate the size of the file we need to allocate.
390 # Default free space in the FS is 50GB, but you can specify more via
391 # SCRATCH_DEV_EMPTY_SPACE
392 file_size=$(($fs_size - 50*1024*1024*1024))
393 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
395 # mount the filesystem, create the file, unmount it
396 _scratch_mount 2>&1 >$tmp_dir/mnt.err
398 if [ $status -ne 0 ]; then
400 cat $tmp_dir/mnt.err >&2
401 rm -f $tmp_dir/mnt.err
404 rm -f $tmp_dir/mnt.err
407 -c "truncate $file_size" \
408 -c "falloc -k 0 $file_size" \
410 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
411 export NUM_SPACE_FILES=1
414 if [ $status -ne 0 ]; then
415 echo "large file prealloc failed"
416 cat $tmp_dir/mnt.err >&2
422 _scratch_mkfs_xfs_opts()
426 # remove crc related mkfs options if mkfs.xfs doesn't support v5 xfs
427 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
428 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+crc=.//"`
431 _scratch_options mkfs
433 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
437 _scratch_mkfs_xfs_supported()
441 _scratch_options mkfs
443 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
448 # extra mkfs options can be added by tests
449 local extra_mkfs_options=$*
453 # save mkfs output in case conflict means we need to run again.
454 # only the output for the mkfs that applies should be shown
455 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
456 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
460 # a mkfs failure may be caused by conflicts between
461 # $MKFS_OPTIONS and $extra_mkfs_options
462 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
464 echo -n "** mkfs failed with extra mkfs options "
465 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
466 echo -n "** attempting to mkfs using only test $seq "
467 echo "options: $extra_mkfs_options **"
470 # running mkfs again. overwrite previous mkfs output files
471 _scratch_mkfs_xfs_opts $extra_mkfs_options \
472 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
476 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
477 # manually parse the mkfs output to get the fs size in bytes
479 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
480 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
482 print STDOUT "$size\n";
484 _setup_large_xfs_fs $fs_size
488 # output stored mkfs output, filtering unnecessary warnings from stderr
490 cat $tmp_dir.mkfserr | sed \
491 -e '/less than device physical sector/d' \
492 -e '/switching to logical sector/d' \
494 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
499 # xfs_check script is planned to be deprecated. But, we want to
500 # be able to invoke "xfs_check" behavior in xfstests in order to
501 # maintain the current verification levels.
506 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
508 while getopts "b:fi:l:stvV" c
514 i) OPTS=$OPTS"-i "$OPTARG" ";;
515 b) OPTS=$OPTS"-b "$OPTARG" ";;
516 f) DBOPTS=$DBOPTS" -f";;
517 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
518 V) $XFS_DB_PROG -p xfs_check -V
526 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
536 _setup_large_ext4_fs()
541 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
542 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
543 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
545 # Default free space in the FS is 50GB, but you can specify more via
546 # SCRATCH_DEV_EMPTY_SPACE
547 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
549 # mount the filesystem and create 16TB - 4KB files until we consume
550 # all the necessary space.
551 _scratch_mount 2>&1 >$tmp_dir/mnt.err
553 if [ $status -ne 0 ]; then
555 cat $tmp_dir/mnt.err >&2
556 rm -f $tmp_dir/mnt.err
559 rm -f $tmp_dir/mnt.err
561 file_size=$((16*1024*1024*1024*1024 - 4096))
563 while [ $space_to_consume -gt $file_size ]; do
566 -c "truncate $file_size" \
567 -c "falloc -k 0 $file_size" \
568 $SCRATCH_MNT/.use_space.$nfiles 2>&1
570 if [ $status -ne 0 ]; then
574 space_to_consume=$(( $space_to_consume - $file_size ))
575 nfiles=$(($nfiles + 1))
578 # consume the remaining space.
579 if [ $space_to_consume -gt 0 ]; then
581 -c "truncate $space_to_consume" \
582 -c "falloc -k 0 $space_to_consume" \
583 $SCRATCH_MNT/.use_space.$nfiles 2>&1
586 export NUM_SPACE_FILES=$nfiles
589 if [ $status -ne 0 ]; then
590 echo "large file prealloc failed"
591 cat $tmp_dir/mnt.err >&2
599 # extra mkfs options can be added by tests
600 local extra_mkfs_options=$*
604 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
605 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
608 # a mkfs failure may be caused by conflicts between
609 # $MKFS_OPTIONS and $extra_mkfs_options
610 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
612 echo -n "** mkfs failed with extra mkfs options "
613 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
614 echo -n "** attempting to mkfs using only test $seq "
615 echo "options: $extra_mkfs_options **"
618 # running mkfs again. overwrite previous mkfs output files
619 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
620 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
624 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
625 # manually parse the mkfs output to get the fs size in bytes
626 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
627 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
628 / inodes, / { blks = $3 } \
629 /reserved for the super user/ { resv = $1 } \
630 END { fssize = bs * blks - resv; print fssize }'`
632 _setup_large_ext4_fs $fs_size
636 # output stored mkfs output
637 cat $tmp_dir.mkfserr >&2
639 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
651 # do nothing for cifs
654 # do nothing for overlay
657 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
660 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
663 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
666 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
678 # do nothing for overlay
681 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
684 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
687 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
688 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
692 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
693 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
697 if [ $? -ne 0 ]; then
698 # output stored mkfs output
699 cat $tmp_dir.mkfserr >&2
704 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
707 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
708 _scratch_cleanup_files()
712 # $SCRATCH_DEV is a valid directory in overlay case
713 rm -rf $SCRATCH_DEV/*
717 rm -rf $SCRATCH_MNT/*
730 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
731 # avoid EEXIST caused by the leftover files created in previous runs
732 _scratch_cleanup_files
735 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
736 # avoid EEXIST caused by the leftover files created in previous runs
737 _scratch_cleanup_files
740 # unable to re-create overlay, remove all files in $SCRATCH_MNT to
741 # avoid EEXIST caused by the leftover files created in previous runs
742 _scratch_cleanup_files
745 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
748 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
751 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
754 _scratch_mkfs_ext4 $*
757 # do nothing for tmpfs
760 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
763 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
772 # if dup profile is in mkfs options call _scratch_mkfs instead
773 # because dup profile only works with single device
774 if [[ "$*" =~ dup ]]; then
777 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
781 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
786 # Create fs of certain size on scratch device
787 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
788 _scratch_mkfs_sized()
795 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
797 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
798 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
802 [ -n "$def_blksz" ] && blocksize=$def_blksz
803 [ -z "$blocksize" ] && blocksize=4096
807 if ! [[ $fssize =~ $re ]] ; then
808 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
810 if ! [[ $blocksize =~ $re ]] ; then
811 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
814 blocks=`expr $fssize / $blocksize`
816 if [ "$HOSTOS" == "Linux" ]; then
817 devsize=`blockdev --getsize64 $SCRATCH_DEV`
818 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
823 # don't override MKFS_OPTIONS that set a block size.
824 echo $MKFS_OPTIONS |egrep -q "b?size="
825 if [ $? -eq 0 ]; then
826 _scratch_mkfs_xfs -d size=$fssize
828 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
831 ext2|ext3|ext4|ext4dev)
832 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
835 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
839 (( fssize <= 100 * 1024 * 1024 )) && mixed_opt='--mixed'
840 $MKFS_BTRFS_PROG $MKFS_OPTIONS $mixed_opt -b $fssize $SCRATCH_DEV
843 # mkfs.resier4 requires size in KB as input for creating filesystem
844 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
845 `expr $fssize / 1024`
848 # mkfs.f2fs requires # of sectors as an input for the size
849 sector_size=`blockdev --getss $SCRATCH_DEV`
850 $MKFS_F2FS_PROG $MKFS_OPTIONS $SCRATCH_DEV `expr $fssize / $sector_size`
853 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
858 # Emulate an N-data-disk stripe w/ various stripe units
859 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
865 [ -z "$blocksize" ] && blocksize=4096
867 let sunit_blocks=$sunit_bytes/$blocksize
868 let swidth_blocks=$sunit_blocks*$swidth_mult
872 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
875 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
878 _notrun "can't mkfs $FSTYP with geometry"
884 # Create fs of certain blocksize on scratch device
885 # _scratch_mkfs_blocksized blocksize
886 _scratch_mkfs_blocksized()
891 if ! [[ $blocksize =~ $re ]] ; then
892 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
897 _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
899 ext2|ext3|ext4|ocfs2)
900 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
903 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_blocksized"
912 xfs_io -x -c "resblks $1" $SCRATCH_MNT
919 _scratch_xfs_db_options()
922 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
923 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
924 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
927 _scratch_xfs_logprint()
930 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
931 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
932 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
938 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
939 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
940 [ "$LARGE_SCRATCH_DEV" = yes ] && \
941 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
942 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
945 _scratch_xfs_repair()
948 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
949 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
950 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
951 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
952 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
953 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
960 echo "Usage: _get_pids_by_name process-name" 1>&2
964 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
965 # HH:MM:SS before the psargs field, use this as the search anchor.
967 # Matches with $1 (process-name) occur if the first psarg is $1
968 # or ends in /$1 ... the matching uses sed's regular expressions,
969 # so passing a regex into $1 will work.
977 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
978 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
981 # fix malloc libs output
985 # filter out the Electric Fence notice
988 if (defined $o && /^\s+Electric Fence/) {
994 print $o if (defined $o);
998 print $o if (defined $o);
1002 # check if run as root
1006 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
1009 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
1016 # _df_device : get an IRIX style df line for a given device
1018 # - returns "" if not mounted
1019 # - returns fs type in field two (ala IRIX)
1020 # - joins line together if split by fancy df formatting
1021 # - strips header etc
1028 echo "Usage: _df_device device" 1>&2
1032 # Note that we use "==" here so awk doesn't try to interpret an NFS over
1033 # IPv6 server as a regular expression.
1034 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
1035 ($1==what) && (NF==1) {
1049 # _df_dir : get an IRIX style df line for device where a directory resides
1051 # - returns fs type in field two (ala IRIX)
1052 # - joins line together if split by fancy df formatting
1053 # - strips header etc
1060 echo "Usage: _df_dir device" 1>&2
1064 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
1080 # return percentage used disk space for mounted device
1086 echo "Usage: _used device" 1>&2
1090 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
1093 # return the FS type of a mounted device
1099 echo "Usage: _fs_type device" 1>&2
1104 # The Linux kernel shows NFSv4 filesystems in df output as
1105 # filesystem type nfs4, although we mounted it as nfs earlier.
1106 # Fix the filesystem type up here so that the callers don't
1107 # have to bother with this quirk.
1109 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
1112 # return the FS mount options of a mounted device
1114 # should write a version which just parses the output of mount for IRIX
1115 # compatibility, but since this isn't used at all, at the moment I'll leave
1122 echo "Usage: _fs_options device" 1>&2
1126 $AWK_PROG -v dev=$1 '
1127 match($1,dev) { print $4 }
1131 # returns device number if a file is a block device
1137 echo "Usage: _is_block_dev dev" 1>&2
1142 if [ -L "${_dev}" ]; then
1143 _dev=`readlink -f "${_dev}"`
1146 if [ -b "${_dev}" ]; then
1147 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1151 # Do a command, log it to $seqres.full, optionally test return status
1152 # and die if command fails. If called with one argument _do executes the
1153 # command, logs it, and returns its exit status. With two arguments _do
1154 # first prints the message passed in the first argument, and then "done"
1155 # or "fail" depending on the return status of the command passed in the
1156 # second argument. If the command fails and the variable _do_die_on_error
1157 # is set to "always" or the two argument form is used and _do_die_on_error
1158 # is set to "message_only" _do will print an error message to
1159 # $seqres.out and exit.
1163 if [ $# -eq 1 ]; then
1165 elif [ $# -eq 2 ]; then
1168 echo -n "$_note... "
1170 echo "Usage: _do [note] cmd" 1>&2
1174 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1175 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1176 cat $tmp._out | _fix_malloc >>$seqres.full
1177 if [ $# -eq 2 ]; then
1178 if [ $ret -eq 0 ]; then
1185 && [ "$_do_die_on_error" = "always" \
1186 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1188 [ $# -ne 2 ] && echo
1189 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1196 # bail out, setting up .notrun file. Need to kill the filesystem check files
1197 # here, otherwise they are set incorrectly for the next test.
1201 echo "$*" > $seqres.notrun
1202 echo "$seq not run: $*"
1203 rm -f ${RESULT_DIR}/require_test
1204 rm -f ${RESULT_DIR}/require_scratch
1209 # just plain bail out
1213 echo "$*" | tee -a $seqres.full
1214 echo "(see $seqres.full for details)"
1219 # tests whether $FSTYP is one of the supported filesystems for a test
1225 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1231 _notrun "not suitable for this filesystem type: $FSTYP"
1235 # tests whether $FSTYP is one of the supported OSes for a test
1241 if [ "$h" = "$HOSTOS" ]
1247 _notrun "not suitable for this OS: $HOSTOS"
1250 # this test needs a scratch partition - check we're ok & unmount it
1251 # No post-test check of the device is required. e.g. the test intentionally
1252 # finishes the test with the filesystem in a corrupt state
1253 _require_scratch_nocheck()
1257 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1258 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1259 _notrun "this test requires a valid \$SCRATCH_DEV"
1261 if [ ! -d "$SCRATCH_MNT" ]; then
1262 _notrun "this test requires a valid \$SCRATCH_MNT"
1266 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1267 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1268 _notrun "this test requires a valid \$SCRATCH_DEV"
1270 if [ ! -d "$SCRATCH_MNT" ]; then
1271 _notrun "this test requires a valid \$SCRATCH_MNT"
1275 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_DEV" ]; then
1276 _notrun "this test requires a valid \$SCRATCH_DEV as ovl base dir"
1278 if [ ! -d "$SCRATCH_MNT" ]; then
1279 _notrun "this test requires a valid \$SCRATCH_MNT"
1283 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1285 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1289 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1291 _notrun "this test requires a valid \$SCRATCH_DEV"
1293 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1295 _notrun "this test requires a valid \$SCRATCH_DEV"
1297 if [ ! -d "$SCRATCH_MNT" ]
1299 _notrun "this test requires a valid \$SCRATCH_MNT"
1305 # Note that we use -F here so grep doesn't try to interpret an NFS over
1306 # IPv6 server as a regular expression.
1307 mount_rec=`_mount | grep -F $SCRATCH_DEV`
1310 # if it's mounted, make sure its on $SCRATCH_MNT
1311 if ! echo $mount_rec | grep -q $SCRATCH_MNT
1313 echo "\$SCRATCH_DEV=$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT=$SCRATCH_MNT - aborting"
1314 echo "Already mounted result:"
1318 # and then unmount it
1319 if ! _scratch_unmount
1321 echo "failed to unmount $SCRATCH_DEV"
1325 rm -f ${RESULT_DIR}/require_scratch
1328 # we need the scratch device and it should be checked post test.
1331 _require_scratch_nocheck
1332 touch ${RESULT_DIR}/require_scratch
1336 # this test needs a test partition - check we're ok & mount it
1342 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1343 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1344 _notrun "this test requires a valid \$TEST_DIR"
1346 if [ ! -d "$TEST_DIR" ]; then
1347 _notrun "this test requires a valid \$TEST_DIR"
1351 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1352 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1353 _notrun "this test requires a valid \$TEST_DEV"
1355 if [ ! -d "$TEST_DIR" ]; then
1356 _notrun "this test requires a valid \$TEST_DIR"
1360 if [ -z "$TEST_DEV" -o ! -d "$TEST_DEV" ]; then
1361 _notrun "this test requires a valid \$TEST_DEV as ovl base dir"
1363 if [ ! -d "$TEST_DIR" ]; then
1364 _notrun "this test requires a valid \$TEST_DIR"
1368 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1370 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1374 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1376 _notrun "this test requires a valid \$TEST_DEV"
1378 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1380 _notrun "this test requires a valid \$TEST_DEV"
1382 if [ ! -d "$TEST_DIR" ]
1384 _notrun "this test requires a valid \$TEST_DIR"
1390 # Note that we use -F here so grep doesn't try to interpret an NFS over
1391 # IPv6 server as a regular expression.
1392 mount_rec=`_mount | grep -F $TEST_DEV`
1395 # if it's mounted, make sure its on $TEST_DIR
1396 if ! echo $mount_rec | grep -q $TEST_DIR
1398 echo "\$TEST_DEV=$TEST_DEV is mounted but not on \$TEST_DIR=$TEST_DIR - aborting"
1399 echo "Already mounted result:"
1404 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1405 if [ $? -ne 1 ]; then
1410 touch ${RESULT_DIR}/require_test
1413 # this test needs a logdev
1417 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1418 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1419 [ "$USE_EXTERNAL" != yes ] && \
1420 _notrun "This test requires USE_EXTERNAL to be enabled"
1422 # ensure its not mounted
1423 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1426 # this test requires loopback device support
1430 if [ "$HOSTOS" != "Linux" ]
1432 _notrun "This test requires linux for loopback device support"
1435 modprobe loop >/dev/null 2>&1
1436 if grep loop /proc/devices >/dev/null 2>&1
1440 _notrun "This test requires loopback device support"
1444 # this test requires ext2 filesystem support
1448 if [ "$HOSTOS" != "Linux" ]
1450 _notrun "This test requires linux for ext2 filesystem support"
1453 modprobe ext2 >/dev/null 2>&1
1454 if grep ext2 /proc/filesystems >/dev/null 2>&1
1458 _notrun "This test requires ext2 filesystem support"
1462 # this test requires that (large) loopback device files are not in use
1464 _require_no_large_scratch_dev()
1466 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1467 _notrun "Large filesystem testing in progress, skipped this test"
1470 # this test requires that a realtime subvolume is in use, and
1471 # that the kernel supports realtime as well.
1475 [ "$USE_EXTERNAL" = yes ] || \
1476 _notrun "External volumes not in use, skipped this test"
1477 [ "$SCRATCH_RTDEV" = "" ] && \
1478 _notrun "Realtime device required, skipped this test"
1481 # this test requires that a specified command (executable) exists
1482 # $1 - command, $2 - name for error message
1484 # Note: the command string might have parameters, so strip them before checking
1485 # whether it is executable.
1488 if [ $# -eq 2 ]; then
1490 elif [ $# -eq 1 ]; then
1493 _fail "usage: _require_command <command> [<name>]"
1496 _command=`echo "$1" | awk '{ print $1 }'`
1497 if [ ! -x "$_command" ]; then
1498 _notrun "$_name utility required, skipped this test"
1502 # this test requires the device to be valid block device
1504 _require_block_device()
1506 if [ -z "$1" ]; then
1507 echo "Usage: _require_block_device <dev>" 1>&2
1510 if [ "`_is_block_dev "$1"`" == "" ]; then
1511 _notrun "require $1 to be valid block disk"
1515 # brd based ram disks erase the device when they receive a flush command when no
1516 # active references are present. This causes problems for DM devices sitting on
1517 # top of brd devices as DM doesn't hold active references to the brd device.
1518 _require_sane_bdev_flush()
1520 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1521 if [ $? -eq 0 ]; then
1522 _notrun "This test requires a sane block device flush"
1526 # this test requires a specific device mapper target
1527 _require_dm_target()
1531 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1533 _require_block_device $SCRATCH_DEV
1534 _require_sane_bdev_flush $SCRATCH_DEV
1535 _require_command "$DMSETUP_PROG" dmsetup
1537 modprobe dm-$_target >/dev/null 2>&1
1539 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1540 if [ $? -ne 0 ]; then
1541 _notrun "This test requires dm $_target support"
1545 # this test requires the projid32bit feature to be available in mkfs.xfs.
1547 _require_projid32bit()
1549 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1550 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1553 _require_projid16bit()
1555 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1556 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1559 # this test requires the crc feature to be available in mkfs.xfs
1561 _require_xfs_mkfs_crc()
1563 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1564 || _notrun "mkfs.xfs doesn't have crc feature"
1567 # this test requires the xfs kernel support crc feature
1571 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1572 _scratch_mount >/dev/null 2>&1 \
1573 || _notrun "Kernel doesn't support crc feature"
1577 # this test requires the ext4 kernel support crc feature on scratch device
1579 _require_scratch_ext4_crc()
1581 _scratch_mkfs_ext4 >/dev/null 2>&1
1582 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1583 _scratch_mount >/dev/null 2>&1 \
1584 || _notrun "Kernel doesn't support metadata_csum feature"
1588 # this test requires the xfs kernel support crc feature on scratch device
1590 _require_scratch_xfs_crc()
1592 _scratch_mkfs_xfs >/dev/null 2>&1
1593 _scratch_mount >/dev/null 2>&1 \
1594 || _notrun "Kernel doesn't support crc feature"
1595 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1599 # this test requires the bigalloc feature to be available in mkfs.ext4
1601 _require_ext4_mkfs_bigalloc()
1603 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1604 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1607 # this test requires the ext4 kernel support bigalloc feature
1609 _require_ext4_bigalloc()
1611 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1612 _scratch_mount >/dev/null 2>&1 \
1613 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1617 # this test requires the finobt feature to be available in mkfs.xfs
1619 _require_xfs_mkfs_finobt()
1621 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1622 || _notrun "mkfs.xfs doesn't have finobt feature"
1625 # this test requires the xfs kernel support finobt feature
1627 _require_xfs_finobt()
1629 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1630 _scratch_mount >/dev/null 2>&1 \
1631 || _notrun "Kernel doesn't support finobt feature"
1635 # this test requires xfs sysfs attribute support
1637 _require_xfs_sysfs()
1640 sysfsdir=/sys/fs/xfs
1642 if [ ! -e $sysfsdir ]; then
1643 _notrun "no kernel support for XFS sysfs attributes"
1646 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1647 _notrun "sysfs attribute '$attr' is not supported"
1651 # this test requires the xfs sparse inode feature
1653 _require_xfs_sparse_inodes()
1655 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1656 || _notrun "mkfs.xfs does not support sparse inodes"
1657 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1658 _scratch_mount >/dev/null 2>&1 \
1659 || _notrun "kernel does not support sparse inodes"
1663 # this test requires that external log/realtime devices are not in use
1665 _require_nonexternal()
1667 [ "$USE_EXTERNAL" = yes ] && \
1668 _notrun "External device testing in progress, skipped this test"
1671 # this test requires that a (specified) aio-dio executable exists
1672 # $1 - command (optional)
1678 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1679 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1681 AIO_TEST=src/aio-dio-regress/$1
1682 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1687 # this test requires that a test program exists under src/
1688 # $1 - command (require)
1690 _require_test_program()
1693 [ -x $SRC_TEST ] || _notrun "$SRC_TEST not built"
1696 # run an aio-dio program
1702 echo "usage: _run_aiodio command_name" 2>&1
1708 local testtemp=$TEST_DIR/aio-testfile
1710 $AIO_TEST $testtemp 2>&1
1717 # indicate whether YP/NIS is active or not
1722 dn=$(domainname 2>/dev/null)
1723 test -n "${dn}" -a "${dn}" != "(none)"
1727 # cat the password file
1731 [ $(_yp_active) -eq 0 ] && ypcat passwd
1735 # cat the group file
1739 [ $(_yp_active) -eq 0 ] && ypcat group
1743 # check for a user on the machine, fsgqa as default
1751 _cat_passwd | grep -q $qa_user
1752 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1753 echo /bin/true | su $qa_user
1754 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1757 # check for a group on the machine, fsgqa as default
1765 _cat_group | grep -q $qa_group
1766 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1772 s,.*Permission\sdenied.*,Permission denied,;
1773 s,.*no\saccess\sto\stty.*,,;
1774 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1781 if [ "$HOSTOS" == "IRIX" ]
1783 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1785 echo $1 | su $qa_user 2>&1 | _filter_user_do
1789 _require_xfs_io_command()
1793 echo "Usage: _require_xfs_io_command command" 1>&2
1798 testfile=$TEST_DIR/$$.xfs_io
1801 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1803 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1804 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1805 -c "$command 4k 8k" $testfile 2>&1`
1808 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1809 -c "fiemap -v" $testfile 2>&1`
1812 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1814 echo $testio | egrep -q "invalid option|Is a directory" && \
1815 _notrun "xfs_io $command support is missing"
1818 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1821 rm -f $testfile 2>&1 > /dev/null
1822 echo $testio | grep -q "not found" && \
1823 _notrun "xfs_io $command support is missing"
1824 echo $testio | grep -q "Operation not supported" && \
1825 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1828 # check that xfs_db supports a specific command
1829 _require_xfs_db_command()
1833 echo "Usage: _require_xfs_db_command command" 1>&2
1838 $XFS_DB_PROG -x -c "help" $SCRATCH_DEV | grep $command > /dev/null || \
1839 _notrun "xfs_db $command support is missing"
1842 # check that kernel and filesystem support direct I/O
1845 testfile=$TEST_DIR/$$.direct
1846 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1847 if [ $? -ne 0 ]; then
1848 _notrun "O_DIRECT is not supported"
1850 rm -f $testfile 2>&1 > /dev/null
1853 # Check that a fs has enough free space (in 1024b blocks)
1858 BLOCKS=$2 # in units of 1024
1859 let GB=$BLOCKS/1024/1024
1861 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1862 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1863 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1867 # Check if the filesystem supports sparse files.
1869 # Unfortunately there is no better way to do this than a manual black list.
1871 _require_sparse_files()
1875 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1884 #boot_params always present in debugfs
1885 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1888 _require_fail_make_request()
1890 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1891 || _notrun "$DEBUGFS_MNT/fail_make_request \
1892 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1896 # Check if the file system supports seek_data/hole
1898 _require_seek_data_hole()
1900 testfile=$TEST_DIR/$$.seek
1901 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1902 rm -f $testfile &>/dev/null
1903 echo $testseek | grep -q "Kernel does not support" && \
1904 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1907 # check that a FS on a device is mounted
1908 # if so, return mount point
1914 echo "Usage: _is_mounted device" 1>&2
1920 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1921 pattern { print $3 ; exit 0 }
1925 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1930 # remount a FS to a new mode (ro or rw)
1936 echo "Usage: _remount device ro/rw" 1>&2
1942 if ! mount -o remount,$mode $device
1944 echo "_remount: failed to remount filesystem on $device as $mode"
1949 # Run the appropriate repair/check on a filesystem
1951 # if the filesystem is mounted, it's either remounted ro before being
1952 # checked or it's unmounted and then remounted
1955 # If set, we remount ro instead of unmounting for fsck
1958 _umount_or_remount_ro()
1962 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1967 mountpoint=`_is_mounted $device`
1969 if [ $USE_REMOUNT -eq 0 ]; then
1970 $UMOUNT_PROG $device
1977 _mount_or_remount_rw()
1979 if [ $# -ne 3 ]; then
1980 echo "Usage: _mount_or_remount_rw <opts> <dev> <mnt>" 1>&2
1987 if [ $USE_REMOUNT -eq 0 ]; then
1988 if [ "$FSTYP" != "overlay" ]; then
1989 _mount -t $FSTYP $mount_opts $device $mountpoint
1991 _overlay_mount $device $mountpoint
1993 if [ $? -ne 0 ]; then
1994 echo "!!! failed to remount $device on $mountpoint"
2004 # Check a generic filesystem in no-op mode; this assumes that the
2005 # underlying fsck program accepts "-n" for a no-op (check-only) run,
2006 # and that it will still return an errno for corruption in this mode.
2008 # Filesystems which don't support this will need to define their
2009 # own check routine.
2011 _check_generic_filesystem()
2015 # If type is set, we're mounted
2016 type=`_fs_type $device`
2019 if [ "$type" = "$FSTYP" ]
2022 mountpoint=`_umount_or_remount_ro $device`
2025 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
2028 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2030 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
2031 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2032 cat $tmp.fsck >>$seqres.full
2033 echo "*** end fsck.$FSTYP output" >>$seqres.full
2041 echo "*** mount output ***" >>$seqres.full
2042 _mount >>$seqres.full
2043 echo "*** end mount output" >>$seqres.full
2044 elif [ "$type" = "$FSTYP" ]
2047 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2051 if [ $ok -eq 0 ]; then
2053 if [ "$iam" != "check" ]; then
2062 # run xfs_check and friends on a FS.
2064 _check_xfs_filesystem()
2068 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
2072 extra_mount_options=""
2073 extra_log_options=""
2076 if [ -f $device ];then
2080 if [ "$2" != "none" ]; then
2081 extra_log_options="-l$2"
2082 extra_mount_options="-ologdev=$2"
2085 if [ "$3" != "none" ]; then
2086 extra_rt_options="-r$3"
2087 extra_mount_options=$extra_mount_options" -ortdev=$3"
2089 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
2091 [ "$FSTYP" != xfs ] && return 0
2093 type=`_fs_type $device`
2096 if [ "$type" = "xfs" ]
2099 mountpoint=`_umount_or_remount_ro $device`
2102 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
2103 | tee $tmp.logprint | grep -q "<CLEAN>"
2104 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
2106 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
2108 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
2109 echo "*** xfs_logprint -t output ***" >>$seqres.full
2110 cat $tmp.logprint >>$seqres.full
2111 echo "*** end xfs_logprint output" >>$seqres.full
2116 # xfs_check runs out of memory on large files, so even providing the test
2117 # option (-t) to avoid indexing the free space trees doesn't make it pass on
2118 # large filesystems. Avoid it.
2119 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
2120 _xfs_check $extra_log_options $device 2>&1 |\
2121 _fix_malloc >$tmp.fs_check
2123 if [ -s $tmp.fs_check ]
2125 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
2127 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2128 echo "*** xfs_check output ***" >>$seqres.full
2129 cat $tmp.fs_check >>$seqres.full
2130 echo "*** end xfs_check output" >>$seqres.full
2135 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
2138 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
2140 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2141 echo "*** xfs_repair -n output ***" >>$seqres.full
2142 cat $tmp.repair | _fix_malloc >>$seqres.full
2143 echo "*** end xfs_repair output" >>$seqres.full
2147 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
2151 echo "*** mount output ***" >>$seqres.full
2152 _mount >>$seqres.full
2153 echo "*** end mount output" >>$seqres.full
2154 elif [ "$type" = "xfs" ]
2156 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
2159 if [ $ok -eq 0 ]; then
2161 if [ "$iam" != "check" ]; then
2170 # Filter the knowen errors the UDF Verifier reports.
2171 _udf_test_known_error_filter()
2173 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."
2177 _check_udf_filesystem()
2179 [ "$DISABLE_UDF_TEST" == "1" ] && return
2181 if [ $# -ne 1 -a $# -ne 2 ]
2183 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
2187 if [ ! -x $here/src/udf_test ]
2189 echo "udf_test not installed, please download and build the Philips"
2190 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2191 echo "Then copy the udf_test binary to $here/src/."
2192 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2200 LAST_BLOCK=`expr \( $2 - 1 \)`
2201 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2204 rm -f $seqres.checkfs
2205 sleep 1 # Due to a problem with time stamps in udf_test
2206 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2207 _udf_test_known_error_filter | \
2208 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2209 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2213 _check_xfs_test_fs()
2217 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2218 TEST_LOG="$TEST_LOGDEV"
2220 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2221 TEST_RT="$TEST_RTDEV"
2223 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2225 # check for ipath consistency
2226 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2227 # errors go to stderr
2228 xfs_check_ipaths $TEST_DIR >/dev/null
2229 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2233 _check_btrfs_filesystem()
2237 # If type is set, we're mounted
2238 type=`_fs_type $device`
2241 if [ "$type" = "$FSTYP" ]
2244 mountpoint=`_umount_or_remount_ro $device`
2247 btrfsck $device >$tmp.fsck 2>&1
2250 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2252 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2253 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2254 cat $tmp.fsck >>$seqres.full
2255 echo "*** end fsck.$FSTYP output" >>$seqres.full
2263 echo "*** mount output ***" >>$seqres.full
2264 _mount >>$seqres.full
2265 echo "*** end mount output" >>$seqres.full
2266 elif [ "$type" = "$FSTYP" ]
2269 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2273 if [ $ok -eq 0 ]; then
2275 if [ "$iam" != "check" ]; then
2291 # no way to check consistency for nfs
2294 # no way to check consistency for cifs
2297 # no way to check consistency for overlay
2300 # do nothing for now
2303 _check_btrfs_filesystem $TEST_DEV
2306 # no way to check consistency for tmpfs
2309 _check_generic_filesystem $TEST_DEV
2317 [ $# -eq 1 ] && device=$1
2323 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2324 SCRATCH_LOG="$SCRATCH_LOGDEV"
2326 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2327 SCRATCH_RT="$SCRATCH_RTDEV"
2329 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2332 _check_udf_filesystem $device $udf_fsize
2335 # Don't know how to check an NFS filesystem, yet.
2338 # Don't know how to check a CIFS filesystem, yet.
2341 # no way to check consistency for overlay
2344 _check_btrfs_filesystem $device
2347 # no way to check consistency for tmpfs
2350 _check_generic_filesystem $device
2355 _full_fstyp_details()
2357 [ -z "$FSTYP" ] && FSTYP=xfs
2358 if [ $FSTYP = xfs ]; then
2359 if [ -d /proc/fs/xfs ]; then
2360 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2361 FSTYP="$FSTYP (non-debug)"
2362 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2363 FSTYP="$FSTYP (debug)"
2366 if uname -a | grep -qi 'debug'; then
2367 FSTYP="$FSTYP (debug)"
2369 FSTYP="$FSTYP (non-debug)"
2376 _full_platform_details()
2382 echo "$os/$platform $host $kernel"
2387 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2389 elif [ "`uname`" == "Linux" ]; then
2392 echo Unknown operating system: `uname`
2397 _link_out_file_named()
2402 my $feature, $result, $suffix, $opts;
2404 foreach $feature (split(/,/, $ENV{"FEATURES"})) {
2405 $feathash{$feature} = 1;
2407 $result = "default";
2412 ($opts, $suffix) = split(/ *: */);
2413 foreach my $opt (split(/,/, $opts)) {
2414 if (!exists($feathash{$opt})) {
2428 ln -fs $SRC.$SUFFIX $1
2433 if [ $# -eq 0 ]; then
2434 FEATURES="$(_get_os_name)"
2435 if [ -n "$MOUNT_OPTIONS" ]; then
2436 FEATURES=$FEATURES,${MOUNT_OPTIONS##"-o "}
2442 _link_out_file_named $seqfull.out "$FEATURES"
2451 #takes files, randomdata
2459 if [ $size -gt 0 ]; then
2460 if [ "$2" == "false" ]; then
2461 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2463 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2470 # takes dirname, depth, randomdata
2473 dirname=$1; depth=$2; randomdata=$3
2474 mkdir $dirname || die "mkdir $dirname failed"
2477 _nfiles $files $randomdata # files for this dir and data type
2479 [ $depth -eq 0 ] && return
2480 let deep=$depth-1 # go 1 down
2482 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2485 while [ $d -lt $dirs ]
2487 _descend d$d $deep &
2493 # Populate a filesystem with inodes for performance experiments
2495 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2500 dirs=5 # ndirs in each subdir till leaves
2501 size=0 # sizeof files in K
2502 files=100 # num files in _each_ subdir
2503 depth=2 # depth of tree from root to leaves
2505 root=root # path of initial root of directory tree
2506 randomdata=false # -x data type urandom or zero
2509 while getopts "d:f:n:r:s:v:x" c
2518 x) randomdata=true;;
2522 _descend $root $depth $randomdata
2527 [ $verbose = true ] && echo done
2530 # query whether the given file has the given inode flag set
2537 if which $XFS_IO_PROG >/dev/null; then
2538 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2545 # query the given files extsize allocator hint in bytes (if any)
2552 if which $XFS_IO_PROG >/dev/null; then
2553 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2554 awk '/^xattr.extsize =/ { print $3 }'`
2556 [ -z "$blocks" ] && blocks="0"
2560 # scratch_dev_pool should contain the disks pool for the btrfs raid
2561 _require_scratch_dev_pool()
2566 if [ -z "$SCRATCH_DEV_POOL" ]; then
2567 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2570 if [ -z "$1" ]; then
2576 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2580 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2581 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2585 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2589 for i in $SCRATCH_DEV_POOL; do
2590 if [ "`_is_block_dev "$i"`" = "" ]; then
2591 _notrun "this test requires valid block disk $i"
2593 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2594 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2596 if _mount | grep -q $i; then
2597 if ! $UMOUNT_PROG $i; then
2598 echo "failed to unmount $i - aborting"
2602 # to help better debug when something fails, we remove
2603 # traces of previous btrfs FS on the dev.
2604 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2608 # ensure devices in SCRATCH_DEV_POOL are of the same size
2609 # must be called after _require_scratch_dev_pool
2610 _require_scratch_dev_pool_equal_size()
2616 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2617 _size=`_get_device_size $SCRATCH_DEV`
2618 for _dev in $SCRATCH_DEV_POOL; do
2619 _newsize=`_get_device_size $_dev`
2620 if [ $_size -ne $_newsize ]; then
2621 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2626 # We will check if the device is deletable
2627 _require_deletable_scratch_dev_pool()
2631 for i in $SCRATCH_DEV_POOL; do
2632 x=`echo $i | cut -d"/" -f 3`
2633 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2634 _notrun "$i is a device which is not deletable"
2639 # We check for btrfs and (optionally) features of the btrfs command
2643 _require_command "$BTRFS_UTIL_PROG" btrfs
2644 if [ -z "$1" ]; then
2647 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2648 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2651 # Check that fio is present, and it is able to execute given jobfile
2656 _require_command "$FIO_PROG" fio
2657 if [ -z "$1" ]; then
2661 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2662 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2665 # Does freeze work on this fs?
2668 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2670 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2671 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2674 # Does shutdown work on this fs?
2675 _require_scratch_shutdown()
2677 [ -x src/godown ] || _notrun "src/godown executable not found"
2679 _scratch_mkfs > /dev/null 2>&1
2681 src/godown -f $SCRATCH_MNT 2>&1 \
2682 || _notrun "$FSTYP does not support shutdown"
2686 # Does norecovery support by this fs?
2687 _require_norecovery()
2689 _scratch_mount -o ro,norecovery || \
2690 _notrun "$FSTYP does not support norecovery"
2694 # Does this filesystem support metadata journaling?
2695 # We exclude ones here that don't; otherwise we assume that it does, so the
2696 # test will run, fail, and motivate someone to update this test for a new
2699 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2700 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2702 _require_metadata_journaling()
2712 _notrun "$FSTYP does not support metadata journaling"
2715 # ext4 could be mkfs'd without a journal...
2717 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2718 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2721 # by default we pass; if you need to, add your fs above!
2726 # Does fiemap support?
2729 _require_xfs_io_command "fiemap"
2734 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2739 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2742 # arg 1 is dev to remove and is output of the below eg.
2743 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2749 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2751 stat $disk > /dev/null 2>&1
2752 while [ $? -eq 0 ]; do
2754 stat $disk > /dev/null 2>&1
2758 # arg 1 is dev to add and is output of the below eg.
2759 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2764 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2765 h=`echo ${1} | cut -d":" -f 1`
2766 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2768 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2770 # ensure the device comes online
2772 for i in `seq 1 10`; do
2773 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2774 dev=`ls /sys/class/scsi_device/${1}/device/block`
2775 for j in `seq 1 10`;
2777 stat /dev/$dev > /dev/null 2>&1
2778 if [ $? -eq 0 ]; then
2789 if [ $dev_back_oneline -eq 0 ]; then
2790 echo "/dev/$dev online failed" >> $seqres.full
2792 echo "/dev/$dev is back online" >> $seqres.full
2798 if [ -z "$FSTRIM_PROG" ]; then
2799 _notrun "This test requires fstrim utility."
2803 _require_batched_discard()
2805 if [ $# -ne 1 ]; then
2806 echo "Usage: _require_batched_discard mnt_point" 1>&2
2810 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2815 if [ -z "$DUMPE2FS_PROG" ]; then
2816 _notrun "This test requires dumpe2fs utility."
2822 if [ ! -e /proc/self/uid_map ]; then
2823 _notrun "This test requires procfs uid_map support."
2825 if [ ! -e /proc/self/gid_map ]; then
2826 _notrun "This test requires procfs gid_map support."
2832 FSSUM_PROG=$here/src/fssum
2833 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2838 CLONER_PROG=$here/src/cloner
2839 [ -x $CLONER_PROG ] || \
2840 _notrun "cloner binary not present at $CLONER_PROG"
2845 if [ "$FSTYP" == "nfs" ]; then
2846 _notrun "atime related mount options have no effect on NFS"
2852 _scratch_mkfs > /dev/null 2>&1
2853 _scratch_mount -o relatime || \
2854 _notrun "relatime not supported by the current kernel"
2860 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2861 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2864 _create_loop_device()
2867 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2871 _destroy_loop_device()
2874 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2877 _scale_fsstress_args()
2880 while [ $# -gt 0 ]; do
2882 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2883 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2884 *) args="$args $1" ;;
2892 # Return the logical block size if running on a block device,
2893 # else substitute the page size.
2895 _min_dio_alignment()
2899 if [ -b "$dev" ]; then
2900 blockdev --getss $dev
2902 $here/src/feature -s
2908 echo "# $@" >> $seqres.full 2>&1
2909 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2912 _run_btrfs_util_prog()
2914 run_check $BTRFS_UTIL_PROG $*
2917 _require_btrfs_send_stream_version()
2919 $BTRFS_UTIL_PROG send 2>&1 | \
2920 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2921 if [ $? -ne 0 ]; then
2922 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2925 # test if btrfs kernel supports send stream version 2
2926 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2927 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2931 _require_btrfs_mkfs_feature()
2934 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2938 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2939 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2941 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2944 _require_btrfs_fs_feature()
2947 echo "Missing feature name argument for _require_btrfs_fs_feature"
2951 modprobe btrfs > /dev/null 2>&1
2952 [ -e /sys/fs/btrfs/features/$feat ] || \
2953 _notrun "Feature $feat not supported by the available btrfs version"
2956 _require_test_symlinks()
2958 # IRIX UDF does not support symlinks
2959 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2960 _notrun "Require symlinks support"
2961 target=`mktemp -p $TEST_DIR`
2962 link=`mktemp -p $TEST_DIR -u`
2963 ln -s `basename $target` $link
2964 if [ "$?" -ne 0 ]; then
2966 _notrun "Require symlinks support"
2971 _require_test_fcntl_advisory_locks()
2973 [ "$FSTYP" != "cifs" ] && return 0
2974 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2975 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2976 _notrun "Require fcntl advisory locks support"
2979 # XFS ability to change UUIDs on V5/CRC filesystems
2981 _require_meta_uuid()
2983 # This will create a crc fs on $SCRATCH_DEV
2986 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
2987 | grep -q "invalid UUID\|supported on V5 fs" \
2988 && _notrun "Userspace doesn't support meta_uuid feature"
2990 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
2992 _scratch_mount >/dev/null 2>&1 \
2993 || _notrun "Kernel doesn't support meta_uuid feature"
2997 _require_btrfs_dev_del_by_devid()
2999 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
3000 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
3001 "(must support 'btrfs device delete <devid> /<mnt>')"
3004 _require_test_lsattr()
3006 testio=$(lsattr -d $TEST_DIR 2>&1)
3007 echo $testio | grep -q "Operation not supported" && \
3008 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3009 echo $testio | grep -q "Inappropriate ioctl for device" && \
3010 _notrun "lsattr not supported by test filesystem type: $FSTYP"
3015 if [ -z "$1" ]; then
3016 echo "Usage: _get_total_inode <mnt>"
3020 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
3026 if [ -z "$1" ]; then
3027 echo "Usage: _get_used_inode <mnt>"
3031 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
3035 _get_used_inode_percent()
3037 if [ -z "$1" ]; then
3038 echo "Usage: _get_used_inode_percent <mnt>"
3042 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
3049 if [ -z "$1" ]; then
3050 echo "Usage: _get_free_inode <mnt>"
3054 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
3058 # get the available space in bytes
3060 _get_available_space()
3062 if [ -z "$1" ]; then
3063 echo "Usage: _get_available_space <mnt>"
3067 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
3068 echo $((avail_kb * 1024))
3071 # get btrfs profile configs being tested
3073 # A set of pre-set profile configs are exported via _btrfs_profile_configs
3074 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
3075 # var in the format "metadata_profile:data_profile", multiple configs can be
3076 # seperated by space, e.g.
3077 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
3078 _btrfs_get_profile_configs()
3080 if [ "$FSTYP" != "btrfs" ]; then
3084 # no user specified btrfs profile configs, export the default configs
3085 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
3087 _btrfs_profile_configs=(
3088 "-m single -d single"
3093 "-m raid10 -d raid10"
3098 # remove dup/raid5/raid6 profiles if we're doing device replace
3099 # dup profile indicates only one device being used (SCRATCH_DEV),
3100 # but we don't want to replace SCRATCH_DEV, which will be used in
3101 # _scratch_mount/_check_scratch_fs etc.
3102 # and raid5/raid6 doesn't support replace yet
3103 if [ "$1" == "replace" ]; then
3104 _btrfs_profile_configs=(
3105 "-m single -d single"
3109 "-m raid10 -d raid10"
3110 # add these back when raid5/6 is working with replace
3111 #"-m raid5 -d raid5"
3112 #"-m raid6 -d raid6"
3115 export _btrfs_profile_configs
3119 # parse user specified btrfs profile configs
3122 for cfg in $BTRFS_PROFILE_CONFIGS; do
3123 # turn "metadata:data" format to "-m metadata -d data"
3124 # and assign it to _btrfs_profile_configs array
3125 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
3126 _btrfs_profile_configs[$i]="$cfg"
3130 if [ "$1" == "replace" ]; then
3131 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
3132 _notrun "RAID5/6 doesn't support btrfs device replace yet"
3134 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
3135 _notrun "Do not set dup profile in btrfs device replace test"
3138 export _btrfs_profile_configs
3141 # stress btrfs by running balance operation in a loop
3142 _btrfs_stress_balance()
3146 $BTRFS_UTIL_PROG balance start $btrfs_mnt
3150 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
3151 _btrfs_stress_subvolume()
3155 local subvol_name=$3
3158 mkdir -p $subvol_mnt
3160 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
3161 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
3162 $UMOUNT_PROG $subvol_mnt
3163 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
3167 # stress btrfs by running scrub in a loop
3168 _btrfs_stress_scrub()
3172 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
3176 # stress btrfs by defragmenting every file/dir in a loop and compress file
3177 # contents while defragmenting if second argument is not "nocompress"
3178 _btrfs_stress_defrag()
3184 if [ "$compress" == "nocompress" ]; then
3185 find $btrfs_mnt \( -type f -o -type d \) -exec \
3186 $BTRFS_UTIL_PROG filesystem defrag {} \;
3188 find $btrfs_mnt \( -type f -o -type d \) -exec \
3189 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
3190 find $btrfs_mnt \( -type f -o -type d \) -exec \
3191 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
3196 # stress btrfs by remounting it with different compression algorithms in a loop
3197 # run this with fsstress running at background could exercise the compression
3198 # code path and ensure no race when switching compression algorithm with constant
3200 _btrfs_stress_remount_compress()
3204 for algo in no zlib lzo; do
3205 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
3210 # stress btrfs by replacing devices in a loop
3211 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
3212 # device should be free(not used by btrfs)
3213 _btrfs_stress_replace()
3217 # The device number in SCRATCH_DEV_POOL should be at least 3,
3218 # one is SCRATCH_DEV, one is to be replaced, one is free device
3219 # we won't replace SCRATCH_DEV, see below for reason
3220 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
3221 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
3225 # take the last device as the first free_dev
3226 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
3228 # free_dev should be really free
3229 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
3230 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3234 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3235 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3236 # _scratch_mount and _check_scratch_fs etc.
3237 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3238 -e "s# *$free_dev *##"`
3240 # set the first device in dev_pool as the first src_dev to be replaced
3241 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3243 echo "dev_pool=$dev_pool"
3244 echo "free_dev=$free_dev, src_dev=$src_dev"
3246 echo "Replacing $src_dev with $free_dev"
3247 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3248 if [ $? -ne 0 ]; then
3249 # don't update src_dev and free_dev if replace failed
3252 dev_pool="$dev_pool $free_dev"
3253 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3255 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3259 # find the right option to force output in bytes, older versions of btrfs-progs
3260 # print that by default, newer print human readable numbers with unit suffix
3261 _btrfs_qgroup_units()
3263 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3266 # return device size in kb
3269 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3272 # check dmesg log for WARNING/Oops/etc.
3275 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3278 rm -f ${RESULT_DIR}/check_dmesg
3280 # default filter is a simple cat command, caller could provide a
3281 # customized filter and pass the name through the first argument, to
3282 # filter out intentional WARNINGs or Oopses
3285 # search the dmesg log of last run of $seqnum for possible failures
3286 # use sed \cregexpc address type, since $seqnum contains "/"
3287 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3288 tac | $filter >$seqres.dmesg
3289 grep -q -e "kernel BUG at" \
3293 -e "possible recursive locking detected" \
3294 -e "Internal error" \
3295 -e "INFO: suspicious RCU usage" \
3296 -e "INFO: possible circular locking dependency detected" \
3298 if [ $? -eq 0 ]; then
3299 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3307 # don't check dmesg log after test
3308 _disable_dmesg_check()
3310 rm -f ${RESULT_DIR}/check_dmesg
3315 if [ "$iam" == new ]
3319 # make some further configuration checks here
3320 if [ "$TEST_DEV" = "" ]
3322 echo "common/rc: Error: \$TEST_DEV is not set"
3326 # if $TEST_DEV is not mounted, mount it now as XFS
3327 if [ -z "`_fs_type $TEST_DEV`" ]
3329 # $TEST_DEV is not mounted
3332 echo "common/rc: retrying test device mount with external set"
3333 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3336 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3342 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3344 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3345 # raw $DF_PROG cannot handle NFS/CIFS/overlay correctly
3346 _df_device $TEST_DEV
3349 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3350 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3351 export XFS_IO_PROG="$XFS_IO_PROG -F"
3353 # xfs_copy doesn't work on v5 xfs yet without -d option
3354 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3355 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3359 # get real device path name by following link
3363 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3364 _dev=`readlink -f "$_dev"`
3369 # basename of a device
3372 echo `basename $(_real_dev $1)`
3378 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3379 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3380 _maj=$(echo "ibase=16; $_maj" | bc)
3381 _min=$(echo "ibase=16; $_min" | bc)
3382 echo /sys/dev/block/$_maj:$_min
3387 if [ -z $1 ] || [ ! -d $1 ]; then
3388 echo "Missing mount point argument for get_block_size"
3391 echo `stat -f -c %S $1`
3396 echo $(getconf PAGE_SIZE)
3403 args=`echo $@ | sed -e "s/ BSIZE / $bsize /g" -e "s/ PSIZE / $psize /g"`
3404 set -- $here/ltp/fsx $args $FSX_AVOID $TEST_DIR/junk
3405 echo "$@" >>$seqres.full
3406 rm -f $TEST_DIR/junk
3407 "$@" 2>&1 | tee -a $seqres.full >$tmp.fsx
3408 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3416 ################################################################################
3417 # make sure this script returns success