2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/087
7 # Test a very complex scenario for a btrfs incremental send operation where a
8 # large directory hierarchy had many subtrees moved between parent directories,
9 # preserving the names of some directories and inverting the parent-child
10 # relationship between some directories (a child in the parent snapshot became
11 # a parent, in the send snapshot, of the directory that is its parent in the
14 # This test made the incremental send fail with -ENOMEM because it entered an
15 # infinite loop when building path strings that are used as operands of the
16 # rename operations issued in the send stream.
17 # This issue was fixed by the following linux kernel btrfs patch:
19 # Btrfs: incremental send, don't delay directory renames unnecessarily
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
31 rm -fr $send_files_dir
35 # get standard environment, filters and checks
39 # real QA test starts here
44 send_files_dir=$TEST_DIR/btrfs-test-$seq
47 rm -fr $send_files_dir
50 _scratch_mkfs >>$seqres.full 2>&1
53 mkdir $SCRATCH_MNT/data
54 mkdir $SCRATCH_MNT/data/n1
55 mkdir $SCRATCH_MNT/data/n1/n2
56 mkdir $SCRATCH_MNT/data/n4
57 mkdir $SCRATCH_MNT/data/n1/n2/p1
58 mkdir $SCRATCH_MNT/data/n1/n2/p1/p2
59 mkdir $SCRATCH_MNT/data/t6
60 mkdir $SCRATCH_MNT/data/t7
61 mkdir -p $SCRATCH_MNT/data/t5/t7
62 mkdir $SCRATCH_MNT/data/t2
63 mkdir $SCRATCH_MNT/data/t4
64 mkdir -p $SCRATCH_MNT/data/t1/t3
65 mkdir $SCRATCH_MNT/data/p1
66 mv $SCRATCH_MNT/data/t1 $SCRATCH_MNT/data/p1
67 mkdir -p $SCRATCH_MNT/data/p1/p2
68 mv $SCRATCH_MNT/data/t4 $SCRATCH_MNT/data/p1/p2/t1
69 mv $SCRATCH_MNT/data/t5 $SCRATCH_MNT/data/n4/t5
70 mv $SCRATCH_MNT/data/n1/n2/p1/p2 $SCRATCH_MNT/data/n4/t5/p2
71 mv $SCRATCH_MNT/data/t7 $SCRATCH_MNT/data/n4/t5/p2/t7
72 mv $SCRATCH_MNT/data/t2 $SCRATCH_MNT/data/n4/t1
73 mv $SCRATCH_MNT/data/p1 $SCRATCH_MNT/data/n4/t5/p2/p1
74 mv $SCRATCH_MNT/data/n1/n2 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2
75 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1
76 mv $SCRATCH_MNT/data/n4/t5/t7 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7
77 mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1/t3 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3
78 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/p1 \
79 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1
80 mv $SCRATCH_MNT/data/t6 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t5
81 mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t1
82 mv $SCRATCH_MNT/data/n1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/n1
84 # Filesystem looks like:
87 # |--- data/ (ino 257)
93 # | |--- p2/ (ino 272)
94 # | |--- n2/ (ino 259)
95 # | |--- t1/ (ino 268)
96 # | |--- t3/ (ino 270)
97 # | | |--- t1/ (ino 269)
98 # | | |--- t5/ (ino 263)
100 # | |--- t7/ (ino 266)
101 # | |--- p1/ (ino 261)
102 # | |--- n1 (ino 258)
106 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
108 # The following sequence of directory renames resulted in an infinite path build
109 # loop when attempting to build the path for inode 266. This is because the
110 # inode's new parent, inode 261, was part of a circular dependency of delayed
111 # rename operations. This circular dependency should jave never been built (it
112 # happened due to a bug), and was the following:
114 # ino 272 <- ino 261 <- ino 259 <- ino 268 <- ino 267 <- ino 261
116 # Where the notation "X <- Y" means that rename of inode X is delayed to happen
117 # after the rename of inode Y.
119 mv $SCRATCH_MNT/data/n4/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/t1
120 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1 $SCRATCH_MNT/data/n4/
121 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2 $SCRATCH_MNT/data/n4/t1/n2
122 mv $SCRATCH_MNT/data/n4/t1/t7/p1 $SCRATCH_MNT/data/n4/t1/n2/p1
123 mv $SCRATCH_MNT/data/n4/t1/t3/t1 $SCRATCH_MNT/data/n4/t1/n2/t1
124 mv $SCRATCH_MNT/data/n4/t1/t3 $SCRATCH_MNT/data/n4/t1/n2/t1/t3
125 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2 $SCRATCH_MNT/data/n4/t1/n2/p1/p2
126 mv $SCRATCH_MNT/data/n4/t1/t7 $SCRATCH_MNT/data/n4/t1/n2/p1/t7
127 mv $SCRATCH_MNT/data/n4/t5/p2/p1 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1
128 mv $SCRATCH_MNT/data/n4/t1/n2/t1/t3/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/t5
129 mv $SCRATCH_MNT/data/n4/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5
130 mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5/p2 \
131 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2
132 mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2/t7 $SCRATCH_MNT/data/n4/t1/t7
134 # Filesystem now looks like:
137 # |--- data (ino 257)
141 # | |--- p1/ (ino 261)
142 # | | |--- n1/ (ino 258)
143 # | | |--- p2/ (ino 272)
144 # | | | |--- p1/ (ino 271)
145 # | | | | |--- p2/ (ino 262)
146 # | | | | |--- t5/ (ino 265)
148 # | | | |--- t5/ (ino 263)
150 # | | |--- t1/ (ino 267)
151 # | | |--- t7/ (ino 266)
153 # | |--- t1/ (ino 269)
154 # | |--- t3/ (ino 270)
158 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
160 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
161 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
162 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
164 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
165 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
168 # Now recreate the filesystem by receiving both send streams and verify we get
169 # the same content that the original filesystem had.
171 _scratch_mkfs >>$seqres.full 2>&1
174 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
175 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
176 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
177 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
179 echo "Silence is golden"