generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 127
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/127
6 #
7 # Test that an incremental send operation works after doing radical changes
8 # in the directory hierarchy that involve switching the inode that directory
9 # entries point to.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick send
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         cd /
18         rm -fr $send_files_dir
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs btrfs
27 _require_test
28 _require_scratch
29 _require_fssum
30
31 send_files_dir=$TEST_DIR/btrfs-test-$seq
32
33 rm -fr $send_files_dir
34 mkdir $send_files_dir
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _scratch_mount
38
39 # case 1
40 mkdir -p $SCRATCH_MNT/case_1/d/p1
41 mkdir $SCRATCH_MNT/case_1/p1
42
43 # case 2
44 mkdir -p $SCRATCH_MNT/case_2/a
45 mkdir $SCRATCH_MNT/case_2/d
46 mkdir $SCRATCH_MNT/case_2/e
47 mkdir $SCRATCH_MNT/case_2/f
48 mkdir $SCRATCH_MNT/case_2/ance
49 mkdir $SCRATCH_MNT/case_2/d/ance
50 mkdir $SCRATCH_MNT/case_2/a/c
51 mv $SCRATCH_MNT/case_2/e $SCRATCH_MNT/case_2/d/ance
52 mv $SCRATCH_MNT/case_2/f $SCRATCH_MNT/case_2/d/ance
53 mv $SCRATCH_MNT/case_2/ance $SCRATCH_MNT/case_2/d/ance
54
55 # case 3
56 mkdir -p $SCRATCH_MNT/case_3/d
57 mkdir $SCRATCH_MNT/case_3/a
58 mkdir $SCRATCH_MNT/case_3/waiting_dir
59 mkdir -p $SCRATCH_MNT/case_3/pre/ance
60 mkdir $SCRATCH_MNT/case_3/d/ance
61 mkdir $SCRATCH_MNT/case_3/a/c
62 mv $SCRATCH_MNT/case_3/waiting_dir $SCRATCH_MNT/case_3/d/ance
63
64 # case 4
65 mkdir -p $SCRATCH_MNT/case_4/tmp
66 mkdir $SCRATCH_MNT/case_4/below_ance
67 mkdir -p $SCRATCH_MNT/case_4/pre/wait_dir
68 mkdir $SCRATCH_MNT/case_4/desc
69 mkdir $SCRATCH_MNT/case_4/ance
70 mv $SCRATCH_MNT/case_4/below_ance $SCRATCH_MNT/case_4/ance
71 mkdir $SCRATCH_MNT/case_4/other_dir
72
73 # Filesystem looks like:
74 #
75 # .                                                                  (ino 256)
76 # |--- case_1/                                                       (ino 257)
77 # |       |---- d/                                                   (ino 258)
78 # |       |     |--- p1/                                             (ino 259)
79 # |       |
80 # |       |---- p1/                                                  (ino 260)
81 # |
82 # |--- case_2/                                                       (ino 261)
83 # |       |---- a/                                                   (ino 262)
84 # |       |     |---- c/                                             (ino 268)
85 # |       |
86 # |       |---- d/                                                   (ino 263)
87 # |             |---- ance/                                          (ino 267)
88 # |                     |---- e/                                     (ino 264)
89 # |                     |---- f/                                     (ino 265)
90 # |                     |---- ance/                                  (ino 266)
91 # |
92 # |--- case_3/                                                       (ino 269)
93 # |       |---- a/                                                   (ino 271)
94 # |       |     |---- c/                                             (ino 276)
95 # |       |
96 # |       |---- d/                                                   (ino 270)
97 # |       |     |---- ance/                                          (ino 275)
98 # |       |             |---- waiting_dir/                           (ino 272)
99 # |       |
100 # |       |---- pre/                                                 (ino 273)
101 # |              |---- ance/                                         (ino 274)
102 # |
103 # |--- case_4/                                                       (ino 277)
104 #         |---- tmp/                                                 (ino 278)
105 #         |---- pre/                                                 (ino 280)
106 #         |      |---- wait_dir/                                     (ino 281)
107 #         |
108 #         |---- desc/                                                (ino 282)
109 #         |---- ance/                                                (ino 283)
110 #         |       |---- below_ance/                                  (ino 279)
111 #         |
112 #         |---- other_dir/                                           (ino 284)
113 #
114 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
115
116 # case 1
117 #
118 # The directory named "d" (inode 257) has in both snapshots an entry with the
119 # name "p1" but it refers to different inodes in both snapshots (inode 258 in
120 # the parent snapshot and inode 259 in the send snapshot). When attempting to
121 # move inode 258, the operation is delayed because its new parent, inode 259,
122 # was not yet moved/renamed (as the stream is currently processing inode 258).
123 # Later on when processing inode 259, btrfs' send also ended up delaying the
124 # move/rename operation for this inode, so that it would happen after inode 258
125 # was processed, creating a circular dependency that resulted in the send stream
126 # terminating without issuing a rename operations for the inodes 258 and 259.
127 #
128 mv $SCRATCH_MNT/case_1/d/p1 $SCRATCH_MNT/case_1/p1
129 mv $SCRATCH_MNT/case_1/p1 $SCRATCH_MNT/case_1/d
130
131 # case 2
132 #
133 # When the inode 265 is processed, the path for inode 267 is computed, which at
134 # that time corresponds to "case_2/d/ance", and it was stored in the name cache
135 # (to avoid recomputing it again later when needed).
136 # Later on when processing inode 266, btrfs' send end up orphanizing (renaming
137 # to a name matching the pattern o<ino>-<gen>-<seq>) inode 267 because it has
138 # the same name as inode 266 and at that time it's a child of the new parent
139 # directory (inode 263) for inode 266. After the orphanization and while still
140 # processing inode 266, a rename operation for inode 266 was generated. However
141 # the source path for that rename operation was incorrect because it ended up
142 # using the old, pre-orphanization, name of inode 267.
143 #
144 mv $SCRATCH_MNT/case_2/a/c $SCRATCH_MNT/case_2
145 mv $SCRATCH_MNT/case_2/d/ance $SCRATCH_MNT/case_2/c
146 mv $SCRATCH_MNT/case_2/c/ance/ance $SCRATCH_MNT/case_2/d
147 mv $SCRATCH_MNT/case_2/c/ance/f $SCRATCH_MNT/case_2
148 mv $SCRATCH_MNT/case_2/c/ance/e $SCRATCH_MNT/case_2/f
149
150 # case 3
151 #
152 # This is similar to cases 1 and 2, but adding more complexity just to exercise
153 # btrfs' incremental send correctness.
154 #
155 mv $SCRATCH_MNT/case_3/d/ance $SCRATCH_MNT/case_3/a
156 mv $SCRATCH_MNT/case_3/a/c $SCRATCH_MNT/case_3
157 mv $SCRATCH_MNT/case_3/a/ance/waiting_dir $SCRATCH_MNT/case_3/c
158 mv $SCRATCH_MNT/case_3/pre/ance $SCRATCH_MNT/case_3/d
159 mv $SCRATCH_MNT/case_3/pre $SCRATCH_MNT/case_3/c/waiting_dir
160
161 # case 4
162 #
163 # When attempting to rename inode 283, the incremental send stream included an
164 # invalid destination path for the rename command. This was due to a missing
165 # path loop detection in the send code that made the rename of inode 283 happen
166 # without waiting for the rename of inode 284 to happen first (since it's an
167 # ancestor in the send snapshot that is beyond the current progress and it was
168 # also renamed/moved).
169 #
170 mv $SCRATCH_MNT/case_4/other_dir $SCRATCH_MNT/case_4/tmp
171 mv $SCRATCH_MNT/case_4/ance/below_ance $SCRATCH_MNT/case_4/tmp/other_dir
172 mv $SCRATCH_MNT/case_4/pre/wait_dir $SCRATCH_MNT/case_4/tmp/other_dir
173 mv $SCRATCH_MNT/case_4/pre $SCRATCH_MNT/case_4/tmp/other_dir/below_ance
174 mv $SCRATCH_MNT/case_4/desc $SCRATCH_MNT/case_4/tmp/other_dir/wait_dir
175 mv $SCRATCH_MNT/case_4/ance $SCRATCH_MNT/case_4/tmp/other_dir/wait_dir/desc
176
177 # Filesystem now looks like:
178 #
179 # .                                                                  (ino 256)
180 # |--- case_1/                                                       (ino 257)
181 # |        |--- d/                                                   (ino 258)
182 # |             |--- p1/                                             (ino 260)
183 # |                   |--- p1/                                       (ino 259)
184 # |
185 # |--- case_2/                                                       (ino 261)
186 # |       |---- a/                                                   (ino 262)
187 # |       |---- c/                                                   (ino 268)
188 # |       |     |---- ance/                                          (ino 267)
189 # |       |
190 # |       |---- d/                                                   (ino 263)
191 # |       |     |---- ance/                                          (ino 266)
192 # |       |
193 # |       |---- f/                                                   (ino 265)
194 # |             |---- e/                                             (ino 264)
195 # |
196 # |--- case_3/                                                       (ino 269)
197 # |       |---- a/                                                   (ino 271)
198 # |       |     |---- ance/                                          (ino 275)
199 # |       |
200 # |       |---- c/                                                   (ino 276)
201 # |       |     |---- waiting_dir/                                   (ino 272)
202 # |       |                   |---- pre/                             (ino 273)
203 # |       |
204 # |       |---- d/                                                   (ino 270)
205 # |             |---- ance/                                          (ino 274)
206 # |
207 # |--- case_4/                                                       (ino 277)
208 #         |---- tmp/                                                 (ino 278)
209 #                |---- other_dir/                                    (ino 284)
210 #                            |---- below_ance/                       (ino 279)
211 #                            |            |---- pre/                 (ino 280)
212 #                            |
213 #                            |---- wait_dir/                         (ino 281)
214 #                                       |---- desc/                  (ino 282)
215 #                                               |---- ance/          (ino 283)
216 #
217 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
218
219 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
220 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
221         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
222
223 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
224 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
225         $SCRATCH_MNT/mysnap2
226
227 # Now recreate the filesystem by receiving both send streams and verify we get
228 # the same content that the original filesystem had.
229 _scratch_unmount
230 _scratch_mkfs >>$seqres.full 2>&1
231 _scratch_mount
232
233 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
234 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
235 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
236 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
237
238 echo "Silence is golden"
239 status=0
240 exit