fstests: fix group list generation for whacky test names
[xfstests-dev.git] / tests / btrfs / 157
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test 157
6 #
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.
10 #
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
17 # unallocated blocks.
18 #
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
22 #
23 . ./common/preamble
24 _begin_fstest auto quick raid read_repair
25
26 # Import common functions.
27 . ./common/filter
28
29 # real QA test starts here
30
31 # Modify as appropriate.
32 _supported_fs btrfs
33 _require_scratch_dev_pool 4
34 _require_btrfs_command inspect-internal dump-tree
35 _require_btrfs_fs_feature raid56
36
37 get_physical()
38 {
39         local stripe=$1
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 \$6 }"
43 }
44
45 get_devid()
46 {
47         local stripe=$1
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 ~ /$stripe/) { print \$4 }"
51 }
52
53 get_device_path()
54 {
55         local devid=$1
56         echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
57 }
58
59 _scratch_dev_pool_get 4
60 # step 1: create a raid6 btrfs and create a 128K file
61 echo "step 1......mkfs.btrfs" >>$seqres.full
62
63 _check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
64 mkfs_opts="-d raid6 -b 1G"
65 _scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1
66
67 # make sure data is written to the start position of the data chunk
68 _scratch_mount $(_btrfs_no_v1_cache_opt)
69
70 # [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
71 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
72         "$SCRATCH_MNT/foobar" | _filter_xfs_io
73
74 logical=`${FILEFRAG_PROG} -v $SCRATCH_MNT/foobar | _filter_filefrag | cut -d '#' -f 1`
75 _scratch_unmount
76
77 phy0=$(get_physical 0)
78 devid0=$(get_devid 0)
79 devpath0=$(get_device_path $devid0)
80 phy1=$(get_physical 1)
81 devid1=$(get_devid 1)
82 devpath1=$(get_device_path $devid1)
83
84 # step 2: corrupt stripe #0 and #1
85 echo "step 2......simulate bitrot at:" >>$seqres.full
86 echo "      ......stripe #0: devid $devid0 devpath $devpath0 phy $phy0" \
87         >>$seqres.full
88 echo "      ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
89         >>$seqres.full
90
91 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy0 64K" $devpath0 > /dev/null
92 $XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null
93
94 # step 3: read foobar to repair the bitrot
95 echo "step 3......repair the bitrot" >> $seqres.full
96 _scratch_mount $(_btrfs_no_v1_cache_opt)
97
98 # read the 2nd stripe, i.e. [64K, 128K), to trigger repair
99 od -x -j 64K $SCRATCH_MNT/foobar
100
101 _scratch_dev_pool_put
102
103 # success, all done
104 status=0
105 exit