2 # FS QA Test No. btrfs/108
4 # Test that a send operation works correctly with reflinked files (cloned
5 # extents which multiple files point to).
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
9 # Author: Filipe Manana <fdmanana@suse.com>
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
31 status=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
37 rm -fr $send_files_dir
41 # get standard environment, filters and checks
46 # real QA test starts here
52 _require_xfs_io_command "fpunch"
54 send_files_dir=$TEST_DIR/btrfs-test-$seq
57 rm -fr $send_files_dir
60 _scratch_mkfs >>$seqres.full 2>&1
63 # Create our test file with a single 100K extent.
64 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" $SCRATCH_MNT/foo | _filter_xfs_io
66 # Clone our file into a new file named bar.
67 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
69 # Now overwrite parts of our foo file.
70 $XFS_IO_PROG -c "pwrite -S 0xbb 50K 10K" \
71 -c "pwrite -S 0xcc 90K 10K" \
73 $SCRATCH_MNT/foo | _filter_xfs_io
75 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
77 echo "File digests in the original filesystem:"
78 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
79 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
81 _run_btrfs_util_prog send $SCRATCH_MNT/snap -f $send_files_dir/1.snap
83 # Now recreate the filesystem by receiving the send stream and verify we get
84 # the same file contents that the original filesystem had.
86 _scratch_mkfs >>$seqres.full 2>&1
89 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
91 # We expect the destination filesystem to have exactly the same file data as
92 # the original filesystem.
93 # The btrfs send implementation had a bug where it sent a clone operation from
94 # file foo into file bar covering the whole [0, 100K[ range after creating
95 # and writing the file foo. This was incorrect because the file bar now included
96 # the updates done to file foo after we cloned foo to bar, breaking the COW
97 # nature of reflink copies (cloned extents).
98 echo "File digests in the new filesystem:"
99 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
100 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch