2 # FS QA Test No. btrfs/094
4 # Test that an incremental send issues valid clone operations for compressed
7 # For some compressed extents, namely those referred by a file extent item with
8 # a non-zero data offset, btrfs could issue a clone operation in the send stream
9 # with an offset and length pair that were not entirely contained in the source
10 # file's range, causing the receiving side to get -EINVAL errors from the clone
11 # ioctl when attempting to perform the clone operations.
13 # This issue was fixed by the following linux kernel btrfs patch:
15 # Btrfs: incremental send, fix clone operations for compressed extents
17 #-----------------------------------------------------------------------
18 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
19 # Author: Filipe Manana <fdmanana@suse.com>
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License as
23 # published by the Free Software Foundation.
25 # This program is distributed in the hope that it would be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write the Free Software Foundation,
32 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
41 status=1 # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
46 rm -fr $send_files_dir
50 # get standard environment, filters and checks
54 # real QA test starts here
61 send_files_dir=$TEST_DIR/btrfs-test-$seq
64 rm -fr $send_files_dir
67 _scratch_mkfs >>$seqres.full 2>&1
68 _scratch_mount "-o compress"
70 BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
72 # Create the file with a single extent of 32 blocks. This creates a metadata
73 # file extent item with a data start offset of 0 and a logical length of
75 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((16 * $BLOCK_SIZE)) $((32 * $BLOCK_SIZE))" \
76 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
78 # Now rewrite the block range [16, 28[ of our file. This will make
79 # the inode's metadata continue to point to the single 32 block extent
80 # we created before, but now with an extent item that points to the
81 # extent with a data start offset referring to the 28th block and a
82 # logical length of 4 blocks.
83 # That metadata file extent item is associated with the block range
85 $XFS_IO_PROG -c "pwrite -S 0xbb $((16 * $BLOCK_SIZE)) $((28 * $BLOCK_SIZE))" \
86 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
89 # Now rewrite the block range [45, 48[. This will make the inode's
90 # metadata continue to point the 32 block extent we created earlier,
91 # with a single extent item that points to it with a start offset
92 # referring to the 28th block and a logical length of 1 block.
93 # That metadata file extent item is associated with the block range
95 $XFS_IO_PROG -c "pwrite -S 0xcc $((45 * $BLOCK_SIZE)) $((3 * $BLOCK_SIZE))" \
96 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
98 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
100 # Now clone that same region of the 32 block extent into a new file, so that it
101 # gets referenced twice and the incremental send operation below decides to
102 # issue a clone operation instead of copying the data.
103 touch $SCRATCH_MNT/bar
104 $CLONER_PROG -s $((44 * $BLOCK_SIZE)) -d $((44 * $BLOCK_SIZE)) -l $BLOCK_SIZE \
105 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
107 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
109 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
110 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
111 -f $send_files_dir/2.snap
113 echo "File contents in the original filesystem:"
115 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
117 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
119 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od
121 # Now recreate the filesystem by receiving both send streams and verify we get
122 # the same file contents that the original filesystem had.
124 _scratch_mkfs >>$seqres.full 2>&1
127 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
128 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
130 echo "File contents in the new filesystem:"
132 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
134 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
136 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od