4 # The test case is to reproduce a bug in raid6 reconstruction process that
5 # would end up with read failure if there is data corruption on two disks in
6 # the same horizontal stripe, e.g. due to bitrot.
9 # a) all disks are good to read,
10 # b) there is corrupted data on two disks in the same horizontal stripe due to
11 # something like bitrot,
12 # c) when rebuilding data after crc fails, btrfs is not able to tell whether
13 # other copies are good or corrupted because btrfs doesn't have crc for
16 # The kernel fixes are
17 # Btrfs: do not merge rbios if their fail stripe index are not identical
18 # Btrfs: make raid6 rebuild retry more
20 #-----------------------------------------------------------------------
21 # Copyright (c) 2017 Oracle. All Rights Reserved.
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License as
25 # published by the Free Software Foundation.
27 # This program is distributed in the hope that it would be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write the Free Software Foundation,
34 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #-----------------------------------------------------------------------
39 seqres=$RESULT_DIR/$seq
40 echo "QA output created by $seq"
44 status=1 # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
53 # get standard environment, filters and checks
57 # remove previous $seqres.full before test
60 # real QA test starts here
62 # Modify as appropriate.
65 _require_scratch_dev_pool 4
66 _require_btrfs_command inspect-internal dump-tree
68 get_physical_stripe0()
70 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
71 grep " DATA\|RAID6" -A 10 | \
72 $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /0/) { print $6 }'
75 get_physical_stripe1()
77 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
78 grep " DATA\|RAID6" -A 10 | \
79 $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /1/) { print $6 }'
82 _scratch_dev_pool_get 4
83 # step 1: create a raid6 btrfs and create a 4K file
84 echo "step 1......mkfs.btrfs" >>$seqres.full
86 mkfs_opts="-d raid6 -b 1G"
87 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
89 # -o nospace_cache makes sure data is written to the start position of the data
91 _scratch_mount -o nospace_cache
93 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
94 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
95 "$SCRATCH_MNT/foobar" | _filter_xfs_io
99 stripe_0=`get_physical_stripe0`
100 stripe_1=`get_physical_stripe1`
101 dev4=`echo $SCRATCH_DEV_POOL | awk '{print $4}'`
102 dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
104 # step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
105 echo "step 2......simulate bitrot at offset $stripe_0 of device_4($dev4) and offset $stripe_1 of device_3($dev3)" >>$seqres.full
107 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_0 64K" $dev4 | _filter_xfs_io
108 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_1 64K" $dev3 | _filter_xfs_io
110 # step 3: read foobar to repair the bitrot
111 echo "step 3......repair the bitrot" >> $seqres.full
112 _scratch_mount -o nospace_cache
114 # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
115 od -x -j 64K $SCRATCH_MNT/foobar
117 _scratch_dev_pool_put