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 ZED handles missed events from a pool when starting.
30#
31# STRATEGY:
32# 1. Clear the events and create a pool to generate some events.
33# 2. Start the ZED and verify it handles missed events.
34# 3. Stop the ZED
35# 4. Generate additional events.
36# 5. Start the ZED and verify it only handles the new missed events.
37
38. $STF_SUITE/include/libtest.shlib
39. $STF_SUITE/tests/functional/events/events_common.kshlib
40
41verify_runnable "both"
42
43function cleanup
44{
45	if poolexists $MPOOL; then
46		destroy_pool $MPOOL
47	fi
48
49	for file in $VDEV1 $VDEV2; do
50		[[ -f $file ]] && rm -f $file
51	done
52
53	log_must rm -f $TMP_EVENTS_ZED
54	log_must zed_stop
55}
56
57log_assert "Verify ZED handles missed events when starting"
58log_onexit cleanup
59
60log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
61
62# 1. Create a pool and generate some events.
63log_must truncate -s 0 $ZED_DEBUG_LOG
64log_must zpool events -c
65log_must zpool create -O compression=off $MPOOL mirror $VDEV1 $VDEV2
66
67# 2. Start the ZED and verify it handles missed events.
68log_must zed_start
69log_must file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.config_sync' 150
70log_must cp $ZED_DEBUG_LOG $TMP_EVENTS_ZED
71
72awk -v event="sysevent.fs.zfs.pool_create" \
73    'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
74    $TMP_EVENTS_ZED >$TMP_EVENT_ZED
75log_must grep -q "^ZEVENT_POOL=$MPOOL" $TMP_EVENT_ZED
76
77# 3. Stop the ZED
78zed_stop
79log_must truncate -s 0 $ZED_DEBUG_LOG
80
81# 4. Generate additional events.
82log_must zpool offline $MPOOL $VDEV1
83log_must zpool online $MPOOL $VDEV1
84log_must zpool wait -t resilver $MPOOL
85
86log_must zpool scrub $MPOOL
87
88# Wait for the scrub to wrap, or is_healthy will be wrong.
89while ! is_pool_scrubbed $MPOOL; do
90	sleep 1
91done
92
93# 5. Start the ZED and verify it only handled the new missed events.
94log_must zed_start
95log_must file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.resilver_finish' 150
96log_must cp $ZED_DEBUG_LOG $TMP_EVENTS_ZED
97
98log_mustnot file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.pool_create' 30
99log_must grep -q "sysevent.fs.zfs.vdev_online" $TMP_EVENTS_ZED
100log_must grep -q "sysevent.fs.zfs.resilver_start" $TMP_EVENTS_ZED
101
102log_pass "Verify ZED handles missed events on when starting"
103