Files
apfstests/tests/btrfs/284
T
Eric Sandeen 91f87e3b89 xfstests btrfs/284: shorten duration, fix output
test 284 had... some issues.

First, it took so long nobody ran it; so shorten the extent
count by a factor of about 100.

Having fixed that, we see failures in 2 cases; when start or
len is -1, but the golden output file didn't have error
output, as if they should pass.

I'm going to argue that these *should* both fail; start = -1
has no real meaning.  length = -1 might mean "the rest
of the file" but if that's what you really want, just
don't specify -l.

So add failure output for those cases.

Send all command output to $seq.full, in case that changes
in the future; just capture the return value.

Then remove the return value echo on failure (50?) because
who knows when that might change to some other magic value.

Ok, then when defrag actually works, old defrag returned
"20" (because?) but a recent commit changed it to 0.
So accommodate that too.

And remove a stray "HAVE_DEFRAG=1" while we're at it.
That variable is never used.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Josef Bacik <jbacik@fusionio.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
2013-05-15 07:18:07 -05:00

175 lines
4.0 KiB
Bash
Executable File

#! /bin/bash
# FS QA Test No. 284
#
# Btrfs Online defragmentation tests
#
#-----------------------------------------------------------------------
# Copyright (c) 2012 Fujitsu Liu Bo. 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
#-----------------------------------------------------------------------
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
echo "QA output created by $seq"
here="`pwd`"
tmp=/tmp/$$
cnt=119
filesize=48000
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
cd /
rm -f $tmp.*
}
_create_file()
{
if [ $1 -ne 2 ]; then
tmpfile="$SCRATCH_MNT/tmp_file"
else
mkdir -p $SCRATCH_MNT/tmp_dir
tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
fi
for i in `seq $cnt -1 0`; do
dd if=/dev/zero of=$tmpfile bs=4k count=1 \
conv=notrunc seek=$i oflag=sync &>/dev/null
done
# get md5sum
md5sum $tmpfile > /tmp/checksum
}
_btrfs_online_defrag()
{
str=""
# start = -1 is invalid, should fail
if [ "$2" = "2" ];then
str="$str -s -1 -l $((filesize / 2)) "
elif [ "$2" = "3" ];then
str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
# len = -1 is invalid, should fail
elif [ "$2" = "4" ];then
str="$str -l -1 "
elif [ "$2" = "5" ];then
str="$str -l $((filesize + 1)) "
elif [ "$2" = "6" ];then
str="$str -l $((filesize / 2)) "
fi
if [ "$3" = "2" ];then
str="$str -c "
fi
if [ "$str" != "" ]; then
$BTRFS_UTIL_PROG filesystem defragment $str $SCRATCH_MNT/tmp_file >> $seq.full 2>&1
else
if [ "$1" = "1" ];then
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_file >> $seq.full 2>&1
elif [ "$1" = "2" ];then
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_dir >> $seq.full 2>&1
elif [ "$1" = "3" ];then
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT >> $seq.full 2>&1
fi
fi
ret_val=$?
_scratch_remount
# Older defrag returned "20" for success
# e9393c2 btrfs-progs: defrag return zero on success
if [ $ret_val -ne 0 -a $ret_val -ne 20 ]; then
echo "btrfs filesystem defragment failed!"
fi
}
_checksum()
{
md5sum -c /tmp/checksum > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "md5 checksum failed!"
fi
}
_cleanup_defrag()
{
umount $SCRATCH_MNT > /dev/null 2>&1
}
_setup_defrag()
{
umount $SCRATCH_MNT > /dev/null 2>&1
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
_create_file $1
}
_rundefrag()
{
_setup_defrag $1
_btrfs_online_defrag $1 $2 $3
_checksum
_cleanup_defrag
_check_scratch_fs
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
. ./common/defrag
# real QA test starts here
_supported_fs btrfs
_supported_os Linux
_setup_testdir
## We require scratch so that we'll have free contiguous space
_require_scratch
_scratch_mkfs >/dev/null 2>&1
_scratch_mount
_require_defrag
echo "defrag object | defragment range | defragment compress"
echo "a single file | default | off"
_rundefrag 1 1 1
echo "a single file | default | on"
_rundefrag 1 1 2
echo "a single file | start < 0 && 0 < len < file size | off (should fail)"
_rundefrag 1 2 1
echo "a single file | start > file size && 0 < len < file size | off"
_rundefrag 1 3 1
echo "a single file | start = 0 && len < 0 | off (should fail)"
_rundefrag 1 4 1
echo "a single file | start = 0 && len > file size | off"
_rundefrag 1 5 1
echo "a single file | start = 0 && 0 < len < file size | off"
_rundefrag 1 6 1
echo "a directory | default | off"
_rundefrag 2 1 1
echo "a filesystem | default | off"
_rundefrag 3 1 1
status=0
exit