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 5*49b225e1SGavin Maltby * Common Development and Distribution License (the "License"). 6*49b225e1SGavin 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 */ 21*49b225e1SGavin Maltby 227c478bd9Sstevel@tonic-gate /* 23*49b225e1SGavin Maltby * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 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> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifndef NULL 377c478bd9Sstevel@tonic-gate #if defined(_LP64) && !defined(__cplusplus) 387c478bd9Sstevel@tonic-gate #define NULL 0L 397c478bd9Sstevel@tonic-gate #else 407c478bd9Sstevel@tonic-gate #define NULL 0 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* Internal registration class and subclass */ 457c478bd9Sstevel@tonic-gate #define EC_ALL "register_all_classes" 467c478bd9Sstevel@tonic-gate #define EC_SUB_ALL "register_all_subclasses" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * Event allocation/enqueuing sleep/nosleep flags 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate #define SE_SLEEP 0 527c478bd9Sstevel@tonic-gate #define SE_NOSLEEP 1 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* Framework error codes */ 557c478bd9Sstevel@tonic-gate #define SE_EINVAL 1 /* Invalid argument */ 567c478bd9Sstevel@tonic-gate #define SE_ENOMEM 2 /* Unable to allocate memory */ 577c478bd9Sstevel@tonic-gate #define SE_EQSIZE 3 /* Maximum event q size exceeded */ 587c478bd9Sstevel@tonic-gate #define SE_EFAULT 4 /* Copy fault */ 597c478bd9Sstevel@tonic-gate #define SE_NOTFOUND 5 /* Attribute not found */ 607c478bd9Sstevel@tonic-gate #define SE_NO_TRANSPORT 6 /* sysevent transport down */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* Internal data types */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_BYTE DATA_TYPE_BYTE 657c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_INT16 DATA_TYPE_INT16 667c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_UINT16 DATA_TYPE_UINT16 677c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_INT32 DATA_TYPE_INT32 687c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_UINT32 DATA_TYPE_UINT32 697c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_INT64 DATA_TYPE_INT64 707c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_UINT64 DATA_TYPE_UINT64 717c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_STRING DATA_TYPE_STRING 727c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_BYTES DATA_TYPE_BYTE_ARRAY 737c478bd9Sstevel@tonic-gate #define SE_DATA_TYPE_TIME DATA_TYPE_HRTIME 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define SE_KERN_PID 0 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #define SUNW_VENDOR "SUNW" 787c478bd9Sstevel@tonic-gate #define SE_USR_PUB "usr:" 797c478bd9Sstevel@tonic-gate #define SE_KERN_PUB "kern:" 807c478bd9Sstevel@tonic-gate #define SUNW_KERN_PUB SUNW_VENDOR":"SE_KERN_PUB 817c478bd9Sstevel@tonic-gate #define SUNW_USR_PUB SUNW_VENDOR":"SE_USR_PUB 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * Event header and attribute value limits 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate #define MAX_ATTR_NAME 1024 877c478bd9Sstevel@tonic-gate #define MAX_STRING_SZ 1024 887c478bd9Sstevel@tonic-gate #define MAX_BYTE_ARRAY 1024 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #define MAX_CLASS_LEN 64 917c478bd9Sstevel@tonic-gate #define MAX_SUBCLASS_LEN 64 927c478bd9Sstevel@tonic-gate #define MAX_PUB_LEN 128 937c478bd9Sstevel@tonic-gate #define MAX_CHNAME_LEN 128 947c478bd9Sstevel@tonic-gate #define MAX_SUBID_LEN 16 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * Limit for the event payload size 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate #define MAX_EV_SIZE_LEN (SHRT_MAX/4) 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* Opaque sysevent_t data type */ 1027c478bd9Sstevel@tonic-gate typedef void *sysevent_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* Opaque channel bind data type */ 1057c478bd9Sstevel@tonic-gate typedef void evchan_t; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* sysevent attribute list */ 1087c478bd9Sstevel@tonic-gate typedef nvlist_t sysevent_attr_list_t; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* sysevent attribute name-value pair */ 1117c478bd9Sstevel@tonic-gate typedef nvpair_t sysevent_attr_t; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* Unique event identifier */ 1147c478bd9Sstevel@tonic-gate typedef struct sysevent_id { 1157c478bd9Sstevel@tonic-gate uint64_t eid_seq; 1167c478bd9Sstevel@tonic-gate hrtime_t eid_ts; 1177c478bd9Sstevel@tonic-gate } sysevent_id_t; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* Event attribute value structures */ 1207c478bd9Sstevel@tonic-gate typedef struct sysevent_bytes { 1217c478bd9Sstevel@tonic-gate int32_t size; 1227c478bd9Sstevel@tonic-gate uchar_t *data; 1237c478bd9Sstevel@tonic-gate } sysevent_bytes_t; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate typedef struct sysevent_value { 1267c478bd9Sstevel@tonic-gate int32_t value_type; /* data type */ 1277c478bd9Sstevel@tonic-gate union { 1287c478bd9Sstevel@tonic-gate uchar_t sv_byte; 1297c478bd9Sstevel@tonic-gate int16_t sv_int16; 1307c478bd9Sstevel@tonic-gate uint16_t sv_uint16; 1317c478bd9Sstevel@tonic-gate int32_t sv_int32; 1327c478bd9Sstevel@tonic-gate uint32_t sv_uint32; 1337c478bd9Sstevel@tonic-gate int64_t sv_int64; 1347c478bd9Sstevel@tonic-gate uint64_t sv_uint64; 1357c478bd9Sstevel@tonic-gate hrtime_t sv_time; 1367c478bd9Sstevel@tonic-gate char *sv_string; 1377c478bd9Sstevel@tonic-gate sysevent_bytes_t sv_bytes; 1387c478bd9Sstevel@tonic-gate } value; 1397c478bd9Sstevel@tonic-gate } sysevent_value_t; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * The following flags determine the memory allocation semantics to use for 1437c478bd9Sstevel@tonic-gate * kernel event buffer allocation by userland and kernel versions of 1447c478bd9Sstevel@tonic-gate * sysevent_evc_publish(). 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * EVCH_SLEEP and EVCH_NOSLEEP respectively map to KM_SLEEP and KM_NOSLEEP. 1477c478bd9Sstevel@tonic-gate * EVCH_TRYHARD is a kernel-only publish flag that allow event allocation 1487c478bd9Sstevel@tonic-gate * routines to use use alternate kmem caches in situations where free memory 1497c478bd9Sstevel@tonic-gate * may be low. Kernel callers of sysevent_evc_publish() must set flags to 1507c478bd9Sstevel@tonic-gate * one of EVCH_SLEEP, EVCH_NOSLEEP or EVCH_TRYHARD. Userland callers of 1517c478bd9Sstevel@tonic-gate * sysevent_evc_publish() must set flags to one of EVCH_SLEEP or EVCH_NOSLEEP. 1527c478bd9Sstevel@tonic-gate * 1537c478bd9Sstevel@tonic-gate * EVCH_QWAIT determines whether or not we should wait for slots in the event 1547c478bd9Sstevel@tonic-gate * queue at publication time. EVCH_QWAIT may be used by kernel and userland 1557c478bd9Sstevel@tonic-gate * publishers and must be used in conjunction with any of one of EVCH_SLEEP, 1567c478bd9Sstevel@tonic-gate * EVCH_NOSLEEP or EVCH_TRYHARD (kernel-only). 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #define EVCH_NOSLEEP 0x0001 /* No sleep on kmem_alloc() */ 1607c478bd9Sstevel@tonic-gate #define EVCH_SLEEP 0x0002 /* Sleep on kmem_alloc() */ 1617c478bd9Sstevel@tonic-gate #define EVCH_TRYHARD 0x0004 /* May use alternate kmem cache for alloc */ 1627c478bd9Sstevel@tonic-gate #define EVCH_QWAIT 0x0008 /* Wait for slot in event queue */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 165*49b225e1SGavin Maltby * Meaning of flags for subscribe. Bits 8 to 15 are dedicated to 166*49b225e1SGavin Maltby * the consolidation private interface, so flags defined here are restricted 167*49b225e1SGavin Maltby * to the LSB. 168*49b225e1SGavin Maltby * 169*49b225e1SGavin Maltby * EVCH_SUB_KEEP indicates that this subscription should persist even if 170*49b225e1SGavin Maltby * this subscriber id should die unexpectedly; matching events will be 171*49b225e1SGavin Maltby * queued (up to a limit) and will be delivered if/when we restart again 172*49b225e1SGavin Maltby * with the same subscriber id. 1737c478bd9Sstevel@tonic-gate */ 174*49b225e1SGavin Maltby #define EVCH_SUB_KEEP 0x01 175*49b225e1SGavin Maltby 176*49b225e1SGavin Maltby /* 177*49b225e1SGavin Maltby * Subscriptions may be wildcarded, but we limit the number of 178*49b225e1SGavin Maltby * wildcards permitted. 179*49b225e1SGavin Maltby */ 180*49b225e1SGavin Maltby #define EVCH_WILDCARD_MAX 10 181*49b225e1SGavin Maltby 182*49b225e1SGavin Maltby /* 183*49b225e1SGavin Maltby * Used in unsubscribe to indicate all subscriber ids for a channel. 184*49b225e1SGavin Maltby */ 1857c478bd9Sstevel@tonic-gate #define EVCH_ALLSUB "all_subs" 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate * Meaning of flags parameter of channel bind function 189*49b225e1SGavin Maltby * 190*49b225e1SGavin Maltby * EVCH_CREAT indicates to create a channel if not already present. 191*49b225e1SGavin Maltby * 192*49b225e1SGavin Maltby * EVCH_HOLD_PEND indicates that events should be published to this 193*49b225e1SGavin Maltby * channel even if there are no matching subscribers present; when 194*49b225e1SGavin Maltby * a subscriber belatedly binds to the channel and registers their 195*49b225e1SGavin Maltby * subscriptions they will receive events that predate their bind. 196*49b225e1SGavin Maltby * If the channel is closed, however, with no remaining bindings then 197*49b225e1SGavin Maltby * the channel is destroyed. 198*49b225e1SGavin Maltby * 199*49b225e1SGavin Maltby * EVCH_HOLD_PEND_INDEF is a stronger version of EVCH_HOLD_PEND - 200*49b225e1SGavin Maltby * even if the channel has no remaining bindings it will not be 201*49b225e1SGavin Maltby * destroyed so long as events remain unconsumed. This is suitable for 202*49b225e1SGavin Maltby * use with short-lived event producers that may bind to (create) the 203*49b225e1SGavin Maltby * channel and exit before the intended consumer has started. 2047c478bd9Sstevel@tonic-gate */ 205*49b225e1SGavin Maltby #define EVCH_CREAT 0x0001 2067c478bd9Sstevel@tonic-gate #define EVCH_HOLD_PEND 0x0002 207*49b225e1SGavin Maltby #define EVCH_HOLD_PEND_INDEF 0x0004 208*49b225e1SGavin Maltby #define EVCH_B_FLAGS 0x0007 /* All valid bits */ 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Meaning of commands of evc_control function 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN_MAX 1 /* Get event queue length limit */ 2147c478bd9Sstevel@tonic-gate #define EVCH_GET_CHAN_LEN 2 /* Get event queue length */ 2157c478bd9Sstevel@tonic-gate #define EVCH_SET_CHAN_LEN 3 /* Set event queue length */ 2167c478bd9Sstevel@tonic-gate #define EVCH_CMD_LAST EVCH_SET_CHAN_LEN /* Last command */ 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* 219*49b225e1SGavin Maltby * Shared user/kernel event channel interface definitions 2207c478bd9Sstevel@tonic-gate */ 221*49b225e1SGavin Maltby extern int sysevent_evc_bind(const char *, evchan_t **, uint32_t); 222*49b225e1SGavin Maltby extern int sysevent_evc_unbind(evchan_t *); 223*49b225e1SGavin Maltby extern int sysevent_evc_subscribe(evchan_t *, const char *, const char *, 2247c478bd9Sstevel@tonic-gate int (*)(sysevent_t *, void *), void *, uint32_t); 225*49b225e1SGavin Maltby extern int sysevent_evc_unsubscribe(evchan_t *, const char *); 226*49b225e1SGavin Maltby extern int sysevent_evc_publish(evchan_t *, const char *, const char *, 2277c478bd9Sstevel@tonic-gate const char *, const char *, nvlist_t *, uint32_t); 228*49b225e1SGavin Maltby extern int sysevent_evc_control(evchan_t *, int, ...); 2297c478bd9Sstevel@tonic-gate 230*49b225e1SGavin Maltby #ifndef _KERNEL 231*49b225e1SGavin Maltby 232*49b225e1SGavin Maltby /* 233*49b225e1SGavin Maltby * Userland-only event channel interfaces 234*49b225e1SGavin Maltby */ 235*49b225e1SGavin Maltby 236*49b225e1SGavin Maltby #include <door.h> 237*49b225e1SGavin Maltby 238*49b225e1SGavin Maltby typedef struct sysevent_subattr sysevent_subattr_t; 239*49b225e1SGavin Maltby 240*49b225e1SGavin Maltby extern sysevent_subattr_t *sysevent_subattr_alloc(void); 241*49b225e1SGavin Maltby extern void sysevent_subattr_free(sysevent_subattr_t *); 242*49b225e1SGavin Maltby 243*49b225e1SGavin Maltby extern void sysevent_subattr_thrattr(sysevent_subattr_t *, pthread_attr_t *); 244*49b225e1SGavin Maltby extern void sysevent_subattr_sigmask(sysevent_subattr_t *, sigset_t *); 245*49b225e1SGavin Maltby 246*49b225e1SGavin Maltby extern void sysevent_subattr_thrcreate(sysevent_subattr_t *, 247*49b225e1SGavin Maltby door_xcreate_server_func_t *, void *); 248*49b225e1SGavin Maltby extern void sysevent_subattr_thrsetup(sysevent_subattr_t *, 249*49b225e1SGavin Maltby door_xcreate_thrsetup_func_t *, void *); 250*49b225e1SGavin Maltby 251*49b225e1SGavin Maltby extern int sysevent_evc_xsubscribe(evchan_t *, const char *, const char *, 252*49b225e1SGavin Maltby int (*)(sysevent_t *, void *), void *, uint32_t, sysevent_subattr_t *); 253*49b225e1SGavin Maltby 254*49b225e1SGavin Maltby #else 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * Kernel log_event interfaces. 2587c478bd9Sstevel@tonic-gate */ 259*49b225e1SGavin Maltby extern int log_sysevent(sysevent_t *, int, sysevent_id_t *); 2607c478bd9Sstevel@tonic-gate 261*49b225e1SGavin Maltby extern sysevent_t *sysevent_alloc(char *, char *, char *, int); 262*49b225e1SGavin Maltby extern void sysevent_free(sysevent_t *); 263*49b225e1SGavin Maltby extern int sysevent_add_attr(sysevent_attr_list_t **, char *, 264*49b225e1SGavin Maltby sysevent_value_t *, int); 265*49b225e1SGavin Maltby extern void sysevent_free_attr(sysevent_attr_list_t *); 266*49b225e1SGavin Maltby extern int sysevent_attach_attributes(sysevent_t *, sysevent_attr_list_t *); 267*49b225e1SGavin Maltby extern void sysevent_detach_attributes(sysevent_t *); 268*49b225e1SGavin Maltby extern char *sysevent_get_class_name(sysevent_t *); 269*49b225e1SGavin Maltby extern char *sysevent_get_subclass_name(sysevent_t *); 270*49b225e1SGavin Maltby extern uint64_t sysevent_get_seq(sysevent_t *); 271*49b225e1SGavin Maltby extern void sysevent_get_time(sysevent_t *, hrtime_t *); 272*49b225e1SGavin Maltby extern size_t sysevent_get_size(sysevent_t *); 273*49b225e1SGavin Maltby extern char *sysevent_get_pub(sysevent_t *); 274*49b225e1SGavin Maltby extern int sysevent_get_attr_list(sysevent_t *, nvlist_t **); 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate #endif 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate #endif /* _SYS_SYSEVENT_H */ 283