summaryrefslogtreecommitdiff
path: root/tests/btrfs/096
blob: 8e014cd24cc1fa53685c9629796b11660ff18942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 096
#
# Test that we can not clone an inline extent into a non-zero file offset.
#
. ./common/preamble
_begin_fstest auto quick clone

. ./common/filter
. ./common/filter.btrfs

_supported_fs btrfs
_require_scratch
_require_cloner

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)

# Create our test files. File foo has the same 2k of data at offset $BLOCK_SIZE
# as file bar has at its offset 0.
$XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 $BLOCK_SIZE" \
		-c "pwrite -S 0xbb $BLOCK_SIZE 2k" \
		-c "pwrite -S 0xcc $(($BLOCK_SIZE * 2)) $BLOCK_SIZE" \
		$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified

# File bar consists of a single inline extent (2k in size).
$XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2k" \
		$SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified

# Now call the clone ioctl to clone the extent of file bar into file
# foo at its $BLOCK_SIZE offset. This made file foo have an inline
# extent at offset $BLOCK_SIZE, something which the btrfs code can not
# deal with in future IO operations because all inline extents are
# supposed to start at an offset of 0, resulting in all sorts of
# chaos.
# So here we validate that the clone ioctl returns an EOPNOTSUPP or
# EINVAL which is what it returns for other cases dealing with inlined
# extents.
$CLONER_PROG -s 0 -d $BLOCK_SIZE -l 2048 \
	$SCRATCH_MNT/bar $SCRATCH_MNT/foo | _filter_btrfs_cloner_error

# Because of the inline extent at offset $BLOCK_SIZE, the following
# write made the kernel crash with a BUG_ON().
$XFS_IO_PROG -c "pwrite -S 0xdd $(($BLOCK_SIZE + 2048)) 2k" \
	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified

status=0
exit