xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 030
1 #! /bin/bash
2 # FS QA Test No. btrfs/030
3 #
4 # Regression test for btrfs' incremental send feature:
5 #
6 # 1) Create several nested directories;
7 # 2) Create a read only snapshot;
8 # 3) Change the parentship of some of the deepest directories in a reverse
9 #    way, so that parents become children and children become parents;
10 # 4) Create another read only snapshot and use it for an incremental send
11 #    relative to the first snapshot.
12 #
13 # At step 4 btrfs' send entered an infinite loop, increasing the memory it
14 # used while building path strings until a krealloc was unable to allocate
15 # more memory, which caused a warning dump in dmesg.
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 tmp=`mktemp -d`
40 status=1        # failure is the default!
41 trap "_cleanup; exit \$status" 0 1 2 3 15
42
43 _cleanup()
44 {
45     rm -fr $tmp
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch
56 _require_fssum
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >/dev/null 2>&1
61 _scratch_mount
62
63
64 mkdir -p $SCRATCH_MNT/a/b/c
65 echo "hello" > $SCRATCH_MNT/a/b/c/file.txt
66 mkdir $SCRATCH_MNT/a/b/c/d
67 mkdir $SCRATCH_MNT/a/b/c2
68 mkdir $SCRATCH_MNT/a/b/www
69 echo "hey" > $SCRATCH_MNT/a/b/foobar.txt
70 mkdir -p $SCRATCH_MNT/a/b/c3/x/y
71
72 mkdir -p $SCRATCH_MNT/a/b/foo1/foo2
73 echo "hey" > $SCRATCH_MNT/a/b/foo1/foo2/f.txt
74 mkdir $SCRATCH_MNT/a/b/foo3
75
76 mkdir -p $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4
77 echo "ola" > $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4/hello.txt
78
79 # Directory tree looks like:
80 #
81 # .                                      (ino 256)
82 # |-- a/                                 (ino 257)
83 #     |-- b/                             (ino 258)
84 #         |-- c/                         (ino 259)
85 #         |   |-- file.txt               (ino 260)
86 #         |   |-- d/                     (ino 261)
87 #         |
88 #         |-- c2/                        (ino 262)
89 #         |-- www/                       (ino 263)
90 #         |-- foobar.txt                 (ino 264)
91 #         |
92 #         |-- c3/                        (ino 265)
93 #         |   |-- x/                     (ino 266)
94 #         |       |-- y/                 (ino 267)
95 #         |
96 #         |-- foo1/                      (ino 268)
97 #         |    |---foo2/                 (ino 269)
98 #         |         |---f.txt            (ino 270)
99 #         |
100 #         |-- foo3/                      (ino 271)
101 #         |
102 #         |-- bar1/                      (ino 272)
103 #              |-- bar2/                 (ino 273)
104 #                  |-- bar3/             (ino 274)
105 #                      |-- bar4          (ino 275)
106 #                           |--hello.txt (ino 276)
107
108 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
109
110 echo " world" >> $SCRATCH_MNT/a/b/c/file.txt
111 mv $SCRATCH_MNT/a/b/c/d $SCRATCH_MNT/a/b/c2/d2
112 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/c2/d2/cc
113 mv $SCRATCH_MNT/a/b/c3/x/y $SCRATCH_MNT/a/b/c2/y2
114 mv $SCRATCH_MNT/a/b/c3/x $SCRATCH_MNT/a/b/c2/y2/x2
115 mv $SCRATCH_MNT/a/b/c3 $SCRATCH_MNT/a/b/c2/y2/x2/Z
116 mv $SCRATCH_MNT/a/b/www $SCRATCH_MNT/a/b/c2/y2/x2/WWW
117 mv $SCRATCH_MNT/a/b/foobar.txt $SCRATCH_MNT/a/b/c2/y2/x2/qwerty.txt
118 ln $SCRATCH_MNT/a/b/c2/d2/cc/file.txt $SCRATCH_MNT/a/b/c2/y2/x2/Z/file_link.txt
119 mv $SCRATCH_MNT/a/b/c2/d2/cc/file.txt $SCRATCH_MNT/a/b/c2/y2/x2
120
121 mv $SCRATCH_MNT/a/b/foo3 $SCRATCH_MNT/a/b/foo1/foo33
122 mv $SCRATCH_MNT/a/b/foo1/foo2 $SCRATCH_MNT/a/b/foo1/foo33/foo22
123 mv $SCRATCH_MNT/a/b/foo1/foo33/foo22/f.txt \
124     $SCRATCH_MNT/a/b/foo1/foo33/foo22/fff.txt
125
126 echo " hello" >> $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4/hello.txt
127 mv $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4/hello.txt \
128     $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4/hello2.txt
129 mv $SCRATCH_MNT/a/b/bar1/bar2/bar3/bar4 $SCRATCH_MNT/a/b/k44
130 mv $SCRATCH_MNT/a/b/bar1/bar2/bar3 $SCRATCH_MNT/a/b/k44
131 mv $SCRATCH_MNT/a/b/bar1/bar2 $SCRATCH_MNT/a/b/k44/bar3
132 mv $SCRATCH_MNT/a/b/bar1 $SCRATCH_MNT/a/b/k44/bar3/bar2/k11
133
134 # Directory tree now looks like:
135 #
136 # .                                         (ino 256)
137 # |-- a/                                    (ino 257)
138 #     |-- b/                                (ino 258)
139 #         |-- c2/                           (ino 262)
140 #         |   |-- d2/                       (ino 261)
141 #         |   |   |-- cc/                   (ino 259)
142 #         |   |
143 #         |   |-- y2/                       (ino 267)
144 #         |       |-- x2/                   (ino 266)
145 #         |           |-- file.txt          (ino 260)
146 #         |           |-- qwerty.txt        (ino 264)
147 #         |           |-- WWW/              (ino 263)
148 #         |           |-- Z/                (ino 265)
149 #         |               |-- file_link.txt
150 #         |
151 #         |-- foo1/                         (ino 268)
152 #         |    |---foo33/                   (ino 271)
153 #         |          |---foo22/             (ino 269)
154 #         |                |---fff.txt      (ino 270)
155 #         |
156 #         |-- k44/                          (ino 275)
157 #              |-- hello2.txt               (ino 276)
158 #              |-- bar3/                    (ino 274)
159 #                   |-- bar2/               (ino 273)
160 #                        |-- k11/           (ino 272)
161
162 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
163
164 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
165 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
166     $SCRATCH_MNT/mysnap2
167
168 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
169 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
170     -f $tmp/2.snap
171
172 _scratch_unmount
173 _check_btrfs_filesystem $SCRATCH_DEV
174 _scratch_mkfs >/dev/null 2>&1
175 _scratch_mount
176
177 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/1.snap
178 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
179
180 _run_btrfs_util_prog receive $SCRATCH_MNT -f $tmp/2.snap
181 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
182
183 _scratch_unmount
184 _check_btrfs_filesystem $SCRATCH_DEV
185
186 status=0
187 exit