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 the xfs sparse inode feature
1454 _require_xfs_sparse_inodes()
1456 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
1457 || _notrun "mkfs.xfs does not support sparse inodes"
1458 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
1459 _scratch_mount >/dev/null 2>&1 \
1460 || _notrun "kernel does not support sparse inodes"
1464 # this test requires that external log/realtime devices are not in use
1466 _require_nonexternal()
1468 [ "$USE_EXTERNAL" = yes ] && \
1469 _notrun "External device testing in progress, skipped this test"
1472 # this test requires that a (specified) aio-dio executable exists
1473 # $1 - command (optional)
1479 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1480 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1482 AIO_TEST=src/aio-dio-regress/$1
1483 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1488 # run an aio-dio program
1494 echo "usage: _run_aiodio command_name" 2>&1
1500 local testtemp=$TEST_DIR/aio-testfile
1502 $AIO_TEST $testtemp 2>&1
1509 # indicate whether YP/NIS is active or not
1514 dn=$(domainname 2>/dev/null)
1515 test -n "${dn}" -a "${dn}" != "(none)"
1519 # cat the password file
1523 [ $(_yp_active) -eq 0 ] && ypcat passwd
1527 # cat the group file
1531 [ $(_yp_active) -eq 0 ] && ypcat group
1535 # check for the fsgqa user on the machine
1540 _cat_passwd | grep -q $qa_user
1541 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1542 echo /bin/true | su $qa_user
1543 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1546 # check for the fsgqa group on the machine
1551 _cat_group | grep -q $qa_group
1552 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1558 s,.*Permission\sdenied.*,Permission denied,;
1559 s,.*no\saccess\sto\stty.*,,;
1560 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1567 if [ "$HOSTOS" == "IRIX" ]
1569 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1571 echo $1 | su $qa_user 2>&1 | _filter_user_do
1575 _require_xfs_io_command()
1579 echo "Usage: _require_xfs_io_command command" 1>&2
1584 testfile=$TEST_DIR/$$.xfs_io
1587 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1589 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1590 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1591 -c "$command 4k 8k" $testfile 2>&1`
1594 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1595 -c "fiemap -v" $testfile 2>&1`
1598 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1600 echo $testio | egrep -q "invalid option|Is a directory" && \
1601 _notrun "xfs_io $command support is missing"
1604 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1607 rm -f $testfile 2>&1 > /dev/null
1608 echo $testio | grep -q "not found" && \
1609 _notrun "xfs_io $command support is missing"
1610 echo $testio | grep -q "Operation not supported" && \
1611 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1614 # check that kernel and filesystem support direct I/O
1617 testfile=$TEST_DIR/$$.direct
1618 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1619 if [ $? -ne 0 ]; then
1620 _notrun "O_DIRECT is not supported"
1622 rm -f $testfile 2>&1 > /dev/null
1625 # Check that a fs has enough free space (in 1024b blocks)
1630 BLOCKS=$2 # in units of 1024
1631 let GB=$BLOCKS/1024/1024
1633 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1634 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1635 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1639 # Check if the filesystem supports sparse files.
1641 # Unfortunately there is no better way to do this than a manual black list.
1643 _require_sparse_files()
1647 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1656 #boot_params always present in debugfs
1657 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1660 _require_fail_make_request()
1662 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1663 || _notrun "$DEBUGFS_MNT/fail_make_request \
1664 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1668 # Check if the file system supports seek_data/hole
1670 _require_seek_data_hole()
1672 testfile=$TEST_DIR/$$.seek
1673 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1674 rm -f $testfile &>/dev/null
1675 echo $testseek | grep -q "Kernel does not support" && \
1676 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1679 # check that a FS on a device is mounted
1680 # if so, return mount point
1686 echo "Usage: _is_mounted device" 1>&2
1692 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1693 pattern { print $3 ; exit 0 }
1697 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1702 # remount a FS to a new mode (ro or rw)
1708 echo "Usage: _remount device ro/rw" 1>&2
1714 if ! mount -o remount,$mode $device
1716 echo "_remount: failed to remount filesystem on $device as $mode"
1721 # Run the appropriate repair/check on a filesystem
1723 # if the filesystem is mounted, it's either remounted ro before being
1724 # checked or it's unmounted and then remounted
1727 # If set, we remount ro instead of unmounting for fsck
1730 _umount_or_remount_ro()
1734 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1739 mountpoint=`_is_mounted $device`
1741 if [ $USE_REMOUNT -eq 0 ]; then
1742 $UMOUNT_PROG $device
1749 _mount_or_remount_rw()
1753 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1760 if [ $USE_REMOUNT -eq 0 ]
1762 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1764 echo "!!! failed to remount $device on $mountpoint"
1774 # Check a generic filesystem in no-op mode; this assumes that the
1775 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1776 # and that it will still return an errno for corruption in this mode.
1778 # Filesystems which don't support this will need to define their
1779 # own check routine.
1781 _check_generic_filesystem()
1785 # If type is set, we're mounted
1786 type=`_fs_type $device`
1789 if [ "$type" = "$FSTYP" ]
1792 mountpoint=`_umount_or_remount_ro $device`
1795 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1798 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1800 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1801 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1802 cat $tmp.fsck >>$seqres.full
1803 echo "*** end fsck.$FSTYP output" >>$seqres.full
1811 echo "*** mount output ***" >>$seqres.full
1812 _mount >>$seqres.full
1813 echo "*** end mount output" >>$seqres.full
1814 elif [ "$type" = "$FSTYP" ]
1817 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1821 if [ $ok -eq 0 ]; then
1823 if [ "$iam" != "check" ]; then
1832 # run xfs_check and friends on a FS.
1834 _check_xfs_filesystem()
1838 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1842 extra_mount_options=""
1844 if [ "$2" != "none" ]; then
1845 extra_log_options="-l$2"
1846 extra_mount_options="-ologdev=$2"
1849 if [ "$3" != "none" ]; then
1850 extra_rt_options="-r$3"
1851 extra_mount_options=$extra_mount_options" -ortdev=$3"
1853 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1855 [ "$FSTYP" != xfs ] && return 0
1857 type=`_fs_type $device`
1860 if [ "$type" = "xfs" ]
1863 mountpoint=`_umount_or_remount_ro $device`
1866 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1867 | tee $tmp.logprint | grep -q "<CLEAN>"
1868 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1870 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1872 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1873 echo "*** xfs_logprint -t output ***" >>$seqres.full
1874 cat $tmp.logprint >>$seqres.full
1875 echo "*** end xfs_logprint output" >>$seqres.full
1880 # xfs_check runs out of memory on large files, so even providing the test
1881 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1882 # large filesystems. Avoid it.
1883 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1884 _xfs_check $extra_log_options $device 2>&1 |\
1885 _fix_malloc >$tmp.fs_check
1887 if [ -s $tmp.fs_check ]
1889 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1891 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1892 echo "*** xfs_check output ***" >>$seqres.full
1893 cat $tmp.fs_check >>$seqres.full
1894 echo "*** end xfs_check output" >>$seqres.full
1899 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1902 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1904 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1905 echo "*** xfs_repair -n output ***" >>$seqres.full
1906 cat $tmp.repair | _fix_malloc >>$seqres.full
1907 echo "*** end xfs_repair output" >>$seqres.full
1911 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1915 echo "*** mount output ***" >>$seqres.full
1916 _mount >>$seqres.full
1917 echo "*** end mount output" >>$seqres.full
1918 elif [ "$type" = "xfs" ]
1920 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1923 if [ $ok -eq 0 ]; then
1925 if [ "$iam" != "check" ]; then
1934 # Filter the knowen errors the UDF Verifier reports.
1935 _udf_test_known_error_filter()
1937 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."
1941 _check_udf_filesystem()
1943 [ "$DISABLE_UDF_TEST" == "1" ] && return
1945 if [ $# -ne 1 -a $# -ne 2 ]
1947 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1951 if [ ! -x $here/src/udf_test ]
1953 echo "udf_test not installed, please download and build the Philips"
1954 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1955 echo "Then copy the udf_test binary to $here/src/."
1956 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1964 LAST_BLOCK=`expr \( $2 - 1 \)`
1965 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1968 rm -f $seqres.checkfs
1969 sleep 1 # Due to a problem with time stamps in udf_test
1970 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1971 _udf_test_known_error_filter | \
1972 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1973 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
1977 _check_xfs_test_fs()
1981 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1982 TEST_LOG="$TEST_LOGDEV"
1984 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1985 TEST_RT="$TEST_RTDEV"
1987 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1989 # check for ipath consistency
1990 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1991 # errors go to stderr
1992 xfs_check_ipaths $TEST_DIR >/dev/null
1993 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1997 _check_btrfs_filesystem()
2001 # If type is set, we're mounted
2002 type=`_fs_type $device`
2005 if [ "$type" = "$FSTYP" ]
2008 mountpoint=`_umount_or_remount_ro $device`
2011 btrfsck $device >$tmp.fsck 2>&1
2014 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
2016 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
2017 echo "*** fsck.$FSTYP output ***" >>$seqres.full
2018 cat $tmp.fsck >>$seqres.full
2019 echo "*** end fsck.$FSTYP output" >>$seqres.full
2027 echo "*** mount output ***" >>$seqres.full
2028 _mount >>$seqres.full
2029 echo "*** end mount output" >>$seqres.full
2030 elif [ "$type" = "$FSTYP" ]
2033 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2037 if [ $ok -eq 0 ]; then
2039 if [ "$iam" != "check" ]; then
2055 # no way to check consistency for nfs
2058 # no way to check consistency for cifs
2061 # do nothing for now
2064 _check_btrfs_filesystem $TEST_DEV
2067 # no way to check consistency for tmpfs
2070 _check_generic_filesystem $TEST_DEV
2078 [ $# -eq 1 ] && device=$1
2084 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2085 SCRATCH_LOG="$SCRATCH_LOGDEV"
2087 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2088 SCRATCH_RT="$SCRATCH_RTDEV"
2090 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2093 _check_udf_filesystem $device $udf_fsize
2096 # Don't know how to check an NFS filesystem, yet.
2099 # Don't know how to check a CIFS filesystem, yet.
2102 _check_btrfs_filesystem $device
2105 # no way to check consistency for tmpfs
2108 _check_generic_filesystem $device
2113 _full_fstyp_details()
2115 [ -z "$FSTYP" ] && FSTYP=xfs
2116 if [ $FSTYP = xfs ]; then
2117 if [ -d /proc/fs/xfs ]; then
2118 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2119 FSTYP="$FSTYP (non-debug)"
2120 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2121 FSTYP="$FSTYP (debug)"
2124 if uname -a | grep -qi 'debug'; then
2125 FSTYP="$FSTYP (debug)"
2127 FSTYP="$FSTYP (non-debug)"
2134 _full_platform_details()
2140 echo "$os/$platform $host $kernel"
2145 if [ -z "$1" -o -z "$2" ]; then
2146 echo Error must pass src and dst.
2150 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2152 elif [ "`uname`" == "Linux" ]; then
2155 echo Error test $seq does not run on the operating system: `uname`
2166 #takes files, randomdata
2174 if [ $size -gt 0 ]; then
2175 if [ "$2" == "false" ]; then
2176 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2178 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2185 # takes dirname, depth, randomdata
2188 dirname=$1; depth=$2; randomdata=$3
2189 mkdir $dirname || die "mkdir $dirname failed"
2192 _nfiles $files $randomdata # files for this dir and data type
2194 [ $depth -eq 0 ] && return
2195 let deep=$depth-1 # go 1 down
2197 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2200 while [ $d -lt $dirs ]
2202 _descend d$d $deep &
2208 # Populate a filesystem with inodes for performance experiments
2210 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2215 dirs=5 # ndirs in each subdir till leaves
2216 size=0 # sizeof files in K
2217 files=100 # num files in _each_ subdir
2218 depth=2 # depth of tree from root to leaves
2220 root=root # path of initial root of directory tree
2221 randomdata=false # -x data type urandom or zero
2224 while getopts "d:f:n:r:s:v:x" c
2233 x) randomdata=true;;
2237 _descend $root $depth $randomdata
2242 [ $verbose = true ] && echo done
2245 # query whether the given file has the given inode flag set
2252 if which $XFS_IO_PROG >/dev/null; then
2253 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2260 # query the given files extsize allocator hint in bytes (if any)
2267 if which $XFS_IO_PROG >/dev/null; then
2268 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2269 awk '/^xattr.extsize =/ { print $3 }'`
2271 [ -z "$blocks" ] && blocks="0"
2275 # scratch_dev_pool should contain the disks pool for the btrfs raid
2276 _require_scratch_dev_pool()
2281 if [ -z "$SCRATCH_DEV_POOL" ]; then
2282 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2285 if [ -z "$1" ]; then
2291 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2295 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2296 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2300 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2304 for i in $SCRATCH_DEV_POOL; do
2305 if [ "`_is_block_dev "$i"`" = "" ]; then
2306 _notrun "this test requires valid block disk $i"
2308 if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
2309 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2311 if _mount | grep -q $i; then
2312 if ! $UMOUNT_PROG $i; then
2313 echo "failed to unmount $i - aborting"
2317 # to help better debug when something fails, we remove
2318 # traces of previous btrfs FS on the dev.
2319 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2323 # ensure devices in SCRATCH_DEV_POOL are of the same size
2324 # must be called after _require_scratch_dev_pool
2325 _require_scratch_dev_pool_equal_size()
2331 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2332 _size=`_get_device_size $SCRATCH_DEV`
2333 for _dev in $SCRATCH_DEV_POOL; do
2334 _newsize=`_get_device_size $_dev`
2335 if [ $_size -ne $_newsize ]; then
2336 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2341 # We will check if the device is deletable
2342 _require_deletable_scratch_dev_pool()
2346 for i in $SCRATCH_DEV_POOL; do
2347 x=`echo $i | cut -d"/" -f 3`
2348 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2349 _notrun "$i is a device which is not deletable"
2354 # We check for btrfs and (optionally) features of the btrfs command
2358 _require_command "$BTRFS_UTIL_PROG" btrfs
2359 if [ -z "$1" ]; then
2362 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2363 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2366 # Check that fio is present, and it is able to execute given jobfile
2371 _require_command "$FIO_PROG" fio
2372 if [ -z "$1" ]; then
2376 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2377 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2380 # Does freeze work on this fs?
2383 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2385 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2386 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2389 # Does shutdown work on this fs?
2390 _require_scratch_shutdown()
2392 [ -x src/godown ] || _notrun "src/godown executable not found"
2394 _scratch_mkfs > /dev/null 2>&1
2396 src/godown -f $SCRATCH_MNT 2>&1 \
2397 || _notrun "$FSTYP does not support shutdown"
2401 # Does norecovery support by this fs?
2402 _require_norecovery()
2404 _scratch_mount -o ro,norecovery || \
2405 _notrun "$FSTYP does not support norecovery"
2409 # Does this filesystem support metadata journaling?
2410 # We exclude ones here that don't; otherwise we assume that it does, so the
2411 # test will run, fail, and motivate someone to update this test for a new
2414 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2415 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2417 _require_metadata_journaling()
2427 _notrun "$FSTYP does not support metadata journaling"
2430 # ext4 could be mkfs'd without a journal...
2432 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2433 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2436 # by default we pass; if you need to, add your fs above!
2441 # Does fiemap support?
2444 _require_xfs_io_command "fiemap"
2449 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2450 echo $res | grep -v hole | wc -l | $AWK_PROG '{print $1}'
2455 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2456 echo $res | grep hole | wc -l | $AWK_PROG '{print $1}'
2459 # arg 1 is dev to remove and is output of the below eg.
2460 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2466 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2468 stat $disk > /dev/null 2>&1
2469 while [ $? -eq 0 ]; do
2471 stat $disk > /dev/null 2>&1
2475 # arg 1 is dev to add and is output of the below eg.
2476 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2481 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2482 h=`echo ${1} | cut -d":" -f 1`
2483 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2485 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2487 # ensure the device comes online
2489 for i in `seq 1 10`; do
2490 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2491 dev=`ls /sys/class/scsi_device/${1}/device/block`
2492 for j in `seq 1 10`;
2494 stat /dev/$dev > /dev/null 2>&1
2495 if [ $? -eq 0 ]; then
2506 if [ $dev_back_oneline -eq 0 ]; then
2507 echo "/dev/$dev online failed" >> $seqres.full
2509 echo "/dev/$dev is back online" >> $seqres.full
2515 if [ -z "$FSTRIM_PROG" ]; then
2516 _notrun "This test requires fstrim utility."
2520 _require_batched_discard()
2522 if [ $# -ne 1 ]; then
2523 echo "Usage: _require_batched_discard mnt_point" 1>&2
2527 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2532 if [ -z "$DUMPE2FS_PROG" ]; then
2533 _notrun "This test requires dumpe2fs utility."
2539 if [ ! -e /proc/self/uid_map ]; then
2540 _notrun "This test requires procfs uid_map support."
2542 if [ ! -e /proc/self/gid_map ]; then
2543 _notrun "This test requires procfs gid_map support."
2547 _require_cp_reflink()
2549 cp --help | grep -q reflink || \
2550 _notrun "This test requires a cp with --reflink support."
2555 FSSUM_PROG=$here/src/fssum
2556 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2561 CLONER_PROG=$here/src/cloner
2562 [ -x $CLONER_PROG ] || \
2563 _notrun "cloner binary not present at $CLONER_PROG"
2566 # Given 2 files, verify that they have the same mapping but different
2567 # inodes - i.e. an undisturbed reflink
2568 # Silent if so, make noise if not
2571 # not a hard link or symlink?
2572 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2573 && echo "$1 and $2 are not reflinks: same inode number"
2576 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2577 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2578 || echo "$1 and $2 are not reflinks: different extents"
2583 if [ "$FSTYP" == "nfs" ]; then
2584 _notrun "atime related mount options have no effect on NFS"
2590 _scratch_mkfs > /dev/null 2>&1
2591 _scratch_mount -o relatime || \
2592 _notrun "relatime not supported by the current kernel"
2598 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2599 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2602 _create_loop_device()
2605 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2609 _destroy_loop_device()
2612 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2615 _scale_fsstress_args()
2618 while [ $# -gt 0 ]; do
2620 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2621 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2622 *) args="$args $1" ;;
2630 # Return the logical block size if running on a block device,
2631 # else substitute the page size.
2633 _min_dio_alignment()
2637 if [ -b "$dev" ]; then
2638 blockdev --getss $dev
2640 $here/src/feature -s
2646 echo "# $@" >> $seqres.full 2>&1
2647 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2650 _run_btrfs_util_prog()
2652 run_check $BTRFS_UTIL_PROG $*
2655 _require_btrfs_send_stream_version()
2657 $BTRFS_UTIL_PROG send 2>&1 | \
2658 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2659 if [ $? -ne 0 ]; then
2660 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2663 # test if btrfs kernel supports send stream version 2
2664 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2665 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2669 _require_btrfs_mkfs_feature()
2672 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2676 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2677 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2679 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2682 _require_btrfs_fs_feature()
2685 echo "Missing feature name argument for _require_btrfs_fs_feature"
2689 modprobe btrfs > /dev/null 2>&1
2690 [ -e /sys/fs/btrfs/features/$feat ] || \
2691 _notrun "Feature $feat not supported by the available btrfs version"
2694 _require_test_symlinks()
2696 # IRIX UDF does not support symlinks
2697 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2698 _notrun "Require symlinks support"
2699 target=`mktemp -p $TEST_DIR`
2700 link=`mktemp -p $TEST_DIR -u`
2701 ln -s `basename $target` $link
2702 if [ "$?" -ne 0 ]; then
2704 _notrun "Require symlinks support"
2709 _require_test_fcntl_advisory_locks()
2711 [ "$FSTYP" != "cifs" ] && return 0
2712 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2713 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2714 _notrun "Require fcntl advisory locks support"
2719 if [ -z "$1" ]; then
2720 echo "Usage: _get_total_inode <mnt>"
2724 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2730 if [ -z "$1" ]; then
2731 echo "Usage: _get_used_inode <mnt>"
2735 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2739 _get_used_inode_percent()
2741 if [ -z "$1" ]; then
2742 echo "Usage: _get_used_inode_percent <mnt>"
2746 pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
2753 if [ -z "$1" ]; then
2754 echo "Usage: _get_free_inode <mnt>"
2758 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2762 # get the available space in bytes
2764 _get_available_space()
2766 if [ -z "$1" ]; then
2767 echo "Usage: _get_available_space <mnt>"
2771 avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
2772 echo $((avail_kb * 1024))
2775 # get btrfs profile configs being tested
2777 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2778 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2779 # var in the format "metadata_profile:data_profile", multiple configs can be
2780 # seperated by space, e.g.
2781 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2782 _btrfs_get_profile_configs()
2784 if [ "$FSTYP" != "btrfs" ]; then
2788 # no user specified btrfs profile configs, export the default configs
2789 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2791 _btrfs_profile_configs=(
2792 "-m single -d single"
2797 "-m raid10 -d raid10"
2802 # remove dup/raid5/raid6 profiles if we're doing device replace
2803 # dup profile indicates only one device being used (SCRATCH_DEV),
2804 # but we don't want to replace SCRATCH_DEV, which will be used in
2805 # _scratch_mount/_check_scratch_fs etc.
2806 # and raid5/raid6 doesn't support replace yet
2807 if [ "$1" == "replace" ]; then
2808 _btrfs_profile_configs=(
2809 "-m single -d single"
2813 "-m raid10 -d raid10"
2814 # add these back when raid5/6 is working with replace
2815 #"-m raid5 -d raid5"
2816 #"-m raid6 -d raid6"
2819 export _btrfs_profile_configs
2823 # parse user specified btrfs profile configs
2826 for cfg in $BTRFS_PROFILE_CONFIGS; do
2827 # turn "metadata:data" format to "-m metadata -d data"
2828 # and assign it to _btrfs_profile_configs array
2829 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2830 _btrfs_profile_configs[$i]="$cfg"
2834 if [ "$1" == "replace" ]; then
2835 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2836 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2838 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2839 _notrun "Do not set dup profile in btrfs device replace test"
2842 export _btrfs_profile_configs
2845 # stress btrfs by running balance operation in a loop
2846 _btrfs_stress_balance()
2850 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2854 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2855 _btrfs_stress_subvolume()
2859 local subvol_name=$3
2862 mkdir -p $subvol_mnt
2864 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2865 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2866 $UMOUNT_PROG $subvol_mnt
2867 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2871 # stress btrfs by running scrub in a loop
2872 _btrfs_stress_scrub()
2876 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2880 # stress btrfs by defragmenting every file/dir in a loop and compress file
2881 # contents while defragmenting if second argument is not "nocompress"
2882 _btrfs_stress_defrag()
2888 if [ "$compress" == "nocompress" ]; then
2889 find $btrfs_mnt \( -type f -o -type d \) -exec \
2890 $BTRFS_UTIL_PROG filesystem defrag {} \;
2892 find $btrfs_mnt \( -type f -o -type d \) -exec \
2893 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2894 find $btrfs_mnt \( -type f -o -type d \) -exec \
2895 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2900 # stress btrfs by remounting it with different compression algorithms in a loop
2901 # run this with fsstress running at background could exercise the compression
2902 # code path and ensure no race when switching compression algorithm with constant
2904 _btrfs_stress_remount_compress()
2908 for algo in no zlib lzo; do
2909 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2914 # stress btrfs by replacing devices in a loop
2915 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2916 # device should be free(not used by btrfs)
2917 _btrfs_stress_replace()
2921 # The device number in SCRATCH_DEV_POOL should be at least 3,
2922 # one is SCRATCH_DEV, one is to be replaced, one is free device
2923 # we won't replace SCRATCH_DEV, see below for reason
2924 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2925 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2929 # take the last device as the first free_dev
2930 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2932 # free_dev should be really free
2933 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2934 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2938 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2939 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2940 # _scratch_mount and _check_scratch_fs etc.
2941 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2942 -e "s# *$free_dev *##"`
2944 # set the first device in dev_pool as the first src_dev to be replaced
2945 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2947 echo "dev_pool=$dev_pool"
2948 echo "free_dev=$free_dev, src_dev=$src_dev"
2950 echo "Replacing $src_dev with $free_dev"
2951 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2952 if [ $? -ne 0 ]; then
2953 # don't update src_dev and free_dev if replace failed
2956 dev_pool="$dev_pool $free_dev"
2957 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2959 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2963 # find the right option to force output in bytes, older versions of btrfs-progs
2964 # print that by default, newer print human readable numbers with unit suffix
2965 _btrfs_qgroup_units()
2967 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
2970 # return device size in kb
2973 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2976 # check dmesg log for WARNING/Oops/etc.
2979 if [ ! -f ${RESULT_DIR}/check_dmesg ]; then
2982 rm -f ${RESULT_DIR}/check_dmesg
2984 # default filter is a simple cat command, caller could provide a
2985 # customized filter and pass the name through the first argument, to
2986 # filter out intentional WARNINGs or Oopses
2989 # search the dmesg log of last run of $seqnum for possible failures
2990 # use sed \cregexpc address type, since $seqnum contains "/"
2991 dmesg | tac | sed -ne "0,\#run fstests $seqnum at $date_time#p" | \
2992 tac | $filter >$seqres.dmesg
2993 grep -q -e "kernel BUG at" \
2997 -e "possible recursive locking detected" \
2998 -e "Internal error" \
3000 if [ $? -eq 0 ]; then
3001 echo "_check_dmesg: something found in dmesg (see $seqres.dmesg)"
3009 # don't check dmesg log after test
3010 _disable_dmesg_check()
3012 rm -f ${RESULT_DIR}/check_dmesg
3017 if [ "$iam" == new ]
3021 # make some further configuration checks here
3022 if [ "$TEST_DEV" = "" ]
3024 echo "common/rc: Error: \$TEST_DEV is not set"
3028 # if $TEST_DEV is not mounted, mount it now as XFS
3029 if [ -z "`_fs_type $TEST_DEV`" ]
3031 # $TEST_DEV is not mounted
3034 echo "common/rc: retrying test device mount with external set"
3035 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
3038 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
3044 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
3046 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
3050 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
3051 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
3052 export XFS_IO_PROG="$XFS_IO_PROG -F"
3054 # xfs_copy doesn't work on v5 xfs yet without -d option
3055 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
3056 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
3060 # get real device path name by following link
3064 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
3065 _dev=`readlink -f "$_dev"`
3070 # basename of a device
3073 echo `basename $(_real_dev $1)`
3079 local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
3080 local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
3081 _maj=$(echo "ibase=16; $_maj" | bc)
3082 _min=$(echo "ibase=16; $_min" | bc)
3083 echo /sys/dev/block/$_maj:$_min
3088 if [ -z $1 ] || [ ! -d $1 ]; then
3089 echo "Missing mount point argument for get_block_size"
3092 echo `stat -f -c %S $1`
3097 ################################################################################
3098 # make sure this script returns success