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
57 send_files_dir=$TEST_DIR/btrfs-test-$seq
60 rm -fr $send_files_dir
63 _scratch_mkfs >>$seqres.full 2>&1
69 touch $SCRATCH_MNT/a/file
73 touch $SCRATCH_MNT/e/file2
76 # Filesystem looks like:
80 # | |---- file (ino 260)
86 # | |--- file2 (ino 263)
90 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
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:
100 # 1 - rename inode 259 ('c' -> 'x')
101 # 2 - rename inode 257 ('a' -> 'x/y')
102 # 3 - rename inode 258 ('b' -> 'a')
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'.
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.
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
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
120 # Filesystem now looks like:
126 # | |---- y/ (ino 257)
127 # | |----- file (ino 260)
130 # |---- f2/ (ino 264)
131 # | |----- e2/ (ino 262)
132 # |---- file2 (ino 263)
134 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
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
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
144 # Now recreate the filesystem by receiving both send streams and verify we get
145 # the same content that the original filesystem had.
147 _scratch_mkfs >>$seqres.full 2>&1
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
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
156 echo "Silence is golden"