e4b676779a0b43995c4e0ed16046933c4477c9ca
[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 _need_to_be_root
56
57 send_files_dir=$TEST_DIR/btrfs-test-$seq
58
59 rm -f $seqres.full
60 rm -fr $send_files_dir
61 mkdir $send_files_dir
62
63 _scratch_mkfs >>$seqres.full 2>&1
64 _scratch_mount
65
66 mkdir $SCRATCH_MNT/a
67 mkdir $SCRATCH_MNT/b
68 mkdir $SCRATCH_MNT/c
69 touch $SCRATCH_MNT/a/file
70
71 mkdir $SCRATCH_MNT/d
72 mkdir $SCRATCH_MNT/e
73 touch $SCRATCH_MNT/e/file2
74 mkdir $SCRATCH_MNT/f
75
76 # Filesystem looks like:
77 #
78 # .                                       (ino 256)
79 # |---- a/                                (ino 257)
80 # |     |---- file                        (ino 260)
81 # |
82 # |---- b/                                (ino 258)
83 # |---- c/                                (ino 259)
84 # |---- d/                                (ino 261)
85 # |---- e/                                (ino 262)
86 # |     |--- file2                        (ino 263)
87 # |
88 # |---- f/                                (ino 264)
89 #
90 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
91
92 # Now make inode 257 a child of inode 259 and rename inode 258 to the name that
93 # inode 257 had before. When the incremental send processes inode 257, it can't
94 # do the rename immediately because inode 259 must be renamed first, so inode's
95 # 257 rename is delayed and happens after the rename for inode 259 is done.
96 # Since send processes inodes by ascending order of their number, inode 258
97 # can't be renamed before inode 257 is renamed and therefore must be delayed
98 # as well. So the send stream must issue rename commands in the following order:
99 #
100 # 1 - rename inode 259 ('c' -> 'x')
101 # 2 - rename inode 257 ('a' -> 'x/y')
102 # 3 - rename inode 258 ('b' -> 'a')
103 #
104 # Before the fix mentioned above, the send stream attempted to rename inode 258
105 # before inode 257 was renamed, resulting in a client error mentioning
106 # 'directory not empty'.
107 #
108 # Same logic applies to 'd', 'e' and 'f', but the difference is that in the
109 # second snapshot 'e' is associated to an inode with a lower inode number than
110 # in the first snapshot.
111 #
112 mv $SCRATCH_MNT/c $SCRATCH_MNT/x
113 mv $SCRATCH_MNT/a $SCRATCH_MNT/x/y
114 mv $SCRATCH_MNT/b $SCRATCH_MNT/a
115
116 mv $SCRATCH_MNT/f $SCRATCH_MNT/f2
117 mv $SCRATCH_MNT/e $SCRATCH_MNT/f2/e2
118 mv $SCRATCH_MNT/d $SCRATCH_MNT/e
119
120 # Filesystem now looks like:
121 #
122 #
123 # .                                       (ino 256)
124 # |---- a/                                (ino 258)
125 # |---- x/                                (ino 259)
126 # |     |---- y/                          (ino 257)
127 # |           |----- file                 (ino 260)
128 # |
129 # |---- e/                                (ino 261)
130 # |---- f2/                               (ino 264)
131 # |     |----- e2/                        (ino 262)
132 #              |---- file2                (ino 263)
133
134 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
135
136 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
137 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
138         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
139
140 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
141 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
142         -f $send_files_dir/2.snap
143
144 # Now recreate the filesystem by receiving both send streams and verify we get
145 # the same content that the original filesystem had.
146 _scratch_unmount
147 _scratch_mkfs >>$seqres.full 2>&1
148 _scratch_mount
149
150 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
151 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
152
153 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
154 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
155
156 echo "Silence is golden"
157
158 status=0
159 exit