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 _scratch_options mkfs
313 $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
317 _scratch_mkfs_xfs_supported()
321 _scratch_options mkfs
323 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
328 # extra mkfs options can be added by tests
329 local extra_mkfs_options=$*
333 # save mkfs output in case conflict means we need to run again.
334 # only the output for the mkfs that applies should be shown
335 _scratch_mkfs_xfs_opts $MKFS_OPTIONS $extra_mkfs_options \
336 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
340 # a mkfs failure may be caused by conflicts between
341 # $MKFS_OPTIONS and $extra_mkfs_options
342 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
344 echo -n "** mkfs failed with extra mkfs options "
345 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
346 echo -n "** attempting to mkfs using only test $seq "
347 echo "options: $extra_mkfs_options **"
350 # running mkfs again. overwrite previous mkfs output files
351 _scratch_mkfs_xfs_opts $extra_mkfs_options \
352 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
356 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
357 # manually parse the mkfs output to get the fs size in bytes
359 fs_size=`cat $tmp_dir.mkfsstd | perl -ne '
360 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
362 print STDOUT "$size\n";
364 _setup_large_xfs_fs $fs_size
368 # output stored mkfs output
369 cat $tmp_dir.mkfserr >&2
371 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
376 # xfs_check script is planned to be deprecated. But, we want to
377 # be able to invoke "xfs_check" behavior in xfstests in order to
378 # maintain the current verification levels.
383 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
385 while getopts "b:fi:l:stvV" c
391 i) OPTS=$OPTS"-i "$OPTARG" ";;
392 b) OPTS=$OPTS"-b "$OPTARG" ";;
393 f) DBOPTS=$DBOPTS" -f";;
394 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
395 V) $XFS_DB_PROG -p xfs_check -V
403 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
413 _setup_large_ext4_fs()
418 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
419 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
420 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
422 # Default free space in the FS is 50GB, but you can specify more via
423 # SCRATCH_DEV_EMPTY_SPACE
424 space_to_consume=$(($fs_size - 50*1024*1024*1024 - $SCRATCH_DEV_EMPTY_SPACE))
426 # mount the filesystem and create 16TB - 4KB files until we consume
427 # all the necessary space.
428 _scratch_mount 2>&1 >$tmp_dir/mnt.err
430 if [ $status -ne 0 ]; then
432 cat $tmp_dir/mnt.err >&2
433 rm -f $tmp_dir/mnt.err
436 rm -f $tmp_dir/mnt.err
438 file_size=$((16*1024*1024*1024*1024 - 4096))
440 while [ $space_to_consume -gt $file_size ]; do
443 -c "truncate $file_size" \
444 -c "falloc -k 0 $file_size" \
445 $SCRATCH_MNT/.use_space.$nfiles 2>&1
447 if [ $status -ne 0 ]; then
451 space_to_consume=$(( $space_to_consume - $file_size ))
452 nfiles=$(($nfiles + 1))
455 # consume the remaining space.
456 if [ $space_to_consume -gt 0 ]; then
458 -c "truncate $space_to_consume" \
459 -c "falloc -k 0 $space_to_consume" \
460 $SCRATCH_MNT/.use_space.$nfiles 2>&1
463 export NUM_SPACE_FILES=$nfiles
466 if [ $status -ne 0 ]; then
467 echo "large file prealloc failed"
468 cat $tmp_dir/mnt.err >&2
476 # extra mkfs options can be added by tests
477 local extra_mkfs_options=$*
481 $MKFS_EXT4_PROG -F $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV \
482 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
485 # a mkfs failure may be caused by conflicts between
486 # $MKFS_OPTIONS and $extra_mkfs_options
487 if [ $mkfs_status -ne 0 -a ! -z "$extra_mkfs_options" ]; then
489 echo -n "** mkfs failed with extra mkfs options "
490 echo "added to \"$MKFS_OPTIONS\" by test $seq **"
491 echo -n "** attempting to mkfs using only test $seq "
492 echo "options: $extra_mkfs_options **"
495 # running mkfs again. overwrite previous mkfs output files
496 $MKFS_EXT4_PROG -F $extra_mkfs_options $SCRATCH_DEV \
497 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
501 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
502 # manually parse the mkfs output to get the fs size in bytes
503 fs_size=`cat $tmp_dir.mkfsstd | awk ' \
504 /^Block size/ { split($2, a, "="); bs = a[2] ; } \
505 / inodes, / { blks = $3 } \
506 /reserved for the super user/ { resv = $1 } \
507 END { fssize = bs * blks - resv; print fssize }'`
509 _setup_large_ext4_fs $fs_size
513 # output stored mkfs output
514 cat $tmp_dir.mkfserr >&2
516 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
528 # do nothing for cifs
531 $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
534 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
537 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV
540 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV
552 $MKFS_UDF_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
555 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
558 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* \
559 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
563 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* \
564 2>$tmp_dir.mkfserr 1>$tmp_dir.mkfsstd
568 if [ $? -ne 0 ]; then
569 # output stored mkfs output
570 cat $tmp_dir.mkfserr >&2
575 rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
578 # remove all files in $SCRATCH_MNT, useful when testing on NFS/CIFS
579 _scratch_cleanup_files()
582 rm -rf $SCRATCH_MNT/*
593 # unable to re-create NFS, just remove all files in $SCRATCH_MNT to
594 # avoid EEXIST caused by the leftover files created in previous runs
595 _scratch_cleanup_files
598 # unable to re-create CIFS, just remove all files in $SCRATCH_MNT to
599 # avoid EEXIST caused by the leftover files created in previous runs
600 _scratch_cleanup_files
603 $MKFS_UDF_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
606 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
609 $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $SCRATCH_DEV
612 _scratch_mkfs_ext4 $*
615 # do nothing for tmpfs
618 $MKFS_F2FS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV > /dev/null
621 yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $SCRATCH_DEV
630 # if dup profile is in mkfs options call _scratch_mkfs instead
631 # because dup profile only works with single device
632 if [[ "$*" =~ dup ]]; then
635 $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $SCRATCH_DEV_POOL > /dev/null
639 echo "_scratch_pool_mkfs is not implemented for $FSTYP" 1>&2
644 # Create fs of certain size on scratch device
645 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
646 _scratch_mkfs_sized()
653 def_blksz=`echo $MKFS_OPTIONS|sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
655 ext2|ext3|ext4|ext4dev|udf|btrfs|reiser4)
656 def_blksz=`echo $MKFS_OPTIONS| sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
660 [ -n "$def_blksz" ] && blocksize=$def_blksz
661 [ -z "$blocksize" ] && blocksize=4096
665 if ! [[ $fssize =~ $re ]] ; then
666 _notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
668 if ! [[ $blocksize =~ $re ]] ; then
669 _notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
672 blocks=`expr $fssize / $blocksize`
674 if [ "$HOSTOS" == "Linux" ]; then
675 devsize=`blockdev --getsize64 $SCRATCH_DEV`
676 [ "$fssize" -gt "$devsize" ] && _notrun "Scratch device too small"
681 # don't override MKFS_OPTIONS that set a block size.
682 echo $MKFS_OPTIONS |egrep -q "b?size="
683 if [ $? -eq 0 ]; then
684 _scratch_mkfs_xfs -d size=$fssize
686 _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
689 ext2|ext3|ext4|ext4dev)
690 ${MKFS_PROG}.$FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
693 $MKFS_UDF_PROG $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
696 $MKFS_BTRFS_PROG $MKFS_OPTIONS -b $fssize $SCRATCH_DEV
699 # mkfs.resier4 requires size in KB as input for creating filesystem
700 $MKFS_REISER4_PROG $MKFS_OPTIONS -y -b $blocksize $SCRATCH_DEV \
701 `expr $fssize / 1024`
704 _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
709 # Emulate an N-data-disk stripe w/ various stripe units
710 # _scratch_mkfs_geom <sunit bytes> <swidth multiplier> [optional blocksize]
716 [ -z "$blocksize" ] && blocksize=4096
718 let sunit_blocks=$sunit_bytes/$blocksize
719 let swidth_blocks=$sunit_blocks*$swidth_mult
723 MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
726 MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
729 _notrun "can't mkfs $FSTYP with geometry"
739 xfs_io -x -c "resblks $1" $SCRATCH_MNT
746 _scratch_xfs_db_options()
749 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
750 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
751 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
754 _scratch_xfs_logprint()
757 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
758 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
759 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
765 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
766 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
767 [ "$LARGE_SCRATCH_DEV" = yes ] && \
768 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
769 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
772 _scratch_xfs_repair()
775 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
776 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
777 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
778 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
779 [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
780 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
787 echo "Usage: _get_pids_by_name process-name" 1>&2
791 # Algorithm ... all ps(1) variants have a time of the form MM:SS or
792 # HH:MM:SS before the psargs field, use this as the search anchor.
794 # Matches with $1 (process-name) occur if the first psarg is $1
795 # or ends in /$1 ... the matching uses sed's regular expressions,
796 # so passing a regex into $1 will work.
804 -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
805 -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
808 # fix malloc libs output
812 # filter out the Electric Fence notice
815 if (defined $o && /^\s+Electric Fence/) {
821 print $o if (defined $o);
825 print $o if (defined $o);
829 # check if run as root
833 id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
836 echo "Arrgh ... you need to be root (not uid=$id) to run this test"
843 # _df_device : get an IRIX style df line for a given device
845 # - returns "" if not mounted
846 # - returns fs type in field two (ala IRIX)
847 # - joins line together if split by fancy df formatting
848 # - strips header etc
855 echo "Usage: _df_device device" 1>&2
859 # Note that we use "==" here so awk doesn't try to interpret an NFS over
860 # IPv6 server as a regular expression.
861 $DF_PROG 2>/dev/null | $AWK_PROG -v what=$1 '
862 ($1==what) && (NF==1) {
876 # _df_dir : get an IRIX style df line for device where a directory resides
878 # - returns fs type in field two (ala IRIX)
879 # - joins line together if split by fancy df formatting
880 # - strips header etc
887 echo "Usage: _df_dir device" 1>&2
891 $DF_PROG $1 2>/dev/null | $AWK_PROG -v what=$1 '
907 # return percentage used disk space for mounted device
913 echo "Usage: _used device" 1>&2
917 _df_device $1 | $AWK_PROG '{ sub("%", "") ; print $6 }'
920 # return the FS type of a mounted device
926 echo "Usage: _fs_type device" 1>&2
931 # The Linux kernel shows NFSv4 filesystems in df output as
932 # filesystem type nfs4, although we mounted it as nfs earlier.
933 # Fix the filesystem type up here so that the callers don't
934 # have to bother with this quirk.
936 _df_device $1 | $AWK_PROG '{ print $2 }' | sed -e 's/nfs4/nfs/'
939 # return the FS mount options of a mounted device
941 # should write a version which just parses the output of mount for IRIX
942 # compatibility, but since this isn't used at all, at the moment I'll leave
949 echo "Usage: _fs_options device" 1>&2
953 $AWK_PROG -v dev=$1 '
954 match($1,dev) { print $4 }
958 # returns device number if a file is a block device
964 echo "Usage: _is_block_dev dev" 1>&2
969 if [ -L "${_dev}" ]; then
970 _dev=`readlink -f ${_dev}`
973 if [ -b "${_dev}" ]; then
974 src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
978 # Do a command, log it to $seqres.full, optionally test return status
979 # and die if command fails. If called with one argument _do executes the
980 # command, logs it, and returns its exit status. With two arguments _do
981 # first prints the message passed in the first argument, and then "done"
982 # or "fail" depending on the return status of the command passed in the
983 # second argument. If the command fails and the variable _do_die_on_error
984 # is set to "always" or the two argument form is used and _do_die_on_error
985 # is set to "message_only" _do will print an error message to
986 # $seqres.out and exit.
990 if [ $# -eq 1 ]; then
992 elif [ $# -eq 2 ]; then
997 echo "Usage: _do [note] cmd" 1>&2
1001 (eval "echo '---' \"$_cmd\"") >>$seqres.full
1002 (eval "$_cmd") >$tmp._out 2>&1; ret=$?
1003 cat $tmp._out | _fix_malloc >>$seqres.full
1004 if [ $# -eq 2 ]; then
1005 if [ $ret -eq 0 ]; then
1012 && [ "$_do_die_on_error" = "always" \
1013 -o \( $# -eq 2 -a "$_do_die_on_error" = "message_only" \) ]
1015 [ $# -ne 2 ] && echo
1016 eval "echo \"$_cmd\" failed \(returned $ret\): see $seqres.full"
1023 # bail out, setting up .notrun file. Need to kill the filesystem check files
1024 # here, otherwise they are set incorrectly for the next test.
1028 echo "$*" > $seqres.notrun
1029 echo "$seq not run: $*"
1030 rm -f ${RESULT_DIR}/require_test
1031 rm -f ${RESULT_DIR}/require_scratch
1036 # just plain bail out
1040 echo "$*" | tee -a $seqres.full
1041 echo "(see $seqres.full for details)"
1046 # tests whether $FSTYP is one of the supported filesystems for a test
1052 if [ "$f" = "$FSTYP" -o "$f" = "generic" ]
1058 _notrun "not suitable for this filesystem type: $FSTYP"
1062 # tests whether $FSTYP is one of the supported OSes for a test
1068 if [ "$h" = "$HOSTOS" ]
1074 _notrun "not suitable for this OS: $HOSTOS"
1077 # this test needs a scratch partition - check we're ok & unmount it
1078 # No post-test check of the device is required. e.g. the test intentionally
1079 # finishes the test with the filesystem in a corrupt state
1080 _require_scratch_nocheck()
1084 echo $SCRATCH_DEV | grep -q ":/" > /dev/null 2>&1
1085 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1086 _notrun "this test requires a valid \$SCRATCH_DEV"
1088 if [ ! -d "$SCRATCH_MNT" ]; then
1089 _notrun "this test requires a valid \$SCRATCH_MNT"
1093 echo $SCRATCH_DEV | grep -q "//" > /dev/null 2>&1
1094 if [ -z "$SCRATCH_DEV" -o "$?" != "0" ]; then
1095 _notrun "this test requires a valid \$SCRATCH_DEV"
1097 if [ ! -d "$SCRATCH_MNT" ]; then
1098 _notrun "this test requires a valid \$SCRATCH_MNT"
1102 if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
1104 _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
1108 if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
1110 _notrun "this test requires a valid \$SCRATCH_DEV"
1112 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1114 _notrun "this test requires a valid \$SCRATCH_DEV"
1116 if [ ! -d "$SCRATCH_MNT" ]
1118 _notrun "this test requires a valid \$SCRATCH_MNT"
1124 # Note that we use -F here so grep doesn't try to interpret an NFS over
1125 # IPv6 server as a regular expression.
1126 if _mount | grep -F -q $SCRATCH_DEV
1128 # if it's mounted, make sure its on $SCRATCH_MNT
1129 if ! _mount | grep -F $SCRATCH_DEV | grep -q $SCRATCH_MNT
1131 echo "\$SCRATCH_DEV is mounted but not on \$SCRATCH_MNT - aborting"
1134 # and then unmount it
1135 if ! $UMOUNT_PROG $SCRATCH_DEV
1137 echo "failed to unmount $SCRATCH_DEV"
1141 rm -f ${RESULT_DIR}/require_scratch
1144 # we need the scratch device and it should be checked post test.
1147 _require_scratch_nocheck
1148 touch ${RESULT_DIR}/require_scratch
1152 # this test needs a test partition - check we're ok & mount it
1158 echo $TEST_DEV | grep -q ":/" > /dev/null 2>&1
1159 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1160 _notrun "this test requires a valid \$TEST_DIR"
1162 if [ ! -d "$TEST_DIR" ]; then
1163 _notrun "this test requires a valid \$TEST_DIR"
1167 echo $TEST_DEV | grep -q "//" > /dev/null 2>&1
1168 if [ -z "$TEST_DEV" -o "$?" != "0" ]; then
1169 _notrun "this test requires a valid \$TEST_DEV"
1171 if [ ! -d "$TEST_DIR" ]; then
1172 _notrun "this test requires a valid \$TEST_DIR"
1176 if [ -z "$TEST_DEV" -o ! -d "$TEST_DIR" ];
1178 _notrun "this test requires a valid \$TEST_DIR and unique $TEST_DEV"
1182 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
1184 _notrun "this test requires a valid \$TEST_DEV"
1186 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
1188 _notrun "this test requires a valid \$TEST_DEV"
1190 if [ ! -d "$TEST_DIR" ]
1192 _notrun "this test requires a valid \$TEST_DIR"
1198 # Note that we use -F here so grep doesn't try to interpret an NFS over
1199 # IPv6 server as a regular expression.
1200 if _mount | grep -F -q $TEST_DEV
1202 # if it's mounted, make sure its on $TEST_DIR
1203 if ! _mount | grep -F $TEST_DEV | grep -q $TEST_DIR
1205 echo "\$TEST_DEV is mounted but not on \$TEST_DIR - aborting"
1209 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
1210 if [ $? -ne 1 ]; then
1215 touch ${RESULT_DIR}/require_test
1218 # this test needs a logdev
1222 [ -z "$SCRATCH_LOGDEV" -o ! -b "$SCRATCH_LOGDEV" ] && \
1223 _notrun "This test requires a valid \$SCRATCH_LOGDEV"
1224 [ "$USE_EXTERNAL" != yes ] && \
1225 _notrun "This test requires USE_EXTERNAL to be enabled"
1227 # ensure its not mounted
1228 $UMOUNT_PROG $SCRATCH_LOGDEV 2>/dev/null
1231 # this test requires loopback device support
1235 if [ "$HOSTOS" != "Linux" ]
1237 _notrun "This test requires linux for loopback device support"
1240 modprobe loop >/dev/null 2>&1
1241 if grep loop /proc/devices >/dev/null 2>&1
1245 _notrun "This test requires loopback device support"
1249 # this test requires ext2 filesystem support
1253 if [ "$HOSTOS" != "Linux" ]
1255 _notrun "This test requires linux for ext2 filesystem support"
1258 modprobe ext2 >/dev/null 2>&1
1259 if grep ext2 /proc/filesystems >/dev/null 2>&1
1263 _notrun "This test requires ext2 filesystem support"
1267 # this test requires that (large) loopback device files are not in use
1269 _require_no_large_scratch_dev()
1271 [ "$LARGE_SCRATCH_DEV" = yes ] && \
1272 _notrun "Large filesystem testing in progress, skipped this test"
1275 # this test requires that a realtime subvolume is in use, and
1276 # that the kernel supports realtime as well.
1280 [ "$USE_EXTERNAL" = yes ] || \
1281 _notrun "External volumes not in use, skipped this test"
1282 [ "$SCRATCH_RTDEV" = "" ] && \
1283 _notrun "Realtime device required, skipped this test"
1286 # this test requires that a specified command (executable) exists
1287 # $1 - command, $2 - name for error message
1291 [ -n "$1" ] && _cmd="$1" || _cmd="$2"
1292 [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
1295 # this test requires the device to be valid block device
1297 _require_block_device()
1299 if [ -z "$1" ]; then
1300 echo "Usage: _require_block_device <dev>" 1>&2
1303 if [ "`_is_block_dev "$1"`" == "" ]; then
1304 _notrun "require $1 to be valid block disk"
1308 # brd based ram disks erase the device when they receive a flush command when no
1309 # active references are present. This causes problems for DM devices sitting on
1310 # top of brd devices as DM doesn't hold active references to the brd device.
1311 _require_sane_bdev_flush()
1313 echo $1 | grep -q "^/dev/ram[0-9]\+$"
1314 if [ $? -eq 0 ]; then
1315 _notrun "This test requires a sane block device flush"
1319 # this test requires the device mapper flakey target
1321 _require_dm_flakey()
1323 # require SCRATCH_DEV to be a valid block device with sane BLKFLSBUF
1325 _require_block_device $SCRATCH_DEV
1326 _require_sane_bdev_flush $SCRATCH_DEV
1327 _require_command "$DMSETUP_PROG" dmsetup
1329 modprobe dm-flakey >/dev/null 2>&1
1330 $DMSETUP_PROG targets | grep flakey >/dev/null 2>&1
1331 if [ $? -ne 0 ]; then
1332 _notrun "This test requires dm flakey support"
1336 _require_dm_snapshot()
1338 _require_block_device $SCRATCH_DEV
1339 _require_sane_bdev_flush $SCRATCH_DEV
1340 _require_command "$DMSETUP_PROG" dmsetup
1341 modprobe dm-snapshot >/dev/null 2>&1
1342 $DMSETUP_PROG targets | grep -q snapshot
1343 if [ $? -ne 0 ]; then
1344 _notrun "This test requires dm snapshot support"
1348 # this test requires the projid32bit feature to be available in mkfs.xfs.
1350 _require_projid32bit()
1352 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
1353 || _notrun "mkfs.xfs doesn't have projid32bit feature"
1356 _require_projid16bit()
1358 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
1359 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
1362 # this test requires the crc feature to be available in mkfs.xfs
1364 _require_xfs_mkfs_crc()
1366 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
1367 || _notrun "mkfs.xfs doesn't have crc feature"
1370 # this test requires the xfs kernel support crc feature
1374 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
1375 _scratch_mount >/dev/null 2>&1 \
1376 || _notrun "Kernel doesn't support crc feature"
1380 # this test requires the bigalloc feature to be available in mkfs.ext4
1382 _require_ext4_mkfs_bigalloc()
1384 $MKFS_EXT4_PROG -F -O bigalloc -n $SCRATCH_DEV 512m >/dev/null 2>&1 \
1385 || _notrun "mkfs.ext4 doesn't have bigalloc feature"
1388 # this test requires the ext4 kernel support bigalloc feature
1390 _require_ext4_bigalloc()
1392 $MKFS_EXT4_PROG -F -O bigalloc $SCRATCH_DEV 512m >/dev/null 2>&1
1393 _scratch_mount >/dev/null 2>&1 \
1394 || _notrun "Ext4 kernel doesn't support bigalloc feature"
1398 # this test requires the finobt feature to be available in mkfs.xfs
1400 _require_xfs_mkfs_finobt()
1402 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
1403 || _notrun "mkfs.xfs doesn't have finobt feature"
1406 # this test requires the xfs kernel support finobt feature
1408 _require_xfs_finobt()
1410 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
1411 _scratch_mount >/dev/null 2>&1 \
1412 || _notrun "Kernel doesn't support finobt feature"
1416 # this test requires xfs sysfs attribute support
1418 _require_xfs_sysfs()
1421 sysfsdir=/sys/fs/xfs
1423 if [ ! -e $sysfsdir ]; then
1424 _notrun "no kernel support for XFS sysfs attributes"
1427 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
1428 _notrun "sysfs attribute '$attr' is not supported"
1432 # this test requires that external log/realtime devices are not in use
1434 _require_nonexternal()
1436 [ "$USE_EXTERNAL" = yes ] && \
1437 _notrun "External device testing in progress, skipped this test"
1440 # this test requires that a (specified) aio-dio executable exists
1441 # $1 - command (optional)
1447 AIO_TEST=src/aio-dio-regress/aiodio_sparse2
1448 [ -x $AIO_TEST ] || _notrun "aio-dio utilities required"
1450 AIO_TEST=src/aio-dio-regress/$1
1451 [ -x $AIO_TEST ] || _notrun "$AIO_TEST not built"
1456 # run an aio-dio program
1462 echo "usage: _run_aiodio command_name" 2>&1
1468 local testtemp=$TEST_DIR/aio-testfile
1470 $AIO_TEST $testtemp 2>&1
1477 # indicate whether YP/NIS is active or not
1482 dn=$(domainname 2>/dev/null)
1483 test -n "${dn}" -a "${dn}" != "(none)"
1487 # cat the password file
1491 [ $(_yp_active) -eq 0 ] && ypcat passwd
1495 # cat the group file
1499 [ $(_yp_active) -eq 0 ] && ypcat group
1503 # check for the fsgqa user on the machine
1508 _cat_passwd | grep -q $qa_user
1509 [ "$?" == "0" ] || _notrun "$qa_user user not defined."
1510 echo /bin/true | su $qa_user
1511 [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands."
1514 # check for the fsgqa group on the machine
1519 _cat_group | grep -q $qa_group
1520 [ "$?" == "0" ] || _notrun "$qa_group user not defined."
1526 s,.*Permission\sdenied.*,Permission denied,;
1527 s,.*no\saccess\sto\stty.*,,;
1528 s,.*no\sjob\scontrol\sin\sthis\sshell.*,,;
1535 if [ "$HOSTOS" == "IRIX" ]
1537 echo $1 | /bin/bash "su $qa_user 2>&1" | _filter_user_do
1539 echo $1 | su $qa_user 2>&1 | _filter_user_do
1543 _require_xfs_io_command()
1547 echo "Usage: _require_xfs_io_command command" 1>&2
1552 testfile=$TEST_DIR/$$.xfs_io
1555 testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
1557 "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" )
1558 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1559 -c "$command 4k 8k" $testfile 2>&1`
1562 testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
1563 -c "fiemap -v" $testfile 2>&1`
1566 testio=`$XFS_IO_PROG -T -F -c "flink $testfile" \
1568 echo $testio | egrep -q "invalid option|Is a directory" && \
1569 _notrun "xfs_io $command support is missing"
1572 testio=`$XFS_IO_PROG -c "$command help" 2>&1`
1575 rm -f $testfile 2>&1 > /dev/null
1576 echo $testio | grep -q "not found" && \
1577 _notrun "xfs_io $command support is missing"
1578 echo $testio | grep -q "Operation not supported" && \
1579 _notrun "xfs_io $command failed (old kernel/wrong fs?)"
1582 # check that kernel and filesystem support direct I/O
1585 testfile=$TEST_DIR/$$.direct
1586 $XFS_IO_PROG -F -f -d -c "pwrite 0 20k" $testfile > /dev/null 2>&1
1587 if [ $? -ne 0 ]; then
1588 _notrun "O_DIRECT is not supported"
1590 rm -f $testfile 2>&1 > /dev/null
1593 # Check that a fs has enough free space (in 1024b blocks)
1598 BLOCKS=$2 # in units of 1024
1599 let GB=$BLOCKS/1024/1024
1601 FREE_BLOCKS=`df -klP $MNT | grep -v Filesystem | awk '{print $4}'`
1602 [ $FREE_BLOCKS -lt $BLOCKS ] && \
1603 _notrun "This test requires at least ${GB}GB free on $MNT to run"
1607 # Check if the filesystem supports sparse files.
1609 # Unfortunately there is no better way to do this than a manual black list.
1611 _require_sparse_files()
1615 _notrun "Sparse files not supported by this filesystem type: $FSTYP"
1624 #boot_params always present in debugfs
1625 [ -d "$DEBUGFS_MNT/boot_params" ] || _notrun "Debugfs not mounted"
1628 _require_fail_make_request()
1630 [ -f "$DEBUGFS_MNT/fail_make_request/probability" ] \
1631 || _notrun "$DEBUGFS_MNT/fail_make_request \
1632 not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
1636 # Check if the file system supports seek_data/hole
1638 _require_seek_data_hole()
1640 testfile=$TEST_DIR/$$.seek
1641 testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
1642 rm -f $testfile &>/dev/null
1643 echo $testseek | grep -q "Kernel does not support" && \
1644 _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
1647 # check that a FS on a device is mounted
1648 # if so, return mount point
1654 echo "Usage: _is_mounted device" 1>&2
1660 if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
1661 pattern { print $3 ; exit 0 }
1665 echo "_is_mounted: $device is not a mounted $FSTYP FS"
1670 # remount a FS to a new mode (ro or rw)
1676 echo "Usage: _remount device ro/rw" 1>&2
1682 if ! mount -o remount,$mode $device
1684 echo "_remount: failed to remount filesystem on $device as $mode"
1689 # Run the appropriate repair/check on a filesystem
1691 # if the filesystem is mounted, it's either remounted ro before being
1692 # checked or it's unmounted and then remounted
1695 # If set, we remount ro instead of unmounting for fsck
1698 _umount_or_remount_ro()
1702 echo "Usage: _umount_or_remount_ro <device>" 1>&2
1707 mountpoint=`_is_mounted $device`
1709 if [ $USE_REMOUNT -eq 0 ]; then
1710 $UMOUNT_PROG $device
1717 _mount_or_remount_rw()
1721 echo "Usage: _mount_or_remount_rw <opts> <device> <mountpoint>" 1>&2
1728 if [ $USE_REMOUNT -eq 0 ]
1730 if ! _mount -t $FSTYP $mount_opts $device $mountpoint
1732 echo "!!! failed to remount $device on $mountpoint"
1742 # Check a generic filesystem in no-op mode; this assumes that the
1743 # underlying fsck program accepts "-n" for a no-op (check-only) run,
1744 # and that it will still return an errno for corruption in this mode.
1746 # Filesystems which don't support this will need to define their
1747 # own check routine.
1749 _check_generic_filesystem()
1753 # If type is set, we're mounted
1754 type=`_fs_type $device`
1757 if [ "$type" = "$FSTYP" ]
1760 mountpoint=`_umount_or_remount_ro $device`
1763 fsck -t $FSTYP $FSCK_OPTIONS $device >$tmp.fsck 2>&1
1766 echo "_check_generic_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1768 echo "_check_generic filesystem: filesystem on $device is inconsistent" >>$seqres.full
1769 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1770 cat $tmp.fsck >>$seqres.full
1771 echo "*** end fsck.$FSTYP output" >>$seqres.full
1779 echo "*** mount output ***" >>$seqres.full
1780 _mount >>$seqres.full
1781 echo "*** end mount output" >>$seqres.full
1782 elif [ "$type" = "$FSTYP" ]
1785 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
1789 if [ $ok -eq 0 ]; then
1791 if [ "$iam" != "check" ]; then
1800 # run xfs_check and friends on a FS.
1802 _check_xfs_filesystem()
1806 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
1810 extra_mount_options=""
1812 if [ "$2" != "none" ]; then
1813 extra_log_options="-l$2"
1814 extra_mount_options="-ologdev=$2"
1817 if [ "$3" != "none" ]; then
1818 extra_rt_options="-r$3"
1819 extra_mount_options=$extra_mount_options" -ortdev=$3"
1821 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
1823 [ "$FSTYP" != xfs ] && return 0
1825 type=`_fs_type $device`
1828 if [ "$type" = "xfs" ]
1831 mountpoint=`_umount_or_remount_ro $device`
1834 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
1835 | tee $tmp.logprint | grep -q "<CLEAN>"
1836 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]
1838 echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
1840 echo "_check_xfs_filesystem: filesystem on $device has dirty log" >>$seqres.full
1841 echo "*** xfs_logprint -t output ***" >>$seqres.full
1842 cat $tmp.logprint >>$seqres.full
1843 echo "*** end xfs_logprint output" >>$seqres.full
1848 # xfs_check runs out of memory on large files, so even providing the test
1849 # option (-t) to avoid indexing the free space trees doesn't make it pass on
1850 # large filesystems. Avoid it.
1851 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
1852 _xfs_check $extra_log_options $device 2>&1 |\
1853 _fix_malloc >$tmp.fs_check
1855 if [ -s $tmp.fs_check ]
1857 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (c) (see $seqres.full)"
1859 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1860 echo "*** xfs_check output ***" >>$seqres.full
1861 cat $tmp.fs_check >>$seqres.full
1862 echo "*** end xfs_check output" >>$seqres.full
1867 $XFS_REPAIR_PROG -n $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
1870 echo "_check_xfs_filesystem: filesystem on $device is inconsistent (r) (see $seqres.full)"
1872 echo "_check_xfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1873 echo "*** xfs_repair -n output ***" >>$seqres.full
1874 cat $tmp.repair | _fix_malloc >>$seqres.full
1875 echo "*** end xfs_repair output" >>$seqres.full
1879 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
1883 echo "*** mount output ***" >>$seqres.full
1884 _mount >>$seqres.full
1885 echo "*** end mount output" >>$seqres.full
1886 elif [ "$type" = "xfs" ]
1888 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
1891 if [ $ok -eq 0 ]; then
1893 if [ "$iam" != "check" ]; then
1902 # Filter the knowen errors the UDF Verifier reports.
1903 _udf_test_known_error_filter()
1905 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."
1909 _check_udf_filesystem()
1911 [ "$DISABLE_UDF_TEST" == "1" ] && return
1913 if [ $# -ne 1 -a $# -ne 2 ]
1915 echo "Usage: _check_udf_filesystem device [last_block]" 1>&2
1919 if [ ! -x $here/src/udf_test ]
1921 echo "udf_test not installed, please download and build the Philips"
1922 echo "UDF Verification Software from http://www.extra.research.philips.com/udf/."
1923 echo "Then copy the udf_test binary to $here/src/."
1924 echo "If you do not wish to run udf_test then set environment variable DISABLE_UDF_TEST"
1932 LAST_BLOCK=`expr \( $2 - 1 \)`
1933 OPT_ARG="-lastvalidblock $LAST_BLOCK"
1936 rm -f $seqres.checkfs
1937 sleep 1 # Due to a problem with time stamps in udf_test
1938 $here/src/udf_test $OPT_ARG $device | tee $seqres.checkfs | egrep "Error|Warning" | \
1939 _udf_test_known_error_filter | \
1940 egrep -iv "Error count:.*[0-9]+.*total occurrences:.*[0-9]+|Warning count:.*[0-9]+.*total occurrences:.*[0-9]+" && \
1941 echo "Warning UDF Verifier reported errors see $seqres.checkfs." && return 1
1945 _check_xfs_test_fs()
1949 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
1950 TEST_LOG="$TEST_LOGDEV"
1952 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
1953 TEST_RT="$TEST_RTDEV"
1955 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
1957 # check for ipath consistency
1958 if $XFS_GROWFS_PROG -n $TEST_DIR | grep -q 'inode-paths=1'; then
1959 # errors go to stderr
1960 xfs_check_ipaths $TEST_DIR >/dev/null
1961 xfs_repair_ipaths -n $TEST_DIR >/dev/null
1965 _check_btrfs_filesystem()
1969 # If type is set, we're mounted
1970 type=`_fs_type $device`
1973 if [ "$type" = "$FSTYP" ]
1976 mountpoint=`_umount_or_remount_ro $device`
1979 btrfsck $device >$tmp.fsck 2>&1
1982 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
1984 echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
1985 echo "*** fsck.$FSTYP output ***" >>$seqres.full
1986 cat $tmp.fsck >>$seqres.full
1987 echo "*** end fsck.$FSTYP output" >>$seqres.full
1995 echo "*** mount output ***" >>$seqres.full
1996 _mount >>$seqres.full
1997 echo "*** end mount output" >>$seqres.full
1998 elif [ "$type" = "$FSTYP" ]
2001 _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
2005 if [ $ok -eq 0 ]; then
2007 if [ "$iam" != "check" ]; then
2023 # no way to check consistency for nfs
2026 # no way to check consistency for cifs
2029 # do nothing for now
2032 _check_btrfs_filesystem $TEST_DEV
2035 # no way to check consistency for tmpfs
2038 _check_generic_filesystem $TEST_DEV
2046 [ $# -eq 1 ] && device=$1
2052 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
2053 SCRATCH_LOG="$SCRATCH_LOGDEV"
2055 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
2056 SCRATCH_RT="$SCRATCH_RTDEV"
2058 _check_xfs_filesystem $device $SCRATCH_LOG $SCRATCH_RT
2061 _check_udf_filesystem $device $udf_fsize
2064 # Don't know how to check an NFS filesystem, yet.
2067 # Don't know how to check a CIFS filesystem, yet.
2070 _check_btrfs_filesystem $device
2073 # no way to check consistency for tmpfs
2076 _check_generic_filesystem $device
2081 _full_fstyp_details()
2083 [ -z "$FSTYP" ] && FSTYP=xfs
2084 if [ $FSTYP = xfs ]; then
2085 if [ -d /proc/fs/xfs ]; then
2086 if grep -q 'debug 0' /proc/fs/xfs/stat; then
2087 FSTYP="$FSTYP (non-debug)"
2088 elif grep -q 'debug 1' /proc/fs/xfs/stat; then
2089 FSTYP="$FSTYP (debug)"
2092 if uname -a | grep -qi 'debug'; then
2093 FSTYP="$FSTYP (debug)"
2095 FSTYP="$FSTYP (non-debug)"
2102 _full_platform_details()
2108 echo "$os/$platform $host $kernel"
2113 if [ -z "$1" -o -z "$2" ]; then
2114 echo Error must pass src and dst.
2118 if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
2120 elif [ "`uname`" == "Linux" ]; then
2123 echo Error test $seq does not run on the operating system: `uname`
2134 #takes files, randomdata
2142 if [ $size -gt 0 ]; then
2143 if [ "$2" == "false" ]; then
2144 dd if=/dev/zero of=$file bs=1024 count=$size 2>&1 | _filter_dd
2146 dd if=/dev/urandom of=$file bs=1024 count=$size 2>&1 | _filter_dd
2153 # takes dirname, depth, randomdata
2156 dirname=$1; depth=$2; randomdata=$3
2157 mkdir $dirname || die "mkdir $dirname failed"
2160 _nfiles $files $randomdata # files for this dir and data type
2162 [ $depth -eq 0 ] && return
2163 let deep=$depth-1 # go 1 down
2165 [ $verbose = true ] && echo "descending, depth from leaves = $deep"
2168 while [ $d -lt $dirs ]
2170 _descend d$d $deep &
2176 # Populate a filesystem with inodes for performance experiments
2178 # usage: populate [-v] [-n ndirs] [-f nfiles] [-d depth] [-r root] [-s size] [-x]
2183 dirs=5 # ndirs in each subdir till leaves
2184 size=0 # sizeof files in K
2185 files=100 # num files in _each_ subdir
2186 depth=2 # depth of tree from root to leaves
2188 root=root # path of initial root of directory tree
2189 randomdata=false # -x data type urandom or zero
2192 while getopts "d:f:n:r:s:v:x" c
2201 x) randomdata=true;;
2205 _descend $root $depth $randomdata
2210 [ $verbose = true ] && echo done
2213 # query whether the given file has the given inode flag set
2220 if which $XFS_IO_PROG >/dev/null; then
2221 if $XFS_IO_PROG -r -c 'lsattr -v' "$file" | grep -q "$flag" ; then
2228 # query the given files extsize allocator hint in bytes (if any)
2235 if which $XFS_IO_PROG >/dev/null; then
2236 blocks=`$XFS_IO_PROG -r -c 'stat' "$file" | \
2237 awk '/^xattr.extsize =/ { print $3 }'`
2239 [ -z "$blocks" ] && blocks="0"
2243 # scratch_dev_pool should contain the disks pool for the btrfs raid
2244 _require_scratch_dev_pool()
2249 if [ -z "$SCRATCH_DEV_POOL" ]; then
2250 _notrun "this test requires a valid \$SCRATCH_DEV_POOL"
2253 if [ -z "$1" ]; then
2259 # btrfs test case needs ndevs or more scratch_dev_pool; other FS not sure
2263 if [ "`echo $SCRATCH_DEV_POOL|wc -w`" -lt $ndevs ]; then
2264 _notrun "btrfs and this test needs $ndevs or more disks in SCRATCH_DEV_POOL"
2268 _notrun "dev_pool is not supported by fstype \"$FSTYP\""
2272 for i in $SCRATCH_DEV_POOL; do
2273 if [ "`_is_block_dev $i`" = "" ]; then
2274 _notrun "this test requires valid block disk $i"
2276 if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
2277 _notrun "$i is part of TEST_DEV, this test requires unique disks"
2279 if _mount | grep -q $i; then
2280 if ! $UMOUNT_PROG $i; then
2281 echo "failed to unmount $i - aborting"
2285 # to help better debug when something fails, we remove
2286 # traces of previous btrfs FS on the dev.
2287 dd if=/dev/zero of=$i bs=4096 count=100 > /dev/null 2>&1
2291 # ensure devices in SCRATCH_DEV_POOL are of the same size
2292 # must be called after _require_scratch_dev_pool
2293 _require_scratch_dev_pool_equal_size()
2299 # SCRATCH_DEV has been set to the first device in SCRATCH_DEV_POOL
2300 _size=`_get_device_size $SCRATCH_DEV`
2301 for _dev in $SCRATCH_DEV_POOL; do
2302 _newsize=`_get_device_size $_dev`
2303 if [ $_size -ne $_newsize ]; then
2304 _notrun "This test requires devices in SCRATCH_DEV_POOL have the same size"
2309 # We will check if the device is deletable
2310 _require_deletable_scratch_dev_pool()
2314 for i in $SCRATCH_DEV_POOL; do
2315 x=`echo $i | cut -d"/" -f 3`
2316 if [ ! -f /sys/class/block/${x}/device/delete ]; then
2317 _notrun "$i is a device which is not deletable"
2322 # We check for btrfs and (optionally) features of the btrfs command
2326 _require_command "$BTRFS_UTIL_PROG" btrfs
2327 if [ -z "$1" ]; then
2330 $BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
2331 [ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
2334 # Check that fio is present, and it is able to execute given jobfile
2339 _require_command "$FIO_PROG" fio
2340 if [ -z "$1" ]; then
2344 $FIO_PROG --warnings-fatal --showcmd $job >> $seqres.full 2>&1
2345 [ $? -eq 0 ] || _notrun "$FIO_PROG too old, see $seqres.full"
2348 # Does freeze work on this fs?
2351 xfs_freeze -f "$TEST_DIR" >/dev/null 2>&1
2353 xfs_freeze -u "$TEST_DIR" >/dev/null 2>&1
2354 [ $result -eq 0 ] || _notrun "$FSTYP does not support freezing"
2357 # Does shutdown work on this fs?
2358 _require_scratch_shutdown()
2360 [ -x src/godown ] || _notrun "src/godown executable not found"
2362 _scratch_mkfs > /dev/null 2>&1
2364 src/godown -f $SCRATCH_MNT 2>&1 \
2365 || _notrun "$FSTYP does not support shutdown"
2369 # Does norecovery support by this fs?
2370 _require_norecovery()
2372 _scratch_mount -o ro,norecovery || \
2373 _notrun "$FSTYP does not support norecovery"
2377 # Does this filesystem support metadata journaling?
2378 # We exclude ones here that don't; otherwise we assume that it does, so the
2379 # test will run, fail, and motivate someone to update this test for a new
2382 # It's possible that TEST_DEV and SCRATCH_DEV have different features (it'd be
2383 # odd, but possible) so check $TEST_DEV by default, but we can optionall pass
2385 _require_metadata_journaling()
2395 _notrun "$FSTYP does not support metadata journaling"
2398 # ext4 could be mkfs'd without a journal...
2400 $DUMPE2FS_PROG -h $DEV 2>&1 | grep -q has_journal || \
2401 _notrun "$FSTYP on $DEV not configured with metadata journaling"
2404 # by default we pass; if you need to, add your fs above!
2409 # Does fiemap support?
2412 _require_xfs_io_command "fiemap"
2417 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2418 echo $res | grep -v hole | wc -l | $AWK_PROG '{print $1}'
2423 res=`$XFS_IO_PROG -c "fiemap" $1 | tail -n +2`
2424 echo $res | grep hole | wc -l | $AWK_PROG '{print $1}'
2427 # arg 1 is dev to remove and is output of the below eg.
2428 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2434 echo 1 > /sys/class/scsi_device/${lun}/device/delete || _fail "Remove disk failed"
2436 stat $disk > /dev/null 2>&1
2437 while [ $? -eq 0 ]; do
2439 stat $disk > /dev/null 2>&1
2443 # arg 1 is dev to add and is output of the below eg.
2444 # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
2449 # arg 1 will be in h:t:d:l format now in the h and "t d l" format
2450 h=`echo ${1} | cut -d":" -f 1`
2451 tdl=`echo ${1} | cut -d":" -f 2-|sed 's/:/ /g'`
2453 echo ${tdl} > /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
2455 # ensure the device comes online
2457 for i in `seq 1 10`; do
2458 if [ -d /sys/class/scsi_device/${1}/device/block ]; then
2459 dev=`ls /sys/class/scsi_device/${1}/device/block`
2460 for j in `seq 1 10`;
2462 stat /dev/$dev > /dev/null 2>&1
2463 if [ $? -eq 0 ]; then
2474 if [ $dev_back_oneline -eq 0 ]; then
2475 echo "/dev/$dev online failed" >> $seqres.full
2477 echo "/dev/$dev is back online" >> $seqres.full
2483 if [ -z "$FSTRIM_PROG" ]; then
2484 _notrun "This test requires fstrim utility."
2488 _require_batched_discard()
2490 if [ $# -ne 1 ]; then
2491 echo "Usage: _require_batched_discard mnt_point" 1>&2
2495 $FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
2500 if [ -z "$DUMPE2FS_PROG" ]; then
2501 _notrun "This test requires dumpe2fs utility."
2507 if [ ! -e /proc/self/uid_map ]; then
2508 _notrun "This test requires procfs uid_map support."
2510 if [ ! -e /proc/self/gid_map ]; then
2511 _notrun "This test requires procfs gid_map support."
2515 _require_cp_reflink()
2517 cp --help | grep -q reflink || \
2518 _notrun "This test requires a cp with --reflink support."
2523 FSSUM_PROG=$here/src/fssum
2524 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
2529 CLONER_PROG=$here/src/cloner
2530 [ -x $CLONER_PROG ] || \
2531 _notrun "cloner binary not present at $CLONER_PROG"
2534 # Given 2 files, verify that they have the same mapping but different
2535 # inodes - i.e. an undisturbed reflink
2536 # Silent if so, make noise if not
2539 # not a hard link or symlink?
2540 cmp -s <(stat -c '%i' $1) <(stat -c '%i' $2) \
2541 && echo "$1 and $2 are not reflinks: same inode number"
2544 diff -u <($XFS_IO_PROG -c "fiemap" $1 | grep -v $1) \
2545 <($XFS_IO_PROG -c "fiemap" $2 | grep -v $2) \
2546 || echo "$1 and $2 are not reflinks: different extents"
2551 if [ "$FSTYP" == "nfs" ]; then
2552 _notrun "atime related mount options have no effect on NFS"
2558 _scratch_mkfs > /dev/null 2>&1
2559 _scratch_mount -o relatime || \
2560 _notrun "relatime not supported by the current kernel"
2566 [ -x src/nsexec ] || _notrun "src/nsexec executable not found"
2567 src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
2570 _create_loop_device()
2573 dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
2577 _destroy_loop_device()
2580 losetup -d $dev || _fail "Cannot destroy loop device $dev"
2583 _scale_fsstress_args()
2586 while [ $# -gt 0 ]; do
2588 -n) args="$args $1 $(($2 * $TIME_FACTOR))"; shift ;;
2589 -p) args="$args $1 $(($2 * $LOAD_FACTOR))"; shift ;;
2590 *) args="$args $1" ;;
2598 # Return the logical block size if running on a block device,
2599 # else substitute the page size.
2601 _min_dio_alignment()
2605 if [ -b "$dev" ]; then
2606 blockdev --getss $dev
2608 $here/src/feature -s
2614 echo "# $@" >> $seqres.full 2>&1
2615 "$@" >> $seqres.full 2>&1 || _fail "failed: '$@'"
2618 _run_btrfs_util_prog()
2620 run_check $BTRFS_UTIL_PROG $*
2623 _require_btrfs_send_stream_version()
2625 $BTRFS_UTIL_PROG send 2>&1 | \
2626 grep '^[ \t]*\-\-stream\-version <version>' > /dev/null 2>&1
2627 if [ $? -ne 0 ]; then
2628 _notrun "Missing btrfs-progs send --stream-version command line option, skipped this test"
2631 # test if btrfs kernel supports send stream version 2
2632 if [ ! -f /sys/fs/btrfs/send/stream_version ]; then
2633 _notrun "Missing btrfs kernel patch for send stream version 2, skipped this test"
2637 _require_btrfs_mkfs_feature()
2640 echo "Missing feature name argument for _require_btrfs_mkfs_feature"
2644 $MKFS_BTRFS_PROG -O list-all 2>&1 | \
2645 grep '^[ \t]*'"$feat"'\b' > /dev/null 2>&1
2647 _notrun "Feature $feat not supported in the available version of mkfs.btrfs"
2650 _require_btrfs_fs_feature()
2653 echo "Missing feature name argument for _require_btrfs_fs_feature"
2657 modprobe btrfs > /dev/null 2>&1
2658 [ -e /sys/fs/btrfs/features/$feat ] || \
2659 _notrun "Feature $feat not supported by the available btrfs version"
2662 _require_test_symlinks()
2664 # IRIX UDF does not support symlinks
2665 [ "$HOSTOS" = "IRIX" -a "$FSTYP" = 'udf' ] && \
2666 _notrun "Require symlinks support"
2667 target=`mktemp -p $TEST_DIR`
2668 link=`mktemp -p $TEST_DIR -u`
2669 ln -s `basename $target` $link
2670 if [ "$?" -ne 0 ]; then
2672 _notrun "Require symlinks support"
2677 _require_test_fcntl_advisory_locks()
2679 [ "$FSTYP" != "cifs" ] && return 0
2680 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -q "nobrl" && return 0
2681 cat /proc/mounts | grep $TEST_DEV | grep cifs | grep -qE "nounix|forcemand" && \
2682 _notrun "Require fcntl advisory locks support"
2687 if [ -z "$1" ]; then
2688 echo "Usage: _get_total_inode <mnt>"
2692 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $3}'`
2698 if [ -z "$1" ]; then
2699 echo "Usage: _get_used_inode <mnt>"
2703 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $4}'`
2709 if [ -z "$1" ]; then
2710 echo "Usage: _get_free_inode <mnt>"
2714 nr_inode=`$DF_PROG -i $1 | tail -1 | awk '{print $5}'`
2718 # get btrfs profile configs being tested
2720 # A set of pre-set profile configs are exported via _btrfs_profile_configs
2721 # array. Default configs can be overridden by setting BTRFS_PROFILE_CONFIGS
2722 # var in the format "metadata_profile:data_profile", multiple configs can be
2723 # seperated by space, e.g.
2724 # export BTRFS_PROFILE_CONFIGS="raid0:raid0 raid1:raid1 dup:single"
2725 _btrfs_get_profile_configs()
2727 if [ "$FSTYP" != "btrfs" ]; then
2731 # no user specified btrfs profile configs, export the default configs
2732 if [ -z "$BTRFS_PROFILE_CONFIGS" ]; then
2734 _btrfs_profile_configs=(
2735 "-m single -d single"
2740 "-m raid10 -d raid10"
2745 # remove dup/raid5/raid6 profiles if we're doing device replace
2746 # dup profile indicates only one device being used (SCRATCH_DEV),
2747 # but we don't want to replace SCRATCH_DEV, which will be used in
2748 # _scratch_mount/_check_scratch_fs etc.
2749 # and raid5/raid6 doesn't support replace yet
2750 if [ "$1" == "replace" ]; then
2751 _btrfs_profile_configs=(
2752 "-m single -d single"
2756 "-m raid10 -d raid10"
2757 # add these back when raid5/6 is working with replace
2758 #"-m raid5 -d raid5"
2759 #"-m raid6 -d raid6"
2762 export _btrfs_profile_configs
2766 # parse user specified btrfs profile configs
2769 for cfg in $BTRFS_PROFILE_CONFIGS; do
2770 # turn "metadata:data" format to "-m metadata -d data"
2771 # and assign it to _btrfs_profile_configs array
2772 cfg=`echo "$cfg" | sed -e 's/^/-m /' -e 's/:/ -d /'`
2773 _btrfs_profile_configs[$i]="$cfg"
2777 if [ "$1" == "replace" ]; then
2778 if echo ${_btrfs_profile_configs[*]} | grep -q raid[56]; then
2779 _notrun "RAID5/6 doesn't support btrfs device replace yet"
2781 if echo ${_btrfs_profile_configs[*]} | grep -q dup; then
2782 _notrun "Do not set dup profile in btrfs device replace test"
2785 export _btrfs_profile_configs
2788 # stress btrfs by running balance operation in a loop
2789 _btrfs_stress_balance()
2793 $BTRFS_UTIL_PROG balance start $btrfs_mnt
2797 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
2798 _btrfs_stress_subvolume()
2802 local subvol_name=$3
2805 mkdir -p $subvol_mnt
2807 $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
2808 $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt
2809 $UMOUNT_PROG $subvol_mnt
2810 $BTRFS_UTIL_PROG subvolume delete $btrfs_mnt/$subvol_name
2814 # stress btrfs by running scrub in a loop
2815 _btrfs_stress_scrub()
2819 $BTRFS_UTIL_PROG scrub start -B $btrfs_mnt
2823 # stress btrfs by defragmenting every file/dir in a loop and compress file
2824 # contents while defragmenting if second argument is not "nocompress"
2825 _btrfs_stress_defrag()
2831 if [ "$compress" == "nocompress" ]; then
2832 find $btrfs_mnt \( -type f -o -type d \) -exec \
2833 $BTRFS_UTIL_PROG filesystem defrag {} \;
2835 find $btrfs_mnt \( -type f -o -type d \) -exec \
2836 $BTRFS_UTIL_PROG filesystem defrag -clzo {} \;
2837 find $btrfs_mnt \( -type f -o -type d \) -exec \
2838 $BTRFS_UTIL_PROG filesystem defrag -czlib {} \;
2843 # stress btrfs by remounting it with different compression algorithms in a loop
2844 # run this with fsstress running at background could exercise the compression
2845 # code path and ensure no race when switching compression algorithm with constant
2847 _btrfs_stress_remount_compress()
2851 for algo in no zlib lzo; do
2852 $MOUNT_PROG -o remount,compress=$algo $btrfs_mnt
2857 # stress btrfs by replacing devices in a loop
2858 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
2859 # device should be free(not used by btrfs)
2860 _btrfs_stress_replace()
2864 # The device number in SCRATCH_DEV_POOL should be at least 3,
2865 # one is SCRATCH_DEV, one is to be replaced, one is free device
2866 # we won't replace SCRATCH_DEV, see below for reason
2867 if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt 3 ]; then
2868 echo "_btrfs_stress_replace requires at least 3 devices in SCRATCH_DEV_POOL"
2872 # take the last device as the first free_dev
2873 local free_dev="`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`"
2875 # free_dev should be really free
2876 if $BTRFS_UTIL_PROG filesystem show $btrfs_mnt | grep -q "$free_dev"; then
2877 echo "_btrfs_stress_replace: $free_dev is used by btrfs"
2881 # dev_pool is device list being currently used by btrfs (excluding SCRATCH_DEV)
2882 # and can be replaced. We don't replace SCRATCH_DEV because it will be used in
2883 # _scratch_mount and _check_scratch_fs etc.
2884 local dev_pool=`echo $SCRATCH_DEV_POOL | sed -e "s# *$SCRATCH_DEV *##" \
2885 -e "s# *$free_dev *##"`
2887 # set the first device in dev_pool as the first src_dev to be replaced
2888 local src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2890 echo "dev_pool=$dev_pool"
2891 echo "free_dev=$free_dev, src_dev=$src_dev"
2893 echo "Replacing $src_dev with $free_dev"
2894 $BTRFS_UTIL_PROG replace start -fB $src_dev $free_dev $btrfs_mnt
2895 if [ $? -ne 0 ]; then
2896 # don't update src_dev and free_dev if replace failed
2899 dev_pool="$dev_pool $free_dev"
2900 dev_pool=`echo $dev_pool | sed -e "s# *$src_dev *##"`
2902 src_dev=`echo $dev_pool | $AWK_PROG '{print $1}'`
2906 # find the right option to force output in bytes, older versions of btrfs-progs
2907 # print that by default, newer print human readable numbers with unit suffix
2908 _btrfs_qgroup_units()
2910 $BTRFS_UTIL_PROG qgroup show --help 2>&1 | grep -q -- --raw && echo "--raw"
2913 # return device size in kb
2916 grep `_short_dev $1` /proc/partitions | awk '{print $3}'
2919 # don't check dmesg log after test
2920 _disable_dmesg_check()
2922 rm -f ${RESULT_DIR}/check_dmesg
2927 if [ "$iam" == new ]
2931 # make some further configuration checks here
2932 if [ "$TEST_DEV" = "" ]
2934 echo "common/rc: Error: \$TEST_DEV is not set"
2938 # if $TEST_DEV is not mounted, mount it now as XFS
2939 if [ -z "`_fs_type $TEST_DEV`" ]
2941 # $TEST_DEV is not mounted
2944 echo "common/rc: retrying test device mount with external set"
2945 [ "$USE_EXTERNAL" != "yes" ] && export USE_EXTERNAL=yes
2948 echo "common/rc: could not mount $TEST_DEV on $TEST_DIR"
2954 if [ "`_fs_type $TEST_DEV`" != "$FSTYP" ]
2956 echo "common/rc: Error: \$TEST_DEV ($TEST_DEV) is not a MOUNTED $FSTYP filesystem"
2960 # Figure out if we need to add -F ("foreign", deprecated) option to xfs_io
2961 xfs_io -c stat $TEST_DIR 2>&1 | grep -q "is not on an XFS filesystem" && \
2962 export XFS_IO_PROG="$XFS_IO_PROG -F"
2964 # xfs_copy doesn't work on v5 xfs yet without -d option
2965 if [ "$FSTYP" == "xfs" ] && [[ $MKFS_OPTIONS =~ crc=1 ]]; then
2966 export XFS_COPY_PROG="$XFS_COPY_PROG -d"
2970 # get real device path name by following link
2974 if [ -b "$_dev" ] && [ -L "$_dev" ]; then
2975 _dev=`readlink -f "$_dev"`
2980 # basename of a device
2983 echo `basename $(_real_dev $1)`
2988 if [ -z $1 ] || [ ! -d $1 ]; then
2989 echo "Missing mount point argument for get_block_size"
2992 echo `stat -f -c %S $1`
2997 ################################################################################
2998 # make sure this script returns success