generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 045
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/045
6 #
7 # Regression test for a btrfs incremental send issue where the kernel failed
8 # to build paths strings. This resulted either in sending a wrong path string
9 # to the send stream or entering an infinite loop when building it.
10 # This happened in the following scenarios:
11 #
12 # 1) A directory was made a child of another directory which has a lower inode
13 #    number and has a pending move/rename operation or there's some non-direct
14 #    ancestor directory with a higher inode number that was renamed/moved too.
15 #    This made the incremental send code go into an infinite loop when building
16 #    a path string;
17 #
18 # 2) A directory was made a child of another directory which has a higher inode
19 #    number, but the new parent wasn't moved nor renamed. Instead some other
20 #    ancestor higher in the hierarchy, with an higher inode number too, was
21 #    moved/renamed too. This made the incremental send code go into an infinite
22 #    loop when building a path string;
23 #
24 # 3) An orphan directory is created and at least one of its non-immediate
25 #    descendent directories have a pending move/rename operation. This made
26 #    an incremental send issue to the send stream an invalid path string that
27 #    didn't account for the orphan ancestor directory.
28 #
29 # These issues are fixed by the following linux kernel btrfs patches:
30 #
31 #   Btrfs: fix incremental send's decision to delay a dir move/rename
32 #   Btrfs: part 2, fix incremental send's decision to delay a dir move/rename
33 #   Btrfs: send, fix more issues related to directory renames
34 #   Btrfs: send, account for orphan directories when building path strings
35 #
36 . ./common/preamble
37 _begin_fstest auto quick send
38
39 tmp=`mktemp -d`
40
41 # Override the default cleanup function.
42 _cleanup()
43 {
44     rm -fr $tmp
45 }
46
47 # Import common functions.
48 . ./common/filter
49
50 # real QA test starts here
51 _supported_fs btrfs
52 _require_scratch
53 _require_fssum
54
55 _scratch_mkfs >/dev/null 2>&1
56 _scratch_mount
57
58 # case 1), mentioned above
59 mkdir -p $SCRATCH_MNT/a/b
60 mkdir $SCRATCH_MNT/a/c
61 mkdir $SCRATCH_MNT/a/b/d
62 touch $SCRATCH_MNT/a/file1
63 touch $SCRATCH_MNT/a/b/file2
64 mv $SCRATCH_MNT/a/file1 $SCRATCH_MNT/a/b/d/file3
65 ln $SCRATCH_MNT/a/b/d/file3 $SCRATCH_MNT/a/b/file4
66 mkdir $SCRATCH_MNT/a/b/f
67 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/a/c/b2
68 touch $SCRATCH_MNT/a/c/b2/d/file5
69
70 # case 2), mentioned above
71 mkdir -p $SCRATCH_MNT/a/x1/x2
72 mkdir $SCRATCH_MNT/a/Z
73 mkdir -p $SCRATCH_MNT/a/x1/x2/x3/x4/x5
74
75 # case 2) again, but a more complex scenario
76 mkdir -p $SCRATCH_MNT/_a/_b/_c/_d
77 mkdir $SCRATCH_MNT/_a/_b/_c/_d/_e
78 mkdir $SCRATCH_MNT/_a/_b/_c/_d/_f
79 mv $SCRATCH_MNT/_a/_b/_c/_d/_e $SCRATCH_MNT/_a/_b/_c/_d/_f/_E2
80 mkdir $SCRATCH_MNT/_a/_b/_c/_g
81 mv $SCRATCH_MNT/_a/_b/_c/_d $SCRATCH_MNT/_a/_b/_D2
82
83 # case 3), mentioned above
84 mkdir -p $SCRATCH_MNT/za/zb/zc/zd
85 mkdir $SCRATCH_MNT/za/zb/ze
86 mv $SCRATCH_MNT/za/zb/zc $SCRATCH_MNT/za/zb/ze/zCC
87 mkdir $SCRATCH_MNT/za/zb/ze/zCC/zd/zf
88 mkdir $SCRATCH_MNT/za/zg
89
90 # case 1), more complex scenario
91 mkdir -p $SCRATCH_MNT/y_a/y_b
92 mkdir -p $SCRATCH_MNT/y_a/y_c/y_d
93 mkdir $SCRATCH_MNT/y_a/y_b/y_e
94 mkdir $SCRATCH_MNT/y_a/y_c/y_d/y_f
95 mv $SCRATCH_MNT/y_a/y_b  $SCRATCH_MNT/y_a/y_c/y_d/y_2b
96 mkdir $SCRATCH_MNT/y_a/y_x
97 mkdir $SCRATCH_MNT/y_a/y_y
98
99 # case 1), variation of previous scenario with a subtree is moved into
100 # a directory created after creating the parent snapshot
101 mkdir -p $SCRATCH_MNT/w_a/w_b
102 mkdir -p $SCRATCH_MNT/w_a/w_c/w_d
103 mkdir $SCRATCH_MNT/w_a/w_b/w_e
104 mkdir $SCRATCH_MNT/w_a/w_c/w_d/w_f
105 mv $SCRATCH_MNT/w_a/w_b  $SCRATCH_MNT/w_a/w_c/w_d/w_2b
106
107 mkdir -p $SCRATCH_MNT/xa/xb
108 mkdir $SCRATCH_MNT/xa/xc
109 mv $SCRATCH_MNT/xa/xb $SCRATCH_MNT/xa/xc/xb2
110 mkdir $SCRATCH_MNT/xa/xe
111
112 mkdir -p $SCRATCH_MNT/%a/%b
113 mkdir $SCRATCH_MNT/%a/%c
114 mkdir $SCRATCH_MNT/%a/%b/%d
115 mkdir $SCRATCH_MNT/%a/%c/%e
116
117 # Filesystem looks like:
118 #
119 # .                               (ino 256)
120 # |-- a/                          (ino 257)
121 # |   |-- c/                      (ino 259)
122 # |   |   |-- b2/                 (ino 258)
123 # |   |       |-- d/              (ino 260)
124 # |   |       |   |-- file3       (ino 261)
125 # |   |       |   |-- file5       (ino 264)
126 # |   |       |
127 # |   |       |-- file2           (ino 262)
128 # |   |       |-- file4           (ino 261)
129 # |   |       |-- f/              (ino 263)
130 # |   |
131 # |   |-- x1/                     (ino 265)
132 # |   |   |-- x2/                 (ino 266)
133 # |   |       |-- x3/             (ino 268)
134 # |   |           |-- x4/         (ino 269)
135 # |   |               |-- x5/     (ino 270)
136 # |   |
137 # |   |-- Z/                      (ino 267)
138 # |
139 # |-- _a/                         (ino 271)
140 # |    |-- _b/                    (ino 272)
141 # |         |-- _c/               (ino 273)
142 # |         |    |-- _g/          (ino 277)
143 # |         |
144 # |         |-- _D2/              (ino 274)
145 # |              |-- _f/          (ino 276)
146 # |                   |-- _E2/    (ino 275)
147 # |
148 # |-- za/                         (ino 278)
149 # |   |-- zb/                     (ino 279)
150 # |   |   |-- ze/                 (ino 282)
151 # |   |       |-- zCC/            (ino 280)
152 # |   |            |-- zd/        (ino 281)
153 # |   |                |-- zf/    (ino 283)
154 # |   |
155 # |   |-- zg/                     (ino 284)
156 # |
157 # |-- y_a/                        (ino 285)
158 # |    |-- y_c/                   (ino 287)
159 # |    |    |-- y_d/              (ino 288)
160 # |    |         |-- y_2b/        (ino 286)
161 # |    |         |    |-- y_e/    (ino 289)
162 # |    |         |
163 # |    |         |-- y_f/         (ino 290)
164 # |    |
165 # |    |-- y_x/                   (ino 291)
166 # |    |-- y_y/                   (ino 292)
167 # |
168 # |-- w_a/                        (ino 293)
169 # |    |-- w_c/                   (ino 295)
170 # |         |-- w_d/              (ino 296)
171 # |              |-- w_2b/        (ino 294)
172 # |              |    |-- w_e/    (ino 297)
173 # |              |
174 # |              |-- w_f/         (ino 298)
175 # |
176 # |-- xa/                         (ino 299)
177 # |   |-- xc/                     (ino 301)
178 # |   |   |-- xb2/                (ino 300)
179 # |   |
180 # |   |-- xe/                     (ino 302)
181 # |
182 # |-- %a/                         (ino 303)
183 #     |-- %b/                     (ino 304)
184 #     |   |-- %d/                 (ino 306)
185 #     |
186 #     |-- %c/                     (ino 305)
187 #         |-- %e/                 (ino 307)
188
189 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
190
191 # case 1), mentioned above
192 ln $SCRATCH_MNT/a/c/b2/file4 $SCRATCH_MNT/a/c/b2/f/file6
193 mv $SCRATCH_MNT/a/c/b2/d/file5 $SCRATCH_MNT/a/c/file7
194 touch $SCRATCH_MNT/a/c/b2/d/file8
195 touch $SCRATCH_MNT/a/c/b2/file9
196 ln $SCRATCH_MNT/a/c/b2/file9 $SCRATCH_MNT/a/c/b2/file10
197 mv $SCRATCH_MNT/a/c/b2/f $SCRATCH_MNT/a/f2
198 mv $SCRATCH_MNT/a/c $SCRATCH_MNT/a/c2
199 mv $SCRATCH_MNT/a/c2/b2 $SCRATCH_MNT/a/f2/b3
200 mv $SCRATCH_MNT/a/c2 $SCRATCH_MNT/a/f2/b3/c3
201 touch $SCRATCH_MNT/a/f2/b3/c3/file11
202 mv $SCRATCH_MNT/a $SCRATCH_MNT/a2
203
204 # case 2), mentioned above
205 mv $SCRATCH_MNT/a2/x1/x2/x3 $SCRATCH_MNT/a2/Z/X33
206 mv $SCRATCH_MNT/a2/x1/x2 $SCRATCH_MNT/a2/Z/X33/x4/x5/X22
207
208 # case 2) again, but a more complex scenario
209 mkdir $SCRATCH_MNT/_a/_o
210 mv $SCRATCH_MNT/_a/_b/_c/_g $SCRATCH_MNT/_a/_b/_D2/_f/_G2
211 mv $SCRATCH_MNT/_a/_b/_D2 $SCRATCH_MNT/_a/_b/_dd
212 mv $SCRATCH_MNT/_a/_b/_c $SCRATCH_MNT/_a/_C2
213 mv $SCRATCH_MNT/_a/_b/_dd/_f $SCRATCH_MNT/_a/_o/_FF
214 mv $SCRATCH_MNT/_a/_b $SCRATCH_MNT/_a/_o/_FF/_E2/_BB
215
216 # case 3), mentioned above
217 mkdir $SCRATCH_MNT/za/zg/zh
218 mv $SCRATCH_MNT/za/zb/ze $SCRATCH_MNT/za/zg/zh/zEE
219 mv $SCRATCH_MNT/za/zg/zh/zEE/zCC/zd $SCRATCH_MNT/za/zg/zh/zEE/zDD
220 mv $SCRATCH_MNT/za/zg/zh/zEE/zDD/zf $SCRATCH_MNT/za/zg/zh/zEE/zDD/zFF
221
222 # case 1), more complex scenario
223 mv $SCRATCH_MNT/y_a/y_x $SCRATCH_MNT/y_a/y_y
224 mv $SCRATCH_MNT/y_a/y_c/y_d/y_2b/y_e $SCRATCH_MNT/y_a/y_c/y_d/y_2b/y_2e
225 mv $SCRATCH_MNT/y_a/y_c/y_d $SCRATCH_MNT/y_a/y_y/y_x/y_2d
226 mv $SCRATCH_MNT/y_a/y_c $SCRATCH_MNT/y_a/y_y/y_x/y_2d/y_2b/y_2c
227
228 # case 1), variation of previous scenario with a subtree is moved into
229 # a directory created after creating the parent snapshot
230 mv $SCRATCH_MNT/w_a/w_c/w_d/w_2b/w_e $SCRATCH_MNT/w_a/w_c/w_d/w_2b/w_2e
231 mkdir $SCRATCH_MNT/w_a/w_h
232 mv $SCRATCH_MNT/w_a/w_c/w_d $SCRATCH_MNT/w_a/w_h/w_2d
233 mv $SCRATCH_MNT/w_a/w_c $SCRATCH_MNT/w_a/w_h/w_2d/w_2b/w_2c
234
235 mv $SCRATCH_MNT/xa/xc/xb2 $SCRATCH_MNT/xa/xe/xb3
236 mkdir $SCRATCH_MNT/xa/xe/xb3/xf
237 mkdir $SCRATCH_MNT/xa/xh
238 mv $SCRATCH_MNT/xa/xc $SCRATCH_MNT/xa/xe/xb3/xf/xc2
239 mv $SCRATCH_MNT/xa/xe $SCRATCH_MNT/xa/xh/xe2
240
241 echo "hello" > $SCRATCH_MNT/%a/foo
242 mkdir $SCRATCH_MNT/%a/%b/%d/%f
243 mkdir $SCRATCH_MNT/%a/%b/%g
244 mv $SCRATCH_MNT/%a/%c/%e $SCRATCH_MNT/%a/%b/%g/%e2
245 mv $SCRATCH_MNT/%a/%c $SCRATCH_MNT/%a/%b/%d/%f/%c2
246 mv $SCRATCH_MNT/%a/%b/%d/%f $SCRATCH_MNT/%a/%b/%g/%e2/%f2
247 mv $SCRATCH_MNT/%a/foo $SCRATCH_MNT/%a/%b/%g/%e2/%f2
248
249 # Filesystem now looks like:
250 #
251 # .                                    (ino 256)
252 # |-- a2/                              (ino 257)
253 # |   |-- f2/                          (ino 263)
254 # |   |   |-- file6                    (ino 261)
255 # |   |   |-- b3/                      (ino 258)
256 # |   |       |-- d/                   (ino 260)
257 # |   |       |   |-- file3            (ino 261)
258 # |   |       |   |-- file8            (ino 308)
259 # |   |       |
260 # |   |       |-- file2                (ino 262)
261 # |   |       |-- file4                (ino 261)
262 # |   |       |-- file9                (ino 309)
263 # |   |       |-- file10               (ino 309)
264 # |   |       |
265 # |   |       |-- c3/                  (ino 259)
266 # |   |           |-- file7            (ino 264)
267 # |   |           |-- file11           (ino 310)
268 # |   |
269 # |   |-- x1/                          (ino 265)
270 # |   |-- Z/                           (ino 267)
271 # |       |-- X33/                     (ino 268)
272 # |            |-- x4/                 (ino 269)
273 # |                |-- x5/             (ino 270)
274 # |                    |-- X22/        (ino 266)
275 # |
276 # |-- _a/                              (ino 271)
277 # |    |-- _o/                         (ino 311)
278 # |    |    |-- _FF/                   (ino 276)
279 # |    |         |-- _E2/              (ino 275)
280 # |    |         |    |-- _BB/         (ino 272)
281 # |    |         |         |-- dd/     (ino 274)
282 # |    |         |
283 # |    |         |-- G2/               (ino 277)
284 # |    |-- C2/                         (ino 273)
285 # |
286 # |-- za/                              (ino 278)
287 # |   |-- zb/                          (ino 279)
288 # |   |-- zg/                          (ino 284)
289 # |       |-- zh/                      (ino 312)
290 # |           |-- zEE/                 (ino 282)
291 # |                |-- zCC/            (ino 280)
292 # |                |-- zDD/            (ino 281)
293 # |                     |-- zFF/       (ino 283)
294 # |
295 # |-- y_a/                             (ino 285)
296 # |    |-- y_y/                        (ino 292)
297 # |         |-- y_x/                   (ino 291)
298 # |              |-- y_2d/             (ino 288)
299 # |                   |-- y_2b/        (ino 286)
300 # |                   |    |-- y_2c/   (ino 287)
301 # |                   |    |-- y_2e/   (ino 289)
302 # |                   |-- y_f/         (ino 290)
303 # |
304 # |-- w_a/                             (ino 293)
305 # |    |-- w_h/                        (ino 313)
306 # |         |-- w_2d/                  (ino 296)
307 # |              |-- w_2b/             (ino 294)
308 # |              |    |-- w_2c/        (ino 295)
309 # |              |    |-- w_2e/        (ino 297)
310 # |              |-- w_f/              (ino 298)
311 # |
312 # |-- xa/                              (ino 299)
313 # |    |-- xh/                         (ino 315)
314 # |        |-- xe2                     (ino 302)
315 # |            |-- xb3/                (ino 300)
316 # |                 |-- xf/            (ino 314)
317 # |                     |-- xc2/       (ino 301)
318 # |
319 # |-- %a/                              (ino 303)
320 #     |-- %b/                          (ino 304)
321 #         |-- %d/                      (ino 306)
322 #         |-- %g/                      (ino 318)
323 #             |-- %e2/                 (ino 307)
324 #                  |-- %f2             (ino 317)
325 #                       |-- %c2/       (ino 305)
326 #                            |-- foo   (ino 316)
327
328 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
329
330 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
331 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
332         $SCRATCH_MNT/mysnap2
333
334 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
335
336 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $tmp/2.snap \
337         $SCRATCH_MNT/mysnap2
338
339 _check_scratch_fs
340
341 _scratch_unmount
342 _scratch_mkfs >/dev/null 2>&1
343 _scratch_mount
344
345 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
346 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1
347
348 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
349 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2
350
351 status=0
352 exit