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_NAME="[0-9]\{3\}-\?[[:alnum:]-]*"
38 _notrun "this test requires 'bc' tool for doing math operations"
44 [ $# -le 0 ] && return
46 result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
48 _notrun "this test requires 'bc' tool for doing math operations"
55 if [ "$HOSTOS" == "Linux" ]
57 command dd --help 2>&1 | grep noxfer >/dev/null
61 command dd status=noxfer $@
75 $BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
78 # Prints the md5 checksum of a given file
81 md5sum $1 | cut -d ' ' -f1
85 # ls -l w/ selinux sometimes puts a dot at the end:
86 # -rwxrw-r--. id1 id2 file1
87 # Also filter out lost+found directory on extN file system if present
91 ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
94 # we need common/config
95 if [ "$iam" != "check" ]
97 if ! . ./common/config
99 echo "$iam: failed to source common/config"
104 # check for correct setup
107 [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
108 [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
109 [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
110 [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found"
113 [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
116 [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
119 [ "$MKFS_EXT4_PROG" = "" ] && _fatal "mkfs.ext4 not found"
122 [ "$MKFS_F2FS_PROG" = "" ] && _fatal "mkfs.f2fs not found"
129 [ "$MKFS_REISER4_PROG" = "" ] && _fatal "mkfs.reiser4 not found"
133 # make sure we have a standard umask
138 $MOUNT_PROG `_mount_ops_filter $*`
146 if [ "$FSTYP" != "xfs" ]; then
152 [ "$HOSTOS" != "IRIX" ] && SCRATCH_OPTIONS="$SCRATCH_OPTIONS -f"
161 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
162 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${rt_opt}rtdev=$SCRATCH_RTDEV"
163 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
164 SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}logdev=$SCRATCH_LOGDEV"
172 if [ "$FSTYP" != "xfs" ]; then
186 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
187 TEST_OPTIONS="$TEST_OPTIONS ${rt_opt}rtdev=$TEST_RTDEV"
188 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
189 TEST_OPTIONS="$TEST_OPTIONS ${log_opt}logdev=$TEST_LOGDEV"
196 #get mount point to handle dmapi mtpt option correctly
198 [ $last_index -gt 0 ] && shift $last_index
201 # irix is fussy about how it is fed its mount options
202 # - multiple -o's are not allowed
203 # - no spaces between comma delimitered options
204 # the sed script replaces all -o's (except the first) with a comma
205 # not required for linux, but won't hurt
207 echo $params | sed -e 's/[[:space:]]\+-o[[:space:]]*/UnIqUe/1; s/[[:space:]]\+-o[[:space:]]*/,/g; s/UnIqUe/ -o /1' \
208 | sed -e 's/dmapi/dmi/' \
209 | $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$FS_ESCAPED\1\2#; print;"
213 _scratch_mount_options()
215 _scratch_options mount
217 echo $SCRATCH_OPTIONS $MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS $* $SCRATCH_DEV $SCRATCH_MNT
222 _mount -t $FSTYP `_scratch_mount_options $*`
227 $UMOUNT_PROG $SCRATCH_DEV
239 _mount -t $FSTYP $TEST_OPTIONS $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS $* $TEST_DEV $TEST_DIR
244 $UMOUNT_PROG $TEST_DEV
248 _scratch_mkfs_options()
250 _scratch_options mkfs
251 echo $SCRATCH_OPTIONS $MKFS_OPTIONS $* $SCRATCH_DEV
259 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
260 options="-l $SCRATCH_LOGDEV"
262 xfs_metadump $options $SCRATCH_DEV $dumpfile
265 _setup_large_xfs_fs()
270 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
271 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
272 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
274 # calculate the size of the file we need to allocate.
275 # Default free space in the FS is 50GB, but you can specify more via
276 # SCRATCH_DEV_EMPTY_SPACE
277 file_size=$(($fs_size - 50*1024*1024*1024))
278 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
280 # mount the filesystem, create the file, unmount it
281 _scratch_mount 2>&1 >$tmp_dir/mnt.err
283 if [ $status -ne 0 ]; then
285 cat $tmp_dir/mnt.err >&2
286 rm -f $tmp_dir/mnt.err
289 rm -f $tmp_dir/mnt.err
292 -c "truncate $file_size" \
293 -c "falloc -k 0 $file_size" \
295 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
296 export NUM_SPACE_FILES=1
299 if [ $status -ne 0 ]; then
300 echo "large file prealloc failed"
301 cat $tmp_dir/mnt.err >&2
307 _scratch_mkfs_xfs_opts()
311 # remove crc related mkfs options if mkfs.xfs doesn't support v5 xfs
312 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
313 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+crc=.//"`
316 _scratch_options mkfs
318 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
322 _scratch_mkfs_xfs_supported()
326 _scratch_options mkfs
328 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
333 # extra mkfs options can be added by tests
334 local extra_mkfs_options=$*
338 # save mkfs output in case conflict means we need to run again.
339 # only the output for the mkfs that applies should be shown
340 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
341 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
345 # a mkfs failure may be caused by conflicts between
346 # $MKFS_OPTIONS and $extra_mkfs_options
347 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
349 echo -n "** mkfs failed with extra mkfs options "
350 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
351 echo -n "** attempting to mkfs using only test $seq "
352 echo "options: $extra_mkfs_options **"
355 # running mkfs again. overwrite previous mkfs output files
356 _scratch_mkfs_xfs_opts $extra_mkfs_options \
357 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
361 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
362 # manually parse the mkfs output to get the fs size in bytes
364 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
365 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
367 print STDOUT "$size\n";
369 _setup_large_xfs_fs $fs_size
373 # output stored mkfs output, filtering unnecessary warnings from stderr
375 cat $tmp_dir.mkfserr | sed \
376 -e '/less than device physical sector/d' \
377 -e '/switching to logical sector/d' \
379 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
384 # xfs_check script is planned to be deprecated. But, we want to
385 # be able to invoke "xfs_check" behavior in xfstests in order to
386 # maintain the current verification levels.
391 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
393 while getopts "b:fi:l:stvV" c
399 i) OPTS=$OPTS"-i "$OPTARG" ";;
400 b) OPTS=$OPTS"-b "$OPTARG" ";;
401 f) DBOPTS=$DBOPTS" -f";;
402 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
403 V) $XFS_DB_PROG -p xfs_check -V
411 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
421 _setup_large_ext4_fs()
426 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
427 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
428 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
430 # Default free space in the FS is 50GB, but you can specify more via
431 # SCRATCH_DEV_EMPTY_SPACE
432 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
434 # mount the filesystem and create 16TB - 4KB files until we consume
435 # all the necessary space.
436 _scratch_mount 2>&1 >$tmp_dir/mnt.err
438 if [ $status -ne 0 ]; then
440 cat $tmp_dir/mnt.err >&2
441 rm -f $tmp_dir/mnt.err
444 rm -f $tmp_dir/mnt.err
446 file_size=$((16*1024*1024*1024*1024 - 4096))
448 while [ $space_to_consume -gt $file_size ]; do
451 -c "truncate $file_size" \
452 -c "falloc -k 0 $file_size" \
453 $SCRATCH_MNT/.use_space.$nfiles 2>&1
455 if [ $status -ne 0 ]; then
459 space_to_consume=$(( $space_to_consume - $file_size ))
460 nfiles=$(($nfiles + 1))
463 # consume the remaining space.
464 if [ $space_to_consume -gt 0 ]; then
466 -c "truncate $space_to_consume" \
467 -c "falloc -k 0 $space_to_consume" \
468 $SCRATCH_MNT/.use_space.$nfiles 2>&1
471 export NUM_SPACE_FILES=$nfiles
474 if [ $status -ne 0 ]; then
475 echo "large file prealloc failed"
476 cat $tmp_dir/mnt.err >&2
484 # extra mkfs options can be added by tests
485 local extra_mkfs_options=$*
489 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
490 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
493 # a mkfs failure may be caused by conflicts between
494 # $MKFS_OPTIONS and $extra_mkfs_options
495 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
497 echo -n "** mkfs failed with extra mkfs options "
498 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
499 echo -n "** attempting to mkfs using only test $seq "
500 echo "options: $extra_mkfs_options **"
503 # running mkfs again. overwrite previous mkfs output files
504 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
505 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
509 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
510 # manually parse the mkfs output to get the fs size in bytes
511 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
512 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
513 / inodes, / { blks = $3 } \
514 /reserved for the super user/ { resv = $1 } \
515 END { fssize = bs * blks - resv; print fssize }'`
517 _setup_large_ext4_fs $fs_size
521 # output stored mkfs output
522 cat $tmp_dir.mkfserr >&2
524 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
536 # do nothing for cifs
539 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
542 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
545 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
548 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
560 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
563 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
566 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
567 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
571 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
572 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
576 if [ $? -ne 0 ]; then
577 # output stored mkfs output
578 cat $tmp_dir.mkfserr >&2
583 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
586 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
587 _scratch_cleanup_files()
590 rm -rf $SCRATCH_MNT/*
601 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
602 # avoid EEXIST caused by the leftover files created in previous runs
603 _scratch_cleanup_files
606 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
607 # avoid EEXIST caused by the leftover files created in previous runs
608 _scratch_cleanup_files
611 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
614 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
617 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
620 _scratch_mkfs_ext4 $*
623 # do nothing for tmpfs
626 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
629 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
638 # if dup profile is in mkfs options call _scratch_mkfs instead
639 # because dup profile only works with single device
640 if [[ "$*" =~ dup ]]; then
643 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
647 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
652 # Create fs of certain size on scratch device
653 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
654 _scratch_mkfs_sized()
661 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
663 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
664 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
668 [ -n "$def_blksz" ] && blocksize=$def_blksz
669 [ -z "$blocksize" ] && blocksize=4096
673 if ! [[ $fssize =~ $re ]] ; then
674 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
676 if ! [[ $blocksize =~ $re ]] ; then
677 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
680 blocks=`expr $fssize / $blocksize`
682 if [ "$HOSTOS" == "Linux" ]; then
683 devsize=`blockdev --getsize64 $SCRATCH_DEV`
684 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
689 # don't override MKFS_OPTIONS that set a block size.
690 echo $MKFS_OPTIONS |egrep -q "b?size="
691 if [ $? -eq 0 ]; then
692 _scratch_mkfs_xfs -d size=$fssize
694 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
697 ext2|ext3|ext4|ext4dev)
698 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
701 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
704 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
707 # mkfs.resier4 requires size in KB as input for creating filesystem
708 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
709 `expr $fssize / 1024`
712 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
717 # Emulate an N-data-disk stripe w/ various stripe units
718 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
724 [ -z "$blocksize" ] && blocksize=4096
726 let sunit_blocks=$sunit_bytes/$blocksize
727 let swidth_blocks=$sunit_blocks*$swidth_mult
731 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
734 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
737 _notrun "can't mkfs $FSTYP with geometry"
747 xfs_io -x -c "resblks $1" $SCRATCH_MNT
754 _scratch_xfs_db_options()
757 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
758 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
759 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
762 _scratch_xfs_logprint()
765 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
766 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
767 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
773 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
774 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
775 [ "$LARGE_SCRATCH_DEV" = yes ] && \
776 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
777 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
780 _scratch_xfs_repair()
783 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
784 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
785 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
786 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
787 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
788 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
795 echo "Usage: _get_pids_by_name process-name" 1>&2
799 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
800 # HH:MM:SS before the psargs field, use this as the search anchor.
802 # Matches with $1 (process-name) occur if the first psarg is $1
803 # or ends in /$1 ... the matching uses sed's regular expressions,
804 # so passing a regex into $1 will work.
812 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
813 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
816 # fix malloc libs output
820 # filter out the Electric Fence notice
823 if (defined $o && /^\s+Electric Fence/) {
829 print $o if (defined $o);
833 print $o if (defined $o);
837 # check if run as root
841 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
844 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
851 # _df_device : get an IRIX style df line for a given device
853 # - returns "" if not mounted
854 # - returns fs type in field two (ala IRIX)
855 # - joins line together if split by fancy df formatting
856 # - strips header etc
863 echo "Usage: _df_device device" 1>&2
867 # Note that we use "==" here so awk doesn't try to interpret an NFS over
868 # IPv6 server as a regular expression.
869 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
870 ($1==what) && (NF==1) {
884 # _df_dir : get an IRIX style df line for device where a directory resides
886 # - returns fs type in field two (ala IRIX)
887 # - joins line together if split by fancy df formatting
888 # - strips header etc
895 echo "Usage: _df_dir device" 1>&2
899 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
915 # return percentage used disk space for mounted device
921 echo "Usage: _used device" 1>&2
925 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
928 # return the FS type of a mounted device
934 echo "Usage: _fs_type device" 1>&2
939 # The Linux kernel shows NFSv4 filesystems in df output as
940 # filesystem type nfs4, although we mounted it as nfs earlier.
941 # Fix the filesystem type up here so that the callers don't
942 # have to bother with this quirk.
944 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
947 # return the FS mount options of a mounted device
949 # should write a version which just parses the output of mount for IRIX
950 # compatibility, but since this isn't used at all, at the moment I'll leave
957 echo "Usage: _fs_options device" 1>&2
961 $AWK_PROG -v dev=$1 '
962 match($1,dev) { print $4 }
966 # returns device number if a file is a block device
972 echo "Usage: _is_block_dev dev" 1>&2
977 if [ -L "${_dev}" ]; then
978 _dev=`readlink -f "${_dev}"`
981 if [ -b "${_dev}" ]; then
982 src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
986 # Do a command, log it to $seqres.full, optionally test return status
987 # and die if command fails. If called with one argument _do executes the
988 # command, logs it, and returns its exit status. With two arguments _do
989 # first prints the message passed in the first argument, and then "done"
990 # or "fail" depending on the return status of the command passed in the
991 # second argument. If the command fails and the variable _do_die_on_error
992 # is set to "always" or the two argument form is used and _do_die_on_error
993 # is set to "message_only" _do will print an error message to
994 # $seqres.out and exit.
998 if [ $# -eq 1 ]; then
1000 elif [ $# -eq 2 ]; then
1003 echo -n "$_note... "
1005 echo "Usage: _do [note] cmd" 1>&2
1009 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1010 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1011 cat $tmp._out | _fix_malloc >>$seqres.full
1012 if [ $# -eq 2 ]; then
1013 if [ $ret -eq 0 ]; then
1020 && [ "$_do_die_on_error" = "always" \
1021 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1023 [ $# -ne 2 ] && echo
1024 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1031 # bail out, setting up .notrun file. Need to kill the filesystem check files
1032 # here, otherwise they are set incorrectly for the next test.
1036 echo "$*" > $seqres.notrun
1037 echo "$seq not run: $*"
1038 rm -f ${RESULT_DIR}/require_test
1039 rm -f ${RESULT_DIR}/require_scratch
1044 # just plain bail out
1048 echo "$*" | tee -a $seqres.full
1049 echo "(see $seqres.full for details)"
1054 # tests whether $FSTYP is one of the supported filesystems for a test
1060 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1066 _notrun "not suitable for this filesystem type: $FSTYP"
1070 # tests whether $FSTYP is one of the supported OSes for a test
1076 if [ "$h" = "$HOSTOS" ]
1082 _notrun "not suitable for this OS: $HOSTOS"
1085 # this test needs a scratch partition - check we're ok & unmount it
1086 # No post-test check of the device is required. e.g. the test intentionally
1087 # finishes the test with the filesystem in a corrupt state
1088 _require_scratch_nocheck()
1092 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1093 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1094 _notrun "this test requires a valid \$SCRATCH_DEV"
1096 if [ ! -d "$SCRATCH_MNT" ]; then
1097 _notrun "this test requires a valid \$SCRATCH_MNT"
1101 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1102 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1103 _notrun "this test requires a valid \$SCRATCH_DEV"
1105 if [ ! -d "$SCRATCH_MNT" ]; then
1106 _notrun "this test requires a valid \$SCRATCH_MNT"
1110 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1112 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1116 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
1118 _notrun "this test requires a valid \$SCRATCH_DEV"
1120 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1122 _notrun "this test requires a valid \$SCRATCH_DEV"
1124 if [ ! -d "$SCRATCH_MNT" ]
1126 _notrun "this test requires a valid \$SCRATCH_MNT"
1132 # Note that we use -F here so grep doesn't try to interpret an NFS over
1133 # IPv6 server as a regular expression.
1134 if _mount | grep -F -q $SCRATCH_DEV
1136 # if it's mounted, make sure its on $SCRATCH_MNT
1137 if ! _mount | grep -F $SCRATCH_DEV | grep -q $SCRATCH_MNT
1139 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1142 # and then unmount it
1143 if ! $UMOUNT_PROG $SCRATCH_DEV
1145 echo "failed to unmount $SCRATCH_DEV"
1149 rm -f ${RESULT_DIR}/require_scratch
1152 # we need the scratch device and it should be checked post test.
1155 _require_scratch_nocheck
1156 touch ${RESULT_DIR}/require_scratch
1160 # this test needs a test partition - check we're ok & mount it
1166 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1167 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1168 _notrun "this test requires a valid \$TEST_DIR"
1170 if [ ! -d "$TEST_DIR" ]; then
1171 _notrun "this test requires a valid \$TEST_DIR"
1175 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1176 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1177 _notrun "this test requires a valid \$TEST_DEV"
1179 if [ ! -d "$TEST_DIR" ]; then
1180 _notrun "this test requires a valid \$TEST_DIR"
1184 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1186 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1190 if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
1192 _notrun "this test requires a valid \$TEST_DEV"
1194 if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
1196 _notrun "this test requires a valid \$TEST_DEV"
1198 if [ ! -d "$TEST_DIR" ]
1200 _notrun "this test requires a valid \$TEST_DIR"
1206 # Note that we use -F here so grep doesn't try to interpret an NFS over
1207 # IPv6 server as a regular expression.
1208 if _mount | grep -F -q $TEST_DEV
1210 # if it's mounted, make sure its on $TEST_DIR
1211 if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
1213 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1217 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1218 if [ $? -ne 1 ]; then
1223 touch ${RESULT_DIR}/require_test
1226 # this test needs a logdev
1230 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1231 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1232 [ "$USE_EXTERNAL" != yes ] && \
1233 _notrun "This test requires USE_EXTERNAL to be enabled"
1235 # ensure its not mounted
1236 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1239 # this test requires loopback device support
1243 if [ "$HOSTOS" != "Linux" ]
1245 _notrun "This test requires linux for loopback device support"
1248 modprobe loop >/dev/null 2>&1
1249 if grep loop /proc/devices >/dev/null 2>&1
1253 _notrun "This test requires loopback device support"
1257 # this test requires ext2 filesystem support
1261 if [ "$HOSTOS" != "Linux" ]
1263 _notrun "This test requires linux for ext2 filesystem support"
1266 modprobe ext2 >/dev/null 2>&1
1267 if grep ext2 /proc/filesystems >/dev/null 2>&1
1271 _notrun "This test requires ext2 filesystem support"
1275 # this test requires that (large) loopback device files are not in use
1277 _require_no_large_scratch_dev()
1279 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1280 _notrun "Large filesystem testing in progress, skipped this test"
1283 # this test requires that a realtime subvolume is in use, and
1284 # that the kernel supports realtime as well.
1288 [ "$USE_EXTERNAL" = yes ] || \
1289 _notrun "External volumes not in use, skipped this test"
1290 [ "$SCRATCH_RTDEV" = "" ] && \
1291 _notrun "Realtime device required, skipped this test"
1294 # this test requires that a specified command (executable) exists
1295 # $1 - command, $2 - name for error message
1297 # Note: the command string might have parameters, so strip them before checking
1298 # whether it is executable.
1301 if [ $# -eq 2 ]; then
1303 elif [ $# -eq 1 ]; then
1306 _fail "usage: _require_command <command> [<name>]"
1309 _command=`echo "$1" | awk '{ print $1 }'`
1310 if [ ! -x "$_command" ]; then
1311 _notrun "$_name utility required, skipped this test"
1315 # this test requires the device to be valid block device
1317 _require_block_device()
1319 if [ -z "$1" ]; then
1320 echo "Usage: _require_block_device <dev>" 1>&2
1323 if [ "`_is_block_dev "$1"`" == "" ]; then
1324 _notrun "require $1 to be valid block disk"
1328 # brd based ram disks erase the device when they receive a flush command when no
1329 # active references are present. This causes problems for DM devices sitting on
1330 # top of brd devices as DM doesn't hold active references to the brd device.
1331 _require_sane_bdev_flush()
1333 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1334 if [ $? -eq 0 ]; then
1335 _notrun "This test requires a sane block device flush"
1339 # this test requires the device mapper flakey target
1341 _require_dm_flakey()
1343 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1345 _require_block_device $SCRATCH_DEV
1346 _require_sane_bdev_flush $SCRATCH_DEV
1347 _require_command "$DMSETUP_PROG" dmsetup
1349 modprobe dm-flakey >/dev/null 2>&1
1350 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1351 if [ $? -ne 0 ]; then
1352 _notrun "This test requires dm flakey support"
1356 _require_dm_snapshot()
1358 _require_block_device $SCRATCH_DEV
1359 _require_sane_bdev_flush $SCRATCH_DEV
1360 _require_command "$DMSETUP_PROG" dmsetup
1361 modprobe dm-snapshot >/dev/null 2>&1
1362 $DMSETUP_PROG targets | grep -q snapshot
1363 if [ $? -ne 0 ]; then
1364 _notrun "This test requires dm snapshot support"
1368 # this test requires the projid32bit feature to be available in mkfs.xfs.
1370 _require_projid32bit()
1372 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1373 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1376 _require_projid16bit()
1378 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1379 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1382 # this test requires the crc feature to be available in mkfs.xfs
1384 _require_xfs_mkfs_crc()
1386 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1387 || _notrun "mkfs.xfs doesn't have crc feature"
1390 # this test requires the xfs kernel support crc feature
1394 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1395 _scratch_mount >/dev/null 2>&1 \
1396 || _notrun "Kernel doesn't support crc feature"
1400 # this test requires the bigalloc feature to be available in mkfs.ext4
1402 _require_ext4_mkfs_bigalloc()
1404 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1405 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1408 # this test requires the ext4 kernel support bigalloc feature
1410 _require_ext4_bigalloc()
1412 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1413 _scratch_mount >/dev/null 2>&1 \
1414 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1418 # this test requires the finobt feature to be available in mkfs.xfs
1420 _require_xfs_mkfs_finobt()
1422 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1423 || _notrun "mkfs.xfs doesn't have finobt feature"
1426 # this test requires the xfs kernel support finobt feature
1428 _require_xfs_finobt()
1430 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1431 _scratch_mount >/dev/null 2>&1 \
1432 || _notrun "Kernel doesn't support finobt feature"
1436 # this test requires xfs sysfs attribute support
1438 _require_xfs_sysfs()
1441 sysfsdir=/sys/fs/xfs
1443 if [ ! -e $sysfsdir ]; then
1444 _notrun "no kernel support for XFS sysfs attributes"
1447 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1448 _notrun "sysfs attribute '$attr' is not supported"
1452 # this test requires that external log/realtime devices are not in use
1454 _require_nonexternal()
1456 [ "$USE_EXTERNAL" = yes ] && \
1457 _notrun "External device testing in progress, skipped this test"
1460 # this test requires that a (specified) aio-dio executable exists
1461 # $1 - command (optional)
1467 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1468 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1470 AIO_TEST=src/aio-dio-regress/$1
1471 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1476 # run an aio-dio program
1482 echo "usage: _run_aiodio command_name" 2>&1
1488 local testtemp=$TEST_DIR/aio-testfile
1490 $AIO_TEST $testtemp 2>&1
1497 # indicate whether YP/NIS is active or not
1502 dn=$(domainname 2>/dev/null)
1503 test -n "${dn}" -a "${dn}" != "(none)"
1507 # cat the password file
1511 [ $(_yp_active) -eq 0 ] && ypcat passwd
1515 # cat the group file
1519 [ $(_yp_active) -eq 0 ] && ypcat group
1523 # check for the fsgqa user on the machine
1528 _cat_passwd | grep -q $qa_user
1529 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1530 echo /bin/true | su $qa_user
1531 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1534 # check for the fsgqa group on the machine
1539 _cat_group | grep -q $qa_group
1540 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1546 s,.*Permission\sdenied.*,Permission denied,;
1547 s,.*no\saccess\sto\stty.*,,;
1548 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1555 if [ "$HOSTOS" == "IRIX" ]
1557 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1559 echo $1 | su $qa_user 2>&1 | _filter_user_do
1563 _require_xfs_io_command()
1567 echo "Usage: _require_xfs_io_command command" 1>&2
1572 testfile=$TEST_DIR/$$.xfs_io
1575 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1577 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1578 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1579 -c "$command 4k 8k" $testfile 2>&1`
1582 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1583 -c "fiemap -v" $testfile 2>&1`
1586 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1588 echo $testio | egrep -q "invalid option|Is a directory" && \
1589 _notrun "xfs_io $command support is missing"
1592 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1595 rm -f $testfile 2>&1 > /dev/null
1596 echo $testio | grep -q "not found" && \
1597 _notrun "xfs_io $command support is missing"
1598 echo $testio | grep -q "Operation not supported" && \
1599 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1602 # check that kernel and filesystem support direct I/O
1605 testfile=$TEST_DIR/$$.direct
1606 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1607 if [ $? -ne 0 ]; then
1608 _notrun "O_DIRECT is not supported"
1610 rm -f $testfile 2>&1 > /dev/null
1613 # Check that a fs has enough free space (in 1024b blocks)
1618 BLOCKS=$2 # in units of 1024
1619 let GB=$BLOCKS/1024/1024
1621 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1622 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1623 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1627 # Check if the filesystem supports sparse files.
1629 # Unfortunately there is no better way to do this than a manual black list.
1631 _require_sparse_files()
1635 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1644 #boot_params always present in debugfs
1645 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1648 _require_fail_make_request()
1650 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1651 || _notrun "$DEBUGFS_MNT/fail_make_request \
1652 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1656 # Check if the file system supports seek_data/hole
1658 _require_seek_data_hole()
1660 testfile=$TEST_DIR/$$.seek
1661 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1662 rm -f $testfile &>/dev/null
1663 echo $testseek | grep -q "Kernel does not support" && \
1664 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1667 # check that a FS on a device is mounted
1668 # if so, return mount point
1674 echo "Usage: _is_mounted device" 1>&2
1680 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1681 pattern { print $3 ; exit 0 }
1685 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1690 # remount a FS to a new mode (ro or rw)
1696 echo "Usage: _remount device ro/rw" 1>&2
1702 if ! mount -o remount,$mode $device
1704 echo "_remount: failed to remount filesystem on $device as $mode"
1709 # Run the appropriate repair/check on a filesystem
1711 # if the filesystem is mounted, it's either remounted ro before being
1712 # checked or it's unmounted and then remounted
1715 # If set, we remount ro instead of unmounting for fsck
1718 _umount_or_remount_ro()
1722 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1727 mountpoint=`_is_mounted $device`
1729 if [ $USE_REMOUNT -eq 0 ]; then
1730 $UMOUNT_PROG $device
1737 _mount_or_remount_rw()
1741 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1748 if [ $USE_REMOUNT -eq 0 ]
1750 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1752 echo "!!! failed to remount $device on $mountpoint"
1762 # Check a generic filesystem in no-op mode; this assumes that the
1763 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1764 # and that it will still return an errno for corruption in this mode.
1766 # Filesystems which don't support this will need to define their
1767 # own check routine.
1769 _check_generic_filesystem()
1773 # If type is set, we're mounted
1774 type=`_fs_type $device`
1777 if [ "$type" = "$FSTYP" ]
1780 mountpoint=`_umount_or_remount_ro $device`
1783 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1786 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1788 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1789 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1790 cat $tmp.fsck >>$seqres.full
1791 echo "*** end fsck.$FSTYP output" >>$seqres.full
1799 echo "*** mount output ***" >>$seqres.full
1800 _mount >>$seqres.full
1801 echo "*** end mount output" >>$seqres.full
1802 elif [ "$type" = "$FSTYP" ]
1805 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1809 if [ $ok -eq 0 ]; then
1811 if [ "$iam" != "check" ]; then
1820 # run xfs_check and friends on a FS.
1822 _check_xfs_filesystem()
1826 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1830 extra_mount_options=""
1832 if [ "$2" != "none" ]; then
1833 extra_log_options="-l$2"
1834 extra_mount_options="-ologdev=$2"
1837 if [ "$3" != "none" ]; then
1838 extra_rt_options="-r$3"
1839 extra_mount_options=$extra_mount_options" -ortdev=$3"
1841 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1843 [ "$FSTYP" != xfs ] && return 0
1845 type=`_fs_type $device`
1848 if [ "$type" = "xfs" ]
1851 mountpoint=`_umount_or_remount_ro $device`
1854 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1855 | tee $tmp.logprint | grep -q "<CLEAN>"
1856 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1858 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1860 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1861 echo "*** xfs_logprint -t output ***" >>$seqres.full
1862 cat $tmp.logprint >>$seqres.full
1863 echo "*** end xfs_logprint output" >>$seqres.full
1868 # xfs_check runs out of memory on large files, so even providing the test
1869 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1870 # large filesystems. Avoid it.
1871 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1872 _xfs_check $extra_log_options $device 2>&1 |\
1873 _fix_malloc >$tmp.fs_check
1875 if [ -s $tmp.fs_check ]
1877 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1879 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1880 echo "*** xfs_check output ***" >>$seqres.full
1881 cat $tmp.fs_check >>$seqres.full
1882 echo "*** end xfs_check output" >>$seqres.full
1887 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1890 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1892 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1893 echo "*** xfs_repair -n output ***" >>$seqres.full
1894 cat $tmp.repair | _fix_malloc >>$seqres.full
1895 echo "*** end xfs_repair output" >>$seqres.full
1899 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1903 echo "*** mount output ***" >>$seqres.full
1904 _mount >>$seqres.full
1905 echo "*** end mount output" >>$seqres.full
1906 elif [ "$type" = "xfs" ]
1908 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1911 if [ $ok -eq 0 ]; then
1913 if [ "$iam" != "check" ]; then
1922 # Filter the knowen errors the UDF Verifier reports.
1923 _udf_test_known_error_filter()
1925 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."
1929 _check_udf_filesystem()
1931 [ "$DISABLE_UDF_TEST" == "1" ] && return
1933 if [ $# -ne 1 -a $# -ne 2 ]
1935 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1939 if [ ! -x $here/src/udf_test ]
1941 echo "udf_test not installed, please download and build the Philips"
1942 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1943 echo "Then copy the udf_test binary to $here/src/."
1944 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1952 LAST_BLOCK=`expr \( $2 - 1 \)`
1953 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1956 rm -f $seqres.checkfs
1957 sleep 1 # Due to a problem with time stamps in udf_test
1958 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1959 _udf_test_known_error_filter | \
1960 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1961 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
1965 _check_xfs_test_fs()
1969 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1970 TEST_LOG="$TEST_LOGDEV"
1972 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1973 TEST_RT="$TEST_RTDEV"
1975 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1977 # check for ipath consistency
1978 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1979 # errors go to stderr
1980 xfs_check_ipaths $TEST_DIR >/dev/null
1981 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1985 _check_btrfs_filesystem()
1989 # If type is set, we're mounted
1990 type=`_fs_type $device`
1993 if [ "$type" = "$FSTYP" ]
1996 mountpoint=`_umount_or_remount_ro $device`
1999 btrfsck $device >$tmp.fsck 2>&1
2002 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2004 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2005 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2006 cat $tmp.fsck >>$seqres.full
2007 echo "*** end fsck.$FSTYP output" >>$seqres.full
2015 echo "*** mount output ***" >>$seqres.full
2016 _mount >>$seqres.full
2017 echo "*** end mount output" >>$seqres.full
2018 elif [ "$type" = "$FSTYP" ]
2021 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2025 if [ $ok -eq 0 ]; then
2027 if [ "$iam" != "check" ]; then
2043 # no way to check consistency for nfs
2046 # no way to check consistency for cifs
2049 # do nothing for now
2052 _check_btrfs_filesystem $TEST_DEV
2055 # no way to check consistency for tmpfs
2058 _check_generic_filesystem $TEST_DEV
2066 [ $# -eq 1 ] && device=$1
2072 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2073 SCRATCH_LOG="$SCRATCH_LOGDEV"
2075 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2076 SCRATCH_RT="$SCRATCH_RTDEV"
2078 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2081 _check_udf_filesystem $device $udf_fsize
2084 # Don't know how to check an NFS filesystem, yet.
2087 # Don't know how to check a CIFS filesystem, yet.
2090 _check_btrfs_filesystem $device
2093 # no way to check consistency for tmpfs
2096 _check_generic_filesystem $device
2101 _full_fstyp_details()
2103 [ -z "$FSTYP" ] && FSTYP=xfs
2104 if [ $FSTYP = xfs ]; then
2105 if [ -d /proc/fs/xfs ]; then
2106 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2107 FSTYP="$FSTYP (non-debug)"
2108 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2109 FSTYP="$FSTYP (debug)"
2112 if uname -a | grep -qi 'debug'; then
2113 FSTYP="$FSTYP (debug)"
2115 FSTYP="$FSTYP (non-debug)"
2122 _full_platform_details()
2128 echo "$os/$platform $host $kernel"
2133 if [ -z "$1" -o -z "$2" ]; then
2134 echo Error must pass src and dst.
2138 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2140 elif [ "`uname`" == "Linux" ]; then
2143 echo Error test $seq does not run on the operating system: `uname`
2154 #takes files, randomdata
2162 if [ $size -gt 0 ]; then
2163 if [ "$2" == "false" ]; then
2164 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2166 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2173 # takes dirname, depth, randomdata
2176 dirname=$1; depth=$2; randomdata=$3
2177 mkdir $dirname || die "mkdir $dirname failed"
2180 _nfiles $files $randomdata # files for this dir and data type
2182 [ $depth -eq 0 ] && return
2183 let deep=$depth-1 # go 1 down
2185 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2188 while [ $d -lt $dirs ]
2190 _descend d$d $deep &
2196 # Populate a filesystem with inodes for performance experiments
2198 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2203 dirs=5 # ndirs in each subdir till leaves
2204 size=0 # sizeof files in K
2205 files=100 # num files in _each_ subdir
2206 depth=2 # depth of tree from root to leaves
2208 root=root # path of initial root of directory tree
2209 randomdata=false # -x data type urandom or zero
2212 while getopts "d:f:n:r:s:v:x" c
2221 x) randomdata=true;;
2225 _descend $root $depth $randomdata
2230 [ $verbose = true ] && echo done
2233 # query whether the given file has the given inode flag set
2240 if which $XFS_IO_PROG >/dev/null; then
2241 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2248 # query the given files extsize allocator hint in bytes (if any)
2255 if which $XFS_IO_PROG >/dev/null; then
2256 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2257 awk '/^xattr.extsize =/ { print $3 }'`
2259 [ -z "$blocks" ] && blocks="0"
2263 # scratch_dev_pool should contain the disks pool for the btrfs raid
2264 _require_scratch_dev_pool()
2269 if [ -z "$SCRATCH_DEV_POOL" ]; then
2270 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2273 if [ -z "$1" ]; then
2279 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2283 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2284 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2288 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2292 for i in $SCRATCH_DEV_POOL; do
2293 if [ "`_is_block_dev "$i"`" = "" ]; then
2294 _notrun "this test requires valid block disk $i"
2296 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2297 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2299 if _mount | grep -q $i; then
2300 if ! $UMOUNT_PROG $i; then
2301 echo "failed to unmount $i - aborting"
2305 # to help better debug when something fails, we remove
2306 # traces of previous btrfs FS on the dev.
2307 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2311 # ensure devices in SCRATCH_DEV_POOL are of the same size
2312 # must be called after _require_scratch_dev_pool
2313 _require_scratch_dev_pool_equal_size()
2319 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2320 _size=`_get_device_size $SCRATCH_DEV`
2321 for _dev in $SCRATCH_DEV_POOL; do
2322 _newsize=`_get_device_size $_dev`
2323 if [ $_size -ne $_newsize ]; then
2324 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2329 # We will check if the device is deletable
2330 _require_deletable_scratch_dev_pool()
2334 for i in $SCRATCH_DEV_POOL; do
2335 x=`echo $i | cut -d"/" -f 3`
2336 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2337 _notrun "$i is a device which is not deletable"
2342 # We check for btrfs and (optionally) features of the btrfs command
2346 _require_command "$BTRFS_UTIL_PROG" btrfs
2347 if [ -z "$1" ]; then
2350 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2351 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2354 # Check that fio is present, and it is able to execute given jobfile
2359 _require_command "$FIO_PROG" fio
2360 if [ -z "$1" ]; then
2364 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2365 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2368 # Does freeze work on this fs?
2371 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2373 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2374 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2377 # Does shutdown work on this fs?
2378 _require_scratch_shutdown()
2380 [ -x src/godown ] || _notrun "src/godown executable not found"
2382 _scratch_mkfs > /dev/null 2>&1
2384 src/godown -f $SCRATCH_MNT 2>&1 \
2385 || _notrun "$FSTYP does not support shutdown"
2389 # Does norecovery support by this fs?
2390 _require_norecovery()
2392 _scratch_mount -o ro,norecovery || \
2393 _notrun "$FSTYP does not support norecovery"
2397 # Does this filesystem support metadata journaling?
2398 # We exclude ones here that don't; otherwise we assume that it does, so the
2399 # test will run, fail, and motivate someone to update this test for a new
2402 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2403 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2405 _require_metadata_journaling()
2415 _notrun "$FSTYP does not support metadata journaling"
2418 # ext4 could be mkfs'd without a journal...
2420 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2421 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2424 # by default we pass; if you need to, add your fs above!
2429 # Does fiemap support?
2432 _require_xfs_io_command "fiemap"
2437 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2438 echo $res | grep -v hole | wc -l | $AWK_PROG '{print $1}'
2443 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2444 echo $res | grep hole | wc -l | $AWK_PROG '{print $1}'
2447 # arg 1 is dev to remove and is output of the below eg.
2448 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2454 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2456 stat $disk > /dev/null 2>&1
2457 while [ $? -eq 0 ]; do
2459 stat $disk > /dev/null 2>&1
2463 # arg 1 is dev to add and is output of the below eg.
2464 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2469 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2470 h=`echo ${1} | cut -d":" -f 1`
2471 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2473 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2475 # ensure the device comes online
2477 for i in `seq 1 10`; do
2478 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2479 dev=`ls /sys/class/scsi_device/${1}/device/block`
2480 for j in `seq 1 10`;
2482 stat /dev/$dev > /dev/null 2>&1
2483 if [ $? -eq 0 ]; then
2494 if [ $dev_back_oneline -eq 0 ]; then
2495 echo "/dev/$dev online failed" >> $seqres.full
2497 echo "/dev/$dev is back online" >> $seqres.full
2503 if [ -z "$FSTRIM_PROG" ]; then
2504 _notrun "This test requires fstrim utility."
2508 _require_batched_discard()
2510 if [ $# -ne 1 ]; then
2511 echo "Usage: _require_batched_discard mnt_point" 1>&2
2515 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2520 if [ -z "$DUMPE2FS_PROG" ]; then
2521 _notrun "This test requires dumpe2fs utility."
2527 if [ ! -e /proc/self/uid_map ]; then
2528 _notrun "This test requires procfs uid_map support."
2530 if [ ! -e /proc/self/gid_map ]; then
2531 _notrun "This test requires procfs gid_map support."
2535 _require_cp_reflink()
2537 cp --help | grep -q reflink || \
2538 _notrun "This test requires a cp with --reflink support."
2543 FSSUM_PROG=$here/src/fssum
2544 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2549 CLONER_PROG=$here/src/cloner
2550 [ -x $CLONER_PROG ] || \
2551 _notrun "cloner binary not present at $CLONER_PROG"
2554 # Given 2 files, verify that they have the same mapping but different
2555 # inodes - i.e. an undisturbed reflink
2556 # Silent if so, make noise if not
2559 # not a hard link or symlink?
2560 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2561 && echo "$1 and $2 are not reflinks: same inode number"
2564 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2565 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2566 || echo "$1 and $2 are not reflinks: different extents"
2571 if [ "$FSTYP" == "nfs" ]; then
2572 _notrun "atime related mount options have no effect on NFS"
2578 _scratch_mkfs > /dev/null 2>&1
2579 _scratch_mount -o relatime || \
2580 _notrun "relatime not supported by the current kernel"
2586 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2587 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2590 _create_loop_device()
2593 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2597 _destroy_loop_device()
2600 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2603 _scale_fsstress_args()
2606 while [ $# -gt 0 ]; do
2608 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2609 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2610 *) args="$args $1" ;;
2618 # Return the logical block size if running on a block device,
2619 # else substitute the page size.
2621 _min_dio_alignment()
2625 if [ -b "$dev" ]; then
2626 blockdev --getss $dev
2628 $here/src/feature -s
2634 echo "# $@" >> $seqres.full 2>&1
2635 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2638 _run_btrfs_util_prog()
2640 run_check $BTRFS_UTIL_PROG $*
2643 _require_btrfs_send_stream_version()
2645 $BTRFS_UTIL_PROG send 2>&1 | \
2646 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2647 if [ $? -ne 0 ]; then
2648 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2651 # test if btrfs kernel supports send stream version 2
2652 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2653 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2657 _require_btrfs_mkfs_feature()
2660 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2664 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2665 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2667 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2670 _require_btrfs_fs_feature()
2673 echo "Missing feature name argument for _require_btrfs_fs_feature"
2677 modprobe btrfs > /dev/null 2>&1
2678 [ -e /sys/fs/btrfs/features/$feat ] || \
2679 _notrun "Feature $feat not supported by the available btrfs version"
2682 _require_test_symlinks()
2684 # IRIX UDF does not support symlinks
2685 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2686 _notrun "Require symlinks support"
2687 target=`mktemp -p $TEST_DIR`
2688 link=`mktemp -p $TEST_DIR -u`
2689 ln -s `basename $target` $link
2690 if [ "$?" -ne 0 ]; then
2692 _notrun "Require symlinks support"
2697 _require_test_fcntl_advisory_locks()
2699 [ "$FSTYP" != "cifs" ] && return 0
2700 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2701 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2702 _notrun "Require fcntl advisory locks support"
2707 if [ -z "$1" ]; then
2708 echo "Usage: _get_total_inode <mnt>"
2712 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2718 if [ -z "$1" ]; then
2719 echo "Usage: _get_used_inode <mnt>"
2723 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2729 if [ -z "$1" ]; then
2730 echo "Usage: _get_free_inode <mnt>"
2734 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2738 # get btrfs profile configs being tested
2740 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2741 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2742 # var in the format "metadata_profile:data_profile", multiple configs can be
2743 # seperated by space, e.g.
2744 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2745 _btrfs_get_profile_configs()
2747 if [ "$FSTYP" != "btrfs" ]; then
2751 # no user specified btrfs profile configs, export the default configs
2752 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2754 _btrfs_profile_configs=(
2755 "-m single -d single"
2760 "-m raid10 -d raid10"
2765 # remove dup/raid5/raid6 profiles if we're doing device replace
2766 # dup profile indicates only one device being used (SCRATCH_DEV),
2767 # but we don't want to replace SCRATCH_DEV, which will be used in
2768 # _scratch_mount/_check_scratch_fs etc.
2769 # and raid5/raid6 doesn't support replace yet
2770 if [ "$1" == "replace" ]; then
2771 _btrfs_profile_configs=(
2772 "-m single -d single"
2776 "-m raid10 -d raid10"
2777 # add these back when raid5/6 is working with replace
2778 #"-m raid5 -d raid5"
2779 #"-m raid6 -d raid6"
2782 export _btrfs_profile_configs
2786 # parse user specified btrfs profile configs
2789 for cfg in $BTRFS_PROFILE_CONFIGS; do
2790 # turn "metadata:data" format to "-m metadata -d data"
2791 # and assign it to _btrfs_profile_configs array
2792 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2793 _btrfs_profile_configs[$i]="$cfg"
2797 if [ "$1" == "replace" ]; then
2798 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2799 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2801 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2802 _notrun "Do not set dup profile in btrfs device replace test"
2805 export _btrfs_profile_configs
2808 # stress btrfs by running balance operation in a loop
2809 _btrfs_stress_balance()
2813 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2817 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2818 _btrfs_stress_subvolume()
2822 local subvol_name=$3
2825 mkdir -p $subvol_mnt
2827 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2828 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2829 $UMOUNT_PROG $subvol_mnt
2830 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2834 # stress btrfs by running scrub in a loop
2835 _btrfs_stress_scrub()
2839 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2843 # stress btrfs by defragmenting every file/dir in a loop and compress file
2844 # contents while defragmenting if second argument is not "nocompress"
2845 _btrfs_stress_defrag()
2851 if [ "$compress" == "nocompress" ]; then
2852 find $btrfs_mnt \( -type f -o -type d \) -exec \
2853 $BTRFS_UTIL_PROG filesystem defrag {} \;
2855 find $btrfs_mnt \( -type f -o -type d \) -exec \
2856 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2857 find $btrfs_mnt \( -type f -o -type d \) -exec \
2858 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2863 # stress btrfs by remounting it with different compression algorithms in a loop
2864 # run this with fsstress running at background could exercise the compression
2865 # code path and ensure no race when switching compression algorithm with constant
2867 _btrfs_stress_remount_compress()
2871 for algo in no zlib lzo; do
2872 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2877 # stress btrfs by replacing devices in a loop
2878 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2879 # device should be free(not used by btrfs)
2880 _btrfs_stress_replace()
2884 # The device number in SCRATCH_DEV_POOL should be at least 3,
2885 # one is SCRATCH_DEV, one is to be replaced, one is free device
2886 # we won't replace SCRATCH_DEV, see below for reason
2887 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2888 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2892 # take the last device as the first free_dev
2893 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2895 # free_dev should be really free
2896 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2897 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2901 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2902 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2903 # _scratch_mount and _check_scratch_fs etc.
2904 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2905 -e "s# *$free_dev *##"`
2907 # set the first device in dev_pool as the first src_dev to be replaced
2908 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2910 echo "dev_pool=$dev_pool"
2911 echo "free_dev=$free_dev, src_dev=$src_dev"
2913 echo "Replacing $src_dev with $free_dev"
2914 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2915 if [ $? -ne 0 ]; then
2916 # don't update src_dev and free_dev if replace failed
2919 dev_pool="$dev_pool $free_dev"
2920 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2922 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2926 # find the right option to force output in bytes, older versions of btrfs-progs
2927 # print that by default, newer print human readable numbers with unit suffix
2928 _btrfs_qgroup_units()
2930 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
2933 # return device size in kb
2936 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2939 # don't check dmesg log after test
2940 _disable_dmesg_check()
2942 rm -f ${RESULT_DIR}/check_dmesg
2947 if [ "$iam" == new ]
2951 # make some further configuration checks here
2952 if [ "$TEST_DEV" = "" ]
2954 echo "common/rc: Error: \$TEST_DEV is not set"
2958 # if $TEST_DEV is not mounted, mount it now as XFS
2959 if [ -z "`_fs_type $TEST_DEV`" ]
2961 # $TEST_DEV is not mounted
2964 echo "common/rc: retrying test device mount with external set"
2965 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2968 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2974 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2976 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2980 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2981 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2982 export XFS_IO_PROG="$XFS_IO_PROG -F"
2984 # xfs_copy doesn't work on v5 xfs yet without -d option
2985 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
2986 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
2990 # get real device path name by following link
2994 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2995 _dev=`readlink -f "$_dev"`
3000 # basename of a device
3003 echo `basename $(_real_dev $1)`
3009 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3010 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3011 _maj=$(echo "ibase=16; $_maj" | bc)
3012 _min=$(echo "ibase=16; $_min" | bc)
3013 echo /sys/dev/block/$_maj:$_min
3018 if [ -z $1 ] || [ ! -d $1 ]; then
3019 echo "Missing mount point argument for get_block_size"
3022 echo `stat -f -c %S $1`
3027 ################################################################################
3028 # make sure this script returns success