xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_event.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
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 http://www.opensolaris.org/os/licensing.
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_EVENT_H
28 #define	_FMD_EVENT_H
29 
30 #include <pthread.h>
31 #include <libnvpair.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <fmd_time.h>
38 #include <fmd_api.h>
39 
40 struct fmd_log;				/* see <fmd_log.h> */
41 
42 typedef struct fmd_event_impl {
43 	pthread_mutex_t ev_lock;	/* lock protecting structure contents */
44 	uint32_t ev_refs;		/* reference count */
45 	uint8_t ev_type;		/* event type (see below) */
46 	uint8_t ev_state;		/* event state (see below) */
47 	uint8_t ev_flags;		/* event flags (see below) */
48 	uint8_t ev_ttl;			/* event time-to-live */
49 	nvlist_t *ev_nvl;		/* event name/value pair payload */
50 	void *ev_data;			/* event type-specific data pointer */
51 	fmd_timeval_t ev_time;		/* upper bound on event time-of-day */
52 	hrtime_t ev_hrt;		/* upper bound on event hrtime */
53 	struct fmd_log *ev_log;		/* event log (or NULL) */
54 	off64_t ev_off;			/* event log offset (or zero) */
55 	size_t ev_len;			/* event log record length (or zero) */
56 } fmd_event_impl_t;
57 
58 #define	FMD_EVT_PROTOCOL	0	/* protocol event (error/fault/list) */
59 #define	FMD_EVT_TIMEOUT		1	/* timeout expiry notification */
60 #define	FMD_EVT_CLOSE		2	/* case close request */
61 #define	FMD_EVT_STATS		3	/* statistics snapshot request */
62 #define	FMD_EVT_GC		4	/* garbage collection request */
63 #define	FMD_EVT_CTL		5	/* fmd control event (see fmd_ctl.c) */
64 #define	FMD_EVT_PUBLISH		6	/* case publish request */
65 #define	FMD_EVT_TOPO		7	/* topology change notification */
66 #define	FMD_EVT_NTYPES		8	/* number of event types */
67 
68 #define	FMD_EVS_DISCARDED	0	/* discarded by all subscribers */
69 #define	FMD_EVS_RECEIVED	1	/* received but not yet processed */
70 #define	FMD_EVS_ACCEPTED	2	/* accepted and assigned to a case */
71 #define	FMD_EVS_DIAGNOSED	3	/* diagnosed and assigned to a case */
72 
73 #define	FMD_EVF_VOLATILE	0x1	/* event is not yet written to a log */
74 #define	FMD_EVF_REPLAY		0x2	/* event is set for replay on restart */
75 #define	FMD_EVF_LOCAL		0x4	/* event is from fmd or a local xprt */
76 
77 #define	FMD_HRT_NOW		0	/* use current hrtime as event time */
78 
79 #define	FMD_EVENT_TYPE(e)	(((fmd_event_impl_t *)e)->ev_type)
80 #define	FMD_EVENT_DATA(e)	(((fmd_event_impl_t *)e)->ev_data)
81 #define	FMD_EVENT_NVL(e)	(((fmd_event_impl_t *)e)->ev_nvl)
82 #define	FMD_EVENT_TTL(e)	(((fmd_event_impl_t *)e)->ev_ttl)
83 
84 #define	FMD_EVN_TOD	"__tod"		/* private name-value pair for ev_tod */
85 #define	FMD_EVN_TTL	"__ttl"		/* private name-value pair for ev_ttl */
86 #define	FMD_EVN_UUID	"__uuid"	/* private name-value pair for UUIDs */
87 
88 extern fmd_event_t *fmd_event_recreate(uint_t, const fmd_timeval_t *,
89     nvlist_t *, void *, struct fmd_log *, off64_t, size_t);
90 
91 extern fmd_event_t *fmd_event_create(uint_t, hrtime_t, nvlist_t *, void *);
92 extern void fmd_event_destroy(fmd_event_t *);
93 extern void fmd_event_hold(fmd_event_t *);
94 extern void fmd_event_rele(fmd_event_t *);
95 
96 extern void fmd_event_transition(fmd_event_t *, uint_t);
97 extern void fmd_event_commit(fmd_event_t *);
98 
99 extern hrtime_t fmd_event_delta(fmd_event_t *, fmd_event_t *);
100 extern hrtime_t fmd_event_hrtime(fmd_event_t *);
101 
102 extern int fmd_event_match(fmd_event_t *, uint_t, const void *);
103 extern int fmd_event_equal(fmd_event_t *, fmd_event_t *);
104 
105 #ifdef	__cplusplus
106 }
107 #endif
108 
109 #endif	/* _FMD_EVENT_H */
110