2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle. All Rights Reserved.
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.
11 # The kernel fixes are
12 # Btrfs: make raid6 rebuild retry more
13 # Btrfs: fix scrub to repair raid6 corruption
16 _begin_fstest auto quick raid scrub
18 # Import common functions.
21 # real QA test starts here
23 # Modify as appropriate.
25 _require_scratch_dev_pool 4
26 _require_btrfs_command inspect-internal dump-tree
27 _require_btrfs_fs_feature raid56
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 }"
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 }"
48 echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
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
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
59 # -o nospace_cache makes sure data is written to the start position of the data
61 _scratch_mount -o nospace_cache
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
69 phy0=$(get_physical 0)
71 devpath0=$(get_device_path $devid0)
72 phy1=$(get_physical 1)
74 devpath1=$(get_device_path $devid1)
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" \
80 echo " ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
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
86 # step 3: scrub filesystem to repair the bitrot
87 echo "step 3......repair the bitrot" >> $seqres.full
88 _scratch_mount -o nospace_cache
90 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
92 od -x $SCRATCH_MNT/foobar