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 _begin_fstest auto quick send
14 # Override the default cleanup function.
18 rm -fr $send_files_dir
22 # Import common functions.
25 # real QA test starts here
31 send_files_dir=$TEST_DIR/btrfs-test-$seq
33 rm -fr $send_files_dir
36 _scratch_mkfs >>$seqres.full 2>&1
40 mkdir -p $SCRATCH_MNT/case_1/d/p1
41 mkdir $SCRATCH_MNT/case_1/p1
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
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
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
73 # Filesystem looks like:
76 # |--- case_1/ (ino 257)
77 # | |---- d/ (ino 258)
78 # | | |--- p1/ (ino 259)
80 # | |---- p1/ (ino 260)
82 # |--- case_2/ (ino 261)
83 # | |---- a/ (ino 262)
84 # | | |---- c/ (ino 268)
86 # | |---- d/ (ino 263)
87 # | |---- ance/ (ino 267)
88 # | |---- e/ (ino 264)
89 # | |---- f/ (ino 265)
90 # | |---- ance/ (ino 266)
92 # |--- case_3/ (ino 269)
93 # | |---- a/ (ino 271)
94 # | | |---- c/ (ino 276)
96 # | |---- d/ (ino 270)
97 # | | |---- ance/ (ino 275)
98 # | | |---- waiting_dir/ (ino 272)
100 # | |---- pre/ (ino 273)
101 # | |---- ance/ (ino 274)
103 # |--- case_4/ (ino 277)
104 # |---- tmp/ (ino 278)
105 # |---- pre/ (ino 280)
106 # | |---- wait_dir/ (ino 281)
108 # |---- desc/ (ino 282)
109 # |---- ance/ (ino 283)
110 # | |---- below_ance/ (ino 279)
112 # |---- other_dir/ (ino 284)
114 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
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.
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
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.
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
152 # This is similar to cases 1 and 2, but adding more complexity just to exercise
153 # btrfs' incremental send correctness.
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
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).
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
177 # Filesystem now looks like:
180 # |--- case_1/ (ino 257)
181 # | |--- d/ (ino 258)
182 # | |--- p1/ (ino 260)
183 # | |--- p1/ (ino 259)
185 # |--- case_2/ (ino 261)
186 # | |---- a/ (ino 262)
187 # | |---- c/ (ino 268)
188 # | | |---- ance/ (ino 267)
190 # | |---- d/ (ino 263)
191 # | | |---- ance/ (ino 266)
193 # | |---- f/ (ino 265)
194 # | |---- e/ (ino 264)
196 # |--- case_3/ (ino 269)
197 # | |---- a/ (ino 271)
198 # | | |---- ance/ (ino 275)
200 # | |---- c/ (ino 276)
201 # | | |---- waiting_dir/ (ino 272)
202 # | | |---- pre/ (ino 273)
204 # | |---- d/ (ino 270)
205 # | |---- ance/ (ino 274)
207 # |--- case_4/ (ino 277)
208 # |---- tmp/ (ino 278)
209 # |---- other_dir/ (ino 284)
210 # |---- below_ance/ (ino 279)
211 # | |---- pre/ (ino 280)
213 # |---- wait_dir/ (ino 281)
214 # |---- desc/ (ino 282)
215 # |---- ance/ (ino 283)
217 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
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
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 \
227 # Now recreate the filesystem by receiving both send streams and verify we get
228 # the same content that the original filesystem had.
230 _scratch_mkfs >>$seqres.full 2>&1
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
238 echo "Silence is golden"