summaryrefslogtreecommitdiff
path: root/tests/btrfs/087
blob: 28222e58505bfa42fa6c07e5f4cc02fd9d0db6ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. btrfs/087
#
# Test a very complex scenario for a btrfs incremental send operation where a
# large directory hierarchy had many subtrees moved between parent directories,
# preserving the names of some directories and inverting the parent-child
# relationship between some directories (a child in the parent snapshot became
# a parent, in the send snapshot, of the directory that is its parent in the
# parent snapshot).
#
# This test made the incremental send fail with -ENOMEM because it entered an
# infinite loop when building path strings that are used as operands of the
# rename operations issued in the send stream.
# This issue was fixed by the following linux kernel btrfs patch:
#
#   Btrfs: incremental send, don't delay directory renames unnecessarily
#
. ./common/preamble
_begin_fstest auto quick send

# Override the default cleanup function.
_cleanup()
{
	rm -fr $send_files_dir
	rm -f $tmp.*
}

. ./common/filter

_supported_fs btrfs
_require_scratch
_require_fssum

send_files_dir=$TEST_DIR/btrfs-test-$seq

rm -fr $send_files_dir
mkdir $send_files_dir

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

mkdir $SCRATCH_MNT/data
mkdir $SCRATCH_MNT/data/n1
mkdir $SCRATCH_MNT/data/n1/n2
mkdir $SCRATCH_MNT/data/n4
mkdir $SCRATCH_MNT/data/n1/n2/p1
mkdir $SCRATCH_MNT/data/n1/n2/p1/p2
mkdir $SCRATCH_MNT/data/t6
mkdir $SCRATCH_MNT/data/t7
mkdir -p $SCRATCH_MNT/data/t5/t7
mkdir $SCRATCH_MNT/data/t2
mkdir $SCRATCH_MNT/data/t4
mkdir -p $SCRATCH_MNT/data/t1/t3
mkdir $SCRATCH_MNT/data/p1
mv $SCRATCH_MNT/data/t1 $SCRATCH_MNT/data/p1
mkdir -p $SCRATCH_MNT/data/p1/p2
mv $SCRATCH_MNT/data/t4 $SCRATCH_MNT/data/p1/p2/t1
mv $SCRATCH_MNT/data/t5 $SCRATCH_MNT/data/n4/t5
mv $SCRATCH_MNT/data/n1/n2/p1/p2 $SCRATCH_MNT/data/n4/t5/p2
mv $SCRATCH_MNT/data/t7 $SCRATCH_MNT/data/n4/t5/p2/t7
mv $SCRATCH_MNT/data/t2 $SCRATCH_MNT/data/n4/t1
mv $SCRATCH_MNT/data/p1 $SCRATCH_MNT/data/n4/t5/p2/p1
mv $SCRATCH_MNT/data/n1/n2 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2
mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1
mv $SCRATCH_MNT/data/n4/t5/t7 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7
mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1/t3 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3
mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/p1 \
	$SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1
mv $SCRATCH_MNT/data/t6 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t5
mv $SCRATCH_MNT/data/n4/t5/p2/p1/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t3/t1
mv $SCRATCH_MNT/data/n1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/n1

# Filesystem looks like:
#
# .                                                             (ino 256)
# |--- data/                                                    (ino 257)
#        |--- n4/                                               (ino 260)
#             |--- t1/                                          (ino 267)
#             |--- t5/                                          (ino 265)
#                  |--- p2/                                     (ino 262)
#                       |--- p1/                                (ino 271)
#                       |    |--- p2/                           (ino 272)
#                       |         |--- n2/                      (ino 259)
#                       |              |--- t1/                 (ino 268)
#                       |                   |--- t3/            (ino 270)
#                       |                   |    |--- t1/       (ino 269)
#                       |                   |    |--- t5/       (ino 263)
#                       |                   |
#                       |                   |--- t7/            (ino 266)
#                       |                        |--- p1/       (ino 261)
#                       |                             |--- n1   (ino 258)
#                       |
#                       |--- t7/                                (ino 264)
#
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1

# The following sequence of directory renames resulted in an infinite path build
# loop when attempting to build the path for inode 266. This is because the
# inode's new parent, inode 261, was part of a circular dependency of delayed
# rename operations. This circular dependency should jave never been built (it
# happened due to a bug), and was the following:
#
#   ino 272 <- ino 261 <- ino 259 <- ino 268 <- ino 267 <- ino 261
#
# Where the notation "X <- Y" means that rename of inode X is delayed to happen
# after the rename of inode Y.

mv $SCRATCH_MNT/data/n4/t1 $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1/t7/p1/t1
mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2/t1 $SCRATCH_MNT/data/n4/
mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2/n2 $SCRATCH_MNT/data/n4/t1/n2
mv $SCRATCH_MNT/data/n4/t1/t7/p1 $SCRATCH_MNT/data/n4/t1/n2/p1
mv $SCRATCH_MNT/data/n4/t1/t3/t1 $SCRATCH_MNT/data/n4/t1/n2/t1
mv $SCRATCH_MNT/data/n4/t1/t3 $SCRATCH_MNT/data/n4/t1/n2/t1/t3
mv $SCRATCH_MNT/data/n4/t5/p2/p1/p2 $SCRATCH_MNT/data/n4/t1/n2/p1/p2
mv $SCRATCH_MNT/data/n4/t1/t7 $SCRATCH_MNT/data/n4/t1/n2/p1/t7
mv $SCRATCH_MNT/data/n4/t5/p2/p1 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1
mv $SCRATCH_MNT/data/n4/t1/n2/t1/t3/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/t5
mv $SCRATCH_MNT/data/n4/t5 $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5
mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/t5/p2 \
	$SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2
mv $SCRATCH_MNT/data/n4/t1/n2/p1/p2/p1/p2/t7 $SCRATCH_MNT/data/n4/t1/t7

# Filesystem now looks like:
#
# .                                                   (ino 256)
# |--- data                                           (ino 257)
#        |--- n4/                                     (ino 260)
#             |--- t1/                                (ino 268)
#                  |--- n2/                           (ino 259)
#                  |    |--- p1/                      (ino 261)
#                  |    |    |--- n1/                 (ino 258)
#                  |    |    |--- p2/                 (ino 272)
#                  |    |    |    |--- p1/            (ino 271)
#                  |    |    |    |    |--- p2/       (ino 262)
#                  |    |    |    |    |--- t5/       (ino 265)
#                  |    |    |    |
#                  |    |    |    |--- t5/            (ino 263)
#                  |    |    |
#                  |    |    |--- t1/                 (ino 267)
#                  |    |    |--- t7/                 (ino 266)
#                  |    |
#                  |    |--- t1/                      (ino 269)
#                  |         |--- t3/                 (ino 270)
#                  |
#                  |--- t7/                           (ino 264)
#
_btrfs subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2

run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
	-x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2

_btrfs send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
_btrfs send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
	$SCRATCH_MNT/mysnap2

# Now recreate the filesystem by receiving both send streams and verify we get
# the same content that the original filesystem had.
_scratch_unmount
_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

_btrfs receive -f $send_files_dir/1.snap $SCRATCH_MNT
run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
_btrfs receive -f $send_files_dir/2.snap $SCRATCH_MNT
run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2

echo "Silence is golden"
status=0
exit