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"
151 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
155 # make sure we have a standard umask
160 $MOUNT_PROG `_mount_ops_filter $*`
168 if [ "$FSTYP" != "xfs" ]; then
174 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
183 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
184 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
185 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
186 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
194 if [ "$FSTYP" != "xfs" ]; then
208 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
209 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
210 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
211 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
218 #get mount point to handle dmapi mtpt option correctly
220 [ $last_index -gt 0 ] && shift $last_index
223 # irix is fussy about how it is fed its mount options
224 # - multiple -o's are not allowed
225 # - no spaces between comma delimitered options
226 # the sed script replaces all -o's (except the first) with a comma
227 # not required for linux, but won't hurt
229 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
230 | sed -e 's/dmapi/dmi/' \
231 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
235 # Used for mounting non-scratch devices (e.g. loop, dm constructs)
236 # with the safe set of scratch mount options (e.g. loop image may be
237 # hosted on $SCRATCH_DEV, so can't use external scratch devices).
238 _common_dev_mount_options()
240 echo $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $*
243 _scratch_mount_options()
245 _scratch_options mount
247 echo `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
248 $SCRATCH_DEV $SCRATCH_MNT
253 _mount -t $FSTYP `_scratch_mount_options $*`
258 $UMOUNT_PROG $SCRATCH_DEV
270 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
275 $UMOUNT_PROG $TEST_DEV
279 _scratch_mkfs_options()
281 _scratch_options mkfs
282 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
290 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
291 options="-l $SCRATCH_LOGDEV"
293 xfs_metadump $options $SCRATCH_DEV $dumpfile
296 _setup_large_xfs_fs()
301 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
302 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
303 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
305 # calculate the size of the file we need to allocate.
306 # Default free space in the FS is 50GB, but you can specify more via
307 # SCRATCH_DEV_EMPTY_SPACE
308 file_size=$(($fs_size - 50*1024*1024*1024))
309 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
311 # mount the filesystem, create the file, unmount it
312 _scratch_mount 2>&1 >$tmp_dir/mnt.err
314 if [ $status -ne 0 ]; then
316 cat $tmp_dir/mnt.err >&2
317 rm -f $tmp_dir/mnt.err
320 rm -f $tmp_dir/mnt.err
323 -c "truncate $file_size" \
324 -c "falloc -k 0 $file_size" \
326 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
327 export NUM_SPACE_FILES=1
330 if [ $status -ne 0 ]; then
331 echo "large file prealloc failed"
332 cat $tmp_dir/mnt.err >&2
338 _scratch_mkfs_xfs_opts()
342 # remove crc related mkfs options if mkfs.xfs doesn't support v5 xfs
343 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
344 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+crc=.//"`
347 _scratch_options mkfs
349 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
353 _scratch_mkfs_xfs_supported()
357 _scratch_options mkfs
359 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
364 # extra mkfs options can be added by tests
365 local extra_mkfs_options=$*
369 # save mkfs output in case conflict means we need to run again.
370 # only the output for the mkfs that applies should be shown
371 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
372 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
376 # a mkfs failure may be caused by conflicts between
377 # $MKFS_OPTIONS and $extra_mkfs_options
378 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
380 echo -n "** mkfs failed with extra mkfs options "
381 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
382 echo -n "** attempting to mkfs using only test $seq "
383 echo "options: $extra_mkfs_options **"
386 # running mkfs again. overwrite previous mkfs output files
387 _scratch_mkfs_xfs_opts $extra_mkfs_options \
388 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
392 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
393 # manually parse the mkfs output to get the fs size in bytes
395 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
396 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
398 print STDOUT "$size\n";
400 _setup_large_xfs_fs $fs_size
404 # output stored mkfs output, filtering unnecessary warnings from stderr
406 cat $tmp_dir.mkfserr | sed \
407 -e '/less than device physical sector/d' \
408 -e '/switching to logical sector/d' \
410 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
415 # xfs_check script is planned to be deprecated. But, we want to
416 # be able to invoke "xfs_check" behavior in xfstests in order to
417 # maintain the current verification levels.
422 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
424 while getopts "b:fi:l:stvV" c
430 i) OPTS=$OPTS"-i "$OPTARG" ";;
431 b) OPTS=$OPTS"-b "$OPTARG" ";;
432 f) DBOPTS=$DBOPTS" -f";;
433 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
434 V) $XFS_DB_PROG -p xfs_check -V
442 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
452 _setup_large_ext4_fs()
457 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
458 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
459 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
461 # Default free space in the FS is 50GB, but you can specify more via
462 # SCRATCH_DEV_EMPTY_SPACE
463 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
465 # mount the filesystem and create 16TB - 4KB files until we consume
466 # all the necessary space.
467 _scratch_mount 2>&1 >$tmp_dir/mnt.err
469 if [ $status -ne 0 ]; then
471 cat $tmp_dir/mnt.err >&2
472 rm -f $tmp_dir/mnt.err
475 rm -f $tmp_dir/mnt.err
477 file_size=$((16*1024*1024*1024*1024 - 4096))
479 while [ $space_to_consume -gt $file_size ]; do
482 -c "truncate $file_size" \
483 -c "falloc -k 0 $file_size" \
484 $SCRATCH_MNT/.use_space.$nfiles 2>&1
486 if [ $status -ne 0 ]; then
490 space_to_consume=$(( $space_to_consume - $file_size ))
491 nfiles=$(($nfiles + 1))
494 # consume the remaining space.
495 if [ $space_to_consume -gt 0 ]; then
497 -c "truncate $space_to_consume" \
498 -c "falloc -k 0 $space_to_consume" \
499 $SCRATCH_MNT/.use_space.$nfiles 2>&1
502 export NUM_SPACE_FILES=$nfiles
505 if [ $status -ne 0 ]; then
506 echo "large file prealloc failed"
507 cat $tmp_dir/mnt.err >&2
515 # extra mkfs options can be added by tests
516 local extra_mkfs_options=$*
520 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
521 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
524 # a mkfs failure may be caused by conflicts between
525 # $MKFS_OPTIONS and $extra_mkfs_options
526 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
528 echo -n "** mkfs failed with extra mkfs options "
529 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
530 echo -n "** attempting to mkfs using only test $seq "
531 echo "options: $extra_mkfs_options **"
534 # running mkfs again. overwrite previous mkfs output files
535 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
536 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
540 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
541 # manually parse the mkfs output to get the fs size in bytes
542 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
543 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
544 / inodes, / { blks = $3 } \
545 /reserved for the super user/ { resv = $1 } \
546 END { fssize = bs * blks - resv; print fssize }'`
548 _setup_large_ext4_fs $fs_size
552 # output stored mkfs output
553 cat $tmp_dir.mkfserr >&2
555 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
567 # do nothing for cifs
570 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
573 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
576 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
579 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
591 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
594 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
597 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
598 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
602 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
603 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
607 if [ $? -ne 0 ]; then
608 # output stored mkfs output
609 cat $tmp_dir.mkfserr >&2
614 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
617 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
618 _scratch_cleanup_files()
621 rm -rf $SCRATCH_MNT/*
632 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
633 # avoid EEXIST caused by the leftover files created in previous runs
634 _scratch_cleanup_files
637 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
638 # avoid EEXIST caused by the leftover files created in previous runs
639 _scratch_cleanup_files
642 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
645 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
648 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
651 _scratch_mkfs_ext4 $*
654 # do nothing for tmpfs
657 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
660 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
669 # if dup profile is in mkfs options call _scratch_mkfs instead
670 # because dup profile only works with single device
671 if [[ "$*" =~ dup ]]; then
674 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
678 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
683 # Create fs of certain size on scratch device
684 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
685 _scratch_mkfs_sized()
692 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
694 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
695 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
699 [ -n "$def_blksz" ] && blocksize=$def_blksz
700 [ -z "$blocksize" ] && blocksize=4096
704 if ! [[ $fssize =~ $re ]] ; then
705 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
707 if ! [[ $blocksize =~ $re ]] ; then
708 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
711 blocks=`expr $fssize / $blocksize`
713 if [ "$HOSTOS" == "Linux" ]; then
714 devsize=`blockdev --getsize64 $SCRATCH_DEV`
715 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
720 # don't override MKFS_OPTIONS that set a block size.
721 echo $MKFS_OPTIONS |egrep -q "b?size="
722 if [ $? -eq 0 ]; then
723 _scratch_mkfs_xfs -d size=$fssize
725 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
728 ext2|ext3|ext4|ext4dev)
729 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
732 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
735 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
738 # mkfs.resier4 requires size in KB as input for creating filesystem
739 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
740 `expr $fssize / 1024`
743 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
748 # Emulate an N-data-disk stripe w/ various stripe units
749 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
755 [ -z "$blocksize" ] && blocksize=4096
757 let sunit_blocks=$sunit_bytes/$blocksize
758 let swidth_blocks=$sunit_blocks*$swidth_mult
762 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
765 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
768 _notrun "can't mkfs $FSTYP with geometry"
778 xfs_io -x -c "resblks $1" $SCRATCH_MNT
785 _scratch_xfs_db_options()
788 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
789 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
790 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
793 _scratch_xfs_logprint()
796 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
797 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
798 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
804 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
805 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
806 [ "$LARGE_SCRATCH_DEV" = yes ] && \
807 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
808 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
811 _scratch_xfs_repair()
814 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
815 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
816 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
817 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
818 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
819 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
826 echo "Usage: _get_pids_by_name process-name" 1>&2
830 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
831 # HH:MM:SS before the psargs field, use this as the search anchor.
833 # Matches with $1 (process-name) occur if the first psarg is $1
834 # or ends in /$1 ... the matching uses sed's regular expressions,
835 # so passing a regex into $1 will work.
843 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
844 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
847 # fix malloc libs output
851 # filter out the Electric Fence notice
854 if (defined $o && /^\s+Electric Fence/) {
860 print $o if (defined $o);
864 print $o if (defined $o);
868 # check if run as root
872 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
875 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
882 # _df_device : get an IRIX style df line for a given device
884 # - returns "" if not mounted
885 # - returns fs type in field two (ala IRIX)
886 # - joins line together if split by fancy df formatting
887 # - strips header etc
894 echo "Usage: _df_device device" 1>&2
898 # Note that we use "==" here so awk doesn't try to interpret an NFS over
899 # IPv6 server as a regular expression.
900 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
901 ($1==what) && (NF==1) {
915 # _df_dir : get an IRIX style df line for device where a directory resides
917 # - returns fs type in field two (ala IRIX)
918 # - joins line together if split by fancy df formatting
919 # - strips header etc
926 echo "Usage: _df_dir device" 1>&2
930 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
946 # return percentage used disk space for mounted device
952 echo "Usage: _used device" 1>&2
956 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
959 # return the FS type of a mounted device
965 echo "Usage: _fs_type device" 1>&2
970 # The Linux kernel shows NFSv4 filesystems in df output as
971 # filesystem type nfs4, although we mounted it as nfs earlier.
972 # Fix the filesystem type up here so that the callers don't
973 # have to bother with this quirk.
975 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
978 # return the FS mount options of a mounted device
980 # should write a version which just parses the output of mount for IRIX
981 # compatibility, but since this isn't used at all, at the moment I'll leave
988 echo "Usage: _fs_options device" 1>&2
992 $AWK_PROG -v dev=$1 '
993 match($1,dev) { print $4 }
997 # returns device number if a file is a block device
1003 echo "Usage: _is_block_dev dev" 1>&2
1008 if [ -L "${_dev}" ]; then
1009 _dev=`readlink -f "${_dev}"`
1012 if [ -b "${_dev}" ]; then
1013 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
1017 # Do a command, log it to $seqres.full, optionally test return status
1018 # and die if command fails. If called with one argument _do executes the
1019 # command, logs it, and returns its exit status. With two arguments _do
1020 # first prints the message passed in the first argument, and then "done"
1021 # or "fail" depending on the return status of the command passed in the
1022 # second argument. If the command fails and the variable _do_die_on_error
1023 # is set to "always" or the two argument form is used and _do_die_on_error
1024 # is set to "message_only" _do will print an error message to
1025 # $seqres.out and exit.
1029 if [ $# -eq 1 ]; then
1031 elif [ $# -eq 2 ]; then
1034 echo -n "$_note... "
1036 echo "Usage: _do [note] cmd" 1>&2
1040 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1041 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1042 cat $tmp._out | _fix_malloc >>$seqres.full
1043 if [ $# -eq 2 ]; then
1044 if [ $ret -eq 0 ]; then
1051 && [ "$_do_die_on_error" = "always" \
1052 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1054 [ $# -ne 2 ] && echo
1055 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1062 # bail out, setting up .notrun file. Need to kill the filesystem check files
1063 # here, otherwise they are set incorrectly for the next test.
1067 echo "$*" > $seqres.notrun
1068 echo "$seq not run: $*"
1069 rm -f ${RESULT_DIR}/require_test
1070 rm -f ${RESULT_DIR}/require_scratch
1075 # just plain bail out
1079 echo "$*" | tee -a $seqres.full
1080 echo "(see $seqres.full for details)"
1085 # tests whether $FSTYP is one of the supported filesystems for a test
1091 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1097 _notrun "not suitable for this filesystem type: $FSTYP"
1101 # tests whether $FSTYP is one of the supported OSes for a test
1107 if [ "$h" = "$HOSTOS" ]
1113 _notrun "not suitable for this OS: $HOSTOS"
1116 # this test needs a scratch partition - check we're ok & unmount it
1117 # No post-test check of the device is required. e.g. the test intentionally
1118 # finishes the test with the filesystem in a corrupt state
1119 _require_scratch_nocheck()
1123 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1124 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1125 _notrun "this test requires a valid \$SCRATCH_DEV"
1127 if [ ! -d "$SCRATCH_MNT" ]; then
1128 _notrun "this test requires a valid \$SCRATCH_MNT"
1132 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1133 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1134 _notrun "this test requires a valid \$SCRATCH_DEV"
1136 if [ ! -d "$SCRATCH_MNT" ]; then
1137 _notrun "this test requires a valid \$SCRATCH_MNT"
1141 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1143 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1147 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1149 _notrun "this test requires a valid \$SCRATCH_DEV"
1151 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1153 _notrun "this test requires a valid \$SCRATCH_DEV"
1155 if [ ! -d "$SCRATCH_MNT" ]
1157 _notrun "this test requires a valid \$SCRATCH_MNT"
1163 # Note that we use -F here so grep doesn't try to interpret an NFS over
1164 # IPv6 server as a regular expression.
1165 if _mount | grep -F -q $SCRATCH_DEV
1167 # if it's mounted, make sure its on $SCRATCH_MNT
1168 if ! _mount | grep -F $SCRATCH_DEV | grep -q $SCRATCH_MNT
1170 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1173 # and then unmount it
1174 if ! $UMOUNT_PROG $SCRATCH_DEV
1176 echo "failed to unmount $SCRATCH_DEV"
1180 rm -f ${RESULT_DIR}/require_scratch
1183 # we need the scratch device and it should be checked post test.
1186 _require_scratch_nocheck
1187 touch ${RESULT_DIR}/require_scratch
1191 # this test needs a test partition - check we're ok & mount it
1197 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1198 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1199 _notrun "this test requires a valid \$TEST_DIR"
1201 if [ ! -d "$TEST_DIR" ]; then
1202 _notrun "this test requires a valid \$TEST_DIR"
1206 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1207 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1208 _notrun "this test requires a valid \$TEST_DEV"
1210 if [ ! -d "$TEST_DIR" ]; then
1211 _notrun "this test requires a valid \$TEST_DIR"
1215 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1217 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1221 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1223 _notrun "this test requires a valid \$TEST_DEV"
1225 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1227 _notrun "this test requires a valid \$TEST_DEV"
1229 if [ ! -d "$TEST_DIR" ]
1231 _notrun "this test requires a valid \$TEST_DIR"
1237 # Note that we use -F here so grep doesn't try to interpret an NFS over
1238 # IPv6 server as a regular expression.
1239 if _mount | grep -F -q $TEST_DEV
1241 # if it's mounted, make sure its on $TEST_DIR
1242 if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
1244 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1248 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1249 if [ $? -ne 1 ]; then
1254 touch ${RESULT_DIR}/require_test
1257 # this test needs a logdev
1261 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1262 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1263 [ "$USE_EXTERNAL" != yes ] && \
1264 _notrun "This test requires USE_EXTERNAL to be enabled"
1266 # ensure its not mounted
1267 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1270 # this test requires loopback device support
1274 if [ "$HOSTOS" != "Linux" ]
1276 _notrun "This test requires linux for loopback device support"
1279 modprobe loop >/dev/null 2>&1
1280 if grep loop /proc/devices >/dev/null 2>&1
1284 _notrun "This test requires loopback device support"
1288 # this test requires ext2 filesystem support
1292 if [ "$HOSTOS" != "Linux" ]
1294 _notrun "This test requires linux for ext2 filesystem support"
1297 modprobe ext2 >/dev/null 2>&1
1298 if grep ext2 /proc/filesystems >/dev/null 2>&1
1302 _notrun "This test requires ext2 filesystem support"
1306 # this test requires that (large) loopback device files are not in use
1308 _require_no_large_scratch_dev()
1310 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1311 _notrun "Large filesystem testing in progress, skipped this test"
1314 # this test requires that a realtime subvolume is in use, and
1315 # that the kernel supports realtime as well.
1319 [ "$USE_EXTERNAL" = yes ] || \
1320 _notrun "External volumes not in use, skipped this test"
1321 [ "$SCRATCH_RTDEV" = "" ] && \
1322 _notrun "Realtime device required, skipped this test"
1325 # this test requires that a specified command (executable) exists
1326 # $1 - command, $2 - name for error message
1328 # Note: the command string might have parameters, so strip them before checking
1329 # whether it is executable.
1332 if [ $# -eq 2 ]; then
1334 elif [ $# -eq 1 ]; then
1337 _fail "usage: _require_command <command> [<name>]"
1340 _command=`echo "$1" | awk '{ print $1 }'`
1341 if [ ! -x "$_command" ]; then
1342 _notrun "$_name utility required, skipped this test"
1346 # this test requires the device to be valid block device
1348 _require_block_device()
1350 if [ -z "$1" ]; then
1351 echo "Usage: _require_block_device <dev>" 1>&2
1354 if [ "`_is_block_dev "$1"`" == "" ]; then
1355 _notrun "require $1 to be valid block disk"
1359 # brd based ram disks erase the device when they receive a flush command when no
1360 # active references are present. This causes problems for DM devices sitting on
1361 # top of brd devices as DM doesn't hold active references to the brd device.
1362 _require_sane_bdev_flush()
1364 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1365 if [ $? -eq 0 ]; then
1366 _notrun "This test requires a sane block device flush"
1370 # this test requires a specific device mapper target
1371 _require_dm_target()
1375 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1377 _require_block_device $SCRATCH_DEV
1378 _require_sane_bdev_flush $SCRATCH_DEV
1379 _require_command "$DMSETUP_PROG" dmsetup
1381 modprobe dm-$_target >/dev/null 2>&1
1383 $DMSETUP_PROG targets 2>&1 | grep -q ^$_target
1384 if [ $? -ne 0 ]; then
1385 _notrun "This test requires dm $_target support"
1389 # this test requires the projid32bit feature to be available in mkfs.xfs.
1391 _require_projid32bit()
1393 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1394 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1397 _require_projid16bit()
1399 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1400 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1403 # this test requires the crc feature to be available in mkfs.xfs
1405 _require_xfs_mkfs_crc()
1407 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1408 || _notrun "mkfs.xfs doesn't have crc feature"
1411 # this test requires the xfs kernel support crc feature
1415 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1416 _scratch_mount >/dev/null 2>&1 \
1417 || _notrun "Kernel doesn't support crc feature"
1421 # this test requires the ext4 kernel support crc feature on scratch device
1423 _require_scratch_ext4_crc()
1425 _scratch_mkfs_ext4 >/dev/null 2>&1
1426 dumpe2fs -h $SCRATCH_DEV 2> /dev/null | grep -q metadata_csum || _notrun "metadata_csum not supported by this filesystem"
1427 _scratch_mount >/dev/null 2>&1 \
1428 || _notrun "Kernel doesn't support metadata_csum feature"
1432 # this test requires the xfs kernel support crc feature on scratch device
1434 _require_scratch_xfs_crc()
1436 _scratch_mkfs_xfs >/dev/null 2>&1
1437 _scratch_mount >/dev/null 2>&1 \
1438 || _notrun "Kernel doesn't support crc feature"
1439 xfs_info $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
1443 # this test requires the bigalloc feature to be available in mkfs.ext4
1445 _require_ext4_mkfs_bigalloc()
1447 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1448 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1451 # this test requires the ext4 kernel support bigalloc feature
1453 _require_ext4_bigalloc()
1455 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1456 _scratch_mount >/dev/null 2>&1 \
1457 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1461 # this test requires the finobt feature to be available in mkfs.xfs
1463 _require_xfs_mkfs_finobt()
1465 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1466 || _notrun "mkfs.xfs doesn't have finobt feature"
1469 # this test requires the xfs kernel support finobt feature
1471 _require_xfs_finobt()
1473 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1474 _scratch_mount >/dev/null 2>&1 \
1475 || _notrun "Kernel doesn't support finobt feature"
1479 # this test requires xfs sysfs attribute support
1481 _require_xfs_sysfs()
1484 sysfsdir=/sys/fs/xfs
1486 if [ ! -e $sysfsdir ]; then
1487 _notrun "no kernel support for XFS sysfs attributes"
1490 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1491 _notrun "sysfs attribute '$attr' is not supported"
1495 # this test requires the xfs sparse inode feature
1497 _require_xfs_sparse_inodes()
1499 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1500 || _notrun "mkfs.xfs does not support sparse inodes"
1501 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1502 _scratch_mount >/dev/null 2>&1 \
1503 || _notrun "kernel does not support sparse inodes"
1507 # this test requires that external log/realtime devices are not in use
1509 _require_nonexternal()
1511 [ "$USE_EXTERNAL" = yes ] && \
1512 _notrun "External device testing in progress, skipped this test"
1515 # this test requires that a (specified) aio-dio executable exists
1516 # $1 - command (optional)
1522 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1523 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1525 AIO_TEST=src/aio-dio-regress/$1
1526 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1531 # run an aio-dio program
1537 echo "usage: _run_aiodio command_name" 2>&1
1543 local testtemp=$TEST_DIR/aio-testfile
1545 $AIO_TEST $testtemp 2>&1
1552 # indicate whether YP/NIS is active or not
1557 dn=$(domainname 2>/dev/null)
1558 test -n "${dn}" -a "${dn}" != "(none)"
1562 # cat the password file
1566 [ $(_yp_active) -eq 0 ] && ypcat passwd
1570 # cat the group file
1574 [ $(_yp_active) -eq 0 ] && ypcat group
1578 # check for the fsgqa user on the machine
1583 _cat_passwd | grep -q $qa_user
1584 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1585 echo /bin/true | su $qa_user
1586 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1589 # check for the fsgqa group on the machine
1594 _cat_group | grep -q $qa_group
1595 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1601 s,.*Permission\sdenied.*,Permission denied,;
1602 s,.*no\saccess\sto\stty.*,,;
1603 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1610 if [ "$HOSTOS" == "IRIX" ]
1612 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1614 echo $1 | su $qa_user 2>&1 | _filter_user_do
1618 _require_xfs_io_command()
1622 echo "Usage: _require_xfs_io_command command" 1>&2
1627 testfile=$TEST_DIR/$$.xfs_io
1630 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1632 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1633 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1634 -c "$command 4k 8k" $testfile 2>&1`
1637 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1638 -c "fiemap -v" $testfile 2>&1`
1641 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1643 echo $testio | egrep -q "invalid option|Is a directory" && \
1644 _notrun "xfs_io $command support is missing"
1647 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1650 rm -f $testfile 2>&1 > /dev/null
1651 echo $testio | grep -q "not found" && \
1652 _notrun "xfs_io $command support is missing"
1653 echo $testio | grep -q "Operation not supported" && \
1654 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1657 # check that kernel and filesystem support direct I/O
1660 testfile=$TEST_DIR/$$.direct
1661 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1662 if [ $? -ne 0 ]; then
1663 _notrun "O_DIRECT is not supported"
1665 rm -f $testfile 2>&1 > /dev/null
1668 # Check that a fs has enough free space (in 1024b blocks)
1673 BLOCKS=$2 # in units of 1024
1674 let GB=$BLOCKS/1024/1024
1676 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1677 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1678 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1682 # Check if the filesystem supports sparse files.
1684 # Unfortunately there is no better way to do this than a manual black list.
1686 _require_sparse_files()
1690 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1699 #boot_params always present in debugfs
1700 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1703 _require_fail_make_request()
1705 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1706 || _notrun "$DEBUGFS_MNT/fail_make_request \
1707 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1711 # Check if the file system supports seek_data/hole
1713 _require_seek_data_hole()
1715 testfile=$TEST_DIR/$$.seek
1716 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1717 rm -f $testfile &>/dev/null
1718 echo $testseek | grep -q "Kernel does not support" && \
1719 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1722 # check that a FS on a device is mounted
1723 # if so, return mount point
1729 echo "Usage: _is_mounted device" 1>&2
1735 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1736 pattern { print $3 ; exit 0 }
1740 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1745 # remount a FS to a new mode (ro or rw)
1751 echo "Usage: _remount device ro/rw" 1>&2
1757 if ! mount -o remount,$mode $device
1759 echo "_remount: failed to remount filesystem on $device as $mode"
1764 # Run the appropriate repair/check on a filesystem
1766 # if the filesystem is mounted, it's either remounted ro before being
1767 # checked or it's unmounted and then remounted
1770 # If set, we remount ro instead of unmounting for fsck
1773 _umount_or_remount_ro()
1777 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1782 mountpoint=`_is_mounted $device`
1784 if [ $USE_REMOUNT -eq 0 ]; then
1785 $UMOUNT_PROG $device
1792 _mount_or_remount_rw()
1796 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1803 if [ $USE_REMOUNT -eq 0 ]
1805 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1807 echo "!!! failed to remount $device on $mountpoint"
1817 # Check a generic filesystem in no-op mode; this assumes that the
1818 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1819 # and that it will still return an errno for corruption in this mode.
1821 # Filesystems which don't support this will need to define their
1822 # own check routine.
1824 _check_generic_filesystem()
1828 # If type is set, we're mounted
1829 type=`_fs_type $device`
1832 if [ "$type" = "$FSTYP" ]
1835 mountpoint=`_umount_or_remount_ro $device`
1838 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1841 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1843 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1844 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1845 cat $tmp.fsck >>$seqres.full
1846 echo "*** end fsck.$FSTYP output" >>$seqres.full
1854 echo "*** mount output ***" >>$seqres.full
1855 _mount >>$seqres.full
1856 echo "*** end mount output" >>$seqres.full
1857 elif [ "$type" = "$FSTYP" ]
1860 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1864 if [ $ok -eq 0 ]; then
1866 if [ "$iam" != "check" ]; then
1875 # run xfs_check and friends on a FS.
1877 _check_xfs_filesystem()
1881 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1885 extra_mount_options=""
1888 if [ -f $device ];then
1892 if [ "$2" != "none" ]; then
1893 extra_log_options="-l$2"
1894 extra_mount_options="-ologdev=$2"
1897 if [ "$3" != "none" ]; then
1898 extra_rt_options="-r$3"
1899 extra_mount_options=$extra_mount_options" -ortdev=$3"
1901 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1903 [ "$FSTYP" != xfs ] && return 0
1905 type=`_fs_type $device`
1908 if [ "$type" = "xfs" ]
1911 mountpoint=`_umount_or_remount_ro $device`
1914 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1915 | tee $tmp.logprint | grep -q "<CLEAN>"
1916 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1918 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1920 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1921 echo "*** xfs_logprint -t output ***" >>$seqres.full
1922 cat $tmp.logprint >>$seqres.full
1923 echo "*** end xfs_logprint output" >>$seqres.full
1928 # xfs_check runs out of memory on large files, so even providing the test
1929 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1930 # large filesystems. Avoid it.
1931 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1932 _xfs_check $extra_log_options $device 2>&1 |\
1933 _fix_malloc >$tmp.fs_check
1935 if [ -s $tmp.fs_check ]
1937 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1939 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1940 echo "*** xfs_check output ***" >>$seqres.full
1941 cat $tmp.fs_check >>$seqres.full
1942 echo "*** end xfs_check output" >>$seqres.full
1947 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1950 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1952 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1953 echo "*** xfs_repair -n output ***" >>$seqres.full
1954 cat $tmp.repair | _fix_malloc >>$seqres.full
1955 echo "*** end xfs_repair output" >>$seqres.full
1959 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1963 echo "*** mount output ***" >>$seqres.full
1964 _mount >>$seqres.full
1965 echo "*** end mount output" >>$seqres.full
1966 elif [ "$type" = "xfs" ]
1968 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1971 if [ $ok -eq 0 ]; then
1973 if [ "$iam" != "check" ]; then
1982 # Filter the knowen errors the UDF Verifier reports.
1983 _udf_test_known_error_filter()
1985 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."
1989 _check_udf_filesystem()
1991 [ "$DISABLE_UDF_TEST" == "1" ] && return
1993 if [ $# -ne 1 -a $# -ne 2 ]
1995 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1999 if [ ! -x $here/src/udf_test ]
2001 echo "udf_test not installed, please download and build the Philips"
2002 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
2003 echo "Then copy the udf_test binary to $here/src/."
2004 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
2012 LAST_BLOCK=`expr \( $2 - 1 \)`
2013 OPT_ARG="-lastvalidblock $LAST_BLOCK"
2016 rm -f $seqres.checkfs
2017 sleep 1 # Due to a problem with time stamps in udf_test
2018 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
2019 _udf_test_known_error_filter | \
2020 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
2021 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
2025 _check_xfs_test_fs()
2029 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
2030 TEST_LOG="$TEST_LOGDEV"
2032 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
2033 TEST_RT="$TEST_RTDEV"
2035 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
2037 # check for ipath consistency
2038 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
2039 # errors go to stderr
2040 xfs_check_ipaths $TEST_DIR >/dev/null
2041 xfs_repair_ipaths -n $TEST_DIR >/dev/null
2045 _check_btrfs_filesystem()
2049 # If type is set, we're mounted
2050 type=`_fs_type $device`
2053 if [ "$type" = "$FSTYP" ]
2056 mountpoint=`_umount_or_remount_ro $device`
2059 btrfsck $device >$tmp.fsck 2>&1
2062 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2064 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2065 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2066 cat $tmp.fsck >>$seqres.full
2067 echo "*** end fsck.$FSTYP output" >>$seqres.full
2075 echo "*** mount output ***" >>$seqres.full
2076 _mount >>$seqres.full
2077 echo "*** end mount output" >>$seqres.full
2078 elif [ "$type" = "$FSTYP" ]
2081 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2085 if [ $ok -eq 0 ]; then
2087 if [ "$iam" != "check" ]; then
2103 # no way to check consistency for nfs
2106 # no way to check consistency for cifs
2109 # do nothing for now
2112 _check_btrfs_filesystem $TEST_DEV
2115 # no way to check consistency for tmpfs
2118 _check_generic_filesystem $TEST_DEV
2126 [ $# -eq 1 ] && device=$1
2132 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2133 SCRATCH_LOG="$SCRATCH_LOGDEV"
2135 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2136 SCRATCH_RT="$SCRATCH_RTDEV"
2138 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2141 _check_udf_filesystem $device $udf_fsize
2144 # Don't know how to check an NFS filesystem, yet.
2147 # Don't know how to check a CIFS filesystem, yet.
2150 _check_btrfs_filesystem $device
2153 # no way to check consistency for tmpfs
2156 _check_generic_filesystem $device
2161 _full_fstyp_details()
2163 [ -z "$FSTYP" ] && FSTYP=xfs
2164 if [ $FSTYP = xfs ]; then
2165 if [ -d /proc/fs/xfs ]; then
2166 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2167 FSTYP="$FSTYP (non-debug)"
2168 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2169 FSTYP="$FSTYP (debug)"
2172 if uname -a | grep -qi 'debug'; then
2173 FSTYP="$FSTYP (debug)"
2175 FSTYP="$FSTYP (non-debug)"
2182 _full_platform_details()
2188 echo "$os/$platform $host $kernel"
2193 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2195 elif [ "`uname`" == "Linux" ]; then
2198 echo Unknown operating system: `uname`
2205 if [ -z "$1" -o -z "$2" ]; then
2206 echo Error must pass src and dst.
2210 SUFFIX=$(_get_os_name())
2220 #takes files, randomdata
2228 if [ $size -gt 0 ]; then
2229 if [ "$2" == "false" ]; then
2230 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2232 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2239 # takes dirname, depth, randomdata
2242 dirname=$1; depth=$2; randomdata=$3
2243 mkdir $dirname || die "mkdir $dirname failed"
2246 _nfiles $files $randomdata # files for this dir and data type
2248 [ $depth -eq 0 ] && return
2249 let deep=$depth-1 # go 1 down
2251 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2254 while [ $d -lt $dirs ]
2256 _descend d$d $deep &
2262 # Populate a filesystem with inodes for performance experiments
2264 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2269 dirs=5 # ndirs in each subdir till leaves
2270 size=0 # sizeof files in K
2271 files=100 # num files in _each_ subdir
2272 depth=2 # depth of tree from root to leaves
2274 root=root # path of initial root of directory tree
2275 randomdata=false # -x data type urandom or zero
2278 while getopts "d:f:n:r:s:v:x" c
2287 x) randomdata=true;;
2291 _descend $root $depth $randomdata
2296 [ $verbose = true ] && echo done
2299 # query whether the given file has the given inode flag set
2306 if which $XFS_IO_PROG >/dev/null; then
2307 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2314 # query the given files extsize allocator hint in bytes (if any)
2321 if which $XFS_IO_PROG >/dev/null; then
2322 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2323 awk '/^xattr.extsize =/ { print $3 }'`
2325 [ -z "$blocks" ] && blocks="0"
2329 # scratch_dev_pool should contain the disks pool for the btrfs raid
2330 _require_scratch_dev_pool()
2335 if [ -z "$SCRATCH_DEV_POOL" ]; then
2336 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2339 if [ -z "$1" ]; then
2345 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2349 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2350 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2354 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2358 for i in $SCRATCH_DEV_POOL; do
2359 if [ "`_is_block_dev "$i"`" = "" ]; then
2360 _notrun "this test requires valid block disk $i"
2362 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2363 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2365 if _mount | grep -q $i; then
2366 if ! $UMOUNT_PROG $i; then
2367 echo "failed to unmount $i - aborting"
2371 # to help better debug when something fails, we remove
2372 # traces of previous btrfs FS on the dev.
2373 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2377 # ensure devices in SCRATCH_DEV_POOL are of the same size
2378 # must be called after _require_scratch_dev_pool
2379 _require_scratch_dev_pool_equal_size()
2385 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2386 _size=`_get_device_size $SCRATCH_DEV`
2387 for _dev in $SCRATCH_DEV_POOL; do
2388 _newsize=`_get_device_size $_dev`
2389 if [ $_size -ne $_newsize ]; then
2390 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2395 # We will check if the device is deletable
2396 _require_deletable_scratch_dev_pool()
2400 for i in $SCRATCH_DEV_POOL; do
2401 x=`echo $i | cut -d"/" -f 3`
2402 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2403 _notrun "$i is a device which is not deletable"
2408 # We check for btrfs and (optionally) features of the btrfs command
2412 _require_command "$BTRFS_UTIL_PROG" btrfs
2413 if [ -z "$1" ]; then
2416 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2417 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2420 # Check that fio is present, and it is able to execute given jobfile
2425 _require_command "$FIO_PROG" fio
2426 if [ -z "$1" ]; then
2430 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2431 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2434 # Does freeze work on this fs?
2437 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2439 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2440 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2443 # Does shutdown work on this fs?
2444 _require_scratch_shutdown()
2446 [ -x src/godown ] || _notrun "src/godown executable not found"
2448 _scratch_mkfs > /dev/null 2>&1
2450 src/godown -f $SCRATCH_MNT 2>&1 \
2451 || _notrun "$FSTYP does not support shutdown"
2455 # Does norecovery support by this fs?
2456 _require_norecovery()
2458 _scratch_mount -o ro,norecovery || \
2459 _notrun "$FSTYP does not support norecovery"
2463 # Does this filesystem support metadata journaling?
2464 # We exclude ones here that don't; otherwise we assume that it does, so the
2465 # test will run, fail, and motivate someone to update this test for a new
2468 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2469 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2471 _require_metadata_journaling()
2481 _notrun "$FSTYP does not support metadata journaling"
2484 # ext4 could be mkfs'd without a journal...
2486 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2487 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2490 # by default we pass; if you need to, add your fs above!
2495 # Does fiemap support?
2498 _require_xfs_io_command "fiemap"
2503 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
2508 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep hole | wc -l
2511 # arg 1 is dev to remove and is output of the below eg.
2512 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2518 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2520 stat $disk > /dev/null 2>&1
2521 while [ $? -eq 0 ]; do
2523 stat $disk > /dev/null 2>&1
2527 # arg 1 is dev to add and is output of the below eg.
2528 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2533 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2534 h=`echo ${1} | cut -d":" -f 1`
2535 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2537 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2539 # ensure the device comes online
2541 for i in `seq 1 10`; do
2542 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2543 dev=`ls /sys/class/scsi_device/${1}/device/block`
2544 for j in `seq 1 10`;
2546 stat /dev/$dev > /dev/null 2>&1
2547 if [ $? -eq 0 ]; then
2558 if [ $dev_back_oneline -eq 0 ]; then
2559 echo "/dev/$dev online failed" >> $seqres.full
2561 echo "/dev/$dev is back online" >> $seqres.full
2567 if [ -z "$FSTRIM_PROG" ]; then
2568 _notrun "This test requires fstrim utility."
2572 _require_batched_discard()
2574 if [ $# -ne 1 ]; then
2575 echo "Usage: _require_batched_discard mnt_point" 1>&2
2579 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2584 if [ -z "$DUMPE2FS_PROG" ]; then
2585 _notrun "This test requires dumpe2fs utility."
2591 if [ ! -e /proc/self/uid_map ]; then
2592 _notrun "This test requires procfs uid_map support."
2594 if [ ! -e /proc/self/gid_map ]; then
2595 _notrun "This test requires procfs gid_map support."
2601 FSSUM_PROG=$here/src/fssum
2602 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2607 CLONER_PROG=$here/src/cloner
2608 [ -x $CLONER_PROG ] || \
2609 _notrun "cloner binary not present at $CLONER_PROG"
2614 if [ "$FSTYP" == "nfs" ]; then
2615 _notrun "atime related mount options have no effect on NFS"
2621 _scratch_mkfs > /dev/null 2>&1
2622 _scratch_mount -o relatime || \
2623 _notrun "relatime not supported by the current kernel"
2629 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2630 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2633 _create_loop_device()
2636 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2640 _destroy_loop_device()
2643 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2646 _scale_fsstress_args()
2649 while [ $# -gt 0 ]; do
2651 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2652 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2653 *) args="$args $1" ;;
2661 # Return the logical block size if running on a block device,
2662 # else substitute the page size.
2664 _min_dio_alignment()
2668 if [ -b "$dev" ]; then
2669 blockdev --getss $dev
2671 $here/src/feature -s
2677 echo "# $@" >> $seqres.full 2>&1
2678 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2681 _run_btrfs_util_prog()
2683 run_check $BTRFS_UTIL_PROG $*
2686 _require_btrfs_send_stream_version()
2688 $BTRFS_UTIL_PROG send 2>&1 | \
2689 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2690 if [ $? -ne 0 ]; then
2691 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2694 # test if btrfs kernel supports send stream version 2
2695 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2696 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2700 _require_btrfs_mkfs_feature()
2703 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2707 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2708 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2710 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2713 _require_btrfs_fs_feature()
2716 echo "Missing feature name argument for _require_btrfs_fs_feature"
2720 modprobe btrfs > /dev/null 2>&1
2721 [ -e /sys/fs/btrfs/features/$feat ] || \
2722 _notrun "Feature $feat not supported by the available btrfs version"
2725 _require_test_symlinks()
2727 # IRIX UDF does not support symlinks
2728 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2729 _notrun "Require symlinks support"
2730 target=`mktemp -p $TEST_DIR`
2731 link=`mktemp -p $TEST_DIR -u`
2732 ln -s `basename $target` $link
2733 if [ "$?" -ne 0 ]; then
2735 _notrun "Require symlinks support"
2740 _require_test_fcntl_advisory_locks()
2742 [ "$FSTYP" != "cifs" ] && return 0
2743 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2744 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2745 _notrun "Require fcntl advisory locks support"
2748 # XFS ability to change UUIDs on V5/CRC filesystems
2750 _require_meta_uuid()
2752 # This will create a crc fs on $SCRATCH_DEV
2755 $XFS_DB_PROG -x -c "uuid restore" $SCRATCH_DEV 2>&1 \
2756 | grep -q "invalid UUID\|supported on V5 fs" \
2757 && _notrun "Userspace doesn't support meta_uuid feature"
2759 $XFS_DB_PROG -x -c "uuid generate" $SCRATCH_DEV >/dev/null 2>&1
2761 _scratch_mount >/dev/null 2>&1 \
2762 || _notrun "Kernel doesn't support meta_uuid feature"
2766 _require_btrfs_dev_del_by_devid()
2768 $BTRFS_UTIL_PROG device delete --help | egrep devid > /dev/null 2>&1
2769 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old "\
2770 "(must support 'btrfs device delete <devid> /<mnt>')"
2773 _require_test_lsattr()
2775 testio=$(lsattr -d $TEST_DIR 2>&1)
2776 echo $testio | grep -q "Operation not supported" && \
2777 _notrun "lsattr not supported by test filesystem type: $FSTYP"
2778 echo $testio | grep -q "Inappropriate ioctl for device" && \
2779 _notrun "lsattr not supported by test filesystem type: $FSTYP"
2784 if [ -z "$1" ]; then
2785 echo "Usage: _get_total_inode <mnt>"
2789 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2795 if [ -z "$1" ]; then
2796 echo "Usage: _get_used_inode <mnt>"
2800 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2804 _get_used_inode_percent()
2806 if [ -z "$1" ]; then
2807 echo "Usage: _get_used_inode_percent <mnt>"
2811 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
2818 if [ -z "$1" ]; then
2819 echo "Usage: _get_free_inode <mnt>"
2823 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2827 # get the available space in bytes
2829 _get_available_space()
2831 if [ -z "$1" ]; then
2832 echo "Usage: _get_available_space <mnt>"
2836 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
2837 echo $((avail_kb * 1024))
2840 # get btrfs profile configs being tested
2842 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2843 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2844 # var in the format "metadata_profile:data_profile", multiple configs can be
2845 # seperated by space, e.g.
2846 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2847 _btrfs_get_profile_configs()
2849 if [ "$FSTYP" != "btrfs" ]; then
2853 # no user specified btrfs profile configs, export the default configs
2854 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2856 _btrfs_profile_configs=(
2857 "-m single -d single"
2862 "-m raid10 -d raid10"
2867 # remove dup/raid5/raid6 profiles if we're doing device replace
2868 # dup profile indicates only one device being used (SCRATCH_DEV),
2869 # but we don't want to replace SCRATCH_DEV, which will be used in
2870 # _scratch_mount/_check_scratch_fs etc.
2871 # and raid5/raid6 doesn't support replace yet
2872 if [ "$1" == "replace" ]; then
2873 _btrfs_profile_configs=(
2874 "-m single -d single"
2878 "-m raid10 -d raid10"
2879 # add these back when raid5/6 is working with replace
2880 #"-m raid5 -d raid5"
2881 #"-m raid6 -d raid6"
2884 export _btrfs_profile_configs
2888 # parse user specified btrfs profile configs
2891 for cfg in $BTRFS_PROFILE_CONFIGS; do
2892 # turn "metadata:data" format to "-m metadata -d data"
2893 # and assign it to _btrfs_profile_configs array
2894 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2895 _btrfs_profile_configs[$i]="$cfg"
2899 if [ "$1" == "replace" ]; then
2900 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2901 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2903 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2904 _notrun "Do not set dup profile in btrfs device replace test"
2907 export _btrfs_profile_configs
2910 # stress btrfs by running balance operation in a loop
2911 _btrfs_stress_balance()
2915 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2919 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2920 _btrfs_stress_subvolume()
2924 local subvol_name=$3
2927 mkdir -p $subvol_mnt
2929 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2930 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2931 $UMOUNT_PROG $subvol_mnt
2932 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2936 # stress btrfs by running scrub in a loop
2937 _btrfs_stress_scrub()
2941 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2945 # stress btrfs by defragmenting every file/dir in a loop and compress file
2946 # contents while defragmenting if second argument is not "nocompress"
2947 _btrfs_stress_defrag()
2953 if [ "$compress" == "nocompress" ]; then
2954 find $btrfs_mnt \( -type f -o -type d \) -exec \
2955 $BTRFS_UTIL_PROG filesystem defrag {} \;
2957 find $btrfs_mnt \( -type f -o -type d \) -exec \
2958 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2959 find $btrfs_mnt \( -type f -o -type d \) -exec \
2960 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2965 # stress btrfs by remounting it with different compression algorithms in a loop
2966 # run this with fsstress running at background could exercise the compression
2967 # code path and ensure no race when switching compression algorithm with constant
2969 _btrfs_stress_remount_compress()
2973 for algo in no zlib lzo; do
2974 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2979 # stress btrfs by replacing devices in a loop
2980 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2981 # device should be free(not used by btrfs)
2982 _btrfs_stress_replace()
2986 # The device number in SCRATCH_DEV_POOL should be at least 3,
2987 # one is SCRATCH_DEV, one is to be replaced, one is free device
2988 # we won't replace SCRATCH_DEV, see below for reason
2989 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2990 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2994 # take the last device as the first free_dev
2995 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2997 # free_dev should be really free
2998 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2999 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
3003 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
3004 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
3005 # _scratch_mount and _check_scratch_fs etc.
3006 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
3007 -e "s# *$free_dev *##"`
3009 # set the first device in dev_pool as the first src_dev to be replaced
3010 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3012 echo "dev_pool=$dev_pool"
3013 echo "free_dev=$free_dev, src_dev=$src_dev"
3015 echo "Replacing $src_dev with $free_dev"
3016 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
3017 if [ $? -ne 0 ]; then
3018 # don't update src_dev and free_dev if replace failed
3021 dev_pool="$dev_pool $free_dev"
3022 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
3024 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
3028 # find the right option to force output in bytes, older versions of btrfs-progs
3029 # print that by default, newer print human readable numbers with unit suffix
3030 _btrfs_qgroup_units()
3032 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
3035 # return device size in kb
3038 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
3041 # check dmesg log for WARNING/Oops/etc.
3044 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
3047 rm -f ${RESULT_DIR}/check_dmesg
3049 # default filter is a simple cat command, caller could provide a
3050 # customized filter and pass the name through the first argument, to
3051 # filter out intentional WARNINGs or Oopses
3054 # search the dmesg log of last run of $seqnum for possible failures
3055 # use sed \cregexpc address type, since $seqnum contains "/"
3056 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
3057 tac | $filter >$seqres.dmesg
3058 grep -q -e "kernel BUG at" \
3062 -e "possible recursive locking detected" \
3063 -e "Internal error" \
3064 -e "INFO: suspicious RCU usage" \
3065 -e "INFO: possible circular locking dependency detected" \
3067 if [ $? -eq 0 ]; then
3068 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3076 # don't check dmesg log after test
3077 _disable_dmesg_check()
3079 rm -f ${RESULT_DIR}/check_dmesg
3084 if [ "$iam" == new ]
3088 # make some further configuration checks here
3089 if [ "$TEST_DEV" = "" ]
3091 echo "common/rc: Error: \$TEST_DEV is not set"
3095 # if $TEST_DEV is not mounted, mount it now as XFS
3096 if [ -z "`_fs_type $TEST_DEV`" ]
3098 # $TEST_DEV is not mounted
3101 echo "common/rc: retrying test device mount with external set"
3102 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3105 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3111 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3113 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3117 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3118 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3119 export XFS_IO_PROG="$XFS_IO_PROG -F"
3121 # xfs_copy doesn't work on v5 xfs yet without -d option
3122 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3123 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3127 # get real device path name by following link
3131 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3132 _dev=`readlink -f "$_dev"`
3137 # basename of a device
3140 echo `basename $(_real_dev $1)`
3146 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3147 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3148 _maj=$(echo "ibase=16; $_maj" | bc)
3149 _min=$(echo "ibase=16; $_min" | bc)
3150 echo /sys/dev/block/$_maj:$_min
3155 if [ -z $1 ] || [ ! -d $1 ]; then
3156 echo "Missing mount point argument for get_block_size"
3159 echo `stat -f -c %S $1`
3164 ################################################################################
3165 # make sure this script returns success