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
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
46 mkdir -p $SCRATCH_MNT/case_1/d/p1
47 mkdir $SCRATCH_MNT/case_1/p1
50 mkdir -p $SCRATCH_MNT/case_2/a
51 mkdir $SCRATCH_MNT/case_2/d
52 mkdir $SCRATCH_MNT/case_2/e
53 mkdir $SCRATCH_MNT/case_2/f
54 mkdir $SCRATCH_MNT/case_2/ance
55 mkdir $SCRATCH_MNT/case_2/d/ance
56 mkdir $SCRATCH_MNT/case_2/a/c
57 mv $SCRATCH_MNT/case_2/e $SCRATCH_MNT/case_2/d/ance
58 mv $SCRATCH_MNT/case_2/f $SCRATCH_MNT/case_2/d/ance
59 mv $SCRATCH_MNT/case_2/ance $SCRATCH_MNT/case_2/d/ance
62 mkdir -p $SCRATCH_MNT/case_3/d
63 mkdir $SCRATCH_MNT/case_3/a
64 mkdir $SCRATCH_MNT/case_3/waiting_dir
65 mkdir -p $SCRATCH_MNT/case_3/pre/ance
66 mkdir $SCRATCH_MNT/case_3/d/ance
67 mkdir $SCRATCH_MNT/case_3/a/c
68 mv $SCRATCH_MNT/case_3/waiting_dir $SCRATCH_MNT/case_3/d/ance
71 mkdir -p $SCRATCH_MNT/case_4/tmp
72 mkdir $SCRATCH_MNT/case_4/below_ance
73 mkdir -p $SCRATCH_MNT/case_4/pre/wait_dir
74 mkdir $SCRATCH_MNT/case_4/desc
75 mkdir $SCRATCH_MNT/case_4/ance
76 mv $SCRATCH_MNT/case_4/below_ance $SCRATCH_MNT/case_4/ance
77 mkdir $SCRATCH_MNT/case_4/other_dir
79 # Filesystem looks like:
82 # |--- case_1/ (ino 257)
83 # | |---- d/ (ino 258)
84 # | | |--- p1/ (ino 259)
86 # | |---- p1/ (ino 260)
88 # |--- case_2/ (ino 261)
89 # | |---- a/ (ino 262)
90 # | | |---- c/ (ino 268)
92 # | |---- d/ (ino 263)
93 # | |---- ance/ (ino 267)
94 # | |---- e/ (ino 264)
95 # | |---- f/ (ino 265)
96 # | |---- ance/ (ino 266)
98 # |--- case_3/ (ino 269)
99 # | |---- a/ (ino 271)
100 # | | |---- c/ (ino 276)
102 # | |---- d/ (ino 270)
103 # | | |---- ance/ (ino 275)
104 # | | |---- waiting_dir/ (ino 272)
106 # | |---- pre/ (ino 273)
107 # | |---- ance/ (ino 274)
109 # |--- case_4/ (ino 277)
110 # |---- tmp/ (ino 278)
111 # |---- pre/ (ino 280)
112 # | |---- wait_dir/ (ino 281)
114 # |---- desc/ (ino 282)
115 # |---- ance/ (ino 283)
116 # | |---- below_ance/ (ino 279)
118 # |---- other_dir/ (ino 284)
120 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
124 # The directory named "d" (inode 257) has in both snapshots an entry with the
125 # name "p1" but it refers to different inodes in both snapshots (inode 258 in
126 # the parent snapshot and inode 259 in the send snapshot). When attempting to
127 # move inode 258, the operation is delayed because its new parent, inode 259,
128 # was not yet moved/renamed (as the stream is currently processing inode 258).
129 # Later on when processing inode 259, btrfs' send also ended up delaying the
130 # move/rename operation for this inode, so that it would happen after inode 258
131 # was processed, creating a circular dependency that resulted in the send stream
132 # terminating without issuing a rename operations for the inodes 258 and 259.
134 mv $SCRATCH_MNT/case_1/d/p1 $SCRATCH_MNT/case_1/p1
135 mv $SCRATCH_MNT/case_1/p1 $SCRATCH_MNT/case_1/d
139 # When the inode 265 is processed, the path for inode 267 is computed, which at
140 # that time corresponds to "case_2/d/ance", and it was stored in the name cache
141 # (to avoid recomputing it again later when needed).
142 # Later on when processing inode 266, btrfs' send end up orphanizing (renaming
143 # to a name matching the pattern o<ino>-<gen>-<seq>) inode 267 because it has
144 # the same name as inode 266 and at that time it's a child of the new parent
145 # directory (inode 263) for inode 266. After the orphanization and while still
146 # processing inode 266, a rename operation for inode 266 was generated. However
147 # the source path for that rename operation was incorrect because it ended up
148 # using the old, pre-orphanization, name of inode 267.
150 mv $SCRATCH_MNT/case_2/a/c $SCRATCH_MNT/case_2
151 mv $SCRATCH_MNT/case_2/d/ance $SCRATCH_MNT/case_2/c
152 mv $SCRATCH_MNT/case_2/c/ance/ance $SCRATCH_MNT/case_2/d
153 mv $SCRATCH_MNT/case_2/c/ance/f $SCRATCH_MNT/case_2
154 mv $SCRATCH_MNT/case_2/c/ance/e $SCRATCH_MNT/case_2/f
158 # This is similar to cases 1 and 2, but adding more complexity just to exercise
159 # btrfs' incremental send correctness.
161 mv $SCRATCH_MNT/case_3/d/ance $SCRATCH_MNT/case_3/a
162 mv $SCRATCH_MNT/case_3/a/c $SCRATCH_MNT/case_3
163 mv $SCRATCH_MNT/case_3/a/ance/waiting_dir $SCRATCH_MNT/case_3/c
164 mv $SCRATCH_MNT/case_3/pre/ance $SCRATCH_MNT/case_3/d
165 mv $SCRATCH_MNT/case_3/pre $SCRATCH_MNT/case_3/c/waiting_dir
169 # When attempting to rename inode 283, the incremental send stream included an
170 # invalid destination path for the rename command. This was due to a missing
171 # path loop detection in the send code that made the rename of inode 283 happen
172 # without waiting for the rename of inode 284 to happen first (since it's an
173 # ancestor in the send snapshot that is beyond the current progress and it was
174 # also renamed/moved).
176 mv $SCRATCH_MNT/case_4/other_dir $SCRATCH_MNT/case_4/tmp
177 mv $SCRATCH_MNT/case_4/ance/below_ance $SCRATCH_MNT/case_4/tmp/other_dir
178 mv $SCRATCH_MNT/case_4/pre/wait_dir $SCRATCH_MNT/case_4/tmp/other_dir
179 mv $SCRATCH_MNT/case_4/pre $SCRATCH_MNT/case_4/tmp/other_dir/below_ance
180 mv $SCRATCH_MNT/case_4/desc $SCRATCH_MNT/case_4/tmp/other_dir/wait_dir
181 mv $SCRATCH_MNT/case_4/ance $SCRATCH_MNT/case_4/tmp/other_dir/wait_dir/desc
183 # Filesystem now looks like:
186 # |--- case_1/ (ino 257)
187 # | |--- d/ (ino 258)
188 # | |--- p1/ (ino 260)
189 # | |--- p1/ (ino 259)
191 # |--- case_2/ (ino 261)
192 # | |---- a/ (ino 262)
193 # | |---- c/ (ino 268)
194 # | | |---- ance/ (ino 267)
196 # | |---- d/ (ino 263)
197 # | | |---- ance/ (ino 266)
199 # | |---- f/ (ino 265)
200 # | |---- e/ (ino 264)
202 # |--- case_3/ (ino 269)
203 # | |---- a/ (ino 271)
204 # | | |---- ance/ (ino 275)
206 # | |---- c/ (ino 276)
207 # | | |---- waiting_dir/ (ino 272)
208 # | | |---- pre/ (ino 273)
210 # | |---- d/ (ino 270)
211 # | |---- ance/ (ino 274)
213 # |--- case_4/ (ino 277)
214 # |---- tmp/ (ino 278)
215 # |---- other_dir/ (ino 284)
216 # |---- below_ance/ (ino 279)
217 # | |---- pre/ (ino 280)
219 # |---- wait_dir/ (ino 281)
220 # |---- desc/ (ino 282)
221 # |---- ance/ (ino 283)
223 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
225 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
226 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
227 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
229 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
230 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
233 # Now recreate the filesystem by receiving both send streams and verify we get
234 # the same content that the original filesystem had.
236 _scratch_mkfs >>$seqres.full 2>&1
239 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
240 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
241 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
242 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
244 echo "Silence is golden"