c6c12a9bceebe74083611f980422d465e0240827
[xfstests-dev.git] / tests / btrfs / 105
1 #! /bin/bash
2 # FS QA Test No. btrfs/105
3 #
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.
7 #
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>
12 #
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.
16 #
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.
21 #
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 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -fr $send_files_dir
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # real QA test starts here
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_scratch
51
52 send_files_dir=$TEST_DIR/btrfs-test-$seq
53
54 rm -f $seqres.full
55 rm -fr $send_files_dir
56 mkdir $send_files_dir
57
58 _scratch_mkfs >>$seqres.full 2>&1
59 _scratch_mount
60
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
64
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
67
68 echo "File digest before being replaced:"
69 md5sum $SCRATCH_MNT/mysnap1/foo/bar | _filter_scratch
70
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
86
87 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT/mysnap2 \
88         $SCRATCH_MNT/mysnap2_ro
89
90 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
91 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
92         $SCRATCH_MNT/mysnap2_ro
93
94 echo "File digest in the original filesystem after being replaced:"
95 md5sum $SCRATCH_MNT/mysnap2_ro/foo/bar | _filter_scratch
96
97 # Now recreate the filesystem by receiving both send streams and verify we get
98 # the same file contents that the original filesystem had.
99 _scratch_unmount
100 _scratch_mkfs >>$seqres.full 2>&1
101 _scratch_mount
102
103 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
104 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
105
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
109
110 status=0
111 exit