btrfs/139: require 2GB scratch dev
[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 _supported_os Linux
40 _require_scratch
41 _require_fail_make_request
42 _require_scratch_dev_pool 2
43 _scratch_dev_pool_get 2
44
45 SYSFS_BDEV=`_sysfs_dev $SCRATCH_DEV`
46 enable_io_failure()
47 {
48         echo 100 > $DEBUGFS_MNT/fail_make_request/probability
49         echo 1000 > $DEBUGFS_MNT/fail_make_request/times
50         echo 0 > $DEBUGFS_MNT/fail_make_request/verbose
51         echo 1 > $DEBUGFS_MNT/fail_make_request/task-filter
52         echo 1 > $SYSFS_BDEV/make-it-fail
53 }
54
55 disable_io_failure()
56 {
57         echo 0 > $DEBUGFS_MNT/fail_make_request/probability
58         echo 0 > $DEBUGFS_MNT/fail_make_request/times
59         echo 0 > $DEBUGFS_MNT/fail_make_request/task-filter
60         echo 0 > $SYSFS_BDEV/make-it-fail
61 }
62
63 _scratch_pool_mkfs "-d raid1 -b 1G" >> $seqres.full 2>&1
64
65 # It doesn't matter which compression algorithm we use.
66 _scratch_mount -ocompress
67
68 # Create a file with all data being compressed
69 $XFS_IO_PROG -f -c "pwrite -W 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
70
71 # Raid1 consists of two copies and btrfs decides which copy to read by reader's
72 # %pid.  Now we inject errors to copy #1 and copy #0 is good.  We want to read
73 # the bad copy to trigger read-repair.
74 while [[ -z $result ]]; do
75         # invalidate the page cache
76         $XFS_IO_PROG -f -c "fadvise -d 0 8K" $SCRATCH_MNT/foobar
77
78         enable_io_failure
79
80         result=$(bash -c "
81         if [ \$((\$\$ % 2)) == 1 ]; then
82                 echo 1 > /proc/\$\$/make-it-fail
83                 exec $XFS_IO_PROG -c \"pread 0 8K\" \$SCRATCH_MNT/foobar
84         fi")
85
86         disable_io_failure
87 done
88
89 _scratch_dev_pool_put
90 # success, all done
91 status=0
92 exit