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
45 send_files_dir=$TEST_DIR/btrfs-test-$seq
48 rm -fr $send_files_dir
51 _scratch_mkfs >>$seqres.full 2>&1
54 mkdir $SCRATCH_MNT/data
55 mkdir $SCRATCH_MNT/data/n1
56 mkdir $SCRATCH_MNT/data/n1/n2
57 mkdir $SCRATCH_MNT/data/n4
58 mkdir $SCRATCH_MNT/data/n1/n2/p1
59 mkdir $SCRATCH_MNT/data/n1/n2/p1/p2
60 mkdir $SCRATCH_MNT/data/t6
61 mkdir $SCRATCH_MNT/data/t7
62 mkdir -p $SCRATCH_MNT/data/t5/t7
63 mkdir $SCRATCH_MNT/data/t2
64 mkdir $SCRATCH_MNT/data/t4
65 mkdir -p $SCRATCH_MNT/data/t1/t3
66 mkdir $SCRATCH_MNT/data/p1
67 mv $SCRATCH_MNT/data/t1 $SCRATCH_MNT/data/p1
68 mkdir -p $SCRATCH_MNT/data/p1/p2
69 mv $SCRATCH_MNT/data/t4 $SCRATCH_MNT/data/p1/p2/t1
70 mv $SCRATCH_MNT/data/t5 $SCRATCH_MNT/data/n4/t5
71 mv $SCRATCH_MNT/data/n1/n2/p1/p2 $SCRATCH_MNT/data/n4/t5/p2
72 mv $SCRATCH_MNT/data/t7 $SCRATCH_MNT/data/n4/t5/p2/t7
73 mv $SCRATCH_MNT/data/t2 $SCRATCH_MNT/data/n4/t1
74 mv $SCRATCH_MNT/data/p1 $SCRATCH_MNT/data/n4/t5/p2/p1
75 mv $SCRATCH_MNT/data/n1/n2 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2
76 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1
77 mv $SCRATCH_MNT/data/n4/t5/t7 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7
78 mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1/t3 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3
79 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/p1 \
80 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1
81 mv $SCRATCH_MNT/data/t6 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t5
82 mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t1
83 mv $SCRATCH_MNT/data/n1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/n1
85 # Filesystem looks like:
88 # |--- data/ (ino 257)
94 # | |--- p2/ (ino 272)
95 # | |--- n2/ (ino 259)
96 # | |--- t1/ (ino 268)
97 # | |--- t3/ (ino 270)
98 # | | |--- t1/ (ino 269)
99 # | | |--- t5/ (ino 263)
101 # | |--- t7/ (ino 266)
102 # | |--- p1/ (ino 261)
103 # | |--- n1 (ino 258)
107 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
109 # The following sequence of directory renames resulted in an infinite path build
110 # loop when attempting to build the path for inode 266. This is because the
111 # inode's new parent, inode 261, was part of a circular dependency of delayed
112 # rename operations. This circular dependency should jave never been built (it
113 # happened due to a bug), and was the following:
115 # ino 272 <- ino 261 <- ino 259 <- ino 268 <- ino 267 <- ino 261
117 # Where the notation "X <- Y" means that rename of inode X is delayed to happen
118 # after the rename of inode Y.
120 mv $SCRATCH_MNT/data/n4/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/t1
121 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1 $SCRATCH_MNT/data/n4/
122 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2 $SCRATCH_MNT/data/n4/t1/n2
123 mv $SCRATCH_MNT/data/n4/t1/t7/p1 $SCRATCH_MNT/data/n4/t1/n2/p1
124 mv $SCRATCH_MNT/data/n4/t1/t3/t1 $SCRATCH_MNT/data/n4/t1/n2/t1
125 mv $SCRATCH_MNT/data/n4/t1/t3 $SCRATCH_MNT/data/n4/t1/n2/t1/t3
126 mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2 $SCRATCH_MNT/data/n4/t1/n2/p1/p2
127 mv $SCRATCH_MNT/data/n4/t1/t7 $SCRATCH_MNT/data/n4/t1/n2/p1/t7
128 mv $SCRATCH_MNT/data/n4/t5/p2/p1 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1
129 mv $SCRATCH_MNT/data/n4/t1/n2/t1/t3/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/t5
130 mv $SCRATCH_MNT/data/n4/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5
131 mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5/p2 \
132 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2
133 mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2/t7 $SCRATCH_MNT/data/n4/t1/t7
135 # Filesystem now looks like:
138 # |--- data (ino 257)
142 # | |--- p1/ (ino 261)
143 # | | |--- n1/ (ino 258)
144 # | | |--- p2/ (ino 272)
145 # | | | |--- p1/ (ino 271)
146 # | | | | |--- p2/ (ino 262)
147 # | | | | |--- t5/ (ino 265)
149 # | | | |--- t5/ (ino 263)
151 # | | |--- t1/ (ino 267)
152 # | | |--- t7/ (ino 266)
154 # | |--- t1/ (ino 269)
155 # | |--- t3/ (ino 270)
159 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
161 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
162 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
163 -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
165 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
166 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
169 # Now recreate the filesystem by receiving both send streams and verify we get
170 # the same content that the original filesystem had.
172 _scratch_mkfs >>$seqres.full 2>&1
175 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
176 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
177 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
178 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
180 echo "Silence is golden"