2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/094
7 # Test that an incremental send issues valid clone operations for compressed
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.
16 # This issue was fixed by the following linux kernel btrfs patch:
18 # Btrfs: incremental send, fix clone operations for compressed extents
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
25 status=1 # failure is the default!
26 trap "_cleanup; exit \$status" 0 1 2 3 15
30 rm -fr $send_files_dir
34 # get standard environment, filters and checks
38 # real QA test starts here
43 send_files_dir=$TEST_DIR/btrfs-test-$seq
46 rm -fr $send_files_dir
49 _scratch_mkfs >>$seqres.full 2>&1
50 _scratch_mount "-o compress"
52 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
54 # Create the file with a single extent of 32 blocks. This creates a metadata
55 # file extent item with a data start offset of 0 and a logical length of
57 $XFS_IO_PROG -f -c "pwrite -S 0xaa $((16 * $BLOCK_SIZE)) $((32 * $BLOCK_SIZE))" \
58 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
60 # Now rewrite the block range [16, 28[ of our file. This will make
61 # the inode's metadata continue to point to the single 32 block extent
62 # we created before, but now with an extent item that points to the
63 # extent with a data start offset referring to the 28th block and a
64 # logical length of 4 blocks.
65 # That metadata file extent item is associated with the block range
67 $XFS_IO_PROG -c "pwrite -S 0xbb $((16 * $BLOCK_SIZE)) $((28 * $BLOCK_SIZE))" \
68 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
71 # Now rewrite the block range [45, 48[. This will make the inode's
72 # metadata continue to point the 32 block extent we created earlier,
73 # with a single extent item that points to it with a start offset
74 # referring to the 28th block and a logical length of 1 block.
75 # That metadata file extent item is associated with the block range
77 $XFS_IO_PROG -c "pwrite -S 0xcc $((45 * $BLOCK_SIZE)) $((3 * $BLOCK_SIZE))" \
78 -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
80 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
82 # Now clone that same region of the 32 block extent into a new file, so that it
83 # gets referenced twice and the incremental send operation below decides to
84 # issue a clone operation instead of copying the data.
85 touch $SCRATCH_MNT/bar
86 $CLONER_PROG -s $((44 * $BLOCK_SIZE)) -d $((44 * $BLOCK_SIZE)) -l $BLOCK_SIZE \
87 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
89 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
91 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
92 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
95 echo "File contents in the original filesystem:"
97 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
99 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
101 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od
103 # Now recreate the filesystem by receiving both send streams and verify we get
104 # the same file contents that the original filesystem had.
106 _scratch_mkfs >>$seqres.full 2>&1
109 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
110 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
112 echo "File contents in the new filesystem:"
114 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
116 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
118 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od