1#!/bin/ksh -p
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or https://opensource.org/licenses/CDDL-1.0.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2022, Klara Inc.
24#
25
26# DESCRIPTION:
27#	Verify that vdev properties, io_n and io_t, work with ZED.
28#
29# STRATEGY:
30#	1. Create a mirrored pool.
31#	3. Set io_n/io_t to non-default values
32#	3. Inject io errors
33#	4. Verify that ZED degrades vdev
34
35. $STF_SUITE/include/libtest.shlib
36. $STF_SUITE/tests/functional/events/events_common.kshlib
37
38verify_runnable "both"
39
40MOUNTDIR="$TEST_BASE_DIR/io_mount"
41FILEPATH="$MOUNTDIR/io_file"
42VDEV="$TEST_BASE_DIR/vdevfile.$$"
43VDEV1="$TEST_BASE_DIR/vdevfile1.$$"
44POOL="io_pool"
45
46function cleanup
47{
48	log_must zed_stop
49
50	log_must zinject -c all
51	if poolexists $POOL ; then
52		destroy_pool $POOL
53	fi
54	log_must rm -fd $VDEV $VDEV1 $MOUNTDIR
55	log_must set_tunable32 PREFETCH_DISABLE $zfsprefetch
56}
57log_onexit cleanup
58
59log_assert "Test ZED io_n and io_t configurability"
60
61zfsprefetch=$(get_tunable PREFETCH_DISABLE)
62log_must set_tunable32 PREFETCH_DISABLE 1
63
64function setup_pool
65{
66	log_must zpool create -f -m $MOUNTDIR $POOL mirror $VDEV $VDEV1
67	log_must zpool events -c
68	log_must truncate -s 0 $ZED_DEBUG_LOG
69	log_must zfs set compression=off $POOL
70	log_must zfs set primarycache=none $POOL
71	log_must zfs set recordsize=512 $POOL
72}
73
74function do_clean
75{
76	log_must zinject -c all
77	log_must zpool destroy $POOL
78}
79
80# Test default ZED settings:
81#   io_n=10	(events)
82#   io_t=600	(seconds)
83# fire 10 events over 2.5 seconds, should degrade.
84function default_degrade
85{
86	setup_pool
87
88	log_must dd if=/dev/urandom of=$FILEPATH bs=1M count=64
89	log_must zinject -a -d $VDEV -e io -T read -f 100 $POOL
90
91	blk=0
92	for _ in {1..10}; do
93		dd if=$FILEPATH of=/dev/null bs=1 count=1 skip=$blk 2>/dev/null
94		blk=$((blk+512))
95		sleep 0.25
96	done
97
98	log_must wait_vdev_state $POOL $VDEV "FAULTED" 60
99	do_clean
100}
101
102# set io_n=1
103# fire 1 event, should degrade
104function io_n_degrade
105{
106	setup_pool
107
108	log_must zpool set io_n=1 $POOL $VDEV
109	log_must dd if=/dev/urandom of=$FILEPATH bs=1M count=64
110	log_must zinject -a -d $VDEV -e io -T read -f 100 $POOL
111
112	dd if=$FILEPATH of=/dev/null bs=1 count=1 2>/dev/null
113
114	log_must wait_vdev_state $POOL $VDEV "FAULTED" 60
115	do_clean
116}
117
118# set io_t=1
119# fire 10 events over 2.5 seconds, should not degrade
120function io_t_nodegrade
121{
122	setup_pool
123
124	log_must zpool set io_t=1 $POOL $VDEV
125	log_must dd if=/dev/urandom of=$FILEPATH bs=1M count=64
126	log_must zinject -a -d $VDEV -e io -T read -f 100 $POOL
127
128	blk=0
129	for _ in {1..10}; do
130		dd if=$FILEPATH of=/dev/null bs=1 count=1 skip=$blk 2>/dev/null
131		blk=$((blk+512))
132		sleep 0.25
133	done
134
135	log_must file_wait $ZED_DEBUG_LOG 30
136	log_must wait_vdev_state $POOL $VDEV "ONLINE" 1
137
138	do_clean
139}
140
141log_must truncate -s $MINVDEVSIZE $VDEV
142log_must truncate -s $MINVDEVSIZE $VDEV1
143log_must mkdir -p $MOUNTDIR
144
145log_must zed_start
146default_degrade
147io_n_degrade
148io_t_nodegrade
149
150log_pass "Test ZED io_n and io_t configurability"
151