2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/127
7 # Test that an incremental send operation works after doing radical changes
8 # in the directory hierarchy that involve switching the inode that directory
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # real QA test starts here
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
40 rm -fr $send_files_dir
43 _scratch_mkfs >>$seqres.full 2>&1
47 mkdir -p $SCRATCH_MNT/case_1/d/p1
48 mkdir $SCRATCH_MNT/case_1/p1
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
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
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
80 # Filesystem looks like:
83 # |--- case_1/ (ino 257)
84 # | |---- d/ (ino 258)
85 # | | |--- p1/ (ino 259)
87 # | |---- p1/ (ino 260)
89 # |--- case_2/ (ino 261)
90 # | |---- a/ (ino 262)
91 # | | |---- c/ (ino 268)
93 # | |---- d/ (ino 263)
94 # | |---- ance/ (ino 267)
95 # | |---- e/ (ino 264)
96 # | |---- f/ (ino 265)
97 # | |---- ance/ (ino 266)
99 # |--- case_3/ (ino 269)
100 # | |---- a/ (ino 271)
101 # | | |---- c/ (ino 276)
103 # | |---- d/ (ino 270)
104 # | | |---- ance/ (ino 275)
105 # | | |---- waiting_dir/ (ino 272)
107 # | |---- pre/ (ino 273)
108 # | |---- ance/ (ino 274)
110 # |--- case_4/ (ino 277)
111 # |---- tmp/ (ino 278)
112 # |---- pre/ (ino 280)
113 # | |---- wait_dir/ (ino 281)
115 # |---- desc/ (ino 282)
116 # |---- ance/ (ino 283)
117 # | |---- below_ance/ (ino 279)
119 # |---- other_dir/ (ino 284)
121 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
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.
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
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.
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
159 # This is similar to cases 1 and 2, but adding more complexity just to exercise
160 # btrfs' incremental send correctness.
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
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).
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
184 # Filesystem now looks like:
187 # |--- case_1/ (ino 257)
188 # | |--- d/ (ino 258)
189 # | |--- p1/ (ino 260)
190 # | |--- p1/ (ino 259)
192 # |--- case_2/ (ino 261)
193 # | |---- a/ (ino 262)
194 # | |---- c/ (ino 268)
195 # | | |---- ance/ (ino 267)
197 # | |---- d/ (ino 263)
198 # | | |---- ance/ (ino 266)
200 # | |---- f/ (ino 265)
201 # | |---- e/ (ino 264)
203 # |--- case_3/ (ino 269)
204 # | |---- a/ (ino 271)
205 # | | |---- ance/ (ino 275)
207 # | |---- c/ (ino 276)
208 # | | |---- waiting_dir/ (ino 272)
209 # | | |---- pre/ (ino 273)
211 # | |---- d/ (ino 270)
212 # | |---- ance/ (ino 274)
214 # |--- case_4/ (ino 277)
215 # |---- tmp/ (ino 278)
216 # |---- other_dir/ (ino 284)
217 # |---- below_ance/ (ino 279)
218 # | |---- pre/ (ino 280)
220 # |---- wait_dir/ (ino 281)
221 # |---- desc/ (ino 282)
222 # |---- ance/ (ino 283)
224 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
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
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 \
234 # Now recreate the filesystem by receiving both send streams and verify we get
235 # the same content that the original filesystem had.
237 _scratch_mkfs >>$seqres.full 2>&1
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
245 echo "Silence is golden"