xfstests: kill useless test owner fields
[xfstests-dev.git] / 284
1 #! /bin/bash
2 # FS QA Test No. 284
3 #
4 # Btrfs Online defragmentation tests
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2012 Fujitsu Liu Bo.  All Rights Reserved.
8 #
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.
12 #
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.
17 #
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 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26 here="`pwd`"
27 tmp=/tmp/$$
28 cnt=11999
29 filesize=48000
30
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36     cd /
37     rm -f $tmp.*
38 }
39
40 _create_file()
41 {
42         if [ $1 -ne 2 ]; then
43                 tmpfile="$SCRATCH_MNT/tmp_file"
44         else
45                 mkdir -p $SCRATCH_MNT/tmp_dir
46                 tmpfile="$SCRATCH_MNT/tmp_dir/tmp_file"
47         fi
48                 
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
52         done
53         # get md5sum
54         md5sum $tmpfile > /tmp/checksum
55 }
56
57 _btrfs_online_defrag()
58 {
59         str=""
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)) "
64                 HAVE_DEFRAG=1
65         elif [ "$2" = "4" ];then
66                 str="$str -l -1 "
67         elif [ "$2" = "5" ];then
68                 str="$str -l $((filesize + 1)) "
69         elif [ "$2" = "6" ];then
70                 str="$str -l $((filesize / 2)) "
71         fi
72
73         if [ "$3" = "2" ];then
74                 str="$str -c "
75         fi
76
77         if [ "$str" != "" ]; then
78                 btrfs filesystem defragment $str $SCRATCH_MNT/tmp_file
79         else
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
86                 fi
87         fi
88         ret_val=$?
89         _scratch_remount
90         if [ $ret_val -ne 20 ];then
91                 echo "btrfs filesystem defragment failed! err is $ret_val"
92         fi
93 }
94
95 _checksum()
96 {
97         md5sum -c /tmp/checksum > /dev/null 2>&1
98         if [ $? -ne 0 ]; then
99                 echo "md5 checksum failed!"
100         fi
101 }
102
103 _cleanup_defrag()
104 {
105         umount $SCRATCH_MNT > /dev/null 2>&1
106 }
107
108 _setup_defrag()
109 {
110         umount $SCRATCH_MNT > /dev/null 2>&1
111         _scratch_mkfs > /dev/null 2>&1
112         _scratch_mount
113         _create_file $1
114 }
115
116 _rundefrag()
117 {
118         _setup_defrag $1
119         _btrfs_online_defrag $1 $2 $3
120         _checksum
121         _cleanup_defrag
122         _check_scratch_fs
123 }
124
125 # get standard environment, filters and checks
126 . ./common.rc
127 . ./common.filter
128 . ./common.defrag
129
130 # real QA test starts here
131 _supported_fs btrfs
132 _supported_os Linux
133
134 _setup_testdir
135 ## We require scratch so that we'll have free contiguous space
136 _require_scratch
137 _scratch_mkfs >/dev/null 2>&1
138 _scratch_mount
139 _require_defrag
140
141 echo "defrag object | defragment range | defragment compress"
142 echo "a single file |  default | off"
143 _rundefrag 1 1 1
144
145 echo "a single file | default |  on"
146 _rundefrag 1 1 2
147
148 echo "a single file | start < 0 && 0 < len < file size | off"
149 _rundefrag 1 2 1
150
151 echo "a single file | start > file size && 0 < len < file size | off"
152 _rundefrag 1 3 1
153
154 echo "a single file | start = 0 && len < 0 | off"
155 _rundefrag 1 4 1
156
157 echo "a single file | start = 0 && len > file size | off"
158 _rundefrag 1 5 1
159
160 echo "a single file | start = 0 && 0 < len < file size | off"
161 _rundefrag 1 6 1
162
163 echo "a directory | default | off"
164 _rundefrag 2 1 1
165
166 echo "a filesystem | default | off"
167 _rundefrag 3 1 1
168
169 status=0
170 exit