2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/109
7 # Test that a send operation works correctly with reflinked files (cloned
8 # extents which multiple files point to) that have compressed extents.
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
36 send_files_dir=$TEST_DIR/btrfs-test-$seq
39 rm -fr $send_files_dir
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount "-o compress"
45 # Create our file with an extent of 100K starting at file offset 0K.
46 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 100K" \
48 $SCRATCH_MNT/foo | _filter_xfs_io
50 # Rewrite part of the previous extent (its first 40K) and write a new 100K
51 # extent starting at file offset 100K.
52 $XFS_IO_PROG -c "pwrite -S 0xbb 0K 40K" \
53 -c "pwrite -S 0xcc 100K 100K" \
54 $SCRATCH_MNT/foo | _filter_xfs_io
56 # Our file foo now has 3 file extent items in its metadata:
58 # 1) One covering the file range 0 to 40K;
59 # 2) One covering the file range 40K to 100K, which points to the first extent
60 # we wrote to the file and has a data offset field with value 40K (our file
61 # no longer uses the first 40K of data from that extent);
62 # 3) One covering the file range 100K to 200K.
64 # Now clone our file foo into file bar.
65 cp --reflink=always $SCRATCH_MNT/foo $SCRATCH_MNT/bar
67 # Create our snapshot for the send operation.
68 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap
70 echo "File digests in the original filesystem:"
71 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
72 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch
74 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/snap
76 # Now recreate the filesystem by receiving the send stream and verify we get
77 # the same file contents that the original filesystem had.
78 # Btrfs send used to issue a clone operation from foo's range [80K, 140K[ to
79 # bar's range [40K, 100K[ when cloning the extent pointed to by foo's second
80 # file extent item, this was incorrect because of bad accounting of the file
81 # extent item's data offset field. The correct range to clone from should have
84 _scratch_mkfs >>$seqres.full 2>&1
85 _scratch_mount "-o compress"
87 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
89 echo "File digests in the new filesystem:"
90 # Must match the digests we got in the original filesystem.
91 md5sum $SCRATCH_MNT/snap/foo | _filter_scratch
92 md5sum $SCRATCH_MNT/snap/bar | _filter_scratch