xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 083
1 #! /bin/bash
2 # FS QA Test No. btrfs/083
3 #
4 # Test for incremental send where the difference between the parent and child
5 # snapshots is that a directory A was renamed and a directory B was renamed to
6 # the name directory A had before (in the parent snapshot), but directory A's
7 # rename must happen before some other directory C is renamed.
8 #
9 # This issue was fixed by the following linux kernel btrfs patch:
10 #
11 #   Btrfs: incremental send, don't rename a directory too soon
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
16 #
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
20 #
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29 #-----------------------------------------------------------------------
30 #
31
32 seq=`basename $0`
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
35
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         rm -fr $send_files_dir
43         rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49
50 # real QA test starts here
51 _supported_fs btrfs
52 _supported_os Linux
53 _require_scratch
54 _require_fssum
55
56 send_files_dir=$TEST_DIR/btrfs-test-$seq
57
58 rm -f $seqres.full
59 rm -fr $send_files_dir
60 mkdir $send_files_dir
61
62 _scratch_mkfs >>$seqres.full 2>&1
63 _scratch_mount
64
65 mkdir $SCRATCH_MNT/a
66 mkdir $SCRATCH_MNT/b
67 mkdir $SCRATCH_MNT/c
68 touch $SCRATCH_MNT/a/file
69
70 mkdir $SCRATCH_MNT/d
71 mkdir $SCRATCH_MNT/e
72 touch $SCRATCH_MNT/e/file2
73 mkdir $SCRATCH_MNT/f
74
75 # Filesystem looks like:
76 #
77 # .                                       (ino 256)
78 # |---- a/                                (ino 257)
79 # |     |---- file                        (ino 260)
80 # |
81 # |---- b/                                (ino 258)
82 # |---- c/                                (ino 259)
83 # |---- d/                                (ino 261)
84 # |---- e/                                (ino 262)
85 # |     |--- file2                        (ino 263)
86 # |
87 # |---- f/                                (ino 264)
88 #
89 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
90
91 # Now make inode 257 a child of inode 259 and rename inode 258 to the name that
92 # inode 257 had before. When the incremental send processes inode 257, it can't
93 # do the rename immediately because inode 259 must be renamed first, so inode's
94 # 257 rename is delayed and happens after the rename for inode 259 is done.
95 # Since send processes inodes by ascending order of their number, inode 258
96 # can't be renamed before inode 257 is renamed and therefore must be delayed
97 # as well. So the send stream must issue rename commands in the following order:
98 #
99 # 1 - rename inode 259 ('c' -> 'x')
100 # 2 - rename inode 257 ('a' -> 'x/y')
101 # 3 - rename inode 258 ('b' -> 'a')
102 #
103 # Before the fix mentioned above, the send stream attempted to rename inode 258
104 # before inode 257 was renamed, resulting in a client error mentioning
105 # 'directory not empty'.
106 #
107 # Same logic applies to 'd', 'e' and 'f', but the difference is that in the
108 # second snapshot 'e' is associated to an inode with a lower inode number than
109 # in the first snapshot.
110 #
111 mv $SCRATCH_MNT/c $SCRATCH_MNT/x
112 mv $SCRATCH_MNT/a $SCRATCH_MNT/x/y
113 mv $SCRATCH_MNT/b $SCRATCH_MNT/a
114
115 mv $SCRATCH_MNT/f $SCRATCH_MNT/f2
116 mv $SCRATCH_MNT/e $SCRATCH_MNT/f2/e2
117 mv $SCRATCH_MNT/d $SCRATCH_MNT/e
118
119 # Filesystem now looks like:
120 #
121 #
122 # .                                       (ino 256)
123 # |---- a/                                (ino 258)
124 # |---- x/                                (ino 259)
125 # |     |---- y/                          (ino 257)
126 # |           |----- file                 (ino 260)
127 # |
128 # |---- e/                                (ino 261)
129 # |---- f2/                               (ino 264)
130 # |     |----- e2/                        (ino 262)
131 #              |---- file2                (ino 263)
132
133 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
134
135 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
136 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
137         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
138
139 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
140 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
141         -f $send_files_dir/2.snap
142
143 # Now recreate the filesystem by receiving both send streams and verify we get
144 # the same content that the original filesystem had.
145 _scratch_unmount
146 _scratch_mkfs >>$seqres.full 2>&1
147 _scratch_mount
148
149 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
150 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
151
152 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
153 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
154
155 echo "Silence is golden"
156
157 status=0
158 exit