summaryrefslogtreecommitdiff
path: root/tests/btrfs/158
blob: 78a527c27abc99fc901c363f001c7d99ebb0ad1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Oracle.  All Rights Reserved.
#
# FS QA Test 158
#
# The test case is check if scrub is able fix raid6 data corruption,
# ie. if there is data corruption on two disks in the same horizontal
# stripe, e.g.  due to bitrot.
#
# The kernel fixes are
#	Btrfs: make raid6 rebuild retry more
#	Btrfs: fix scrub to repair raid6 corruption
#
. ./common/preamble
_begin_fstest auto quick raid scrub

. ./common/filter

_supported_fs btrfs
# No data checksums for NOCOW case, so can't detect corruption and repair data.
_require_btrfs_no_nodatacow
_require_scratch_dev_pool 4
_require_btrfs_command inspect-internal dump-tree
_require_btrfs_raid_type raid5

get_physical()
{
	local stripe=$1
	$BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
		grep " DATA\|RAID6" -A 10 | \
		$AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$6 }"
}

get_devid()
{
	local stripe=$1
	$BTRFS_UTIL_PROG inspect-internal dump-tree -t 3 $SCRATCH_DEV | \
		grep " DATA\|RAID6" -A 10 | \
		$AWK_PROG "(\$1 ~ /stripe/ && \$3 ~ /devid/ && \$2 ~ /$stripe/) { print \$4 }"
}

get_device_path()
{
	local devid=$1
	echo "$SCRATCH_DEV_POOL" | $AWK_PROG "{print \$$devid}"
}

_scratch_dev_pool_get 4
# step 1: create a raid6 btrfs and create a 128K file
echo "step 1......mkfs.btrfs" >>$seqres.full

_check_minimal_fs_size $(( 1024 * 1024 * 1024 ))
mkfs_opts="-d raid6 -b 1G"
_scratch_pool_mkfs $mkfs_opts >>$seqres.full 2>&1

# make sure data is written to the start position of the data chunk
_scratch_mount $(_btrfs_no_v1_cache_opt)

# [0,64K) is written to stripe 0 and [64K, 128K) is written to stripe 1
$XFS_IO_PROG -f -d -c "pwrite -S 0xaa 0 128K" -c "fsync" \
	"$SCRATCH_MNT/foobar" | _filter_xfs_io

_scratch_unmount

phy0=$(get_physical 0)
devid0=$(get_devid 0)
devpath0=$(get_device_path $devid0)
phy1=$(get_physical 1)
devid1=$(get_devid 1)
devpath1=$(get_device_path $devid1)

# step 2: corrupt the 1st and 2nd stripe (stripe 0 and 1)
echo "step 2......simulate bitrot at:" >>$seqres.full
echo "      ......stripe #0: devid $devid0 devpath $devpath0 phy $phy0" \
	>>$seqres.full
echo "      ......stripe #1: devid $devid1 devpath $devpath1 phy $phy1" \
	>>$seqres.full

$XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy0 64K" $devpath0 > /dev/null
$XFS_IO_PROG -f -d -c "pwrite -S 0xbb $phy1 64K" $devpath1 > /dev/null

# step 3: scrub filesystem to repair the bitrot
echo "step 3......repair the bitrot" >> $seqres.full
_scratch_mount $(_btrfs_no_v1_cache_opt)

$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1

od -x $SCRATCH_MNT/foobar

_scratch_dev_pool_put

# success, all done
status=0
exit