xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / btrfs / 189
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 189
6 #
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.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         rm -fr $send_files_dir
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _supported_fs btrfs
35 _supported_os Linux
36 _require_fssum
37 _require_test
38 _require_scratch_reflink
39
40 send_files_dir=$TEST_DIR/btrfs-test-$seq
41
42 rm -f $seqres.full
43 rm -fr $send_files_dir
44 mkdir $send_files_dir
45
46 _scratch_mkfs >>$seqres.full 2>&1
47 _scratch_mount
48
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
53
54 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/base 2>&1 \
55         | _filter_scratch
56
57 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap $SCRATCH_MNT/base 2>&1 \
58         | _filter_scratch
59
60 # Clone part of the extent from a higher offset to a lower offset of the same
61 # file.
62 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 640K 128K" $SCRATCH_MNT/bar \
63         | _filter_xfs_io
64
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
67 # file size.
68 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/bar 1600K 0 128K" $SCRATCH_MNT/zoo \
69         | _filter_xfs_io
70
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
76 # operations.
77 $XFS_IO_PROG -c "truncate 710K" $SCRATCH_MNT/bar
78
79 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr 2>&1 \
80         | _filter_scratch
81
82 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base -f $send_files_dir/2.snap \
83         $SCRATCH_MNT/incr 2>&1 | _filter_scratch
84
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
91
92 # Now recreate the filesystem by receiving both send streams and verify we get
93 # the same file contents that the original filesystem had.
94 _scratch_unmount
95 _scratch_mkfs >>$seqres.full 2>&1
96 _scratch_mount
97
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
100
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
105
106 status=0
107 exit