xref: /titanic_44/usr/src/uts/common/sys/sysevent.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_SYSEVENT_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_SYSEVENT_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/nvpair.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifndef	NULL
39*7c478bd9Sstevel@tonic-gate #if defined(_LP64) && !defined(__cplusplus)
40*7c478bd9Sstevel@tonic-gate #define	NULL    0L
41*7c478bd9Sstevel@tonic-gate #else
42*7c478bd9Sstevel@tonic-gate #define	NULL	0
43*7c478bd9Sstevel@tonic-gate #endif
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /* Internal registration class and subclass */
47*7c478bd9Sstevel@tonic-gate #define	EC_ALL		"register_all_classes"
48*7c478bd9Sstevel@tonic-gate #define	EC_SUB_ALL	"register_all_subclasses"
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * Event allocation/enqueuing sleep/nosleep flags
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate #define	SE_SLEEP		0
54*7c478bd9Sstevel@tonic-gate #define	SE_NOSLEEP		1
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate /* Framework error codes */
57*7c478bd9Sstevel@tonic-gate #define	SE_EINVAL		1	/* Invalid argument */
58*7c478bd9Sstevel@tonic-gate #define	SE_ENOMEM		2	/* Unable to allocate memory */
59*7c478bd9Sstevel@tonic-gate #define	SE_EQSIZE		3	/* Maximum event q size exceeded */
60*7c478bd9Sstevel@tonic-gate #define	SE_EFAULT		4	/* Copy fault */
61*7c478bd9Sstevel@tonic-gate #define	SE_NOTFOUND		5	/* Attribute not found */
62*7c478bd9Sstevel@tonic-gate #define	SE_NO_TRANSPORT		6	/* sysevent transport down */
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /* Internal data types */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTE	DATA_TYPE_BYTE
67*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT16	DATA_TYPE_INT16
68*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT16	DATA_TYPE_UINT16
69*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT32	DATA_TYPE_INT32
70*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT32	DATA_TYPE_UINT32
71*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT64	DATA_TYPE_INT64
72*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT64	DATA_TYPE_UINT64
73*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_STRING	DATA_TYPE_STRING
74*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTES	DATA_TYPE_BYTE_ARRAY
75*7c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_TIME	DATA_TYPE_HRTIME
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate #define	SE_KERN_PID	0
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate #define	SUNW_VENDOR	"SUNW"
80*7c478bd9Sstevel@tonic-gate #define	SE_USR_PUB	"usr:"
81*7c478bd9Sstevel@tonic-gate #define	SE_KERN_PUB	"kern:"
82*7c478bd9Sstevel@tonic-gate #define	SUNW_KERN_PUB	SUNW_VENDOR":"SE_KERN_PUB
83*7c478bd9Sstevel@tonic-gate #define	SUNW_USR_PUB	SUNW_VENDOR":"SE_USR_PUB
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  * Event header and attribute value limits
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate #define	MAX_ATTR_NAME	1024
89*7c478bd9Sstevel@tonic-gate #define	MAX_STRING_SZ	1024
90*7c478bd9Sstevel@tonic-gate #define	MAX_BYTE_ARRAY	1024
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate #define	MAX_CLASS_LEN		64
93*7c478bd9Sstevel@tonic-gate #define	MAX_SUBCLASS_LEN	64
94*7c478bd9Sstevel@tonic-gate #define	MAX_PUB_LEN		128
95*7c478bd9Sstevel@tonic-gate #define	MAX_CHNAME_LEN		128
96*7c478bd9Sstevel@tonic-gate #define	MAX_SUBID_LEN		16
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /*
99*7c478bd9Sstevel@tonic-gate  * Limit for the event payload size
100*7c478bd9Sstevel@tonic-gate  */
101*7c478bd9Sstevel@tonic-gate #define	MAX_EV_SIZE_LEN		(SHRT_MAX/4)
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /* Opaque sysevent_t data type */
104*7c478bd9Sstevel@tonic-gate typedef void *sysevent_t;
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate /* Opaque channel bind data type */
107*7c478bd9Sstevel@tonic-gate typedef void evchan_t;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /* sysevent attribute list */
110*7c478bd9Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /* sysevent attribute name-value pair */
113*7c478bd9Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /* Unique event identifier */
116*7c478bd9Sstevel@tonic-gate typedef struct sysevent_id {
117*7c478bd9Sstevel@tonic-gate 	uint64_t eid_seq;
118*7c478bd9Sstevel@tonic-gate 	hrtime_t eid_ts;
119*7c478bd9Sstevel@tonic-gate } sysevent_id_t;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /* Event attribute value structures */
122*7c478bd9Sstevel@tonic-gate typedef struct sysevent_bytes {
123*7c478bd9Sstevel@tonic-gate 	int32_t	size;
124*7c478bd9Sstevel@tonic-gate 	uchar_t	*data;
125*7c478bd9Sstevel@tonic-gate } sysevent_bytes_t;
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate typedef struct sysevent_value {
128*7c478bd9Sstevel@tonic-gate 	int32_t		value_type;		/* data type */
129*7c478bd9Sstevel@tonic-gate 	union {
130*7c478bd9Sstevel@tonic-gate 		uchar_t		sv_byte;
131*7c478bd9Sstevel@tonic-gate 		int16_t		sv_int16;
132*7c478bd9Sstevel@tonic-gate 		uint16_t	sv_uint16;
133*7c478bd9Sstevel@tonic-gate 		int32_t		sv_int32;
134*7c478bd9Sstevel@tonic-gate 		uint32_t	sv_uint32;
135*7c478bd9Sstevel@tonic-gate 		int64_t		sv_int64;
136*7c478bd9Sstevel@tonic-gate 		uint64_t	sv_uint64;
137*7c478bd9Sstevel@tonic-gate 		hrtime_t	sv_time;
138*7c478bd9Sstevel@tonic-gate 		char		*sv_string;
139*7c478bd9Sstevel@tonic-gate 		sysevent_bytes_t	sv_bytes;
140*7c478bd9Sstevel@tonic-gate 	} value;
141*7c478bd9Sstevel@tonic-gate } sysevent_value_t;
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * The following flags determine the memory allocation semantics to use for
145*7c478bd9Sstevel@tonic-gate  * kernel event buffer allocation by userland and kernel versions of
146*7c478bd9Sstevel@tonic-gate  * sysevent_evc_publish().
147*7c478bd9Sstevel@tonic-gate  *
148*7c478bd9Sstevel@tonic-gate  * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP.
149*7c478bd9Sstevel@tonic-gate  * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation
150*7c478bd9Sstevel@tonic-gate  * routines to use use alternate kmem caches in situations where free memory
151*7c478bd9Sstevel@tonic-gate  * may be low.  Kernel callers of sysevent_evc_publish() must set flags to
152*7c478bd9Sstevel@tonic-gate  * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD.  Userland callers of
153*7c478bd9Sstevel@tonic-gate  * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP.
154*7c478bd9Sstevel@tonic-gate  *
155*7c478bd9Sstevel@tonic-gate  * EVCH_QWAIT determines whether or not we should wait for slots in the event
156*7c478bd9Sstevel@tonic-gate  * queue at publication time.  EVCH_QWAIT may be used by kernel and userland
157*7c478bd9Sstevel@tonic-gate  * publishers and must be used in conjunction with any of one of EVCH_SLEEP,
158*7c478bd9Sstevel@tonic-gate  * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only).
159*7c478bd9Sstevel@tonic-gate  */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #define	EVCH_NOSLEEP	0x0001	/* No sleep on kmem_alloc() */
162*7c478bd9Sstevel@tonic-gate #define	EVCH_SLEEP	0x0002	/* Sleep on kmem_alloc() */
163*7c478bd9Sstevel@tonic-gate #define	EVCH_TRYHARD	0x0004	/* May use alternate kmem cache for alloc */
164*7c478bd9Sstevel@tonic-gate #define	EVCH_QWAIT	0x0008	/* Wait for slot in event queue */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  * Meaning of flags for subscribe/unsubscribe. Bits 0 to 7 are dedicated to
168*7c478bd9Sstevel@tonic-gate  * the consolidation private interface.
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate #define	EVCH_SUB_KEEP		0x0001
171*7c478bd9Sstevel@tonic-gate #define	EVCH_ALLSUB		"all_subs"
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate /*
174*7c478bd9Sstevel@tonic-gate  * Meaning of flags parameter of channel bind function
175*7c478bd9Sstevel@tonic-gate  */
176*7c478bd9Sstevel@tonic-gate #define	EVCH_CREAT		0x0001	/* Create a channel if not present */
177*7c478bd9Sstevel@tonic-gate #define	EVCH_HOLD_PEND		0x0002
178*7c478bd9Sstevel@tonic-gate #define	EVCH_B_FLAGS		0x0003	/* All valid bits */
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * Meaning of commands of evc_control function
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN_MAX	 1	/* Get event queue length limit */
184*7c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN	 2	/* Get event queue length */
185*7c478bd9Sstevel@tonic-gate #define	EVCH_SET_CHAN_LEN	 3	/* Set event queue length */
186*7c478bd9Sstevel@tonic-gate #define	EVCH_CMD_LAST		 EVCH_SET_CHAN_LEN	/* Last command */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate  * Event channel interface definitions
190*7c478bd9Sstevel@tonic-gate  */
191*7c478bd9Sstevel@tonic-gate int sysevent_evc_bind(const char *, evchan_t **, uint32_t);
192*7c478bd9Sstevel@tonic-gate void sysevent_evc_unbind(evchan_t *);
193*7c478bd9Sstevel@tonic-gate int sysevent_evc_subscribe(evchan_t *, const char *, const char *,
194*7c478bd9Sstevel@tonic-gate     int (*)(sysevent_t *, void *), void *, uint32_t);
195*7c478bd9Sstevel@tonic-gate void sysevent_evc_unsubscribe(evchan_t *, const char *);
196*7c478bd9Sstevel@tonic-gate int sysevent_evc_publish(evchan_t *, const char *, const char *,
197*7c478bd9Sstevel@tonic-gate     const char *, const char *, nvlist_t *, uint32_t);
198*7c478bd9Sstevel@tonic-gate int sysevent_evc_control(evchan_t *, int, ...);
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate /*
203*7c478bd9Sstevel@tonic-gate  * Kernel log_event interfaces.
204*7c478bd9Sstevel@tonic-gate  */
205*7c478bd9Sstevel@tonic-gate int log_sysevent(sysevent_t *, int, sysevent_id_t *);
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate sysevent_t *sysevent_alloc(char *, char *, char *, int);
208*7c478bd9Sstevel@tonic-gate void sysevent_free(sysevent_t *);
209*7c478bd9Sstevel@tonic-gate int sysevent_add_attr(sysevent_attr_list_t **, char *, sysevent_value_t *, int);
210*7c478bd9Sstevel@tonic-gate void sysevent_free_attr(sysevent_attr_list_t *);
211*7c478bd9Sstevel@tonic-gate int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *);
212*7c478bd9Sstevel@tonic-gate void sysevent_detach_attributes(sysevent_t *);
213*7c478bd9Sstevel@tonic-gate char *sysevent_get_class_name(sysevent_t *);
214*7c478bd9Sstevel@tonic-gate char *sysevent_get_subclass_name(sysevent_t *);
215*7c478bd9Sstevel@tonic-gate uint64_t sysevent_get_seq(sysevent_t *);
216*7c478bd9Sstevel@tonic-gate void sysevent_get_time(sysevent_t *, hrtime_t *);
217*7c478bd9Sstevel@tonic-gate size_t sysevent_get_size(sysevent_t *);
218*7c478bd9Sstevel@tonic-gate char *sysevent_get_pub(sysevent_t *);
219*7c478bd9Sstevel@tonic-gate int sysevent_get_attr_list(sysevent_t *, nvlist_t **);
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate #endif
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSEVENT_H */
228