xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 150
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test btrfs/150
6 #
7 # This is a regression test which ends up with a kernel oops in btrfs.
8 # It occurs when btrfs's read repair happens while reading a compressed
9 # extent.
10 # The patch to fix it is
11 #       Btrfs: fix kernel oops while reading compressed data
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _require_scratch
40 _require_fail_make_request
41 _require_scratch_dev_pool 2
42 _scratch_dev_pool_get 2
43
44 SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
45 enable_io_failure()
46 {
47         echo 100 > $DEBUGFS_MNT/fail_make_request/probability
48         echo 1000 > $DEBUGFS_MNT/fail_make_request/times
49         echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
50         echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
51         echo 1 > $SYSFS_BDEV/make-it-fail
52 }
53
54 disable_io_failure()
55 {
56         echo 0 > $DEBUGFS_MNT/fail_make_request/probability
57         echo 0 > $DEBUGFS_MNT/fail_make_request/times
58         echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
59         echo 0 > $SYSFS_BDEV/make-it-fail
60 }
61
62 _scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
63
64 # It doesn't matter which compression algorithm we use.
65 _scratch_mount -ocompress
66
67 # Create a file with all data being compressed
68 $XFS_IO_PROG -f -c "pwrite -W 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
69
70 # Raid1 consists of two copies and btrfs decides which copy to read by reader's
71 # %pid.  Now we inject errors to copy #1 and copy #0 is good.  We want to read
72 # the bad copy to trigger read-repair.
73 while [[ -z $result ]]; do
74         # invalidate the page cache
75         $XFS_IO_PROG -f -c "fadvise -d 0 8K" $SCRATCH_MNT/foobar
76
77         enable_io_failure
78
79         result=$(bash -c "
80         if [ \$((\$\$ % 2)) == 1 ]; then
81                 echo 1 > /proc/\$\$/make-it-fail
82                 exec $XFS_IO_PROG -c \"pread 0 8K\" \$SCRATCH_MNT/foobar
83         fi")
84
85         disable_io_failure
86 done
87
88 _scratch_dev_pool_put
89 # success, all done
90 status=0
91 exit