2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that we can not clone an inline extent into a non-zero file offset.
10 _begin_fstest auto quick clone
12 # Import common functions.
14 . ./common/filter.btrfs
16 # real QA test starts here
21 _scratch_mkfs >>$seqres.full 2>&1
24 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
26 # Create our test files. File foo has the same 2k of data at offset $BLOCK_SIZE
27 # as file bar has at its offset 0.
28 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 $BLOCK_SIZE" \
29 -c "pwrite -S 0xbb $BLOCK_SIZE 2k" \
30 -c "pwrite -S 0xcc $(($BLOCK_SIZE * 2)) $BLOCK_SIZE" \
31 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
33 # File bar consists of a single inline extent (2k in size).
34 $XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2k" \
35 $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
37 # Now call the clone ioctl to clone the extent of file bar into file
38 # foo at its $BLOCK_SIZE offset. This made file foo have an inline
39 # extent at offset $BLOCK_SIZE, something which the btrfs code can not
40 # deal with in future IO operations because all inline extents are
41 # supposed to start at an offset of 0, resulting in all sorts of
43 # So here we validate that the clone ioctl returns an EOPNOTSUPP or
44 # EINVAL which is what it returns for other cases dealing with inlined
46 $CLONER_PROG -s 0 -d $BLOCK_SIZE -l 2048 \
47 $SCRATCH_MNT/bar $SCRATCH_MNT/foo | _filter_btrfs_cloner_error
49 # Because of the inline extent at offset $BLOCK_SIZE, the following
50 # write made the kernel crash with a BUG_ON().
51 $XFS_IO_PROG -c "pwrite -S 0xdd $(($BLOCK_SIZE + 2048)) 2k" \
52 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified