4 # Btrfs Online defragmentation tests
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2012 Fujitsu Liu Bo. All Rights Reserved.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #-----------------------------------------------------------------------
24 owner=liubo2009@cn.fujitsu.com
27 echo "QA output created by $seq"
33 status=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
45 tmpfile="$SCRATCH_MNT/tmp_file"
47 mkdir -p $SCRATCH_MNT/tmp_dir
48 tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
51 for i in `seq $cnt -1 0`; do
52 dd if=/dev/zero of=$tmpfile bs=4k count=1 \
53 conv=notrunc seek=$i oflag=sync &>/dev/null
56 md5sum $tmpfile > /tmp/checksum
59 _btrfs_online_defrag()
62 if [ "$2" = "2" ];then
63 str="$str -s -1 -l $((filesize / 2)) "
64 elif [ "$2" = "3" ];then
65 str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
67 elif [ "$2" = "4" ];then
69 elif [ "$2" = "5" ];then
70 str="$str -l $((filesize + 1)) "
71 elif [ "$2" = "6" ];then
72 str="$str -l $((filesize / 2)) "
75 if [ "$3" = "2" ];then
79 if [ "$str" != "" ]; then
80 btrfs filesystem defragment $str $SCRATCH_MNT/tmp_file
82 if [ "$1" = "1" ];then
83 btrfs filesystem defragment $SCRATCH_MNT/tmp_file
84 elif [ "$1" = "2" ];then
85 btrfs filesystem defragment $SCRATCH_MNT/tmp_dir
86 elif [ "$1" = "3" ];then
87 btrfs filesystem defragment $SCRATCH_MNT
92 if [ $ret_val -ne 20 ];then
93 echo "btrfs filesystem defragment failed! err is $ret_val"
99 md5sum -c /tmp/checksum > /dev/null 2>&1
100 if [ $? -ne 0 ]; then
101 echo "md5 checksum failed!"
107 umount $SCRATCH_MNT > /dev/null 2>&1
112 umount $SCRATCH_MNT > /dev/null 2>&1
113 _scratch_mkfs > /dev/null 2>&1
121 _btrfs_online_defrag $1 $2 $3
127 # get standard environment, filters and checks
132 # real QA test starts here
137 ## We require scratch so that we'll have free contiguous space
139 _scratch_mkfs >/dev/null 2>&1
143 echo "defrag object | defragment range | defragment compress"
144 echo "a single file | default | off"
147 echo "a single file | default | on"
150 echo "a single file | start < 0 && 0 < len < file size | off"
153 echo "a single file | start > file size && 0 < len < file size | off"
156 echo "a single file | start = 0 && len < 0 | off"
159 echo "a single file | start = 0 && len > file size | off"
162 echo "a single file | start = 0 && 0 < len < file size | off"
165 echo "a directory | default | off"
168 echo "a filesystem | default | off"