2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/108
7 # Test that a send operation works correctly with reflinked files (cloned
8 # extents which multiple files point to).
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
21 rm -fr $send_files_dir
25 # get standard environment, filters and checks
30 # real QA test starts here
34 _require_xfs_io_command "fpunch"
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
45 # Create our test file with a single 100K extent.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" $SCRATCH_MNT/foo | _filter_xfs_io
48 # Clone our file into a new file named bar.
49 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
51 # Now overwrite parts of our foo file.
52 $XFS_IO_PROG -c "pwrite -S 0xbb 50K 10K" \
53 -c "pwrite -S 0xcc 90K 10K" \
55 $SCRATCH_MNT/foo | _filter_xfs_io
57 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
59 echo "File digests in the original filesystem:"
60 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
61 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
63 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
65 # Now recreate the filesystem by receiving the send stream and verify we get
66 # the same file contents that the original filesystem had.
68 _scratch_mkfs >>$seqres.full 2>&1
71 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
73 # We expect the destination filesystem to have exactly the same file data as
74 # the original filesystem.
75 # The btrfs send implementation had a bug where it sent a clone operation from
76 # file foo into file bar covering the whole [0, 100K[ range after creating
77 # and writing the file foo. This was incorrect because the file bar now included
78 # the updates done to file foo after we cloned foo to bar, breaking the COW
79 # nature of reflink copies (cloned extents).
80 echo "File digests in the new filesystem:"
81 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
82 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch