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# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
25# Use is subject to license terms.
26#
27
28# DESCRIPTION:
29#	Verify spa deadman detects a hung txg
30#
31# STRATEGY:
32#	1. Reduce the zfs_deadman_synctime_ms to 5s.
33#	2. Reduce the zfs_deadman_checktime_ms to 1s.
34#	3. Inject a 10s zio delay to force long IOs.
35#	4. Write enough data to force a long txg sync time due to the delay.
36#	5. Verify a "deadman" event is posted.
37#
38
39. $STF_SUITE/include/libtest.shlib
40. $STF_SUITE/tests/functional/deadman/deadman.cfg
41
42verify_runnable "both"
43
44function cleanup
45{
46	log_must zinject -c all
47	default_cleanup_noexit
48
49	log_must set_tunable64 DEADMAN_SYNCTIME_MS $SYNCTIME_DEFAULT
50	log_must set_tunable64 DEADMAN_CHECKTIME_MS $CHECKTIME_DEFAULT
51	log_must set_tunable64 DEADMAN_FAILMODE $FAILMODE_DEFAULT
52}
53
54log_assert "Verify spa deadman detects a hung txg"
55log_onexit cleanup
56
57log_must set_tunable64 DEADMAN_SYNCTIME_MS 5000
58log_must set_tunable64 DEADMAN_CHECKTIME_MS 1000
59log_must set_tunable64 DEADMAN_FAILMODE "wait"
60
61# Create a new pool in order to use the updated deadman settings.
62default_setup_noexit $DISK1
63log_must zpool events -c
64
65# Force each IO to take 10s by allow them to run concurrently.
66log_must zinject -d $DISK1 -D10000:10 $TESTPOOL
67
68mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
69log_must file_write -b 1048576 -c 8 -o create -d 0 -f $mntpnt/file
70sleep 10
71
72log_must zinject -c all
73log_must zpool sync
74
75# Log txg sync times for reference and the zpool event summary.
76if is_freebsd; then
77	log_must sysctl -n kstat.zfs.$TESTPOOL.txgs
78else
79	log_must cat /proc/spl/kstat/zfs/$TESTPOOL/txgs
80fi
81log_must zpool events
82
83# Verify at least 5 deadman events were logged.  The first after 5 seconds,
84# and another each second thereafter until the delay  is clearer.
85events=$(zpool events | grep -c ereport.fs.zfs.deadman)
86if [ "$events" -lt 5 ]; then
87	log_fail "Expect >=5 deadman events, $events found"
88fi
89
90log_pass "Verify spa deadman detected a hung txg and $events deadman events"
91