summaryrefslogtreecommitdiffstats
path: root/tests/24raid10deadlock
blob: ee330aa956b07571c42771000ecff5d84298c440 (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
devs="$dev0 $dev1 $dev2 $dev3"
runtime=120
pid=""
action_pid=""

set_up_injection()
{
	echo -1 > /sys/kernel/debug/fail_make_request/times
	echo 1 > /sys/kernel/debug/fail_make_request/probability
	echo 0 > /sys/kernel/debug/fail_make_request/verbose
	echo 1 > /sys/block/${1##*/}/make-it-fail
}

clean_up_injection()
{
	echo 0 > /sys/block/${1##*/}/make-it-fail
	echo 0 > /sys/kernel/debug/fail_make_request/times
	echo 0 > /sys/kernel/debug/fail_make_request/probability
	echo 2 > /sys/kernel/debug/fail_make_request/verbose
}

test_rdev()
{
	while true; do
		mdadm -f $md0 $1 &> /dev/null
		mdadm -r $md0 $1 &> /dev/null
		mdadm --zero-superblock $1 &> /dev/null
		mdadm -a $md0 $1 &> /dev/null
		sleep $2
	done
}

test_write_action()
{
	while true; do
		echo frozen > /sys/block/md0/md/sync_action
		echo idle > /sys/block/md0/md/sync_action
		sleep 0.1
	done
}

set_up_test()
{
	fio -h &> /dev/null || die "fio not found"

	# create a simple raid10
	mdadm -Cv -R -n 4 -l10 $md0 $devs || die "create raid10 failed"
}

clean_up_test()
{
	clean_up_injection $dev0
	pkill -9 fio
	kill -9 $pid
	kill -9 $action_pid

	sleep 1

	if ps $action_pid | tail -1 | awk '{print $3}' | grep D; then
		die "thread that is writing sysfs is stuck in D state, deadlock is triggered"
	fi
	mdadm -S $md0
}

cat /sys/kernel/debug/fail_make_request/times || die "fault injection is not enabled"

trap 'clean_up_test' EXIT

set_up_test || die "set up test failed"

# backgroup io pressure
fio -filename=$md0 -rw=randwrite -direct=1 -name=test -bs=4k -numjobs=16 -iodepth=16 &

# trigger add/remove device by io failure
set_up_injection $dev0
test_rdev $dev0 2 &
pid="$pid $!"

# add/remove device directly
test_rdev $dev3 10 &
pid="$pid $!"

test_write_action &
action_pid="$!"

sleep $runtime

exit 0