generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 158
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test 158
6 #
7 # The test case is check if scrub is able fix raid6 data corruption,
8 # ie. if there is data corruption on two disks in the same horizontal
9 # stripe, e.g.  due to bitrot.
10 #
11 # The kernel fixes are
12 #       Btrfs: make raid6 rebuild retry more
13 #       Btrfs: fix scrub to repair raid6 corruption
14 #
15 . ./common/preamble
16 _begin_fstest auto quick raid scrub
17
18 # Import common functions.
19 . ./common/filter
20
21 # real QA test starts here
22
23 # Modify as appropriate.
24 _supported_fs btrfs
25 _require_scratch_dev_pool 4
26 _require_btrfs_command inspect-internal dump-tree
27 _require_btrfs_fs_feature raid56
28
29 get_physical()
30 {
31         local stripe=$1
32         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
33                 grep " DATA\|RAID6" -A 10 | \
34                 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$6 }"
35 }
36
37 get_devid()
38 {
39         local stripe=$1
40         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
41                 grep " DATA\|RAID6" -A 10 | \
42                 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$4 }"
43 }
44
45 get_device_path()
46 {
47         local devid=$1
48         echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
49 }
50
51 _scratch_dev_pool_get 4
52 # step 1: create a raid6 btrfs and create a 128K file
53 echo "step 1......mkfs.btrfs" >>$seqres.full
54
55 _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
56 mkfs_opts="-d raid6 -b 1G"
57 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
58
59 # -o nospace_cache makes sure data is written to the start position of the data
60 # chunk
61 _scratch_mount -o nospace_cache
62
63 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
64 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
65         "$SCRATCH_MNT/foobar" | _filter_xfs_io
66
67 _scratch_unmount
68
69 phy0=$(get_physical 0)
70 devid0=$(get_devid 0)
71 devpath0=$(get_device_path $devid0)
72 phy1=$(get_physical 1)
73 devid1=$(get_devid 1)
74 devpath1=$(get_device_path $devid1)
75
76 # step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
77 echo "step 2......simulate bitrot at:" >>$seqres.full
78 echo "      ......stripe #0: devid $devid0 devpath $devpath0 phy $phy0" \
79         >>$seqres.full
80 echo "      ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
81         >>$seqres.full
82
83 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy0 64K" $devpath0 > /dev/null
84 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
85
86 # step 3: scrub filesystem to repair the bitrot
87 echo "step 3......repair the bitrot" >> $seqres.full
88 _scratch_mount -o nospace_cache
89
90 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
91
92 od -x $SCRATCH_MNT/foobar
93
94 _scratch_dev_pool_put
95
96 # success, all done
97 status=0
98 exit