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
44 send_files_dir=$TEST_DIR/btrfs-test-$seq
47 rm -fr $send_files_dir
50 _scratch_mkfs >>$seqres.full 2>&1
51 _scratch_mount "-o compress"
53 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
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
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
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
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
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
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
81 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
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
90 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
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 \
96 echo "File contents in the original filesystem:"
98 od -t x1 $SCRATCH_MNT/mysnap1/foo | _filter_od
100 od -t x1 $SCRATCH_MNT/mysnap2/foo | _filter_od
102 od -t x1 $SCRATCH_MNT/mysnap2/bar | _filter_od
104 # Now recreate the filesystem by receiving both send streams and verify we get
105 # the same file contents that the original filesystem had.
107 _scratch_mkfs >>$seqres.full 2>&1
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
113 echo "File contents in the new 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