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 #-----------------------------------------------------------------------
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
44 tmpfile="$SCRATCH_MNT/tmp_file"
46 mkdir -p $SCRATCH_MNT/tmp_dir
47 tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
50 for i in `seq $cnt -1 0`; do
51 dd if=/dev/zero of=$tmpfile bs=4k count=1 \
52 conv=notrunc seek=$i oflag=sync &>/dev/null
55 md5sum $tmpfile > /tmp/checksum
58 _btrfs_online_defrag()
61 if [ "$2" = "2" ];then
62 str="$str -s -1 -l $((filesize / 2)) "
63 elif [ "$2" = "3" ];then
64 str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
66 elif [ "$2" = "4" ];then
68 elif [ "$2" = "5" ];then
69 str="$str -l $((filesize + 1)) "
70 elif [ "$2" = "6" ];then
71 str="$str -l $((filesize / 2)) "
74 if [ "$3" = "2" ];then
78 if [ "$str" != "" ]; then
79 $BTRFS_UTIL_PROG filesystem defragment $str $SCRATCH_MNT/tmp_file
81 if [ "$1" = "1" ];then
82 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_file
83 elif [ "$1" = "2" ];then
84 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_dir
85 elif [ "$1" = "3" ];then
86 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT
91 if [ $ret_val -ne 20 ];then
92 echo "btrfs filesystem defragment failed! err is $ret_val"
98 md5sum -c /tmp/checksum > /dev/null 2>&1
100 echo "md5 checksum failed!"
106 umount $SCRATCH_MNT > /dev/null 2>&1
111 umount $SCRATCH_MNT > /dev/null 2>&1
112 _scratch_mkfs > /dev/null 2>&1
120 _btrfs_online_defrag $1 $2 $3
126 # get standard environment, filters and checks
131 # real QA test starts here
136 ## We require scratch so that we'll have free contiguous space
138 _scratch_mkfs >/dev/null 2>&1
142 echo "defrag object | defragment range | defragment compress"
143 echo "a single file | default | off"
146 echo "a single file | default | on"
149 echo "a single file | start < 0 && 0 < len < file size | off"
152 echo "a single file | start > file size && 0 < len < file size | off"
155 echo "a single file | start = 0 && len < 0 | off"
158 echo "a single file | start = 0 && len > file size | off"
161 echo "a single file | start = 0 && 0 < len < file size | off"
164 echo "a directory | default | off"
167 echo "a filesystem | default | off"