276: fix up various issues

This commit fixes bd8ee45c. Changes:
- added a _require_btrfs helper function
- check for filefrag with _require_command
- always use _fail in case of errors
- added some comments
- removed $fresh code
- don't set FSTYP

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Jan Schmidt
2012-01-04 18:54:46 +01:00
committed by Christoph Hellwig
parent bd8ee45cf7
commit ae4766ce1a
2 changed files with 81 additions and 44 deletions
+69 -44
View File
@@ -1,5 +1,29 @@
#! /bin/bash #! /bin/bash
# FSQA Test No. 276
#
# Run fsstress to create a reasonably strange file system, make a
# snapshot and run more fsstress. Then select some files from that fs,
# run filefrag to get the extent mapping and follow the backrefs.
# We check to end up back at the original file with the correct offset.
#
#-----------------------------------------------------------------------
# Copyright (C) 2011 STRATO. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
#-----------------------------------------------------------------------
#
# creator # creator
owner=list.btrfs@jan-o-sch.net owner=list.btrfs@jan-o-sch.net
@@ -7,18 +31,13 @@ seq=`basename $0`
echo "QA output created by $seq" echo "QA output created by $seq"
here=`pwd` here=`pwd`
# 1=production, 0=avoid touching the scratch dev (no mount/umount, no writes)
fresh=1
tmp=/tmp/$$ tmp=/tmp/$$
status=1 status=1
FSTYP=btrfs
_cleanup() _cleanup()
{ {
if [ $fresh -ne 0 ]; then echo "*** unmount"
echo "*** unmount" umount $SCRATCH_MNT 2>/dev/null
umount $SCRATCH_MNT 2>/dev/null
fi
rm -f $tmp.* rm -f $tmp.*
} }
trap "_cleanup; exit \$status" 0 1 2 3 15 trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -28,21 +47,14 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
. ./common.filter . ./common.filter
# real QA test starts here # real QA test starts here
_need_to_be_root
_supported_fs btrfs _supported_fs btrfs
_supported_os Linux _supported_os Linux
_require_scratch
if [ $fresh -ne 0 ]; then
_require_scratch
fi
_require_nobigloopfs _require_nobigloopfs
_require_btrfs inspect-internal
[ -n "$BTRFS_UTIL_PROG" ] || _notrun "btrfs executable not found" _require_command "/usr/sbin/filefrag"
$BTRFS_UTIL_PROG inspect-internal --help >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "btrfs executable too old"
which filefrag >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "filefrag missing"
rm -f $seq.full rm -f $seq.full
@@ -52,6 +64,10 @@ FILEFRAG_FILTER='if (/, blocksize (\d+)/) {$blocksize = $1; next} ($ext, '\
'/(?:^|,)inline(?:,|$)/ and next; print $physical * $blocksize, "#", '\ '/(?:^|,)inline(?:,|$)/ and next; print $physical * $blocksize, "#", '\
'$length * $blocksize, "#", $logical * $blocksize, " "' '$length * $blocksize, "#", $logical * $blocksize, " "'
# this makes filefrag output script readable by using a perl helper.
# output is one extent per line, with three numbers separated by '#'
# the numbers are: physical, length, logical (all in bytes)
# sample output: "1234#10#5678" -> physical 1234, length 10, logical 5678
_filter_extents() _filter_extents()
{ {
tee -a $seq.full | $PERL_PROG -ne "$FILEFRAG_FILTER" tee -a $seq.full | $PERL_PROG -ne "$FILEFRAG_FILTER"
@@ -70,6 +86,9 @@ _check_file_extents()
return 0 return 0
} }
# use a logical address and walk the backrefs back to the inode.
# compare to the expected result.
# returns 0 on success, 1 on error (with output made)
_btrfs_inspect_addr() _btrfs_inspect_addr()
{ {
mp=$1 mp=$1
@@ -101,6 +120,9 @@ _btrfs_inspect_addr()
return 1 return 1
} }
# use an inode number and walk the backrefs back to the file name.
# compare to the expected result.
# returns 0 on success, 1 on error (with output made)
_btrfs_inspect_inum() _btrfs_inspect_inum()
{ {
file=$1 file=$1
@@ -134,14 +156,13 @@ _btrfs_inspect_check()
echo "# $cmd" >> $seq.full echo "# $cmd" >> $seq.full
inum=`$cmd` inum=`$cmd`
echo "$inum" >> $seq.full echo "$inum" >> $seq.full
_btrfs_inspect_addr "$SCRATCH_MNT/$snap_name" $physical $logical $inum\ _btrfs_inspect_addr $SCRATCH_MNT $physical $logical $inum $file
$file
ret=$? ret=$?
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
_btrfs_inspect_inum $file $inum $snap_name _btrfs_inspect_inum $file $inum $snap_name
ret=$? ret=$?
fi fi
return $? return $ret
} }
run_check() run_check()
@@ -157,30 +178,34 @@ workout()
procs=$3 procs=$3
snap_name=$4 snap_name=$4
if [ $fresh -ne 0 ]; then umount $SCRATCH_DEV >/dev/null 2>&1
umount $SCRATCH_DEV >/dev/null 2>&1 echo "*** mkfs -dsize=$fsz" >>$seq.full
echo "*** mkfs -dsize=$fsz" >>$seq.full echo "" >>$seq.full
echo "" >>$seq.full _scratch_mkfs_sized $fsz >>$seq.full 2>&1 \
_scratch_mkfs_sized $fsz >>$seq.full 2>&1 \ || _fail "size=$fsz mkfs failed"
|| _fail "size=$fsz mkfs failed" run_check _scratch_mount
_scratch_mount >>$seq.full 2>&1 \ # -w ensures that the only ops are ones which cause write I/O
|| _fail "mount failed" run_check $FSSTRESS_PROG -d $SCRATCH_MNT -w -p $procs -n 1000 \
# -w ensures that the only ops are ones which cause write I/O $FSSTRESS_AVOID
run_check $FSSTRESS_PROG -d $SCRATCH_MNT -w -p $procs -n 1000 \
$FSSTRESS_AVOID
run_check $BTRFS_UTIL_PROG subvol snap $SCRATCH_MNT \ run_check $BTRFS_UTIL_PROG subvol snap $SCRATCH_MNT \
$SCRATCH_MNT/$snap_name $SCRATCH_MNT/$snap_name
run_check umount $SCRATCH_DEV >/dev/null 2>&1 run_check umount $SCRATCH_DEV >/dev/null 2>&1
run_check _scratch_mount "-o compress=lzo" run_check _scratch_mount "-o compress=lzo"
# -w ensures that the only ops are ones which cause write I/O # make some noise but ensure we're not touching existing data
run_check $FSSTRESS_PROG -d $SCRATCH_MNT -w -p $procs -n 2000 \ # extents.
$FSSTRESS_AVOID run_check $FSSTRESS_PROG -d $SCRATCH_MNT -p $procs -n 2000 \
else -z -f chown=3 -f link=1 -f mkdir=2 -f mknod=2 \
echo "*** skipping mkfs part" >>$seq.full -f rename=2 -f setxattr=1 -f symlink=2
fi clean_dir="$SCRATCH_MNT/next"
mkdir $clean_dir
# now make more files to get a higher tree
run_check $FSSTRESS_PROG -d $clean_dir -w -p $procs -n 2000 \
$FSSTRESS_AVOID
run_check umount $SCRATCH_DEV >/dev/null 2>&1
run_check _scratch_mount "-o atime"
cnt=0 cnt=0
errcnt=0 errcnt=0
@@ -212,7 +237,7 @@ workout()
fi fi
done done
if [ $errcnt -gt 0 ]; then if [ $errcnt -gt 0 ]; then
echo "test failed: $errcnt error(s)" _fail "test failed: $errcnt error(s)"
fi fi
} }
+12
View File
@@ -1692,6 +1692,18 @@ _require_deletable_scratch_dev_pool()
done done
} }
# We check for btrfs and (optionally) features of the btrfs command
_require_btrfs()
{
cmd=$1
_require_command $BTRFS_UTIL_PROG btrfs
if [ -z "$1" ]; then
return 1;
fi
$BTRFS_UTIL_PROG $cmd --help >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd)"
}
# arg 1 is dev to remove and is output of the below eg. # arg 1 is dev to remove and is output of the below eg.
# ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev # ls -l /sys/class/block/sdd | rev | cut -d "/" -f 3 | rev
_devmgt_remove() _devmgt_remove()