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 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
39 # Modify as appropriate.
42 _require_scratch_dev_pool 4
43 _require_btrfs_command inspect-internal dump-tree
44 _require_btrfs_fs_feature raid56
46 get_physical_stripe0()
48 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
49 grep " DATA\|RAID6" -A 10 | \
50 $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /0/) { print $6 }'
53 get_physical_stripe1()
55 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
56 grep " DATA\|RAID6" -A 10 | \
57 $AWK_PROG '($1 ~ /stripe/ && $3 ~ /devid/ && $2 ~ /1/) { print $6 }'
60 _scratch_dev_pool_get 4
61 # step 1: create a raid6 btrfs and create a 4K file
62 echo "step 1......mkfs.btrfs" >>$seqres.full
64 mkfs_opts="-d raid6 -b 1G"
65 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
67 # -o nospace_cache makes sure data is written to the start position of the data
69 _scratch_mount -o nospace_cache
71 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
72 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
73 "$SCRATCH_MNT/foobar" | _filter_xfs_io
77 stripe_0=`get_physical_stripe0`
78 stripe_1=`get_physical_stripe1`
79 dev4=`echo $SCRATCH_DEV_POOL | awk '{print $4}'`
80 dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
82 # step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
83 echo "step 2......simulate bitrot at offset $stripe_0 of device_4($dev4) and offset $stripe_1 of device_3($dev3)" >>$seqres.full
85 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_0 64K" $dev4 | _filter_xfs_io
86 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $stripe_1 64K" $dev3 | _filter_xfs_io
88 # step 3: scrub filesystem to repair the bitrot
89 echo "step 3......repair the bitrot" >> $seqres.full
90 _scratch_mount -o nospace_cache
92 $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1
94 od -x $SCRATCH_MNT/foobar