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