1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Portions Copyright 2021 iXsystems, Inc.
25#
26
27# DESCRIPTION:
28#	Verify spa deadman events are rate limited
29#
30# STRATEGY:
31#	1. Reduce the zfs_slow_io_events_per_second to 1.
32#	2. Reduce the zfs_deadman_ziotime_ms to 1ms.
33#	3. Write data to a pool and read it back.
34#	4. Verify deadman events have been produced at a reasonable rate.
35#
36
37. $STF_SUITE/include/libtest.shlib
38. $STF_SUITE/tests/functional/deadman/deadman.cfg
39
40verify_runnable "both"
41
42function cleanup
43{
44	zinject -c all
45	default_cleanup_noexit
46
47	set_tunable64 SLOW_IO_EVENTS_PER_SECOND $OLD_SLOW_IO_EVENTS
48	set_tunable64 DEADMAN_ZIOTIME_MS $ZIOTIME_DEFAULT
49}
50
51log_assert "Verify spa deadman events are rate limited"
52log_onexit cleanup
53
54OLD_SLOW_IO_EVENTS=$(get_tunable SLOW_IO_EVENTS_PER_SECOND)
55log_must set_tunable64 SLOW_IO_EVENTS_PER_SECOND 1
56log_must set_tunable64 DEADMAN_ZIOTIME_MS 1
57
58# Create a new pool in order to use the updated deadman settings.
59default_setup_noexit $DISK1
60log_must zpool events -c
61
62mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
63log_must file_write -b 1048576 -c 8 -o create -d 0 -f $mntpnt/file
64log_must zpool export $TESTPOOL
65log_must zpool import $TESTPOOL
66log_must zinject -d $DISK1 -D 5:1 $TESTPOOL
67log_must dd if=$mntpnt/file of=/dev/null oflag=sync
68
69events=$(zpool events $TESTPOOL | grep -c ereport.fs.zfs.deadman)
70log_note "events=$events"
71if [ "$events" -lt 1 ]; then
72	log_fail "Expect >= 1 deadman events, $events found"
73fi
74if [ "$events" -gt 10 ]; then
75	log_fail "Expect <= 10 deadman events, $events found"
76fi
77
78log_pass "Verify spa deadman events are rate limited"
79