2 # FS QA Test No. btrfs/083
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.
9 # This issue was fixed by the following linux kernel btrfs patch:
11 # Btrfs: incremental send, don't rename a directory too soon
13 #-----------------------------------------------------------------------
14 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
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.
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.
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 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
42 rm -fr $send_files_dir
46 # get standard environment, filters and checks
50 # real QA test starts here
56 send_files_dir=$TEST_DIR/btrfs-test-$seq
59 rm -fr $send_files_dir
62 _scratch_mkfs >>$seqres.full 2>&1
68 touch $SCRATCH_MNT/a/file
72 touch $SCRATCH_MNT/e/file2
75 # Filesystem looks like:
79 # | |---- file (ino 260)
85 # | |--- file2 (ino 263)
89 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
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:
99 # 1 - rename inode 259 ('c' -> 'x')
100 # 2 - rename inode 257 ('a' -> 'x/y')
101 # 3 - rename inode 258 ('b' -> 'a')
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'.
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.
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
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
119 # Filesystem now looks like:
125 # | |---- y/ (ino 257)
126 # | |----- file (ino 260)
129 # |---- f2/ (ino 264)
130 # | |----- e2/ (ino 262)
131 # |---- file2 (ino 263)
133 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
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
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
143 # Now recreate the filesystem by receiving both send streams and verify we get
144 # the same content that the original filesystem had.
146 _scratch_mkfs >>$seqres.full 2>&1
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
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
155 echo "Silence is golden"