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
37 _require_scratch_reflink
39 send_files_dir=$TEST_DIR/btrfs-test-$seq
42 rm -fr $send_files_dir
45 _scratch_mkfs >>$seqres.full 2>&1
48 $XFS_IO_PROG -f -c "pwrite -S 0xb1 0 2M" $SCRATCH_MNT/foo | _filter_xfs_io
49 $XFS_IO_PROG -f -c "pwrite -S 0xc7 0 2M" $SCRATCH_MNT/bar | _filter_xfs_io
50 $XFS_IO_PROG -f -c "pwrite -S 0x4d 0 2M" $SCRATCH_MNT/baz | _filter_xfs_io
51 $XFS_IO_PROG -f -c "pwrite -S 0xe2 0 2M" $SCRATCH_MNT/zoo | _filter_xfs_io
53 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
56 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
59 # Clone part of the extent from a higher offset to a lower offset of the same
61 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 640K 128K" $SCRATCH_MNT/bar \
64 # Now clone from the previous file, same range, into the middle of another file,
65 # such that the end offset at the destination is smaller than the destination's
67 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 0 128K" $SCRATCH_MNT/zoo \
70 # Truncate the source file of the previous clone operation to a smaller size,
71 # which ends up in the middle of the range of previous clone operation from file
72 # bar to file bar. We want to check this doesn't confuse send to issue invalid
73 # clone operations. This smaller size must not be aligned to the sector size of
74 # the filesystem - the unaligned size is what can cause those invalid clone
76 $XFS_IO_PROG -c "truncate 710K" $SCRATCH_MNT/bar
78 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
81 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
82 $SCRATCH_MNT/incr 2>&1 | _filter_scratch
84 # Compute digests of the snapshot trees so that later we can compare against
85 # digests of the trees in the new filesystem, to see if they match (no data or
86 # metadata corruption happened).
87 $FSSUM_PROG -A -f -w $send_files_dir/base.fssum $SCRATCH_MNT/base
88 $FSSUM_PROG -A -f -w $send_files_dir/incr.fssum \
89 -x $SCRATCH_MNT/incr/base $SCRATCH_MNT/incr
91 # Now recreate the filesystem by receiving both send streams and verify we get
92 # the same file contents that the original filesystem had.
94 _scratch_mkfs >>$seqres.full 2>&1
97 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT
98 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT
100 # Compute digests of the snapshot trees in the new filesystem and compare them
101 # to the ones in the original filesystem, they must match.
102 $FSSUM_PROG -r $send_files_dir/base.fssum $SCRATCH_MNT/base
103 $FSSUM_PROG -r $send_files_dir/incr.fssum $SCRATCH_MNT/incr