summaryrefslogtreecommitdiff
path: root/tests/btrfs/261
blob: 50173de351f3829c9504f4550021ece9ff0d99e4 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test 261
#
# Make sure btrfs raid profiles can handling one corrupted device
# without affecting the consistency of the fs.
#
. ./common/preamble
_begin_fstest auto volume raid scrub

_supported_fs btrfs
_require_scratch_dev_pool 4
_btrfs_get_profile_configs replace-missing
_require_fssum

prepare_fs()
{
	local mkfs_opts=$1

	# We don't want too large fs which can take too long to populate
	# And the extra redirection of stderr is to avoid the RAID56 warning
	# message to polluate the golden output
	_scratch_pool_mkfs $mkfs_opts -b 1G >> $seqres.full 2>&1
	if [ $? -ne 0 ]; then
		_fail "mkfs $mkfs_opts failed"
	fi

	# Disable compression, as compressed read repair is known to have problems
	_scratch_mount -o compress=no

	# Fill some part of the fs first
	$XFS_IO_PROG -f -c "pwrite -S 0xfe 0 400M" $SCRATCH_MNT/garbage > /dev/null 2>&1

	# Then use fsstress to generate some extra contents.
	# Disable setattr related operations, as it may set NODATACOW which will
	# not allow us to use btrfs checksum to verify the content.
	$FSSTRESS_PROG -f setattr=0 -d $SCRATCH_MNT -w -n 3000 > /dev/null 2>&1
	sync

	# Save the fssum of this fs
	$FSSUM_PROG -A -f -w $tmp.saved_fssum $SCRATCH_MNT
	_scratch_unmount
}

workload()
{
	local mkfs_opts=$1
	local num_devs=$2

	_scratch_dev_pool_get 4
	echo "=== Testing profile $mkfs_opts ===" >> $seqres.full
	rm -f -- $tmp.saved_fssum
	prepare_fs "$mkfs_opts"

	# $SCRATCH_DEV is always the first device of dev pool.
	# Corrupt the disk but keep the primary superblock.
	$XFS_IO_PROG -c "pwrite 1M 1023M" $SCRATCH_DEV > /dev/null 2>&1

	_scratch_mount

	# All content should be fine
	$FSSUM_PROG -r $tmp.saved_fssum $SCRATCH_MNT > /dev/null

	# Scrub to fix the fs, this is known to report various correctable
	# errors
	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >> $seqres.full 2>&1

	# Make sure above scrub fixed the fs
	# Redirect the stderr to seqres.full as well to avoid warnings if
	# /var/lib filesystem is readonly, as scrub fails to write status.
	$BTRFS_UTIL_PROG scrub start -Br $SCRATCH_MNT >> $seqres.full 2>&1
	if [ $? -ne 0 ]; then
		echo "scrub failed to fix the fs for profile $mkfs_opts"
	fi
	_scratch_unmount
	_scratch_dev_pool_put
}

for t in "${_btrfs_profile_configs[@]}"; do
	workload "$t"
done

echo "Silence is golden"

# success, all done
status=0
exit