generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
14 _begin_fstest auto quick dangerous
15
16 # Import common functions.
17 . ./common/filter
18
19 # real QA test starts here
20
21 # Modify as appropriate.
22 _supported_fs btrfs
23 _require_scratch
24 _require_fail_make_request
25 _require_scratch_dev_pool 2
26 _scratch_dev_pool_get 2
27
28 SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
29 enable_io_failure()
30 {
31         echo 100 > $DEBUGFS_MNT/fail_make_request/probability
32         echo 1000 > $DEBUGFS_MNT/fail_make_request/times
33         echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
34         echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
35         echo 1 > $SYSFS_BDEV/make-it-fail
36 }
37
38 disable_io_failure()
39 {
40         echo 0 > $DEBUGFS_MNT/fail_make_request/probability
41         echo 0 > $DEBUGFS_MNT/fail_make_request/times
42         echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
43         echo 0 > $SYSFS_BDEV/make-it-fail
44 }
45
46 _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
47 _scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
48
49 # It doesn't matter which compression algorithm we use.
50 _scratch_mount -ocompress
51
52 # Create a file with all data being compressed
53 $XFS_IO_PROG -f -c "pwrite -W 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
54
55 # Raid1 consists of two copies and btrfs decides which copy to read by reader's
56 # %pid.  Now we inject errors to copy #1 and copy #0 is good.  We want to read
57 # the bad copy to trigger read-repair.
58 while [[ -z $result ]]; do
59         # invalidate the page cache
60         $XFS_IO_PROG -f -c "fadvise -d 0 8K" $SCRATCH_MNT/foobar
61
62         enable_io_failure
63
64         result=$(bash -c "
65         if [ \$((\$\$ % 2)) == 1 ]; then
66                 echo 1 > /proc/\$\$/make-it-fail
67                 exec $XFS_IO_PROG -c \"pread 0 8K\" \$SCRATCH_MNT/foobar
68         fi")
69
70         disable_io_failure
71 done
72
73 _scratch_dev_pool_put
74 # success, all done
75 status=0
76 exit