xref: /illumos-gate/usr/src/cmd/fm/modules/common/ext-event-transport/fmevt.h (revision 132157d7fb25c120ae1deca2a65fa7c78e8fcfd0)
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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef _FMEVT_H
27 #define	_FMEVT_H
28 
29 /*
30  * ext-event-transport module - implementation detail.
31  */
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <libnvpair.h>
38 #include <fm/fmd_api.h>
39 #include <fm/libfmevent.h>
40 #include <sys/fm/protocol.h>
41 
42 #include "../../../../../lib/fm/libfmevent/common/fmev_channels.h"
43 
44 extern fmd_hdl_t *fmevt_hdl;
45 extern const fmd_prop_t fmevt_props[];
46 
47 extern void fmevt_init_outbound(fmd_hdl_t *);
48 extern void fmevt_fini_outbound(fmd_hdl_t *);
49 
50 extern void fmevt_init_inbound(fmd_hdl_t *);
51 extern void fmevt_fini_inbound(fmd_hdl_t *);
52 
53 extern void fmevt_recv(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);
54 
55 
56 /*
57  * Post-processing
58  */
59 
60 /*
61  * Structure passed to a post-processing functions with details of the
62  * raw event.
63  */
64 struct fmevt_ppargs {
65 	const char *pp_rawclass;	/* class from event publication */
66 	const char *pp_rawsubclass;	/* subclass from event publication */
67 	hrtime_t pp_hrt;		/* hrtime of event publication */
68 	int pp_user;			/* userland or kernel source? */
69 	int pp_priv;			/* privileged? */
70 	fmev_pri_t pp_pri;		/* published priority */
71 	char pp_uuidstr[36 + 1];	/* uuid we'll use for first event */
72 };
73 
74 /*
75  * The maximum length that a protocol event class name generated
76  * in post-processing can be.
77  */
78 #define	FMEVT_MAX_CLASS		64
79 
80 /*
81  * A post-processing function may derive up to this number of separate
82  * protocol events for each raw event.
83  */
84 #define	FMEVT_FANOUT_MAX	5
85 
86 /*
87  * Post-processing function type.  The function receives raw event
88  * details in the struct fmevt_ppargs.  It must prepare up to
89  * FMEVT_FANOUT_MAX protocol events (usually just one event)
90  * based on the raw event, and return the number of events
91  * to be posted.  The array of class pointers must have that
92  * number of non-NULL entries.  You may return 0 to ditch an event;
93  * in this case the caller will not perform an frees so you must
94  * tidy up.
95  *
96  * The array of string pointers has the first member pointed to
97  * some storage of size FMEV_MAX_CLASS into which the post-processing
98  * function must render the protocol event classname.  If fanning
99  * out into more than one event then the post-processing function
100  * must allocate additional buffers (using fmd_hdl_alloc) and return
101  * pointers to these in the array of string pointers (but do not change
102  * the first element); buffers allocated and returned in this way will
103  * be freed by the caller as it iterates over the protocol events to
104  * post them.  Similarly the function must prepare an attributes
105  * nvlist for each event; it can return the raw attributes or it
106  * can fmd_nvl_alloc or fmd_nvl_dup and return those (to be freed
107  * by the caller).
108  *
109  * Events will be generated based on the results as follows:
110  *
111  * event[i] =
112  *
113  *	timestamp = as supplied by incoming event and in pp_hrt
114  *	class = class_array[i];  entry 0 is allocated, fmd_hdl_alloc others
115  *	detector = generated detector as passed to function
116  *	uuid = generated UUID, or that supplied by raw event
117  *	attr = nvlist_array[i], can be absent; may return raw attributes
118  *
119  */
120 typedef uint_t fmevt_pp_func_t(
121     char *[FMEVT_FANOUT_MAX],		/* event class(es) */
122     nvlist_t *[FMEVT_FANOUT_MAX],	/* event attributes */
123     const char *,			/* ruleset */
124     const nvlist_t *,			/* detector */
125     nvlist_t *,				/* raw attributes */
126     const struct fmevt_ppargs *);	/* more raw event info */
127 
128 extern fmevt_pp_func_t fmevt_pp_on_ereport;
129 extern fmevt_pp_func_t fmevt_pp_smf;
130 extern fmevt_pp_func_t fmevt_pp_on_sunos;
131 extern fmevt_pp_func_t fmevt_pp_on_private;
132 extern fmevt_pp_func_t fmevt_pp_unregistered;
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* _FMEVT_H */
139