common: Check the file system consistency on SCRATCH_DEV
[xfstests-dev.git] / tests / btrfs / 046
1 #! /bin/bash
2 # FS QA Test No. btrfs/046
3 #
4 # Regression test for the btrfs incremental send feature, where the kernel
5 # would incorrectly consider a range of a file as a hole and send a stream
6 # of 0 bytes to the destination (send stream) that would overwrite the
7 # corresponding file region.
8 #
9 # This issue is fixed by the following linux kernel btrfs patch:
10 #
11 #   Btrfs: send, fix data corruption due to incorrect hole detection
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=`mktemp -d`
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 send_files_dir=$TEST_DIR/btrfs-test-$seq
40
41 _cleanup()
42 {
43         rm -fr $send_files_dir
44         rm -fr $tmp
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # real QA test starts here
52 _supported_fs btrfs
53 _supported_os Linux
54 _require_scratch
55 _require_fssum
56 _need_to_be_root
57
58 rm -f $seqres.full
59 rm -fr $send_files_dir
60 mkdir $send_files_dir
61
62 _scratch_mkfs >/dev/null 2>&1
63 _scratch_mount
64
65 $XFS_IO_PROG -f -c "falloc -k 0 268435456" $SCRATCH_MNT/foo
66
67 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap0
68
69 $XFS_IO_PROG -c "pwrite -S 0x01 -b 9216 16190218 9216" $SCRATCH_MNT/foo \
70         | _filter_xfs_io
71 $XFS_IO_PROG -c "pwrite -S 0x02 -b 1121 198720104 1121" $SCRATCH_MNT/foo \
72         | _filter_xfs_io
73 $XFS_IO_PROG -c "pwrite -S 0x05 -b 9216 107887439 9216" $SCRATCH_MNT/foo \
74         | _filter_xfs_io
75 $XFS_IO_PROG -c "pwrite -S 0x06 -b 9216 225520207 9216" $SCRATCH_MNT/foo \
76         | _filter_xfs_io
77 $XFS_IO_PROG -c "pwrite -S 0x07 -b 67584 102138300 67584" $SCRATCH_MNT/foo \
78         | _filter_xfs_io
79 $XFS_IO_PROG -c "pwrite -S 0x08 -b 7000 94897484 7000" $SCRATCH_MNT/foo \
80         | _filter_xfs_io
81 $XFS_IO_PROG -c "pwrite -S 0x09 -b 113664 245083212 113664" $SCRATCH_MNT/foo \
82         | _filter_xfs_io
83 $XFS_IO_PROG -c "pwrite -S 0x10 -b 123 17937788 123" $SCRATCH_MNT/foo \
84         | _filter_xfs_io
85 $XFS_IO_PROG -c "pwrite -S 0x11 -b 39936 229573311 39936" $SCRATCH_MNT/foo \
86         | _filter_xfs_io
87 $XFS_IO_PROG -c "pwrite -S 0x12 -b 67584 174792222 67584" $SCRATCH_MNT/foo \
88         | _filter_xfs_io
89 $XFS_IO_PROG -c "pwrite -S 0x13 -b 9216 249253213 9216" $SCRATCH_MNT/foo \
90         | _filter_xfs_io
91 $XFS_IO_PROG -c "pwrite -S 0x16 -b 67584 150046083 67584" $SCRATCH_MNT/foo \
92         | _filter_xfs_io
93 $XFS_IO_PROG -c "pwrite -S 0x17 -b 39936 118246040 39936" $SCRATCH_MNT/foo \
94         | _filter_xfs_io
95 $XFS_IO_PROG -c "pwrite -S 0x18 -b 67584 215965442 67584" $SCRATCH_MNT/foo \
96         | _filter_xfs_io
97 $XFS_IO_PROG -c "pwrite -S 0x19 -b 33792 97096725 33792" $SCRATCH_MNT/foo \
98         | _filter_xfs_io
99 $XFS_IO_PROG -c "pwrite -S 0x20 -b 125952 166300596 125952" $SCRATCH_MNT/foo \
100         | _filter_xfs_io
101 $XFS_IO_PROG -c "pwrite -S 0x21 -b 123 1078957 123" $SCRATCH_MNT/foo \
102         | _filter_xfs_io
103 $XFS_IO_PROG -c "pwrite -S 0x25 -b 9216 212044492 9216" $SCRATCH_MNT/foo \
104         | _filter_xfs_io
105 $XFS_IO_PROG -c "pwrite -S 0x26 -b 7000 265037146 7000" $SCRATCH_MNT/foo \
106         | _filter_xfs_io
107 $XFS_IO_PROG -c "pwrite -S 0x27 -b 42757 215922685 42757" $SCRATCH_MNT/foo \
108         | _filter_xfs_io
109 $XFS_IO_PROG -c "pwrite -S 0x28 -b 7000 69865411 7000" $SCRATCH_MNT/foo \
110         | _filter_xfs_io
111 $XFS_IO_PROG -c "pwrite -S 0x29 -b 67584 67948958 67584" $SCRATCH_MNT/foo \
112         | _filter_xfs_io
113 $XFS_IO_PROG -c "pwrite -S 0x30 -b 39936 266967019 39936" $SCRATCH_MNT/foo \
114         | _filter_xfs_io
115 $XFS_IO_PROG -c "pwrite -S 0x31 -b 1121 19582453 1121" $SCRATCH_MNT/foo \
116         | _filter_xfs_io
117 $XFS_IO_PROG -c "pwrite -S 0x32 -b 17408 257710255 17408" $SCRATCH_MNT/foo \
118         | _filter_xfs_io
119 $XFS_IO_PROG -c "pwrite -S 0x33 -b 39936 3895518 39936" $SCRATCH_MNT/foo \
120         | _filter_xfs_io
121 $XFS_IO_PROG -c "pwrite -S 0x34 -b 125952 12045847 125952" $SCRATCH_MNT/foo \
122         | _filter_xfs_io
123 $XFS_IO_PROG -c "pwrite -S 0x35 -b 17408 19156379 17408" $SCRATCH_MNT/foo \
124         | _filter_xfs_io
125 $XFS_IO_PROG -c "pwrite -S 0x36 -b 39936 50160066 39936" $SCRATCH_MNT/foo \
126         | _filter_xfs_io
127 $XFS_IO_PROG -c "pwrite -S 0x37 -b 113664 9549793 113664" $SCRATCH_MNT/foo \
128         | _filter_xfs_io
129 $XFS_IO_PROG -c "pwrite -S 0x38 -b 105472 94391506 105472" $SCRATCH_MNT/foo \
130         | _filter_xfs_io
131 $XFS_IO_PROG -c "pwrite -S 0x39 -b 23552 143632863 23552" $SCRATCH_MNT/foo \
132         | _filter_xfs_io
133 $XFS_IO_PROG -c "pwrite -S 0x40 -b 39936 241283845 39936" $SCRATCH_MNT/foo \
134         | _filter_xfs_io
135 $XFS_IO_PROG -c "pwrite -S 0x41 -b 113664 199937606 113664" $SCRATCH_MNT/foo \
136         | _filter_xfs_io
137 $XFS_IO_PROG -c "pwrite -S 0x42 -b 67584 67380093 67584" $SCRATCH_MNT/foo \
138         | _filter_xfs_io
139 $XFS_IO_PROG -c "pwrite -S 0x43 -b 67584 26793129 67584" $SCRATCH_MNT/foo \
140         | _filter_xfs_io
141 $XFS_IO_PROG -c "pwrite -S 0x44 -b 39936 14421913 39936" $SCRATCH_MNT/foo \
142         | _filter_xfs_io
143 $XFS_IO_PROG -c "pwrite -S 0x45 -b 123 253097405 123" $SCRATCH_MNT/foo \
144         | _filter_xfs_io
145 $XFS_IO_PROG -c "pwrite -S 0x46 -b 1121 128233424 1121" $SCRATCH_MNT/foo \
146         | _filter_xfs_io
147 $XFS_IO_PROG -c "pwrite -S 0x47 -b 105472 91577959 105472" $SCRATCH_MNT/foo \
148         | _filter_xfs_io
149 $XFS_IO_PROG -c "pwrite -S 0x48 -b 1121 7245381 1121" $SCRATCH_MNT/foo \
150         | _filter_xfs_io
151 $XFS_IO_PROG -c "pwrite -S 0x49 -b 113664 182414694 113664" $SCRATCH_MNT/foo \
152         | _filter_xfs_io
153 $XFS_IO_PROG -c "pwrite -S 0x50 -b 9216 32750608 9216" $SCRATCH_MNT/foo \
154         | _filter_xfs_io
155 $XFS_IO_PROG -c "pwrite -S 0x51 -b 67584 266546049 67584" $SCRATCH_MNT/foo \
156         | _filter_xfs_io
157 $XFS_IO_PROG -c "pwrite -S 0x52 -b 67584 87969398 67584" $SCRATCH_MNT/foo \
158         | _filter_xfs_io
159 $XFS_IO_PROG -c "pwrite -S 0x53 -b 9216 260848797 9216" $SCRATCH_MNT/foo \
160         | _filter_xfs_io
161 $XFS_IO_PROG -c "pwrite -S 0x54 -b 39936 119461243 39936" $SCRATCH_MNT/foo \
162         | _filter_xfs_io
163 $XFS_IO_PROG -c "pwrite -S 0x55 -b 7000 200178693 7000" $SCRATCH_MNT/foo \
164         | _filter_xfs_io
165 $XFS_IO_PROG -c "pwrite -S 0x56 -b 9216 243316029 9216" $SCRATCH_MNT/foo \
166         | _filter_xfs_io
167 $XFS_IO_PROG -c "pwrite -S 0x57 -b 7000 209658229 7000" $SCRATCH_MNT/foo \
168         | _filter_xfs_io
169 $XFS_IO_PROG -c "pwrite -S 0x58 -b 101376 179745192 101376" $SCRATCH_MNT/foo \
170         | _filter_xfs_io
171 $XFS_IO_PROG -c "pwrite -S 0x59 -b 9216 64012300 9216" $SCRATCH_MNT/foo \
172         | _filter_xfs_io
173 $XFS_IO_PROG -c "pwrite -S 0x60 -b 125952 181705139 125952" $SCRATCH_MNT/foo \
174         | _filter_xfs_io
175 $XFS_IO_PROG -c "pwrite -S 0x61 -b 23552 235737348 23552" $SCRATCH_MNT/foo \
176         | _filter_xfs_io
177 $XFS_IO_PROG -c "pwrite -S 0x62 -b 113664 106021355 113664" $SCRATCH_MNT/foo \
178         | _filter_xfs_io
179 $XFS_IO_PROG -c "pwrite -S 0x63 -b 67584 135753552 67584" $SCRATCH_MNT/foo \
180         | _filter_xfs_io
181 $XFS_IO_PROG -c "pwrite -S 0x64 -b 23552 95730888 23552" $SCRATCH_MNT/foo \
182         | _filter_xfs_io
183 $XFS_IO_PROG -c "pwrite -S 0x65 -b 11 17311415 11" $SCRATCH_MNT/foo \
184         | _filter_xfs_io
185 $XFS_IO_PROG -c "pwrite -S 0x66 -b 33792 120695553 33792" $SCRATCH_MNT/foo \
186         | _filter_xfs_io
187 $XFS_IO_PROG -c "pwrite -S 0x67 -b 9216 17164631 9216" $SCRATCH_MNT/foo \
188         | _filter_xfs_io
189 $XFS_IO_PROG -c "pwrite -S 0x68 -b 9216 136065853 9216" $SCRATCH_MNT/foo \
190         | _filter_xfs_io
191 $XFS_IO_PROG -c "pwrite -S 0x69 -b 67584 37752198 67584" $SCRATCH_MNT/foo \
192         | _filter_xfs_io
193 $XFS_IO_PROG -c "pwrite -S 0x70 -b 101376 189717473 101376" $SCRATCH_MNT/foo \
194         | _filter_xfs_io
195 $XFS_IO_PROG -c "pwrite -S 0x71 -b 7000 227463698 7000" $SCRATCH_MNT/foo \
196         | _filter_xfs_io
197 $XFS_IO_PROG -c "pwrite -S 0x72 -b 9216 12655137 9216" $SCRATCH_MNT/foo \
198         | _filter_xfs_io
199 $XFS_IO_PROG -c "pwrite -S 0x73 -b 7000 7488866 7000" $SCRATCH_MNT/foo \
200         | _filter_xfs_io
201 $XFS_IO_PROG -c "pwrite -S 0x74 -b 113664 87813649 113664" $SCRATCH_MNT/foo \
202         | _filter_xfs_io
203 $XFS_IO_PROG -c "pwrite -S 0x75 -b 33792 25802183 33792" $SCRATCH_MNT/foo \
204         | _filter_xfs_io
205 $XFS_IO_PROG -c "pwrite -S 0x76 -b 39936 93524024 39936" $SCRATCH_MNT/foo \
206         | _filter_xfs_io
207 $XFS_IO_PROG -c "pwrite -S 0x77 -b 33792 113336388 33792" $SCRATCH_MNT/foo \
208         | _filter_xfs_io
209 $XFS_IO_PROG -c "pwrite -S 0x78 -b 105472 184955320 105472" $SCRATCH_MNT/foo \
210         | _filter_xfs_io
211 $XFS_IO_PROG -c "pwrite -S 0x79 -b 101376 225691598 101376" $SCRATCH_MNT/foo \
212         | _filter_xfs_io
213 $XFS_IO_PROG -c "pwrite -S 0x80 -b 23552 77023155 23552" $SCRATCH_MNT/foo \
214         | _filter_xfs_io
215 $XFS_IO_PROG -c "pwrite -S 0x81 -b 11 201888192 11" $SCRATCH_MNT/foo \
216         | _filter_xfs_io
217 $XFS_IO_PROG -c "pwrite -S 0x82 -b 11 115332492 11" $SCRATCH_MNT/foo \
218         | _filter_xfs_io
219 $XFS_IO_PROG -c "pwrite -S 0x83 -b 67584 230278015 67584" $SCRATCH_MNT/foo \
220         | _filter_xfs_io
221 $XFS_IO_PROG -c "pwrite -S 0x84 -b 11 120589073 11" $SCRATCH_MNT/foo \
222         | _filter_xfs_io
223 $XFS_IO_PROG -c "pwrite -S 0x85 -b 125952 202207819 125952" $SCRATCH_MNT/foo \
224         | _filter_xfs_io
225 $XFS_IO_PROG -c "pwrite -S 0x86 -b 113664 86672080 113664" $SCRATCH_MNT/foo \
226         | _filter_xfs_io
227 $XFS_IO_PROG -c "pwrite -S 0x87 -b 17408 208459603 17408" $SCRATCH_MNT/foo \
228         | _filter_xfs_io
229 $XFS_IO_PROG -c "pwrite -S 0x88 -b 7000 73372211 7000" $SCRATCH_MNT/foo \
230         | _filter_xfs_io
231 $XFS_IO_PROG -c "pwrite -S 0x89 -b 7000 42252122 7000" $SCRATCH_MNT/foo \
232         | _filter_xfs_io
233 $XFS_IO_PROG -c "pwrite -S 0x90 -b 23552 46784881 23552" $SCRATCH_MNT/foo \
234         | _filter_xfs_io
235 $XFS_IO_PROG -c "pwrite -S 0x91 -b 101376 63172351 101376" $SCRATCH_MNT/foo \
236         | _filter_xfs_io
237 $XFS_IO_PROG -c "pwrite -S 0x92 -b 23552 59341931 23552" $SCRATCH_MNT/foo \
238         | _filter_xfs_io
239 $XFS_IO_PROG -c "pwrite -S 0x93 -b 39936 239599283 39936" $SCRATCH_MNT/foo \
240         | _filter_xfs_io
241 $XFS_IO_PROG -c "pwrite -S 0x94 -b 67584 175643105 67584" $SCRATCH_MNT/foo \
242         | _filter_xfs_io
243 $XFS_IO_PROG -c "pwrite -S 0x97 -b 23552 105534880 23552" $SCRATCH_MNT/foo \
244         | _filter_xfs_io
245 $XFS_IO_PROG -c "pwrite -S 0x98 -b 113664 8236844 113664" $SCRATCH_MNT/foo \
246         | _filter_xfs_io
247 $XFS_IO_PROG -c "pwrite -S 0x99 -b 125952 144489686 125952" $SCRATCH_MNT/foo \
248         | _filter_xfs_io
249 $XFS_IO_PROG -c "pwrite -S 0xa0 -b 7000 73273112 7000" $SCRATCH_MNT/foo \
250         | _filter_xfs_io
251 $XFS_IO_PROG -c "pwrite -S 0xa1 -b 125952 194580243 125952" $SCRATCH_MNT/foo \
252         | _filter_xfs_io
253 $XFS_IO_PROG -c "pwrite -S 0xa2 -b 123 56296779 123" $SCRATCH_MNT/foo \
254         | _filter_xfs_io
255 $XFS_IO_PROG -c "pwrite -S 0xa3 -b 11 233066845 11" $SCRATCH_MNT/foo \
256         | _filter_xfs_io
257 $XFS_IO_PROG -c "pwrite -S 0xa4 -b 39936 197727090 39936" $SCRATCH_MNT/foo \
258         | _filter_xfs_io
259 $XFS_IO_PROG -c "pwrite -S 0xa5 -b 101376 53579812 101376" $SCRATCH_MNT/foo \
260         | _filter_xfs_io
261 $XFS_IO_PROG -c "pwrite -S 0xa6 -b 9216 85669738 9216" $SCRATCH_MNT/foo \
262         | _filter_xfs_io
263 $XFS_IO_PROG -c "pwrite -S 0xa7 -b 125952 21266322 125952" $SCRATCH_MNT/foo \
264         | _filter_xfs_io
265 $XFS_IO_PROG -c "pwrite -S 0xa8 -b 23552 125726568 23552" $SCRATCH_MNT/foo \
266         | _filter_xfs_io
267 $XFS_IO_PROG -c "pwrite -S 0xa9 -b 9216 18423680 9216" $SCRATCH_MNT/foo \
268         | _filter_xfs_io
269 $XFS_IO_PROG -c "pwrite -S 0xb0 -b 1121 165901483 1121" $SCRATCH_MNT/foo \
270         | _filter_xfs_io
271
272 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
273
274 $XFS_IO_PROG -c "pwrite -S 0xff -b 10 16190218 10" $SCRATCH_MNT/foo \
275         | _filter_xfs_io
276
277 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
278
279 echo "File digests in the original filesystem:"
280 md5sum $SCRATCH_MNT/foo | _filter_scratch
281 md5sum $SCRATCH_MNT/mysnap0/foo | _filter_scratch
282 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
283 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
284
285 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
286 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
287         -f $send_files_dir/2.snap
288
289 _check_scratch_fs
290 _scratch_unmount
291 _scratch_mkfs >/dev/null 2>&1
292 _scratch_mount
293
294 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
295 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
296
297 echo "File digests in the replica filesystem:"
298 md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
299 md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
300
301 status=0
302 exit