2012-02-14 18:50:24 +08:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:50 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (c) 2012 Fujitsu Liu Bo. All Rights Reserved.
|
|
|
|
|
#
|
2013-08-13 16:16:27 -05:00
|
|
|
# FS QA Test No. btrfs/005
|
2012-02-14 18:50:24 +08:00
|
|
|
#
|
|
|
|
|
# Btrfs Online defragmentation tests
|
|
|
|
|
#
|
|
|
|
|
seq=`basename $0`
|
2013-03-15 12:28:02 +00:00
|
|
|
seqres=$RESULT_DIR/$seq
|
2012-02-14 18:50:24 +08:00
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
here="`pwd`"
|
|
|
|
|
tmp=/tmp/$$
|
2013-05-15 07:18:07 -05:00
|
|
|
cnt=119
|
2012-02-14 18:50:24 +08:00
|
|
|
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
|
2013-01-06 22:30:38 +08:00
|
|
|
mkdir -p $SCRATCH_MNT/tmp_dir
|
2012-02-14 18:50:24 +08:00
|
|
|
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=""
|
2013-05-15 07:18:07 -05:00
|
|
|
# start = -1 is invalid, should fail
|
2012-02-14 18:50:24 +08:00
|
|
|
if [ "$2" = "2" ];then
|
|
|
|
|
str="$str -s -1 -l $((filesize / 2)) "
|
|
|
|
|
elif [ "$2" = "3" ];then
|
|
|
|
|
str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
|
2013-05-15 07:18:07 -05:00
|
|
|
# len = -1 is invalid, should fail
|
2012-02-14 18:50:24 +08:00
|
|
|
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
|
2014-02-18 21:18:20 +11:00
|
|
|
$BTRFS_UTIL_PROG filesystem defragment $str $SCRATCH_MNT/tmp_file >> $seqres.full 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
else
|
|
|
|
|
if [ "$1" = "1" ];then
|
2014-02-18 21:18:20 +11:00
|
|
|
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_file >> $seqres.full 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
elif [ "$1" = "2" ];then
|
2014-02-18 21:18:20 +11:00
|
|
|
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_dir >> $seqres.full 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
elif [ "$1" = "3" ];then
|
2014-02-18 21:18:20 +11:00
|
|
|
$BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT >> $seqres.full 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
ret_val=$?
|
2016-02-19 10:44:53 +11:00
|
|
|
_scratch_cycle_mount
|
2013-05-15 07:18:07 -05:00
|
|
|
# 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!"
|
2012-02-14 18:50:24 +08:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_checksum()
|
|
|
|
|
{
|
|
|
|
|
md5sum -c /tmp/checksum > /dev/null 2>&1
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
echo "md5 checksum failed!"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cleanup_defrag()
|
|
|
|
|
{
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount > /dev/null 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_setup_defrag()
|
|
|
|
|
{
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount > /dev/null 2>&1
|
2012-02-14 18:50:24 +08:00
|
|
|
_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
|
2013-03-15 12:28:04 +00:00
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
|
|
|
|
. ./common/defrag
|
2012-02-14 18:50:24 +08:00
|
|
|
|
|
|
|
|
# real QA test starts here
|
|
|
|
|
_supported_fs btrfs
|
|
|
|
|
_supported_os Linux
|
|
|
|
|
_require_scratch
|
2014-02-18 21:18:20 +11:00
|
|
|
|
|
|
|
|
rm -f $seqres.full
|
|
|
|
|
|
2012-02-14 18:50:24 +08:00
|
|
|
_scratch_mkfs >/dev/null 2>&1
|
|
|
|
|
_scratch_mount
|
|
|
|
|
_require_defrag
|
|
|
|
|
|
|
|
|
|
echo "defrag object | defragment range | defragment compress"
|
2013-05-15 07:18:07 -05:00
|
|
|
echo "a single file | default | off"
|
2012-02-14 18:50:24 +08:00
|
|
|
_rundefrag 1 1 1
|
|
|
|
|
|
|
|
|
|
echo "a single file | default | on"
|
|
|
|
|
_rundefrag 1 1 2
|
|
|
|
|
|
2013-05-15 07:18:07 -05:00
|
|
|
echo "a single file | start < 0 && 0 < len < file size | off (should fail)"
|
2012-02-14 18:50:24 +08:00
|
|
|
_rundefrag 1 2 1
|
|
|
|
|
|
|
|
|
|
echo "a single file | start > file size && 0 < len < file size | off"
|
|
|
|
|
_rundefrag 1 3 1
|
|
|
|
|
|
2013-05-15 07:18:07 -05:00
|
|
|
echo "a single file | start = 0 && len < 0 | off (should fail)"
|
2012-02-14 18:50:24 +08:00
|
|
|
_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
|