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 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
43 tmpfile="$SCRATCH_MNT/tmp_file"
45 mkdir -p $SCRATCH_MNT/tmp_dir
46 tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
49 for i in `seq $cnt -1 0`; do
50 dd if=/dev/zero of=$tmpfile bs=4k count=1 \
51 conv=notrunc seek=$i oflag=sync &>/dev/null
54 md5sum $tmpfile > /tmp/checksum
57 _btrfs_online_defrag()
60 if [ "$2" = "2" ];then
61 str="$str -s -1 -l $((filesize / 2)) "
62 elif [ "$2" = "3" ];then
63 str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
65 elif [ "$2" = "4" ];then
67 elif [ "$2" = "5" ];then
68 str="$str -l $((filesize + 1)) "
69 elif [ "$2" = "6" ];then
70 str="$str -l $((filesize / 2)) "
73 if [ "$3" = "2" ];then
77 if [ "$str" != "" ]; then
78 btrfs filesystem defragment $str $SCRATCH_MNT/tmp_file
80 if [ "$1" = "1" ];then
81 btrfs filesystem defragment $SCRATCH_MNT/tmp_file
82 elif [ "$1" = "2" ];then
83 btrfs filesystem defragment $SCRATCH_MNT/tmp_dir
84 elif [ "$1" = "3" ];then
85 btrfs filesystem defragment $SCRATCH_MNT
90 if [ $ret_val -ne 20 ];then
91 echo "btrfs filesystem defragment failed! err is $ret_val"
97 md5sum -c /tmp/checksum > /dev/null 2>&1
99 echo "md5 checksum failed!"
105 umount $SCRATCH_MNT > /dev/null 2>&1
110 umount $SCRATCH_MNT > /dev/null 2>&1
111 _scratch_mkfs > /dev/null 2>&1
119 _btrfs_online_defrag $1 $2 $3
125 # get standard environment, filters and checks
130 # real QA test starts here
135 ## We require scratch so that we'll have free contiguous space
137 _scratch_mkfs >/dev/null 2>&1
141 echo "defrag object | defragment range | defragment compress"
142 echo "a single file | default | off"
145 echo "a single file | default | on"
148 echo "a single file | start < 0 && 0 < len < file size | off"
151 echo "a single file | start > file size && 0 < len < file size | off"
154 echo "a single file | start = 0 && len < 0 | off"
157 echo "a single file | start = 0 && len > file size | off"
160 echo "a single file | start = 0 && 0 < len < file size | off"
163 echo "a directory | default | off"
166 echo "a filesystem | default | off"