xfs/{263,106}: erase max warnings printout
[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 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs btrfs
41 _supported_os Linux
42 _require_scratch_dev_pool 4
43 _require_btrfs_command inspect-internal dump-tree
44 _require_btrfs_fs_feature raid56
45
46 get_physical()
47 {
48         local stripe=$1
49         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
50                 grep " DATA\|RAID6" -A 10 | \
51                 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$6 }"
52 }
53
54 get_devid()
55 {
56         local stripe=$1
57         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
58                 grep " DATA\|RAID6" -A 10 | \
59                 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$4 }"
60 }
61
62 get_device_path()
63 {
64         local devid=$1
65         echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
66 }
67
68 _scratch_dev_pool_get 4
69 # step 1: create a raid6 btrfs and create a 128K file
70 echo "step 1......mkfs.btrfs" >>$seqres.full
71
72 mkfs_opts="-d raid6 -b 1G"
73 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
74
75 # -o nospace_cache makes sure data is written to the start position of the data
76 # chunk
77 _scratch_mount -o nospace_cache
78
79 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
80 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
81         "$SCRATCH_MNT/foobar" | _filter_xfs_io
82
83 _scratch_unmount
84
85 phy0=$(get_physical 0)
86 devid0=$(get_devid 0)
87 devpath0=$(get_device_path $devid0)
88 phy1=$(get_physical 1)
89 devid1=$(get_devid 1)
90 devpath1=$(get_device_path $devid1)
91
92 # step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
93 echo "step 2......simulate bitrot at:" >>$seqres.full
94 echo "      ......stripe #0: devid $devid0 devpath $devpath0 phy $phy0" \
95         >>$seqres.full
96 echo "      ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
97         >>$seqres.full
98
99 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy0 64K" $devpath0 > /dev/null
100 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
101
102 # step 3: scrub filesystem to repair the bitrot
103 echo "step 3......repair the bitrot" >> $seqres.full
104 _scratch_mount -o nospace_cache
105
106 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
107
108 od -x $SCRATCH_MNT/foobar
109
110 _scratch_dev_pool_put
111
112 # success, all done
113 status=0
114 exit