2 # FS QA Test No. btrfs/105
4 # Test that an incremental send works after a file from the parent snapshot
5 # gets replaced in the send snapshot by another one at the same exact location,
6 # with the same name and with the same inode number.
8 #-----------------------------------------------------------------------
9 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
10 # Author: Filipe Manana <fdmanana@suse.com>
11 # Copyright (C) 2015 Martin Raiber <martin@urbackup.org>
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
33 status=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
39 rm -fr $send_files_dir
43 # get standard environment, filters and checks
47 # real QA test starts here
52 send_files_dir=$TEST_DIR/btrfs-test-$seq
55 rm -fr $send_files_dir
58 _scratch_mkfs >>$seqres.full 2>&1
61 # Create our test file with a single extent of 64K.
62 mkdir -p $SCRATCH_MNT/foo
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo/bar | _filter_xfs_io
65 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
66 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/mysnap2
68 echo "File digest before being replaced:"
69 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
71 # Remove the file and then create a new one in the same location with the same
72 # name but with different content. This new file ends up getting the same inode
73 # number as the previous one, because that inode number was the highest inode
74 # number used by the snapshot's root and therefore when attempting to find the
75 # a new inode number for the new file, we end up reusing the same inode number.
76 # This happens because currently btrfs uses the highest inode number summed by 1
77 # for the first inode created once a snapshot's root is loaded (done at
78 # fs/btrfs/inode-map.c:btrfs_find_free_objectid in the linux kernel tree).
79 # Having these two different files in the snapshots with the same inode number
80 # (but different generation numbers) caused the btrfs send code to emit an
81 # incorrect path for the file when issuing an unlink operation because it failed
82 # to realize they were different files.
83 rm -f $SCRATCH_MNT/mysnap2/foo/bar
84 $XFS_IO_PROG -f -c "pwrite -S 0xbb 0 96K" \
85 $SCRATCH_MNT/mysnap2/foo/bar | _filter_xfs_io
87 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
88 $SCRATCH_MNT/mysnap2_ro
90 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
91 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2_ro \
92 -f $send_files_dir/2.snap
94 echo "File digest in the original filesystem after being replaced:"
95 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
97 # Now recreate the filesystem by receiving both send streams and verify we get
98 # the same file contents that the original filesystem had.
100 _scratch_mkfs >>$seqres.full 2>&1
103 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
104 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
106 echo "File digest in the new filesystem:"
107 # Must match the digest from the new file.
108 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch