97041b6ce1ad375c66a44e74f2d543fd4d6219fe
[xfstests-dev.git] / tests / btrfs / 150
1 #! /bin/bash
2 # FS QA Test btrfs/150
3 #
4 # This is a regression test which ends up with a kernel oops in btrfs.
5 # It occurs when btrfs's read repair happens while reading a compressed
6 # extent.
7 # The patch to fix it is
8 #       Btrfs: fix kernel oops while reading compressed data
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2017 Oracle.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39         cd /
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # remove previous $seqres.full before test
48 rm -f $seqres.full
49
50 # real QA test starts here
51
52 # Modify as appropriate.
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch
56 _require_fail_make_request
57 _require_scratch_dev_pool 2
58
59 SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
60 enable_io_failure()
61 {
62         echo 100 > $DEBUGFS_MNT/fail_make_request/probability
63         echo 1000 > $DEBUGFS_MNT/fail_make_request/times
64         echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
65         echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
66         echo 1 > $SYSFS_BDEV/make-it-fail
67 }
68
69 disable_io_failure()
70 {
71         echo 0 > $DEBUGFS_MNT/fail_make_request/probability
72         echo 0 > $DEBUGFS_MNT/fail_make_request/times
73         echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
74         echo 0 > $SYSFS_BDEV/make-it-fail
75 }
76
77 _scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
78
79 # It doesn't matter which compression algorithm we use.
80 _scratch_mount -ocompress
81
82 # Create a file with all data being compressed
83 $XFS_IO_PROG -f -c "pwrite -W 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
84
85 # Raid1 consists of two copies and btrfs decides which copy to read by reader's
86 # %pid.  Now we inject errors to copy #1 and copy #0 is good.  We want to read
87 # the bad copy to trigger read-repair.
88 while [[ -z $result ]]; do
89         # invalidate the page cache
90         $XFS_IO_PROG -f -c "fadvise -d 0 8K" $SCRATCH_MNT/foobar
91
92         enable_io_failure
93
94         result=$(bash -c "
95         if [ \$((\$\$ % 2)) == 1 ]; then
96                 echo 1 > /proc/\$\$/make-it-fail
97                 exec $XFS_IO_PROG -c \"pread 0 8K\" \$SCRATCH_MNT/foobar
98         fi")
99
100         disable_io_failure
101 done
102
103 # success, all done
104 status=0
105 exit