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	poolexists $MPOOL && log_must destroy_pool $MPOOL
46	log_must rm -f $VDEV1 $VDEV2 $TMP_EVENTS_ZED
47	log_must zed_stop
48}
49
50log_assert "Verify ZED handles missed events when starting"
51log_onexit cleanup
52
53log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
54
55# 1. Create a pool and generate some events.
56log_must truncate -s 0 $ZED_DEBUG_LOG
57log_must zpool events -c
58log_must zpool create -O compression=off $MPOOL mirror $VDEV1 $VDEV2
59
60# 2. Start the ZED and verify it handles missed events.
61log_must zed_start
62log_must file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.config_sync' 150
63log_must cp $ZED_DEBUG_LOG $TMP_EVENTS_ZED
64
65log_mustnot awk -v event="sysevent.fs.zfs.pool_create" -v crit="\\nZEVENT_POOL=$MPOOL" \
66    'BEGIN{FS="\n"; RS=""} $0 ~ event && $0 ~ crit { exit 1 }' \
67    $TMP_EVENTS_ZED
68
69# 3. Stop the ZED
70zed_stop
71log_must truncate -s 0 $ZED_DEBUG_LOG
72
73# 4. Generate additional events.
74log_must zpool offline $MPOOL $VDEV1
75log_must zpool online $MPOOL $VDEV1
76log_must zpool wait -t resilver $MPOOL
77
78log_must zpool scrub $MPOOL
79
80# Wait for the scrub to wrap, or is_healthy will be wrong.
81while ! is_pool_scrubbed $MPOOL; do
82	sleep 1
83done
84
85# 5. Start the ZED and verify it only handled the new missed events.
86log_must zed_start
87log_must file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.resilver_finish' 150
88log_must cp $ZED_DEBUG_LOG $TMP_EVENTS_ZED
89
90log_mustnot file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.pool_create' 30
91log_must grep -q "sysevent.fs.zfs.vdev_online" $TMP_EVENTS_ZED
92log_must grep -q "sysevent.fs.zfs.resilver_start" $TMP_EVENTS_ZED
93
94log_pass "Verify ZED handles missed events on when starting"
95