xref: /illumos-gate/usr/src/uts/common/sys/sysevent.h (revision fdf1a871)
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.
24a25df667SRobert Mustacchi  * Copyright 2015 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_SYSEVENT_H
287c478bd9Sstevel@tonic-gate #define	_SYS_SYSEVENT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/nvpair.h>
314870e0a7SRichard PALO #include <sys/null.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /* Internal registration class and subclass */
387c478bd9Sstevel@tonic-gate #define	EC_ALL		"register_all_classes"
397c478bd9Sstevel@tonic-gate #define	EC_SUB_ALL	"register_all_subclasses"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Event allocation/enqueuing sleep/nosleep flags
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate #define	SE_SLEEP		0
457c478bd9Sstevel@tonic-gate #define	SE_NOSLEEP		1
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* Framework error codes */
487c478bd9Sstevel@tonic-gate #define	SE_EINVAL		1	/* Invalid argument */
497c478bd9Sstevel@tonic-gate #define	SE_ENOMEM		2	/* Unable to allocate memory */
507c478bd9Sstevel@tonic-gate #define	SE_EQSIZE		3	/* Maximum event q size exceeded */
517c478bd9Sstevel@tonic-gate #define	SE_EFAULT		4	/* Copy fault */
527c478bd9Sstevel@tonic-gate #define	SE_NOTFOUND		5	/* Attribute not found */
537c478bd9Sstevel@tonic-gate #define	SE_NO_TRANSPORT		6	/* sysevent transport down */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /* Internal data types */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTE	DATA_TYPE_BYTE
587c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT16	DATA_TYPE_INT16
597c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT16	DATA_TYPE_UINT16
607c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT32	DATA_TYPE_INT32
617c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT32	DATA_TYPE_UINT32
627c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_INT64	DATA_TYPE_INT64
637c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_UINT64	DATA_TYPE_UINT64
647c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_STRING	DATA_TYPE_STRING
657c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_BYTES	DATA_TYPE_BYTE_ARRAY
667c478bd9Sstevel@tonic-gate #define	SE_DATA_TYPE_TIME	DATA_TYPE_HRTIME
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	SE_KERN_PID	0
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	SUNW_VENDOR	"SUNW"
71a25df667SRobert Mustacchi #define	ILLUMOS_VENDOR	"ILLUMOS"
727c478bd9Sstevel@tonic-gate #define	SE_USR_PUB	"usr:"
737c478bd9Sstevel@tonic-gate #define	SE_KERN_PUB	"kern:"
7499d29265SToomas Soome #define	SUNW_KERN_PUB	SUNW_VENDOR ":" SE_KERN_PUB
7599d29265SToomas Soome #define	SUNW_USR_PUB	SUNW_VENDOR ":" SE_USR_PUB
76*fdf1a871SToomas Soome #define	ILLUMOS_KERN_PUB	ILLUMOS_VENDOR ":" SE_KERN_PUB
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * Event header and attribute value limits
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate #define	MAX_ATTR_NAME	1024
827c478bd9Sstevel@tonic-gate #define	MAX_STRING_SZ	1024
837c478bd9Sstevel@tonic-gate #define	MAX_BYTE_ARRAY	1024
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	MAX_CLASS_LEN		64
867c478bd9Sstevel@tonic-gate #define	MAX_SUBCLASS_LEN	64
877c478bd9Sstevel@tonic-gate #define	MAX_PUB_LEN		128
887c478bd9Sstevel@tonic-gate #define	MAX_CHNAME_LEN		128
897c478bd9Sstevel@tonic-gate #define	MAX_SUBID_LEN		16
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Limit for the event payload size
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	MAX_EV_SIZE_LEN		(SHRT_MAX/4)
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* Opaque sysevent_t data type */
977c478bd9Sstevel@tonic-gate typedef void *sysevent_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* Opaque channel bind data type */
1007c478bd9Sstevel@tonic-gate typedef void evchan_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* sysevent attribute list */
1037c478bd9Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* sysevent attribute name-value pair */
1067c478bd9Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /* Unique event identifier */
1097c478bd9Sstevel@tonic-gate typedef struct sysevent_id {
1107c478bd9Sstevel@tonic-gate 	uint64_t eid_seq;
1117c478bd9Sstevel@tonic-gate 	hrtime_t eid_ts;
1127c478bd9Sstevel@tonic-gate } sysevent_id_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /* Event attribute value structures */
1157c478bd9Sstevel@tonic-gate typedef struct sysevent_bytes {
1167c478bd9Sstevel@tonic-gate 	int32_t	size;
1177c478bd9Sstevel@tonic-gate 	uchar_t	*data;
1187c478bd9Sstevel@tonic-gate } sysevent_bytes_t;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate typedef struct sysevent_value {
1217c478bd9Sstevel@tonic-gate 	int32_t		value_type;		/* data type */
1227c478bd9Sstevel@tonic-gate 	union {
1237c478bd9Sstevel@tonic-gate 		uchar_t		sv_byte;
1247c478bd9Sstevel@tonic-gate 		int16_t		sv_int16;
1257c478bd9Sstevel@tonic-gate 		uint16_t	sv_uint16;
1267c478bd9Sstevel@tonic-gate 		int32_t		sv_int32;
1277c478bd9Sstevel@tonic-gate 		uint32_t	sv_uint32;
1287c478bd9Sstevel@tonic-gate 		int64_t		sv_int64;
1297c478bd9Sstevel@tonic-gate 		uint64_t	sv_uint64;
1307c478bd9Sstevel@tonic-gate 		hrtime_t	sv_time;
1317c478bd9Sstevel@tonic-gate 		char		*sv_string;
1327c478bd9Sstevel@tonic-gate 		sysevent_bytes_t	sv_bytes;
1337c478bd9Sstevel@tonic-gate 	} value;
1347c478bd9Sstevel@tonic-gate } sysevent_value_t;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * The following flags determine the memory allocation semantics to use for
1387c478bd9Sstevel@tonic-gate  * kernel event buffer allocation by userland and kernel versions of
1397c478bd9Sstevel@tonic-gate  * sysevent_evc_publish().
1407c478bd9Sstevel@tonic-gate  *
1417c478bd9Sstevel@tonic-gate  * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP.
1427c478bd9Sstevel@tonic-gate  * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation
1437c478bd9Sstevel@tonic-gate  * routines to use use alternate kmem caches in situations where free memory
1447c478bd9Sstevel@tonic-gate  * may be low.  Kernel callers of sysevent_evc_publish() must set flags to
1457c478bd9Sstevel@tonic-gate  * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD.  Userland callers of
1467c478bd9Sstevel@tonic-gate  * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP.
1477c478bd9Sstevel@tonic-gate  *
1487c478bd9Sstevel@tonic-gate  * EVCH_QWAIT determines whether or not we should wait for slots in the event
1497c478bd9Sstevel@tonic-gate  * queue at publication time.  EVCH_QWAIT may be used by kernel and userland
1507c478bd9Sstevel@tonic-gate  * publishers and must be used in conjunction with any of one of EVCH_SLEEP,
1517c478bd9Sstevel@tonic-gate  * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only).
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	EVCH_NOSLEEP	0x0001	/* No sleep on kmem_alloc() */
1557c478bd9Sstevel@tonic-gate #define	EVCH_SLEEP	0x0002	/* Sleep on kmem_alloc() */
1567c478bd9Sstevel@tonic-gate #define	EVCH_TRYHARD	0x0004	/* May use alternate kmem cache for alloc */
1577c478bd9Sstevel@tonic-gate #define	EVCH_QWAIT	0x0008	/* Wait for slot in event queue */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
16049b225e1SGavin Maltby  * Meaning of flags for subscribe. Bits 8 to 15 are dedicated to
16149b225e1SGavin Maltby  * the consolidation private interface, so flags defined here are restricted
16249b225e1SGavin Maltby  * to the LSB.
16349b225e1SGavin Maltby  *
16449b225e1SGavin Maltby  * EVCH_SUB_KEEP indicates that this subscription should persist even if
16549b225e1SGavin Maltby  * this subscriber id should die unexpectedly; matching events will be
16649b225e1SGavin Maltby  * queued (up to a limit) and will be delivered if/when we restart again
16749b225e1SGavin Maltby  * with the same subscriber id.
16849b225e1SGavin Maltby  */
16949b225e1SGavin Maltby #define	EVCH_SUB_KEEP		0x01
17049b225e1SGavin Maltby 
17149b225e1SGavin Maltby /*
17249b225e1SGavin Maltby  * Subscriptions may be wildcarded, but we limit the number of
17349b225e1SGavin Maltby  * wildcards permitted.
17449b225e1SGavin Maltby  */
17549b225e1SGavin Maltby #define	EVCH_WILDCARD_MAX	10
17649b225e1SGavin Maltby 
17749b225e1SGavin Maltby /*
17849b225e1SGavin Maltby  * Used in unsubscribe to indicate all subscriber ids for a channel.
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate #define	EVCH_ALLSUB		"all_subs"
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate  * Meaning of flags parameter of channel bind function
18449b225e1SGavin Maltby  *
18549b225e1SGavin Maltby  * EVCH_CREAT indicates to create a channel if not already present.
18649b225e1SGavin Maltby  *
18749b225e1SGavin Maltby  * EVCH_HOLD_PEND indicates that events should be published to this
18849b225e1SGavin Maltby  * channel even if there are no matching subscribers present; when
18949b225e1SGavin Maltby  * a subscriber belatedly binds to the channel and registers their
19049b225e1SGavin Maltby  * subscriptions they will receive events that predate their bind.
19149b225e1SGavin Maltby  * If the channel is closed, however, with no remaining bindings then
19249b225e1SGavin Maltby  * the channel is destroyed.
19349b225e1SGavin Maltby  *
19449b225e1SGavin Maltby  * EVCH_HOLD_PEND_INDEF is a stronger version of EVCH_HOLD_PEND -
19549b225e1SGavin Maltby  * even if the channel has no remaining bindings it will not be
19649b225e1SGavin Maltby  * destroyed so long as events remain unconsumed.  This is suitable for
19749b225e1SGavin Maltby  * use with short-lived event producers that may bind to (create) the
19849b225e1SGavin Maltby  * channel and exit before the intended consumer has started.
1997c478bd9Sstevel@tonic-gate  */
20049b225e1SGavin Maltby #define	EVCH_CREAT		0x0001
2017c478bd9Sstevel@tonic-gate #define	EVCH_HOLD_PEND		0x0002
20249b225e1SGavin Maltby #define	EVCH_HOLD_PEND_INDEF	0x0004
20349b225e1SGavin Maltby #define	EVCH_B_FLAGS		0x0007	/* All valid bits */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate  * Meaning of commands of evc_control function
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN_MAX	 1	/* Get event queue length limit */
2097c478bd9Sstevel@tonic-gate #define	EVCH_GET_CHAN_LEN	 2	/* Get event queue length */
2107c478bd9Sstevel@tonic-gate #define	EVCH_SET_CHAN_LEN	 3	/* Set event queue length */
2117c478bd9Sstevel@tonic-gate #define	EVCH_CMD_LAST		 EVCH_SET_CHAN_LEN	/* Last command */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
21449b225e1SGavin Maltby  * Shared user/kernel event channel interface definitions
2157c478bd9Sstevel@tonic-gate  */
21649b225e1SGavin Maltby extern int sysevent_evc_bind(const char *, evchan_t **, uint32_t);
21749b225e1SGavin Maltby extern int sysevent_evc_unbind(evchan_t *);
21849b225e1SGavin Maltby extern int sysevent_evc_subscribe(evchan_t *, const char *, const char *,
2197c478bd9Sstevel@tonic-gate     int (*)(sysevent_t *, void *), void *, uint32_t);
22049b225e1SGavin Maltby extern int sysevent_evc_unsubscribe(evchan_t *, const char *);
22149b225e1SGavin Maltby extern int sysevent_evc_publish(evchan_t *, const char *, const char *,
2227c478bd9Sstevel@tonic-gate     const char *, const char *, nvlist_t *, uint32_t);
22349b225e1SGavin Maltby extern int sysevent_evc_control(evchan_t *, int, ...);
224f6e214c7SGavin Maltby extern int sysevent_evc_setpropnvl(evchan_t *, nvlist_t *);
225f6e214c7SGavin Maltby extern int sysevent_evc_getpropnvl(evchan_t *, nvlist_t **);
2267c478bd9Sstevel@tonic-gate 
22749b225e1SGavin Maltby #ifndef	_KERNEL
22849b225e1SGavin Maltby 
22949b225e1SGavin Maltby /*
23049b225e1SGavin Maltby  * Userland-only event channel interfaces
23149b225e1SGavin Maltby  */
23249b225e1SGavin Maltby 
23349b225e1SGavin Maltby #include <door.h>
23449b225e1SGavin Maltby 
23549b225e1SGavin Maltby typedef struct sysevent_subattr sysevent_subattr_t;
23649b225e1SGavin Maltby 
23749b225e1SGavin Maltby extern sysevent_subattr_t *sysevent_subattr_alloc(void);
23849b225e1SGavin Maltby extern void sysevent_subattr_free(sysevent_subattr_t *);
23949b225e1SGavin Maltby 
24049b225e1SGavin Maltby extern void sysevent_subattr_thrattr(sysevent_subattr_t *, pthread_attr_t *);
24149b225e1SGavin Maltby extern void sysevent_subattr_sigmask(sysevent_subattr_t *, sigset_t *);
24249b225e1SGavin Maltby 
24349b225e1SGavin Maltby extern void sysevent_subattr_thrcreate(sysevent_subattr_t *,
24449b225e1SGavin Maltby     door_xcreate_server_func_t *, void *);
24549b225e1SGavin Maltby extern void sysevent_subattr_thrsetup(sysevent_subattr_t *,
24649b225e1SGavin Maltby     door_xcreate_thrsetup_func_t *, void *);
24749b225e1SGavin Maltby 
24849b225e1SGavin Maltby extern int sysevent_evc_xsubscribe(evchan_t *, const char *, const char *,
24949b225e1SGavin Maltby     int (*)(sysevent_t *, void *), void *, uint32_t, sysevent_subattr_t *);
25049b225e1SGavin Maltby 
25149b225e1SGavin Maltby #else
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate  * Kernel log_event interfaces.
2557c478bd9Sstevel@tonic-gate  */
25649b225e1SGavin Maltby extern int log_sysevent(sysevent_t *, int, sysevent_id_t *);
25749b225e1SGavin Maltby 
25849b225e1SGavin Maltby extern sysevent_t *sysevent_alloc(char *, char *, char *, int);
25949b225e1SGavin Maltby extern void sysevent_free(sysevent_t *);
26049b225e1SGavin Maltby extern int sysevent_add_attr(sysevent_attr_list_t **, char *,
26149b225e1SGavin Maltby     sysevent_value_t *, int);
26249b225e1SGavin Maltby extern void sysevent_free_attr(sysevent_attr_list_t *);
26349b225e1SGavin Maltby extern int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *);
26449b225e1SGavin Maltby extern void sysevent_detach_attributes(sysevent_t *);
26549b225e1SGavin Maltby extern char *sysevent_get_class_name(sysevent_t *);
26649b225e1SGavin Maltby extern char *sysevent_get_subclass_name(sysevent_t *);
26749b225e1SGavin Maltby extern uint64_t sysevent_get_seq(sysevent_t *);
26849b225e1SGavin Maltby extern void sysevent_get_time(sysevent_t *, hrtime_t *);
26949b225e1SGavin Maltby extern size_t sysevent_get_size(sysevent_t *);
27049b225e1SGavin Maltby extern char *sysevent_get_pub(sysevent_t *);
27149b225e1SGavin Maltby extern int sysevent_get_attr_list(sysevent_t *, nvlist_t **);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate #endif
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSEVENT_H */
280