10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 511102SGavin.Maltby@Sun.COM * Common Development and Distribution License (the "License"). 611102SGavin.Maltby@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 2111102SGavin.Maltby@Sun.COM 220Sstevel@tonic-gate /* 23*12967Sgavin.maltby@oracle.com * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_SYSEVENT_H 270Sstevel@tonic-gate #define _SYS_SYSEVENT_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/nvpair.h> 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifndef NULL 360Sstevel@tonic-gate #if defined(_LP64) && !defined(__cplusplus) 370Sstevel@tonic-gate #define NULL 0L 380Sstevel@tonic-gate #else 390Sstevel@tonic-gate #define NULL 0 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate #endif 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* Internal registration class and subclass */ 440Sstevel@tonic-gate #define EC_ALL "register_all_classes" 450Sstevel@tonic-gate #define EC_SUB_ALL "register_all_subclasses" 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * Event allocation/enqueuing sleep/nosleep flags 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate #define SE_SLEEP 0 510Sstevel@tonic-gate #define SE_NOSLEEP 1 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* Framework error codes */ 540Sstevel@tonic-gate #define SE_EINVAL 1 /* Invalid argument */ 550Sstevel@tonic-gate #define SE_ENOMEM 2 /* Unable to allocate memory */ 560Sstevel@tonic-gate #define SE_EQSIZE 3 /* Maximum event q size exceeded */ 570Sstevel@tonic-gate #define SE_EFAULT 4 /* Copy fault */ 580Sstevel@tonic-gate #define SE_NOTFOUND 5 /* Attribute not found */ 590Sstevel@tonic-gate #define SE_NO_TRANSPORT 6 /* sysevent transport down */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* Internal data types */ 620Sstevel@tonic-gate 630Sstevel@tonic-gate #define SE_DATA_TYPE_BYTE DATA_TYPE_BYTE 640Sstevel@tonic-gate #define SE_DATA_TYPE_INT16 DATA_TYPE_INT16 650Sstevel@tonic-gate #define SE_DATA_TYPE_UINT16 DATA_TYPE_UINT16 660Sstevel@tonic-gate #define SE_DATA_TYPE_INT32 DATA_TYPE_INT32 670Sstevel@tonic-gate #define SE_DATA_TYPE_UINT32 DATA_TYPE_UINT32 680Sstevel@tonic-gate #define SE_DATA_TYPE_INT64 DATA_TYPE_INT64 690Sstevel@tonic-gate #define SE_DATA_TYPE_UINT64 DATA_TYPE_UINT64 700Sstevel@tonic-gate #define SE_DATA_TYPE_STRING DATA_TYPE_STRING 710Sstevel@tonic-gate #define SE_DATA_TYPE_BYTES DATA_TYPE_BYTE_ARRAY 720Sstevel@tonic-gate #define SE_DATA_TYPE_TIME DATA_TYPE_HRTIME 730Sstevel@tonic-gate 740Sstevel@tonic-gate #define SE_KERN_PID 0 750Sstevel@tonic-gate 760Sstevel@tonic-gate #define SUNW_VENDOR "SUNW" 770Sstevel@tonic-gate #define SE_USR_PUB "usr:" 780Sstevel@tonic-gate #define SE_KERN_PUB "kern:" 790Sstevel@tonic-gate #define SUNW_KERN_PUB SUNW_VENDOR":"SE_KERN_PUB 800Sstevel@tonic-gate #define SUNW_USR_PUB SUNW_VENDOR":"SE_USR_PUB 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Event header and attribute value limits 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate #define MAX_ATTR_NAME 1024 860Sstevel@tonic-gate #define MAX_STRING_SZ 1024 870Sstevel@tonic-gate #define MAX_BYTE_ARRAY 1024 880Sstevel@tonic-gate 890Sstevel@tonic-gate #define MAX_CLASS_LEN 64 900Sstevel@tonic-gate #define MAX_SUBCLASS_LEN 64 910Sstevel@tonic-gate #define MAX_PUB_LEN 128 920Sstevel@tonic-gate #define MAX_CHNAME_LEN 128 930Sstevel@tonic-gate #define MAX_SUBID_LEN 16 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Limit for the event payload size 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate #define MAX_EV_SIZE_LEN (SHRT_MAX/4) 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* Opaque sysevent_t data type */ 1010Sstevel@tonic-gate typedef void *sysevent_t; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* Opaque channel bind data type */ 1040Sstevel@tonic-gate typedef void evchan_t; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* sysevent attribute list */ 1070Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* sysevent attribute name-value pair */ 1100Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* Unique event identifier */ 1130Sstevel@tonic-gate typedef struct sysevent_id { 1140Sstevel@tonic-gate uint64_t eid_seq; 1150Sstevel@tonic-gate hrtime_t eid_ts; 1160Sstevel@tonic-gate } sysevent_id_t; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* Event attribute value structures */ 1190Sstevel@tonic-gate typedef struct sysevent_bytes { 1200Sstevel@tonic-gate int32_t size; 1210Sstevel@tonic-gate uchar_t *data; 1220Sstevel@tonic-gate } sysevent_bytes_t; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate typedef struct sysevent_value { 1250Sstevel@tonic-gate int32_t value_type; /* data type */ 1260Sstevel@tonic-gate union { 1270Sstevel@tonic-gate uchar_t sv_byte; 1280Sstevel@tonic-gate int16_t sv_int16; 1290Sstevel@tonic-gate uint16_t sv_uint16; 1300Sstevel@tonic-gate int32_t sv_int32; 1310Sstevel@tonic-gate uint32_t sv_uint32; 1320Sstevel@tonic-gate int64_t sv_int64; 1330Sstevel@tonic-gate uint64_t sv_uint64; 1340Sstevel@tonic-gate hrtime_t sv_time; 1350Sstevel@tonic-gate char *sv_string; 1360Sstevel@tonic-gate sysevent_bytes_t sv_bytes; 1370Sstevel@tonic-gate } value; 1380Sstevel@tonic-gate } sysevent_value_t; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * The following flags determine the memory allocation semantics to use for 1420Sstevel@tonic-gate * kernel event buffer allocation by userland and kernel versions of 1430Sstevel@tonic-gate * sysevent_evc_publish(). 1440Sstevel@tonic-gate * 1450Sstevel@tonic-gate * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP. 1460Sstevel@tonic-gate * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation 1470Sstevel@tonic-gate * routines to use use alternate kmem caches in situations where free memory 1480Sstevel@tonic-gate * may be low. Kernel callers of sysevent_evc_publish() must set flags to 1490Sstevel@tonic-gate * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD. Userland callers of 1500Sstevel@tonic-gate * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP. 1510Sstevel@tonic-gate * 1520Sstevel@tonic-gate * EVCH_QWAIT determines whether or not we should wait for slots in the event 1530Sstevel@tonic-gate * queue at publication time. EVCH_QWAIT may be used by kernel and userland 1540Sstevel@tonic-gate * publishers and must be used in conjunction with any of one of EVCH_SLEEP, 1550Sstevel@tonic-gate * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only). 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #define EVCH_NOSLEEP 0x0001 /* No sleep on kmem_alloc() */ 1590Sstevel@tonic-gate #define EVCH_SLEEP 0x0002 /* Sleep on kmem_alloc() */ 1600Sstevel@tonic-gate #define EVCH_TRYHARD 0x0004 /* May use alternate kmem cache for alloc */ 1610Sstevel@tonic-gate #define EVCH_QWAIT 0x0008 /* Wait for slot in event queue */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 16411102SGavin.Maltby@Sun.COM * Meaning of flags for subscribe. Bits 8 to 15 are dedicated to 16511102SGavin.Maltby@Sun.COM * the consolidation private interface, so flags defined here are restricted 16611102SGavin.Maltby@Sun.COM * to the LSB. 16711102SGavin.Maltby@Sun.COM * 16811102SGavin.Maltby@Sun.COM * EVCH_SUB_KEEP indicates that this subscription should persist even if 16911102SGavin.Maltby@Sun.COM * this subscriber id should die unexpectedly; matching events will be 17011102SGavin.Maltby@Sun.COM * queued (up to a limit) and will be delivered if/when we restart again 17111102SGavin.Maltby@Sun.COM * with the same subscriber id. 1720Sstevel@tonic-gate */ 17311102SGavin.Maltby@Sun.COM #define EVCH_SUB_KEEP 0x01 17411102SGavin.Maltby@Sun.COM 17511102SGavin.Maltby@Sun.COM /* 17611102SGavin.Maltby@Sun.COM * Subscriptions may be wildcarded, but we limit the number of 17711102SGavin.Maltby@Sun.COM * wildcards permitted. 17811102SGavin.Maltby@Sun.COM */ 17911102SGavin.Maltby@Sun.COM #define EVCH_WILDCARD_MAX 10 18011102SGavin.Maltby@Sun.COM 18111102SGavin.Maltby@Sun.COM /* 18211102SGavin.Maltby@Sun.COM * Used in unsubscribe to indicate all subscriber ids for a channel. 18311102SGavin.Maltby@Sun.COM */ 1840Sstevel@tonic-gate #define EVCH_ALLSUB "all_subs" 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * Meaning of flags parameter of channel bind function 18811102SGavin.Maltby@Sun.COM * 18911102SGavin.Maltby@Sun.COM * EVCH_CREAT indicates to create a channel if not already present. 19011102SGavin.Maltby@Sun.COM * 19111102SGavin.Maltby@Sun.COM * EVCH_HOLD_PEND indicates that events should be published to this 19211102SGavin.Maltby@Sun.COM * channel even if there are no matching subscribers present; when 19311102SGavin.Maltby@Sun.COM * a subscriber belatedly binds to the channel and registers their 19411102SGavin.Maltby@Sun.COM * subscriptions they will receive events that predate their bind. 19511102SGavin.Maltby@Sun.COM * If the channel is closed, however, with no remaining bindings then 19611102SGavin.Maltby@Sun.COM * the channel is destroyed. 19711102SGavin.Maltby@Sun.COM * 19811102SGavin.Maltby@Sun.COM * EVCH_HOLD_PEND_INDEF is a stronger version of EVCH_HOLD_PEND - 19911102SGavin.Maltby@Sun.COM * even if the channel has no remaining bindings it will not be 20011102SGavin.Maltby@Sun.COM * destroyed so long as events remain unconsumed. This is suitable for 20111102SGavin.Maltby@Sun.COM * use with short-lived event producers that may bind to (create) the 20211102SGavin.Maltby@Sun.COM * channel and exit before the intended consumer has started. 2030Sstevel@tonic-gate */ 20411102SGavin.Maltby@Sun.COM #define EVCH_CREAT 0x0001 2050Sstevel@tonic-gate #define EVCH_HOLD_PEND 0x0002 20611102SGavin.Maltby@Sun.COM #define EVCH_HOLD_PEND_INDEF 0x0004 20711102SGavin.Maltby@Sun.COM #define EVCH_B_FLAGS 0x0007 /* All valid bits */ 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * Meaning of commands of evc_control function 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN_MAX 1 /* Get event queue length limit */ 2130Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN 2 /* Get event queue length */ 2140Sstevel@tonic-gate #define EVCH_SET_CHAN_LEN 3 /* Set event queue length */ 2150Sstevel@tonic-gate #define EVCH_CMD_LAST EVCH_SET_CHAN_LEN /* Last command */ 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate /* 21811102SGavin.Maltby@Sun.COM * Shared user/kernel event channel interface definitions 2190Sstevel@tonic-gate */ 22011102SGavin.Maltby@Sun.COM extern int sysevent_evc_bind(const char *, evchan_t **, uint32_t); 22111102SGavin.Maltby@Sun.COM extern int sysevent_evc_unbind(evchan_t *); 22211102SGavin.Maltby@Sun.COM extern int sysevent_evc_subscribe(evchan_t *, const char *, const char *, 2230Sstevel@tonic-gate int (*)(sysevent_t *, void *), void *, uint32_t); 22411102SGavin.Maltby@Sun.COM extern int sysevent_evc_unsubscribe(evchan_t *, const char *); 22511102SGavin.Maltby@Sun.COM extern int sysevent_evc_publish(evchan_t *, const char *, const char *, 2260Sstevel@tonic-gate const char *, const char *, nvlist_t *, uint32_t); 22711102SGavin.Maltby@Sun.COM extern int sysevent_evc_control(evchan_t *, int, ...); 228*12967Sgavin.maltby@oracle.com extern int sysevent_evc_setpropnvl(evchan_t *, nvlist_t *); 229*12967Sgavin.maltby@oracle.com extern int sysevent_evc_getpropnvl(evchan_t *, nvlist_t **); 23011102SGavin.Maltby@Sun.COM 23111102SGavin.Maltby@Sun.COM #ifndef _KERNEL 23211102SGavin.Maltby@Sun.COM 23311102SGavin.Maltby@Sun.COM /* 23411102SGavin.Maltby@Sun.COM * Userland-only event channel interfaces 23511102SGavin.Maltby@Sun.COM */ 23611102SGavin.Maltby@Sun.COM 23711102SGavin.Maltby@Sun.COM #include <door.h> 23811102SGavin.Maltby@Sun.COM 23911102SGavin.Maltby@Sun.COM typedef struct sysevent_subattr sysevent_subattr_t; 2400Sstevel@tonic-gate 24111102SGavin.Maltby@Sun.COM extern sysevent_subattr_t *sysevent_subattr_alloc(void); 24211102SGavin.Maltby@Sun.COM extern void sysevent_subattr_free(sysevent_subattr_t *); 24311102SGavin.Maltby@Sun.COM 24411102SGavin.Maltby@Sun.COM extern void sysevent_subattr_thrattr(sysevent_subattr_t *, pthread_attr_t *); 24511102SGavin.Maltby@Sun.COM extern void sysevent_subattr_sigmask(sysevent_subattr_t *, sigset_t *); 24611102SGavin.Maltby@Sun.COM 24711102SGavin.Maltby@Sun.COM extern void sysevent_subattr_thrcreate(sysevent_subattr_t *, 24811102SGavin.Maltby@Sun.COM door_xcreate_server_func_t *, void *); 24911102SGavin.Maltby@Sun.COM extern void sysevent_subattr_thrsetup(sysevent_subattr_t *, 25011102SGavin.Maltby@Sun.COM door_xcreate_thrsetup_func_t *, void *); 25111102SGavin.Maltby@Sun.COM 25211102SGavin.Maltby@Sun.COM extern int sysevent_evc_xsubscribe(evchan_t *, const char *, const char *, 25311102SGavin.Maltby@Sun.COM int (*)(sysevent_t *, void *), void *, uint32_t, sysevent_subattr_t *); 25411102SGavin.Maltby@Sun.COM 25511102SGavin.Maltby@Sun.COM #else 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 2580Sstevel@tonic-gate * Kernel log_event interfaces. 2590Sstevel@tonic-gate */ 26011102SGavin.Maltby@Sun.COM extern int log_sysevent(sysevent_t *, int, sysevent_id_t *); 2610Sstevel@tonic-gate 26211102SGavin.Maltby@Sun.COM extern sysevent_t *sysevent_alloc(char *, char *, char *, int); 26311102SGavin.Maltby@Sun.COM extern void sysevent_free(sysevent_t *); 26411102SGavin.Maltby@Sun.COM extern int sysevent_add_attr(sysevent_attr_list_t **, char *, 26511102SGavin.Maltby@Sun.COM sysevent_value_t *, int); 26611102SGavin.Maltby@Sun.COM extern void sysevent_free_attr(sysevent_attr_list_t *); 26711102SGavin.Maltby@Sun.COM extern int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *); 26811102SGavin.Maltby@Sun.COM extern void sysevent_detach_attributes(sysevent_t *); 26911102SGavin.Maltby@Sun.COM extern char *sysevent_get_class_name(sysevent_t *); 27011102SGavin.Maltby@Sun.COM extern char *sysevent_get_subclass_name(sysevent_t *); 27111102SGavin.Maltby@Sun.COM extern uint64_t sysevent_get_seq(sysevent_t *); 27211102SGavin.Maltby@Sun.COM extern void sysevent_get_time(sysevent_t *, hrtime_t *); 27311102SGavin.Maltby@Sun.COM extern size_t sysevent_get_size(sysevent_t *); 27411102SGavin.Maltby@Sun.COM extern char *sysevent_get_pub(sysevent_t *); 27511102SGavin.Maltby@Sun.COM extern int sysevent_get_attr_list(sysevent_t *, nvlist_t **); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate #endif /* _KERNEL */ 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate #ifdef __cplusplus 2800Sstevel@tonic-gate } 2810Sstevel@tonic-gate #endif 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate #endif /* _SYS_SYSEVENT_H */ 284