2 # FS QA Test No. btrfs/005
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 # start = -1 is invalid, should fail
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)) "
66 # len = -1 is invalid, should fail
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_UTIL_PROG filesystem defragment $str $SCRATCH_MNT/tmp_file >> $seq.full 2>&1
82 if [ "$1" = "1" ];then
83 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_file >> $seq.full 2>&1
84 elif [ "$1" = "2" ];then
85 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT/tmp_dir >> $seq.full 2>&1
86 elif [ "$1" = "3" ];then
87 $BTRFS_UTIL_PROG filesystem defragment $SCRATCH_MNT >> $seq.full 2>&1
92 # Older defrag returned "20" for success
93 # e9393c2 btrfs-progs: defrag return zero on success
94 if [ $ret_val -ne 0 -a $ret_val -ne 20 ]; then
95 echo "btrfs filesystem defragment failed!"
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
138 ## We require scratch so that we'll have free contiguous space
140 _scratch_mkfs >/dev/null 2>&1
144 echo "defrag object | defragment range | defragment compress"
145 echo "a single file | default | off"
148 echo "a single file | default | on"
151 echo "a single file | start < 0 && 0 < len < file size | off (should fail)"
154 echo "a single file | start > file size && 0 < len < file size | off"
157 echo "a single file | start = 0 && len < 0 | off (should fail)"
160 echo "a single file | start = 0 && len > file size | off"
163 echo "a single file | start = 0 && 0 < len < file size | off"
166 echo "a directory | default | off"
169 echo "a filesystem | default | off"