2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle. All Rights Reserved.
7 # The test case is to reproduce a bug in raid6 reconstruction process that
8 # would end up with read failure if there is data corruption on two disks in
9 # the same horizontal stripe, e.g. due to bitrot.
11 # The bug happens when
12 # a) all disks are good to read,
13 # b) there is corrupted data on two disks in the same horizontal stripe due to
14 # something like bitrot,
15 # c) when rebuilding data after crc fails, btrfs is not able to tell whether
16 # other copies are good or corrupted because btrfs doesn't have crc for
19 # The kernel fixes are
20 # Btrfs: do not merge rbios if their fail stripe index are not identical
21 # Btrfs: make raid6 rebuild retry more
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
42 # remove previous $seqres.full before test
45 # real QA test starts here
47 # Modify as appropriate.
49 _require_scratch_dev_pool 4
50 _require_btrfs_command inspect-internal dump-tree
51 _require_btrfs_fs_feature raid56
56 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
57 grep " DATA\|RAID6" -A 10 | \
58 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$6 }"
64 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
65 grep " DATA\|RAID6" -A 10 | \
66 $AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$4 }"
72 echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
75 _scratch_dev_pool_get 4
76 # step 1: create a raid6 btrfs and create a 128K file
77 echo "step 1......mkfs.btrfs" >>$seqres.full
79 mkfs_opts="-d raid6 -b 1G"
80 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
82 # -o nospace_cache makes sure data is written to the start position of the data
84 _scratch_mount -o nospace_cache
86 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
87 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
88 "$SCRATCH_MNT/foobar" | _filter_xfs_io
90 logical=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1`
93 phy0=$(get_physical 0)
95 devpath0=$(get_device_path $devid0)
96 phy1=$(get_physical 1)
98 devpath1=$(get_device_path $devid1)
100 # step 2: corrupt stripe #0 and #1
101 echo "step 2......simulate bitrot at:" >>$seqres.full
102 echo " ......stripe #0: devid $devid0 devpath $devpath0 phy $phy0" \
104 echo " ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
107 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy0 64K" $devpath0 > /dev/null
108 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
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