2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that an incremental send receive does not issue clone operations that
8 # attempt to clone the last block of a file, with a size not aligned to the
9 # filesystem's sector size, into the middle of some other file. Such clone
10 # request causes the receiver to fail (with EINVAL), for kernels that include
11 # commit ac765f83f1397646 ("Btrfs: fix data corruption due to cloning of eof
12 # block"), or cause silent data corruption for older kernels.
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
25 rm -fr $send_files_dir
28 # get standard environment, filters and checks
33 # real QA test starts here
38 _require_scratch_reflink
40 send_files_dir=$TEST_DIR/btrfs-test-$seq
43 rm -fr $send_files_dir
46 _scratch_mkfs >>$seqres.full 2>&1
49 $XFS_IO_PROG -f -c "pwrite -S 0xb1 0 2M" $SCRATCH_MNT/foo | _filter_xfs_io
50 $XFS_IO_PROG -f -c "pwrite -S 0xc7 0 2M" $SCRATCH_MNT/bar | _filter_xfs_io
51 $XFS_IO_PROG -f -c "pwrite -S 0x4d 0 2M" $SCRATCH_MNT/baz | _filter_xfs_io
52 $XFS_IO_PROG -f -c "pwrite -S 0xe2 0 2M" $SCRATCH_MNT/zoo | _filter_xfs_io
54 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
57 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
60 # Clone part of the extent from a higher offset to a lower offset of the same
62 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 640K 128K" $SCRATCH_MNT/bar \
65 # Now clone from the previous file, same range, into the middle of another file,
66 # such that the end offset at the destination is smaller than the destination's
68 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 0 128K" $SCRATCH_MNT/zoo \
71 # Truncate the source file of the previous clone operation to a smaller size,
72 # which ends up in the middle of the range of previous clone operation from file
73 # bar to file bar. We want to check this doesn't confuse send to issue invalid
74 # clone operations. This smaller size must not be aligned to the sector size of
75 # the filesystem - the unaligned size is what can cause those invalid clone
77 $XFS_IO_PROG -c "truncate 710K" $SCRATCH_MNT/bar
79 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
82 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
83 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
85 # Compute digests of the snapshot trees so that later we can compare against
86 # digests of the trees in the new filesystem, to see if they match (no data or
87 # metadata corruption happened).
88 $FSSUM_PROG -A -f -w $send_files_dir/base.fssum $SCRATCH_MNT/base
89 $FSSUM_PROG -A -f -w $send_files_dir/incr.fssum \
90 -x $SCRATCH_MNT/incr/base $SCRATCH_MNT/incr
92 # Now recreate the filesystem by receiving both send streams and verify we get
93 # the same file contents that the original filesystem had.
95 _scratch_mkfs >>$seqres.full 2>&1
98 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
99 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
101 # Compute digests of the snapshot trees in the new filesystem and compare them
102 # to the ones in the original filesystem, they must match.
103 $FSSUM_PROG -r $send_files_dir/base.fssum $SCRATCH_MNT/base
104 $FSSUM_PROG -r $send_files_dir/incr.fssum $SCRATCH_MNT/incr