xfstests: add test for btrfs incremental send infinite loop issue
[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 here=`pwd`
40 tmp=`mktemp -d`
41 status=1        # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
43
44 _cleanup()
45 {
46     rm -fr $tmp
47 }
48
49 # get standard environment, filters and checks
50 . ./common/rc
51 . ./common/filter
52
53 # real QA test starts here
54 _supported_fs btrfs
55 _supported_os Linux
56 _require_scratch
57 _need_to_be_root
58
59 FSSUM_PROG=$here/src/fssum
60 [ -x $FSSUM_PROG ] || _notrun "fssum not built"
61
62 rm -f $seqres.full
63
64 _scratch_mkfs >/dev/null 2>&1
65 _scratch_mount
66
67
68 mkdir -p $SCRATCH_MNT/a/b/c
69 echo "hello" > $SCRATCH_MNT/a/b/c/file.txt
70 mkdir $SCRATCH_MNT/a/b/c/d
71 mkdir $SCRATCH_MNT/a/b/c2
72 mkdir $SCRATCH_MNT/a/b/www
73 echo "hey" > $SCRATCH_MNT/a/b/foobar.txt
74 mkdir -p $SCRATCH_MNT/a/b/c3/x/y
75
76 # Directory tree looks like:
77 #
78 # .                         (ino 256)
79 # |-- a/                    (ino 257)
80 #     |-- b/                (ino 258)
81 #         |-- c/            (ino 259)
82 #         |   |-- file.txt  (ino 260)
83 #         |   |-- d/        (ino 261)
84 #         |
85 #         |-- c2/           (ino 262)
86 #         |-- www/          (ino 263)
87 #         |-- foobar.txt    (ino 264)
88 #         |
89 #         |-- c3/           (ino 265)
90 #             |-- x/        (ino 266)
91 #                 |-- y/    (ino 267)
92
93 run_check $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
94     $SCRATCH_MNT/mysnap1
95
96 echo " world" >> $SCRATCH_MNT/a/b/c/file.txt
97 mv $SCRATCH_MNT/a/b/c/d $SCRATCH_MNT/a/b/c2/d2
98 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/c2/d2/cc
99 mv $SCRATCH_MNT/a/b/c3/x/y $SCRATCH_MNT/a/b/c2/y2
100 mv $SCRATCH_MNT/a/b/c3/x $SCRATCH_MNT/a/b/c2/y2/x2
101 mv $SCRATCH_MNT/a/b/c3 $SCRATCH_MNT/a/b/c2/y2/x2/Z
102 mv $SCRATCH_MNT/a/b/www $SCRATCH_MNT/a/b/c2/y2/x2/WWW
103 mv $SCRATCH_MNT/a/b/foobar.txt $SCRATCH_MNT/a/b/c2/y2/x2/qwerty.txt
104 ln $SCRATCH_MNT/a/b/c2/d2/cc/file.txt $SCRATCH_MNT/a/b/c2/y2/x2/Z/file_link.txt
105 mv $SCRATCH_MNT/a/b/c2/d2/cc/file.txt $SCRATCH_MNT/a/b/c2/y2/x2
106
107 # Directory tree now looks like:
108 #
109 # .                                         (ino 256)
110 # |-- a/                                    (ino 257)
111 #     |-- b/                                (ino 258)
112 #         |-- c2/                           (ino 262)
113 #             |-- d2/                       (ino 261)
114 #             |   |-- cc/                   (ino 259)
115 #             |        |-- file.txt         (ino 260)
116 #             |-- y2/                       (ino 267)
117 #                 |-- x2/                   (ino 266)
118 #                     |-- qwerty.txt        (ino 264)
119 #                     |-- WWW/              (ino 263)
120 #                     |-- Z/                (ino 265)
121 #                         |-- file_link.txt
122
123 run_check $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
124     $SCRATCH_MNT/mysnap2
125
126 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
127 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
128     $SCRATCH_MNT/mysnap2
129
130 run_check $BTRFS_UTIL_PROG send $SCRATCH_MNT/mysnap1 -f $tmp/1.snap
131 run_check $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
132     -f $tmp/2.snap
133
134 _scratch_unmount
135 _check_btrfs_filesystem $SCRATCH_DEV
136 _scratch_mkfs >/dev/null 2>&1
137 _scratch_mount
138
139 run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/1.snap
140 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
141
142 run_check $BTRFS_UTIL_PROG receive $SCRATCH_MNT -f $tmp/2.snap
143 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
144
145 _scratch_unmount
146 _check_btrfs_filesystem $SCRATCH_DEV
147
148 status=0
149 exit