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 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
47 tmpfile="$SCRATCH_MNT/tmp_file"
49 mkdir -p $SCRATCH_MNT/tmp_dir
50 tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
53 for i in `seq $cnt -1 0`; do
54 dd if=/dev/zero of=$tmpfile bs=4k count=1 \
55 conv=notrunc seek=$i oflag=sync &>/dev/null
58 md5sum $tmpfile > /tmp/checksum
61 _btrfs_online_defrag()
64 if [ "$2" = "2" ];then
65 str="$str -s -1 -l $((filesize / 2)) "
66 elif [ "$2" = "3" ];then
67 str="$str -s $((filesize + 1)) -l $((filesize / 2)) "
69 elif [ "$2" = "4" ];then
71 elif [ "$2" = "5" ];then
72 str="$str -l $((filesize + 1)) "
73 elif [ "$2" = "6" ];then
74 str="$str -l $((filesize / 2)) "
77 if [ "$3" = "2" ];then
81 if [ "$str" != "" ]; then
82 btrfs filesystem defragment $str $SCRATCH_MNT/tmp_file
84 if [ "$1" = "1" ];then
85 btrfs filesystem defragment $SCRATCH_MNT/tmp_file
86 elif [ "$1" = "2" ];then
87 btrfs filesystem defragment $SCRATCH_MNT/tmp_dir
88 elif [ "$1" = "3" ];then
89 btrfs filesystem defragment $SCRATCH_MNT
94 if [ $ret_val -ne 20 ];then
95 echo "btrfs filesystem defragment failed! err is $ret_val"
101 md5sum -c /tmp/checksum > /dev/null 2>&1
102 if [ $? -ne 0 ]; then
103 echo "md5 checksum failed!"
109 umount $SCRATCH_MNT > /dev/null 2>&1
114 umount $SCRATCH_MNT > /dev/null 2>&1
115 _scratch_mkfs > /dev/null 2>&1
123 _btrfs_online_defrag $1 $2 $3
129 # get standard environment, filters and checks
134 # real QA test starts here
139 ## We require scratch so that we'll have free contiguous space
141 _scratch_mkfs >/dev/null 2>&1
145 echo "defrag object | defragment range | defragment compress"
146 echo "a single file | default | off"
149 echo "a single file | default | on"
152 echo "a single file | start < 0 && 0 < len < file size | off"
155 echo "a single file | start > file size && 0 < len < file size | off"
158 echo "a single file | start = 0 && len < 0 | off"
161 echo "a single file | start = 0 && len > file size | off"
164 echo "a single file | start = 0 && 0 < len < file size | off"
167 echo "a directory | default | off"
170 echo "a filesystem | default | off"