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
51 _require_xfs_io_command "fpunch"
53 send_files_dir=$TEST_DIR/btrfs-test-$seq
56 rm -fr $send_files_dir
59 _scratch_mkfs >>$seqres.full 2>&1
62 # Create our test file with a single 100K extent.
63 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" $SCRATCH_MNT/foo | _filter_xfs_io
65 # Clone our file into a new file named bar.
66 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
68 # Now overwrite parts of our foo file.
69 $XFS_IO_PROG -c "pwrite -S 0xbb 50K 10K" \
70 -c "pwrite -S 0xcc 90K 10K" \
72 $SCRATCH_MNT/foo | _filter_xfs_io
74 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
76 echo "File digests in the original filesystem:"
77 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
78 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
80 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
82 # Now recreate the filesystem by receiving the send stream and verify we get
83 # the same file contents that the original filesystem had.
85 _scratch_mkfs >>$seqres.full 2>&1
88 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
90 # We expect the destination filesystem to have exactly the same file data as
91 # the original filesystem.
92 # The btrfs send implementation had a bug where it sent a clone operation from
93 # file foo into file bar covering the whole [0, 100K[ range after creating
94 # and writing the file foo. This was incorrect because the file bar now included
95 # the updates done to file foo after we cloned foo to bar, breaking the COW
96 # nature of reflink copies (cloned extents).
97 echo "File digests in the new filesystem:"
98 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
99 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch