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