common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 096
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 096
6 #
7 # Test that we can not clone an inline extent into a non-zero file offset.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12 tmp=/tmp/$$
13 status=1        # failure is the default!
14 trap "_cleanup; exit \$status" 0 1 2 3 15
15
16 _cleanup()
17 {
18         rm -f $tmp.*
19 }
20
21 # get standard environment, filters and checks
22 . ./common/rc
23 . ./common/filter
24 . ./common/filter.btrfs
25
26 # real QA test starts here
27 _supported_fs btrfs
28 _supported_os Linux
29 _require_scratch
30 _require_cloner
31
32 rm -f $seqres.full
33
34 _scratch_mkfs >>$seqres.full 2>&1
35 _scratch_mount
36
37 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
38
39 # Create our test files. File foo has the same 2k of data at offset $BLOCK_SIZE
40 # as file bar has at its offset 0.
41 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 $BLOCK_SIZE" \
42                 -c "pwrite -S 0xbb $BLOCK_SIZE 2k" \
43                 -c "pwrite -S 0xcc $(($BLOCK_SIZE * 2)) $BLOCK_SIZE" \
44                 $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
45
46 # File bar consists of a single inline extent (2k in size).
47 $XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2k" \
48                 $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
49
50 # Now call the clone ioctl to clone the extent of file bar into file
51 # foo at its $BLOCK_SIZE offset. This made file foo have an inline
52 # extent at offset $BLOCK_SIZE, something which the btrfs code can not
53 # deal with in future IO operations because all inline extents are
54 # supposed to start at an offset of 0, resulting in all sorts of
55 # chaos.
56 # So here we validate that the clone ioctl returns an EOPNOTSUPP or
57 # EINVAL which is what it returns for other cases dealing with inlined
58 # extents.
59 $CLONER_PROG -s 0 -d $BLOCK_SIZE -l 2048 \
60         $SCRATCH_MNT/bar $SCRATCH_MNT/foo | _filter_btrfs_cloner_error
61
62 # Because of the inline extent at offset $BLOCK_SIZE, the following
63 # write made the kernel crash with a BUG_ON().
64 $XFS_IO_PROG -c "pwrite -S 0xdd $(($BLOCK_SIZE + 2048)) 2k" \
65              $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
66
67 status=0
68 exit