xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 087
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/087
6 #
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
12 # parent snapshot).
13 #
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:
18 #
19 #   Btrfs: incremental send, don't delay directory renames unnecessarily
20 #
21 seq=`basename $0`
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
24
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         rm -fr $send_files_dir
32         rm -f $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs btrfs
41 _require_scratch
42 _require_fssum
43
44 send_files_dir=$TEST_DIR/btrfs-test-$seq
45
46 rm -f $seqres.full
47 rm -fr $send_files_dir
48 mkdir $send_files_dir
49
50 _scratch_mkfs >>$seqres.full 2>&1
51 _scratch_mount
52
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
83
84 # Filesystem looks like:
85 #
86 # .                                                             (ino 256)
87 # |--- data/                                                    (ino 257)
88 #        |--- n4/                                               (ino 260)
89 #             |--- t1/                                          (ino 267)
90 #             |--- t5/                                          (ino 265)
91 #                  |--- p2/                                     (ino 262)
92 #                       |--- p1/                                (ino 271)
93 #                       |    |--- p2/                           (ino 272)
94 #                       |         |--- n2/                      (ino 259)
95 #                       |              |--- t1/                 (ino 268)
96 #                       |                   |--- t3/            (ino 270)
97 #                       |                   |    |--- t1/       (ino 269)
98 #                       |                   |    |--- t5/       (ino 263)
99 #                       |                   |
100 #                       |                   |--- t7/            (ino 266)
101 #                       |                        |--- p1/       (ino 261)
102 #                       |                             |--- n1   (ino 258)
103 #                       |
104 #                       |--- t7/                                (ino 264)
105 #
106 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
107
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:
113 #
114 #   ino 272 <- ino 261 <- ino 259 <- ino 268 <- ino 267 <- ino 261
115 #
116 # Where the notation "X <- Y" means that rename of inode X is delayed to happen
117 # after the rename of inode Y.
118
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
133
134 # Filesystem now looks like:
135 #
136 # .                                                   (ino 256)
137 # |--- data                                           (ino 257)
138 #        |--- n4/                                     (ino 260)
139 #             |--- t1/                                (ino 268)
140 #                  |--- n2/                           (ino 259)
141 #                  |    |--- p1/                      (ino 261)
142 #                  |    |    |--- n1/                 (ino 258)
143 #                  |    |    |--- p2/                 (ino 272)
144 #                  |    |    |    |--- p1/            (ino 271)
145 #                  |    |    |    |    |--- p2/       (ino 262)
146 #                  |    |    |    |    |--- t5/       (ino 265)
147 #                  |    |    |    |
148 #                  |    |    |    |--- t5/            (ino 263)
149 #                  |    |    |
150 #                  |    |    |--- t1/                 (ino 267)
151 #                  |    |    |--- t7/                 (ino 266)
152 #                  |    |
153 #                  |    |--- t1/                      (ino 269)
154 #                  |         |--- t3/                 (ino 270)
155 #                  |
156 #                  |--- t7/                           (ino 264)
157 #
158 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
159
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
163
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 \
166         $SCRATCH_MNT/mysnap2
167
168 # Now recreate the filesystem by receiving both send streams and verify we get
169 # the same content that the original filesystem had.
170 _scratch_unmount
171 _scratch_mkfs >>$seqres.full 2>&1
172 _scratch_mount
173
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
178
179 echo "Silence is golden"
180 status=0
181 exit