xref: /titanic_51/usr/src/uts/common/sys/sysevent.h (revision 4870e0a7381ec2ec57437062574e6ddc3dd48d7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
549b225e1SGavin Maltby  * Common Development and Distribution License (the "License").
649b225e1SGavin Maltby  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2149b225e1SGavin Maltby 
227c478bd9Sstevel@tonic-gate /*
23f6e214c7SGavin Maltby  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SYSEVENT_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SYSEVENT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/nvpair.h>
30*4870e0a7SRichard PALO #include <sys/null.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /* Internal registration class and subclass */
377c478bd9Sstevel@tonic-gate #define	EC_ALL		"register_all_classes"
387c478bd9Sstevel@tonic-gate #define	EC_SUB_ALL	"register_all_subclasses"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Event allocation/enqueuing sleep/nosleep flags
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate #define	SE_SLEEP		0
447c478bd9Sstevel@tonic-gate #define	SE_NOSLEEP		1
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /* Framework error codes */
477c478bd9Sstevel@tonic-gate #define	SE_EINVAL		1	/* Invalid argument */
487c478bd9Sstevel@tonic-gate #define	SE_ENOMEM		2	/* Unable to allocate memory */
497c478bd9Sstevel@tonic-gate #define	SE_EQSIZE		3	/* Maximum event q size exceeded */
507c478bd9Sstevel@tonic-gate #define	SE_EFAULT		4	/* Copy fault */
517c478bd9Sstevel@tonic-gate #define	SE_NOTFOUND		5	/* Attribute not found */
527c478bd9Sstevel@tonic-gate #define	SE_NO_TRANSPORT		6	/* sysevent transport down */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* Internal data types */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTE	DATA_TYPE_BYTE
577c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT16	DATA_TYPE_INT16
587c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT16	DATA_TYPE_UINT16
597c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT32	DATA_TYPE_INT32
607c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT32	DATA_TYPE_UINT32
617c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT64	DATA_TYPE_INT64
627c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT64	DATA_TYPE_UINT64
637c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_STRING	DATA_TYPE_STRING
647c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTES	DATA_TYPE_BYTE_ARRAY
657c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_TIME	DATA_TYPE_HRTIME
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	SE_KERN_PID	0
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	SUNW_VENDOR	"SUNW"
707c478bd9Sstevel@tonic-gate #define	SE_USR_PUB	"usr:"
717c478bd9Sstevel@tonic-gate #define	SE_KERN_PUB	"kern:"
727c478bd9Sstevel@tonic-gate #define	SUNW_KERN_PUB	SUNW_VENDOR":"SE_KERN_PUB
737c478bd9Sstevel@tonic-gate #define	SUNW_USR_PUB	SUNW_VENDOR":"SE_USR_PUB
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Event header and attribute value limits
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate #define	MAX_ATTR_NAME	1024
797c478bd9Sstevel@tonic-gate #define	MAX_STRING_SZ	1024
807c478bd9Sstevel@tonic-gate #define	MAX_BYTE_ARRAY	1024
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	MAX_CLASS_LEN		64
837c478bd9Sstevel@tonic-gate #define	MAX_SUBCLASS_LEN	64
847c478bd9Sstevel@tonic-gate #define	MAX_PUB_LEN		128
857c478bd9Sstevel@tonic-gate #define	MAX_CHNAME_LEN		128
867c478bd9Sstevel@tonic-gate #define	MAX_SUBID_LEN		16
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Limit for the event payload size
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	MAX_EV_SIZE_LEN		(SHRT_MAX/4)
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* Opaque sysevent_t data type */
947c478bd9Sstevel@tonic-gate typedef void *sysevent_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* Opaque channel bind data type */
977c478bd9Sstevel@tonic-gate typedef void evchan_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* sysevent attribute list */
1007c478bd9Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* sysevent attribute name-value pair */
1037c478bd9Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* Unique event identifier */
1067c478bd9Sstevel@tonic-gate typedef struct sysevent_id {
1077c478bd9Sstevel@tonic-gate 	uint64_t eid_seq;
1087c478bd9Sstevel@tonic-gate 	hrtime_t eid_ts;
1097c478bd9Sstevel@tonic-gate } sysevent_id_t;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /* Event attribute value structures */
1127c478bd9Sstevel@tonic-gate typedef struct sysevent_bytes {
1137c478bd9Sstevel@tonic-gate 	int32_t	size;
1147c478bd9Sstevel@tonic-gate 	uchar_t	*data;
1157c478bd9Sstevel@tonic-gate } sysevent_bytes_t;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate typedef struct sysevent_value {
1187c478bd9Sstevel@tonic-gate 	int32_t		value_type;		/* data type */
1197c478bd9Sstevel@tonic-gate 	union {
1207c478bd9Sstevel@tonic-gate 		uchar_t		sv_byte;
1217c478bd9Sstevel@tonic-gate 		int16_t		sv_int16;
1227c478bd9Sstevel@tonic-gate 		uint16_t	sv_uint16;
1237c478bd9Sstevel@tonic-gate 		int32_t		sv_int32;
1247c478bd9Sstevel@tonic-gate 		uint32_t	sv_uint32;
1257c478bd9Sstevel@tonic-gate 		int64_t		sv_int64;
1267c478bd9Sstevel@tonic-gate 		uint64_t	sv_uint64;
1277c478bd9Sstevel@tonic-gate 		hrtime_t	sv_time;
1287c478bd9Sstevel@tonic-gate 		char		*sv_string;
1297c478bd9Sstevel@tonic-gate 		sysevent_bytes_t	sv_bytes;
1307c478bd9Sstevel@tonic-gate 	} value;
1317c478bd9Sstevel@tonic-gate } sysevent_value_t;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * The following flags determine the memory allocation semantics to use for
1357c478bd9Sstevel@tonic-gate  * kernel event buffer allocation by userland and kernel versions of
1367c478bd9Sstevel@tonic-gate  * sysevent_evc_publish().
1377c478bd9Sstevel@tonic-gate  *
1387c478bd9Sstevel@tonic-gate  * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP.
1397c478bd9Sstevel@tonic-gate  * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation
1407c478bd9Sstevel@tonic-gate  * routines to use use alternate kmem caches in situations where free memory
1417c478bd9Sstevel@tonic-gate  * may be low.  Kernel callers of sysevent_evc_publish() must set flags to
1427c478bd9Sstevel@tonic-gate  * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD.  Userland callers of
1437c478bd9Sstevel@tonic-gate  * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP.
1447c478bd9Sstevel@tonic-gate  *
1457c478bd9Sstevel@tonic-gate  * EVCH_QWAIT determines whether or not we should wait for slots in the event
1467c478bd9Sstevel@tonic-gate  * queue at publication time.  EVCH_QWAIT may be used by kernel and userland
1477c478bd9Sstevel@tonic-gate  * publishers and must be used in conjunction with any of one of EVCH_SLEEP,
1487c478bd9Sstevel@tonic-gate  * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only).
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #define	EVCH_NOSLEEP	0x0001	/* No sleep on kmem_alloc() */
1527c478bd9Sstevel@tonic-gate #define	EVCH_SLEEP	0x0002	/* Sleep on kmem_alloc() */
1537c478bd9Sstevel@tonic-gate #define	EVCH_TRYHARD	0x0004	/* May use alternate kmem cache for alloc */
1547c478bd9Sstevel@tonic-gate #define	EVCH_QWAIT	0x0008	/* Wait for slot in event queue */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
15749b225e1SGavin Maltby  * Meaning of flags for subscribe. Bits 8 to 15 are dedicated to
15849b225e1SGavin Maltby  * the consolidation private interface, so flags defined here are restricted
15949b225e1SGavin Maltby  * to the LSB.
16049b225e1SGavin Maltby  *
16149b225e1SGavin Maltby  * EVCH_SUB_KEEP indicates that this subscription should persist even if
16249b225e1SGavin Maltby  * this subscriber id should die unexpectedly; matching events will be
16349b225e1SGavin Maltby  * queued (up to a limit) and will be delivered if/when we restart again
16449b225e1SGavin Maltby  * with the same subscriber id.
1657c478bd9Sstevel@tonic-gate  */
16649b225e1SGavin Maltby #define	EVCH_SUB_KEEP		0x01
16749b225e1SGavin Maltby 
16849b225e1SGavin Maltby /*
16949b225e1SGavin Maltby  * Subscriptions may be wildcarded, but we limit the number of
17049b225e1SGavin Maltby  * wildcards permitted.
17149b225e1SGavin Maltby  */
17249b225e1SGavin Maltby #define	EVCH_WILDCARD_MAX	10
17349b225e1SGavin Maltby 
17449b225e1SGavin Maltby /*
17549b225e1SGavin Maltby  * Used in unsubscribe to indicate all subscriber ids for a channel.
17649b225e1SGavin Maltby  */
1777c478bd9Sstevel@tonic-gate #define	EVCH_ALLSUB		"all_subs"
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Meaning of flags parameter of channel bind function
18149b225e1SGavin Maltby  *
18249b225e1SGavin Maltby  * EVCH_CREAT indicates to create a channel if not already present.
18349b225e1SGavin Maltby  *
18449b225e1SGavin Maltby  * EVCH_HOLD_PEND indicates that events should be published to this
18549b225e1SGavin Maltby  * channel even if there are no matching subscribers present; when
18649b225e1SGavin Maltby  * a subscriber belatedly binds to the channel and registers their
18749b225e1SGavin Maltby  * subscriptions they will receive events that predate their bind.
18849b225e1SGavin Maltby  * If the channel is closed, however, with no remaining bindings then
18949b225e1SGavin Maltby  * the channel is destroyed.
19049b225e1SGavin Maltby  *
19149b225e1SGavin Maltby  * EVCH_HOLD_PEND_INDEF is a stronger version of EVCH_HOLD_PEND -
19249b225e1SGavin Maltby  * even if the channel has no remaining bindings it will not be
19349b225e1SGavin Maltby  * destroyed so long as events remain unconsumed.  This is suitable for
19449b225e1SGavin Maltby  * use with short-lived event producers that may bind to (create) the
19549b225e1SGavin Maltby  * channel and exit before the intended consumer has started.
1967c478bd9Sstevel@tonic-gate  */
19749b225e1SGavin Maltby #define	EVCH_CREAT		0x0001
1987c478bd9Sstevel@tonic-gate #define	EVCH_HOLD_PEND		0x0002
19949b225e1SGavin Maltby #define	EVCH_HOLD_PEND_INDEF	0x0004
20049b225e1SGavin Maltby #define	EVCH_B_FLAGS		0x0007	/* All valid bits */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * Meaning of commands of evc_control function
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN_MAX	 1	/* Get event queue length limit */
2067c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN	 2	/* Get event queue length */
2077c478bd9Sstevel@tonic-gate #define	EVCH_SET_CHAN_LEN	 3	/* Set event queue length */
2087c478bd9Sstevel@tonic-gate #define	EVCH_CMD_LAST		 EVCH_SET_CHAN_LEN	/* Last command */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
21149b225e1SGavin Maltby  * Shared user/kernel event channel interface definitions
2127c478bd9Sstevel@tonic-gate  */
21349b225e1SGavin Maltby extern int sysevent_evc_bind(const char *, evchan_t **, uint32_t);
21449b225e1SGavin Maltby extern int sysevent_evc_unbind(evchan_t *);
21549b225e1SGavin Maltby extern int sysevent_evc_subscribe(evchan_t *, const char *, const char *,
2167c478bd9Sstevel@tonic-gate     int (*)(sysevent_t *, void *), void *, uint32_t);
21749b225e1SGavin Maltby extern int sysevent_evc_unsubscribe(evchan_t *, const char *);
21849b225e1SGavin Maltby extern int sysevent_evc_publish(evchan_t *, const char *, const char *,
2197c478bd9Sstevel@tonic-gate     const char *, const char *, nvlist_t *, uint32_t);
22049b225e1SGavin Maltby extern int sysevent_evc_control(evchan_t *, int, ...);
221f6e214c7SGavin Maltby extern int sysevent_evc_setpropnvl(evchan_t *, nvlist_t *);
222f6e214c7SGavin Maltby extern int sysevent_evc_getpropnvl(evchan_t *, nvlist_t **);
2237c478bd9Sstevel@tonic-gate 
22449b225e1SGavin Maltby #ifndef	_KERNEL
22549b225e1SGavin Maltby 
22649b225e1SGavin Maltby /*
22749b225e1SGavin Maltby  * Userland-only event channel interfaces
22849b225e1SGavin Maltby  */
22949b225e1SGavin Maltby 
23049b225e1SGavin Maltby #include <door.h>
23149b225e1SGavin Maltby 
23249b225e1SGavin Maltby typedef struct sysevent_subattr sysevent_subattr_t;
23349b225e1SGavin Maltby 
23449b225e1SGavin Maltby extern sysevent_subattr_t *sysevent_subattr_alloc(void);
23549b225e1SGavin Maltby extern void sysevent_subattr_free(sysevent_subattr_t *);
23649b225e1SGavin Maltby 
23749b225e1SGavin Maltby extern void sysevent_subattr_thrattr(sysevent_subattr_t *, pthread_attr_t *);
23849b225e1SGavin Maltby extern void sysevent_subattr_sigmask(sysevent_subattr_t *, sigset_t *);
23949b225e1SGavin Maltby 
24049b225e1SGavin Maltby extern void sysevent_subattr_thrcreate(sysevent_subattr_t *,
24149b225e1SGavin Maltby     door_xcreate_server_func_t *, void *);
24249b225e1SGavin Maltby extern void sysevent_subattr_thrsetup(sysevent_subattr_t *,
24349b225e1SGavin Maltby     door_xcreate_thrsetup_func_t *, void *);
24449b225e1SGavin Maltby 
24549b225e1SGavin Maltby extern int sysevent_evc_xsubscribe(evchan_t *, const char *, const char *,
24649b225e1SGavin Maltby     int (*)(sysevent_t *, void *), void *, uint32_t, sysevent_subattr_t *);
24749b225e1SGavin Maltby 
24849b225e1SGavin Maltby #else
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate  * Kernel log_event interfaces.
2527c478bd9Sstevel@tonic-gate  */
25349b225e1SGavin Maltby extern int log_sysevent(sysevent_t *, int, sysevent_id_t *);
2547c478bd9Sstevel@tonic-gate 
25549b225e1SGavin Maltby extern sysevent_t *sysevent_alloc(char *, char *, char *, int);
25649b225e1SGavin Maltby extern void sysevent_free(sysevent_t *);
25749b225e1SGavin Maltby extern int sysevent_add_attr(sysevent_attr_list_t **, char *,
25849b225e1SGavin Maltby     sysevent_value_t *, int);
25949b225e1SGavin Maltby extern void sysevent_free_attr(sysevent_attr_list_t *);
26049b225e1SGavin Maltby extern int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *);
26149b225e1SGavin Maltby extern void sysevent_detach_attributes(sysevent_t *);
26249b225e1SGavin Maltby extern char *sysevent_get_class_name(sysevent_t *);
26349b225e1SGavin Maltby extern char *sysevent_get_subclass_name(sysevent_t *);
26449b225e1SGavin Maltby extern uint64_t sysevent_get_seq(sysevent_t *);
26549b225e1SGavin Maltby extern void sysevent_get_time(sysevent_t *, hrtime_t *);
26649b225e1SGavin Maltby extern size_t sysevent_get_size(sysevent_t *);
26749b225e1SGavin Maltby extern char *sysevent_get_pub(sysevent_t *);
26849b225e1SGavin Maltby extern int sysevent_get_attr_list(sysevent_t *, nvlist_t **);
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate #endif
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSEVENT_H */
277