xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / btrfs / 094
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/094
6 #
7 # Test that an incremental send issues valid clone operations for compressed
8 # file extents.
9 #
10 # For some compressed extents, namely those referred by a file extent item with
11 # a non-zero data offset, btrfs could issue a clone operation in the send stream
12 # with an offset and length pair that were not entirely contained in the source
13 # file's range, causing the receiving side to get -EINVAL errors from the clone
14 # ioctl when attempting to perform the clone operations.
15 #
16 # This issue was fixed by the following linux kernel btrfs patch:
17 #
18 #   Btrfs: incremental send, fix clone operations for compressed extents
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 tmp=/tmp/$$
25 status=1        # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
27
28 _cleanup()
29 {
30         rm -fr $send_files_dir
31         rm -f $tmp.*
32 }
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37
38 # real QA test starts here
39 _supported_fs btrfs
40 _supported_os Linux
41 _require_scratch
42 _require_cloner
43
44 send_files_dir=$TEST_DIR/btrfs-test-$seq
45
46 rm -f $seqres.full
47 rm -fr $send_files_dir
48 mkdir $send_files_dir
49
50 _scratch_mkfs >>$seqres.full 2>&1
51 _scratch_mount "-o compress"
52
53 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
54
55 # Create the file with a single extent of 32 blocks. This creates a metadata
56 # file extent item with a data start offset of 0 and a logical length of
57 # 32 blocks.
58 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((16 * $BLOCK_SIZE)) $((32 * $BLOCK_SIZE))" \
59              -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
60
61 # Now rewrite the block range [16, 28[ of our file. This will make
62 # the inode's metadata continue to point to the single 32 block extent
63 # we created before, but now with an extent item that points to the
64 # extent with a data start offset referring to the 28th block and a
65 # logical length of 4 blocks.
66 # That metadata file extent item is associated with the block range
67 # [44, 48[.
68 $XFS_IO_PROG -c "pwrite -S 0xbb $((16 * $BLOCK_SIZE)) $((28 * $BLOCK_SIZE))" \
69              -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
70
71
72 # Now rewrite the block range [45, 48[. This will make the inode's
73 # metadata continue to point the 32 block extent we created earlier,
74 # with a single extent item that points to it with a start offset
75 # referring to the 28th block and a logical length of 1 block.
76 # That metadata file extent item is associated with the block range
77 # [44, 45[.
78 $XFS_IO_PROG -c "pwrite -S 0xcc $((45 * $BLOCK_SIZE)) $((3 * $BLOCK_SIZE))" \
79              -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
80
81 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
82
83 # Now clone that same region of the 32 block extent into a new file, so that it
84 # gets referenced twice and the incremental send operation below decides to
85 # issue a clone operation instead of copying the data.
86 touch $SCRATCH_MNT/bar
87 $CLONER_PROG -s $((44 * $BLOCK_SIZE)) -d $((44 * $BLOCK_SIZE)) -l $BLOCK_SIZE \
88         $SCRATCH_MNT/foo $SCRATCH_MNT/bar
89
90 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
91
92 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
93 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
94         $SCRATCH_MNT/mysnap2
95
96 echo "File contents in the original filesystem:"
97 echo "mysnap1/foo"
98 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
99 echo "mysnap2/foo"
100 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
101 echo "mysnap2/bar"
102 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od
103
104 # Now recreate the filesystem by receiving both send streams and verify we get
105 # the same file contents that the original filesystem had.
106 _scratch_unmount
107 _scratch_mkfs >>$seqres.full 2>&1
108 _scratch_mount
109
110 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
111 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
112
113 echo "File contents in the new filesystem:"
114 echo "mysnap1/foo"
115 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
116 echo "mysnap2/foo"
117 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
118 echo "mysnap2/bar"
119 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od
120
121 status=0
122 exit