]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/events/events_002_pos.ksh
7769b45c896bd7216d238410f18f89e91260e82b
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / events / events_002_pos.ksh
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. Create a pool and 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
41 verify_runnable "both"
42
43 function 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 $TMP_EVENTS_ZED
54 log_must rm -f $ZEDLET_DIR/zed.debug.log.old
55 log_must zed_stop
56 }
57
58 log_assert "Verify ZED handles missed events on when starting"
59 log_onexit cleanup
60
61 log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
62
63 # 1. Create a pool and generate some events.
64 log_must cp -f $ZEDLET_DIR/zed.debug.log $ZEDLET_DIR/zed.debug.log.old
65 log_must zpool create $MPOOL mirror $VDEV1 $VDEV2
66
67 # 2. Start the ZED and verify it handles missed events.
68 log_must zed_start
69 log_must sleep 1
70 diff $ZEDLET_DIR/zed.debug.log.old $ZEDLET_DIR/zed.debug.log | \
71 grep "^> " | sed 's/^> //g' >$TMP_EVENTS_ZED
72 log_must awk -v event="sysevent.fs.zfs.pool_create" \
73 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
74 $TMP_EVENTS_ZED >$TMP_EVENT_ZED
75 log_must grep -q "^ZEVENT_POOL=$MPOOL" $TMP_EVENT_ZED
76
77 # 3. Stop the ZED
78 zed_stop
79
80 # 4. Generate additional events.
81 log_must cp -f $ZEDLET_DIR/zed.debug.log $ZEDLET_DIR/zed.debug.log.old
82 log_must zpool offline $MPOOL $VDEV1
83 log_must zpool online $MPOOL $VDEV1
84 log_must zpool scrub $MPOOL
85
86 # Wait for the scrub to wrap, or is_healthy will be wrong.
87 while ! is_pool_scrubbed $MPOOL; do
88 sleep 1
89 done
90
91 # 5. Start the ZED and verify it only handled the new missed events.
92 log_must zed_start
93 log_must sleep 3
94 diff $ZEDLET_DIR/zed.debug.log.old $ZEDLET_DIR/zed.debug.log | \
95 grep "^> " | sed 's/^> //g' >$TMP_EVENTS_ZED
96
97 log_mustnot grep -q "sysevent.fs.zfs.pool_create" $TMP_EVENTS_ZED
98 log_must grep -q "sysevent.fs.zfs.vdev_online" $TMP_EVENTS_ZED
99 log_must grep -q "sysevent.fs.zfs.resilver_start" $TMP_EVENTS_ZED
100 log_must grep -q "sysevent.fs.zfs.resilver_finish" $TMP_EVENTS_ZED
101
102 log_pass "Verify ZED handles missed events on when starting"