111102SGavin.Maltby@Sun.COM /* 211102SGavin.Maltby@Sun.COM * CDDL HEADER START 311102SGavin.Maltby@Sun.COM * 411102SGavin.Maltby@Sun.COM * 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. 711102SGavin.Maltby@Sun.COM * 811102SGavin.Maltby@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 911102SGavin.Maltby@Sun.COM * or http://www.opensolaris.org/os/licensing. 1011102SGavin.Maltby@Sun.COM * See the License for the specific language governing permissions 1111102SGavin.Maltby@Sun.COM * and limitations under the License. 1211102SGavin.Maltby@Sun.COM * 1311102SGavin.Maltby@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 1411102SGavin.Maltby@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1511102SGavin.Maltby@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 1611102SGavin.Maltby@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 1711102SGavin.Maltby@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 1811102SGavin.Maltby@Sun.COM * 1911102SGavin.Maltby@Sun.COM * CDDL HEADER END 2011102SGavin.Maltby@Sun.COM */ 2111102SGavin.Maltby@Sun.COM 2211102SGavin.Maltby@Sun.COM /* 23*12967Sgavin.maltby@oracle.com * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2411102SGavin.Maltby@Sun.COM */ 2511102SGavin.Maltby@Sun.COM 2611102SGavin.Maltby@Sun.COM #ifndef _LIBFMEVENT_H 2711102SGavin.Maltby@Sun.COM #define _LIBFMEVENT_H 2811102SGavin.Maltby@Sun.COM 2911102SGavin.Maltby@Sun.COM /* 3011102SGavin.Maltby@Sun.COM * FMA event library. 3111102SGavin.Maltby@Sun.COM * 3211102SGavin.Maltby@Sun.COM * A. Protocol event subscription interfaces (Committed). 33*12967Sgavin.maltby@oracle.com * B. Raw event publication interfaces (Consolidation Private). 3411102SGavin.Maltby@Sun.COM */ 3511102SGavin.Maltby@Sun.COM 3611102SGavin.Maltby@Sun.COM #ifdef __cplusplus 3711102SGavin.Maltby@Sun.COM extern "C" { 3811102SGavin.Maltby@Sun.COM #endif 3911102SGavin.Maltby@Sun.COM 4011102SGavin.Maltby@Sun.COM #include <sys/types.h> 4111102SGavin.Maltby@Sun.COM #include <libnvpair.h> 4211102SGavin.Maltby@Sun.COM #include <stdlib.h> 4311102SGavin.Maltby@Sun.COM #include <door.h> 4411102SGavin.Maltby@Sun.COM #include <sys/time.h> 4511102SGavin.Maltby@Sun.COM #include <sys/fm/protocol.h> 4611102SGavin.Maltby@Sun.COM 4711102SGavin.Maltby@Sun.COM /* 4811102SGavin.Maltby@Sun.COM * Library ABI interface version. Quote the version you are using 4911102SGavin.Maltby@Sun.COM * to fmev_shdl_init. Only interfaces introduced in or prior to the 5011102SGavin.Maltby@Sun.COM * quoted version will be available. Once introduced an interface 5111102SGavin.Maltby@Sun.COM * only ever changes compatibly. 52*12967Sgavin.maltby@oracle.com * 53*12967Sgavin.maltby@oracle.com * Introduced in 54*12967Sgavin.maltby@oracle.com * API Function LIBFMEVENT_VERSION_* 55*12967Sgavin.maltby@oracle.com * ----------------------- -------------------- 56*12967Sgavin.maltby@oracle.com * fmev_attr_list; 1 57*12967Sgavin.maltby@oracle.com * fmev_class; 1 58*12967Sgavin.maltby@oracle.com * fmev_dup; 1 59*12967Sgavin.maltby@oracle.com * fmev_ev2shdl 2 60*12967Sgavin.maltby@oracle.com * fmev_hold; 1 61*12967Sgavin.maltby@oracle.com * fmev_localtime; 1 62*12967Sgavin.maltby@oracle.com * fmev_rele; 1 63*12967Sgavin.maltby@oracle.com * fmev_shdl_alloc; 1 64*12967Sgavin.maltby@oracle.com * fmev_shdl_init; 1 65*12967Sgavin.maltby@oracle.com * fmev_shdl_fini; 1 66*12967Sgavin.maltby@oracle.com * fmev_shdl_free; 1 67*12967Sgavin.maltby@oracle.com * fmev_shdl_getauthority 2 68*12967Sgavin.maltby@oracle.com * fmev_shdl_nvl2str 2 69*12967Sgavin.maltby@oracle.com * fmev_shdl_strdup 2 70*12967Sgavin.maltby@oracle.com * fmev_shdl_strfree 2 71*12967Sgavin.maltby@oracle.com * fmev_shdl_subscribe; 1 72*12967Sgavin.maltby@oracle.com * fmev_shdl_unsubscribe; 1 73*12967Sgavin.maltby@oracle.com * fmev_shdl_zalloc; 1 74*12967Sgavin.maltby@oracle.com * fmev_shdlctl_serialize; 1 75*12967Sgavin.maltby@oracle.com * fmev_shdlctl_sigmask; 1 76*12967Sgavin.maltby@oracle.com * fmev_shdlctl_thrattr; 1 77*12967Sgavin.maltby@oracle.com * fmev_shdlctl_thrcreate; 1 78*12967Sgavin.maltby@oracle.com * fmev_shdlctl_thrsetup; 1 79*12967Sgavin.maltby@oracle.com * fmev_strerror; 1 80*12967Sgavin.maltby@oracle.com * fmev_timespec; 1 81*12967Sgavin.maltby@oracle.com * fmev_time_nsec; 1 82*12967Sgavin.maltby@oracle.com * fmev_time_sec; 1 8311102SGavin.Maltby@Sun.COM */ 84*12967Sgavin.maltby@oracle.com 8511102SGavin.Maltby@Sun.COM #define LIBFMEVENT_VERSION_1 1 86*12967Sgavin.maltby@oracle.com #define LIBFMEVENT_VERSION_2 2 8711102SGavin.Maltby@Sun.COM 88*12967Sgavin.maltby@oracle.com #define LIBFMEVENT_VERSION_LATEST LIBFMEVENT_VERSION_2 8911102SGavin.Maltby@Sun.COM 9011102SGavin.Maltby@Sun.COM /* 9111102SGavin.Maltby@Sun.COM * Success and error return values. The descriptive comment for each 9211102SGavin.Maltby@Sun.COM * FMEVERR_* becomes the string that is returned by fmev_strerror for that 9311102SGavin.Maltby@Sun.COM * error type. 9411102SGavin.Maltby@Sun.COM */ 9511102SGavin.Maltby@Sun.COM typedef enum { 9611102SGavin.Maltby@Sun.COM FMEV_SUCCESS = 0, 9711102SGavin.Maltby@Sun.COM FMEV_OK = FMEV_SUCCESS, /* alias for FMEV_SUCCESS */ 9811102SGavin.Maltby@Sun.COM FMEVERR_UNKNOWN = 0xe000, /* Error details unknown */ 9911102SGavin.Maltby@Sun.COM FMEVERR_VERSION_MISMATCH, /* Library ABI version incompatible with caller */ 10011102SGavin.Maltby@Sun.COM FMEVERR_API, /* Library API usage violation */ 10111102SGavin.Maltby@Sun.COM FMEVERR_ALLOC, /* Failed to allocate additional resources */ 10211102SGavin.Maltby@Sun.COM FMEVERR_MALFORMED_EVENT, /* Event contents are inconsistent or corrupt */ 10311102SGavin.Maltby@Sun.COM FMEVERR_OVERFLOW, /* Operation would overflow result type */ 10411102SGavin.Maltby@Sun.COM FMEVERR_INTERNAL, /* Internal library error */ 10511102SGavin.Maltby@Sun.COM FMEVERR_NOPRIV, /* Insufficient permissions or privilege */ 10611102SGavin.Maltby@Sun.COM FMEVERR_BUSY, /* Resource is busy */ 10711102SGavin.Maltby@Sun.COM FMEVERR_DUPLICATE, /* Duplicate request */ 10811102SGavin.Maltby@Sun.COM FMEVERR_BADCLASS, /* Bad event class or class pattern */ 10911102SGavin.Maltby@Sun.COM FMEVERR_NOMATCH, /* No match to criteria provided */ 11011102SGavin.Maltby@Sun.COM FMEVERR_MAX_SUBSCRIBERS, /* Exceeds maximum subscribers per handle */ 111*12967Sgavin.maltby@oracle.com FMEVERR_INVALIDARG, /* Argument is invalid */ 112*12967Sgavin.maltby@oracle.com FMEVERR_STRING2BIG, /* String argument exceeds maximum length */ 113*12967Sgavin.maltby@oracle.com FMEVERR_VARARGS_MALFORMED, /* Varargs list bad or incorrectly terminated */ 114*12967Sgavin.maltby@oracle.com FMEVERR_VARARGS_TOOLONG, /* Varargs list exceeds maximum length */ 115*12967Sgavin.maltby@oracle.com FMEVERR_BADRULESET, /* Ruleset selected for publication is bad */ 116*12967Sgavin.maltby@oracle.com FMEVERR_BADPRI, /* Priority selected for publication is bad */ 117*12967Sgavin.maltby@oracle.com FMEVERR_TRANSPORT, /* Error in underlying event transport implementation */ 118*12967Sgavin.maltby@oracle.com FMEVERR_NVLIST /* nvlist argument is not of type NV_UNIQUE_NAME */ 11911102SGavin.Maltby@Sun.COM } fmev_err_t; 12011102SGavin.Maltby@Sun.COM 12111102SGavin.Maltby@Sun.COM /* 12211102SGavin.Maltby@Sun.COM * Some interfaces return an fmev_err_t - FMEV_SUCCESS on success, otherwise 12311102SGavin.Maltby@Sun.COM * failure of the indicated type. You can use fmev_strerror to render an 12411102SGavin.Maltby@Sun.COM * fmev_err_t into a string. 12511102SGavin.Maltby@Sun.COM * 12611102SGavin.Maltby@Sun.COM * Other interfaces do not return an fmev_err_t directly. For example 12711102SGavin.Maltby@Sun.COM * where we return a pointer an error is indicated by a NULL return. 12811102SGavin.Maltby@Sun.COM * In these cases you can retrieve the fmev_err_t describing the reason 12911102SGavin.Maltby@Sun.COM * for the failure using fmev_errno or get a string with 13011102SGavin.Maltby@Sun.COM * fmev_strerr(fmev_errno). Note that fmev_errno is per-thread and holds 13111102SGavin.Maltby@Sun.COM * the error value for any error that occured during the last libfmevent 13211102SGavin.Maltby@Sun.COM * API call made by the current thread. Use fmev_errno as you would 13311102SGavin.Maltby@Sun.COM * regular errno, but you should not assign to fmev_errno. 13411102SGavin.Maltby@Sun.COM */ 13511102SGavin.Maltby@Sun.COM extern const fmev_err_t *__fmev_errno(void); /* do not use this directly */ 13611102SGavin.Maltby@Sun.COM #define fmev_errno (*(__fmev_errno())) 13711102SGavin.Maltby@Sun.COM extern const char *fmev_strerror(fmev_err_t); 13811102SGavin.Maltby@Sun.COM 13911102SGavin.Maltby@Sun.COM /* 14011102SGavin.Maltby@Sun.COM * Part A - Protocol Event Subscription 14111102SGavin.Maltby@Sun.COM * ====== 14211102SGavin.Maltby@Sun.COM * 14311102SGavin.Maltby@Sun.COM * Subscribe to FMA protocol events published by the fault management 14411102SGavin.Maltby@Sun.COM * daemon, receiving a callback for each matching event. 14511102SGavin.Maltby@Sun.COM * 14611102SGavin.Maltby@Sun.COM * This is a Committed interface (see attributes(5) for a definition). 14711102SGavin.Maltby@Sun.COM */ 14811102SGavin.Maltby@Sun.COM 14911102SGavin.Maltby@Sun.COM /* 15011102SGavin.Maltby@Sun.COM * Opaque subscription handle and event types. 15111102SGavin.Maltby@Sun.COM */ 15211102SGavin.Maltby@Sun.COM typedef struct fmev_shdl *fmev_shdl_t; 15311102SGavin.Maltby@Sun.COM typedef struct fmev *fmev_t; 15411102SGavin.Maltby@Sun.COM 15511102SGavin.Maltby@Sun.COM /* 15611102SGavin.Maltby@Sun.COM * Subscription callback function type for fmev_shdl_subscribe. 15711102SGavin.Maltby@Sun.COM */ 15811102SGavin.Maltby@Sun.COM typedef void fmev_cbfunc_t(fmev_t, const char *, nvlist_t *, void *); 15911102SGavin.Maltby@Sun.COM 16011102SGavin.Maltby@Sun.COM /* 16111102SGavin.Maltby@Sun.COM * Initialize a new handle using fmev_shdl_init and quoting interface 16211102SGavin.Maltby@Sun.COM * version number along with alloc, zalloc and free function pointers (all 16311102SGavin.Maltby@Sun.COM * NULL to use the defaults. 16411102SGavin.Maltby@Sun.COM * 16511102SGavin.Maltby@Sun.COM * Close the handle and release resources with fmev_shdl_fini. 16611102SGavin.Maltby@Sun.COM */ 16711102SGavin.Maltby@Sun.COM 16811102SGavin.Maltby@Sun.COM extern fmev_shdl_t fmev_shdl_init(uint32_t, 16911102SGavin.Maltby@Sun.COM void *(*)(size_t), /* alloc */ 17011102SGavin.Maltby@Sun.COM void *(*)(size_t), /* zalloc */ 17111102SGavin.Maltby@Sun.COM void (*)(void *, size_t)); /* free */ 17211102SGavin.Maltby@Sun.COM 17311102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdl_fini(fmev_shdl_t); 17411102SGavin.Maltby@Sun.COM 17511102SGavin.Maltby@Sun.COM /* 17611102SGavin.Maltby@Sun.COM * Having created a handle you may optionally configure various properties 17711102SGavin.Maltby@Sun.COM * for this handle using fmev_shdlctl_*. In most cases accepting the defaults 17811102SGavin.Maltby@Sun.COM * (that are obtained through fmev_shdl_init alone) will provide adequate 17911102SGavin.Maltby@Sun.COM * semantics - the controls below are provided for applications 18011102SGavin.Maltby@Sun.COM * that require fine-grained control over event delivery semantics and, in 18111102SGavin.Maltby@Sun.COM * particular, the service threads used to perform delivery callbacks. 18211102SGavin.Maltby@Sun.COM * 18311102SGavin.Maltby@Sun.COM * These controls may only be applied to a subscription handle 18411102SGavin.Maltby@Sun.COM * that has no current subscriptions in place. You therefore cannot 18511102SGavin.Maltby@Sun.COM * change the properties once subscriptions are established, and the 18611102SGavin.Maltby@Sun.COM * handle properties apply uniformly to all subscriptions on that handle. 18711102SGavin.Maltby@Sun.COM * If you require different properties per subscription then use multiple 18811102SGavin.Maltby@Sun.COM * handles. 18911102SGavin.Maltby@Sun.COM * 19011102SGavin.Maltby@Sun.COM * fmev_shdlctl_serialize() will serialize all callbacks arising from all 19111102SGavin.Maltby@Sun.COM * subscriptions on a handle. Event deliveries are normally single-threaded 19211102SGavin.Maltby@Sun.COM * on a per-subscribtion bases, that is a call to fmev_shdl_subscribe 19311102SGavin.Maltby@Sun.COM * will have deliveries arising from that subscription delivered 19411102SGavin.Maltby@Sun.COM * in a serialized fashion on a single thread dedicated to the subscription. 19511102SGavin.Maltby@Sun.COM * If multiple subscriptions are established then each has a dedicated 19611102SGavin.Maltby@Sun.COM * delivery thread - fmev_shdlctl_serialize arranges that only one of these 19711102SGavin.Maltby@Sun.COM * threads services a callback at any one time. 19811102SGavin.Maltby@Sun.COM * 19911102SGavin.Maltby@Sun.COM * fmev_shdlctl_thrattr() allows you to provide thread attributes for use 20011102SGavin.Maltby@Sun.COM * in pthread_create() when server threads are created. The attributes 20111102SGavin.Maltby@Sun.COM * are not copied - the pthread_attr_t object passed must exist for 20211102SGavin.Maltby@Sun.COM * the duration of all subscriptions on the handle. These attributes only 20311102SGavin.Maltby@Sun.COM * apply if fmev_shdlctl_thrcreate() is not in use on this handle. 20411102SGavin.Maltby@Sun.COM * 20511102SGavin.Maltby@Sun.COM * fmev_shdlctl_sigmask() allows you to provide a sigset_t signal mask 20611102SGavin.Maltby@Sun.COM * of signals to block in server threads. The pthread_sigmask is set 20711102SGavin.Maltby@Sun.COM * to this immediately before pthread_create, and restored immediately 20811102SGavin.Maltby@Sun.COM * after pthread_create. This mask only applies if fmev_shdlctl_thrcreate() 20911102SGavin.Maltby@Sun.COM * is not in use on this handle. 21011102SGavin.Maltby@Sun.COM * 21111102SGavin.Maltby@Sun.COM * fmev_shdlctl_thrsetup() allows you to install a custom door server thread 21211102SGavin.Maltby@Sun.COM * setup function - see door_xcreate(3C). This will be used with the 21311102SGavin.Maltby@Sun.COM * default thread creation semantics or with any custom thread creation 21411102SGavin.Maltby@Sun.COM * function appointed with fmev_shdlctl_thrcreate(). 21511102SGavin.Maltby@Sun.COM * 21611102SGavin.Maltby@Sun.COM * fmev_shdlctl_thrcreate() allows you to install a custom door server thread 21711102SGavin.Maltby@Sun.COM * creation function - see door_xcreate(3C). This option excludes 21811102SGavin.Maltby@Sun.COM * fmev_shdlctl_{thrattr,sigmask} but the remaining options 21911102SGavin.Maltby@Sun.COM * of fmev_shdlctl_{serialize,thrsetup} are still available. 22011102SGavin.Maltby@Sun.COM */ 22111102SGavin.Maltby@Sun.COM 22211102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdlctl_serialize(fmev_shdl_t); 22311102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdlctl_thrattr(fmev_shdl_t, pthread_attr_t *); 22411102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdlctl_sigmask(fmev_shdl_t, sigset_t *); 22511102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdlctl_thrsetup(fmev_shdl_t, 22611102SGavin.Maltby@Sun.COM door_xcreate_thrsetup_func_t *, void *); 22711102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdlctl_thrcreate(fmev_shdl_t, 22811102SGavin.Maltby@Sun.COM door_xcreate_server_func_t *, void *); 22911102SGavin.Maltby@Sun.COM 23011102SGavin.Maltby@Sun.COM /* 23111102SGavin.Maltby@Sun.COM * Specify subscription choices on a handle using fmev_shdl_subscribe as 23211102SGavin.Maltby@Sun.COM * many times as needed to describe the full event set. The event class 23311102SGavin.Maltby@Sun.COM * pattern can be wildcarded using simple '*' wildcarding. When an event 23411102SGavin.Maltby@Sun.COM * matching a subscription is received a callback is performed to the 23511102SGavin.Maltby@Sun.COM * nominated function passing a fmev_t handle on the event and the 23611102SGavin.Maltby@Sun.COM * requested cookie argument. 23711102SGavin.Maltby@Sun.COM * 23811102SGavin.Maltby@Sun.COM * See the fault management event protocol specification for a description 23911102SGavin.Maltby@Sun.COM * of event classes. 24011102SGavin.Maltby@Sun.COM * 24111102SGavin.Maltby@Sun.COM * Drop a subscription using fmev_shdl_unsubscribe (which must match an 24211102SGavin.Maltby@Sun.COM * earlier subscription). 24311102SGavin.Maltby@Sun.COM */ 24411102SGavin.Maltby@Sun.COM 24511102SGavin.Maltby@Sun.COM #define FMEV_MAX_CLASS 64 /* Longest class string for subscription */ 24611102SGavin.Maltby@Sun.COM 24711102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdl_subscribe(fmev_shdl_t, const char *, fmev_cbfunc_t, 24811102SGavin.Maltby@Sun.COM void *); 24911102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_shdl_unsubscribe(fmev_shdl_t, const char *); 25011102SGavin.Maltby@Sun.COM 25111102SGavin.Maltby@Sun.COM /* 252*12967Sgavin.maltby@oracle.com * Retrieve an authority nvlist for the fault manager that is forwarding 253*12967Sgavin.maltby@oracle.com * events to us. This may be NULL if the fault manager has not yet 254*12967Sgavin.maltby@oracle.com * started up and made the information available. The caller is 255*12967Sgavin.maltby@oracle.com * responsible for freeing the nvlist returned. 256*12967Sgavin.maltby@oracle.com */ 257*12967Sgavin.maltby@oracle.com extern fmev_err_t fmev_shdl_getauthority(fmev_shdl_t, nvlist_t **); 258*12967Sgavin.maltby@oracle.com 259*12967Sgavin.maltby@oracle.com /* 26011102SGavin.Maltby@Sun.COM * Event access. In the common case that the event is processed to 26111102SGavin.Maltby@Sun.COM * completion in the context of the event callback you need only 26211102SGavin.Maltby@Sun.COM * use fmev_attr_list to access the nvlist of event attributes, 26311102SGavin.Maltby@Sun.COM * with no responsibility for freeing the event or the nvlist; for 26411102SGavin.Maltby@Sun.COM * convenience, fmev_class and fmev_timestamp can both be used to 26511102SGavin.Maltby@Sun.COM * look inside an event without having to work with the attribute list (and 26611102SGavin.Maltby@Sun.COM * the callback receives the class as an argument). 26711102SGavin.Maltby@Sun.COM * 26811102SGavin.Maltby@Sun.COM * See libnvpair(3LIB) for interfaces to access an nvlist_t. 26911102SGavin.Maltby@Sun.COM * 27011102SGavin.Maltby@Sun.COM * The remaining interfaces apply in the case that event handling will 27111102SGavin.Maltby@Sun.COM * continue beyond the context of the event callback in which it is received. 27211102SGavin.Maltby@Sun.COM * 27311102SGavin.Maltby@Sun.COM * The fmev_t handle received in a callback is reference-counted; 27411102SGavin.Maltby@Sun.COM * the initial reference count on entry to the callback is 1, and the 27511102SGavin.Maltby@Sun.COM * count is always decremented when the callback completes. To continue 27611102SGavin.Maltby@Sun.COM * to operate on a received event outside of the context of the callback 27711102SGavin.Maltby@Sun.COM * in which it is first received, take an fmev_hold during the callback 27811102SGavin.Maltby@Sun.COM * and later fmev_rele to release your hold (and free the event if the count 27911102SGavin.Maltby@Sun.COM * drops to 0). 28011102SGavin.Maltby@Sun.COM * 28111102SGavin.Maltby@Sun.COM * To access attributes of an event use fmev_attr_list to receive 28211102SGavin.Maltby@Sun.COM * an nvlist_t pointer valid for the same lifetime as the event itself (i.e., 28311102SGavin.Maltby@Sun.COM * until its reference count drops to zero). 28411102SGavin.Maltby@Sun.COM * 28511102SGavin.Maltby@Sun.COM * If changes are made to a received fmev_t (discouraged) then all who 28611102SGavin.Maltby@Sun.COM * have a hold on the event share the change. To obtain an independent 28711102SGavin.Maltby@Sun.COM * copy of an fmev_t, with a reference count of 1, use fmev_dup. When 28811102SGavin.Maltby@Sun.COM * finished with the copy decrement the reference count 28911102SGavin.Maltby@Sun.COM * using fmev_rele - the event will be freed if the count reaches 0. 29011102SGavin.Maltby@Sun.COM * 29111102SGavin.Maltby@Sun.COM * For convenience you can retrieve the class of an event using fmev_class 29211102SGavin.Maltby@Sun.COM * (it's also available as an argument to a callback, and within the 29311102SGavin.Maltby@Sun.COM * event attribute list). The string returned by fmev_class is valid for 29411102SGavin.Maltby@Sun.COM * the same lifetime as the event itself. 29511102SGavin.Maltby@Sun.COM * 29611102SGavin.Maltby@Sun.COM * The time at which a protocol event was generated is available via 29711102SGavin.Maltby@Sun.COM * fmev_timespec; tv_sec has seconds since the epoch, and tv_nsec nanoseconds 29811102SGavin.Maltby@Sun.COM * past that second. This can fail with FMEVERR_OVERFLOW if the seconds 29911102SGavin.Maltby@Sun.COM * value does not fit within a time_t; you can retrieve the 64-bit second 30011102SGavin.Maltby@Sun.COM * and nanosecond values with fmev_time_sec and fmev_time_nsec. 301*12967Sgavin.maltby@oracle.com * 302*12967Sgavin.maltby@oracle.com * An FMRI in an event payload is typically in nvlist form, i.e 303*12967Sgavin.maltby@oracle.com * DATA_TYPE_NVLIST. That form is useful for extracting individual 304*12967Sgavin.maltby@oracle.com * component fields, but that requires knowledge of the FMRI scheme and 305*12967Sgavin.maltby@oracle.com * Public commitment thereof. FMRIs are typically Private, but in some 306*12967Sgavin.maltby@oracle.com * cases they can be descriptive such as in listing the ASRU(s) affected 307*12967Sgavin.maltby@oracle.com * by a fault; so we offer an API member which will blindly render any 308*12967Sgavin.maltby@oracle.com * FMRI in its string form. Use fmev_shdl_nvl2str to format an nvlist_t 309*12967Sgavin.maltby@oracle.com * as a string (if it is recognized as an FMRI); the caller is responsible 310*12967Sgavin.maltby@oracle.com * for freeing the returned string using fmev_shdl_strfree. If 311*12967Sgavin.maltby@oracle.com * fmev_shdl_nvl2str fails it will return NULL with fmev_errno set - 312*12967Sgavin.maltby@oracle.com * FMEVERR_INVALIDARG if the nvlist_t does not appear to be a valid/known FMRI, 313*12967Sgavin.maltby@oracle.com * FMEVERR_ALLOC if an allocation for memory for the string failed. 314*12967Sgavin.maltby@oracle.com * 315*12967Sgavin.maltby@oracle.com * fmev_ev2shdl will return the fmev_shdl_t with which a received fmev_t 316*12967Sgavin.maltby@oracle.com * is associated. It should only be used in an event delivery callback 317*12967Sgavin.maltby@oracle.com * context and for the event received in that callback. 31811102SGavin.Maltby@Sun.COM */ 31911102SGavin.Maltby@Sun.COM 32011102SGavin.Maltby@Sun.COM extern nvlist_t *fmev_attr_list(fmev_t); 32111102SGavin.Maltby@Sun.COM extern const char *fmev_class(fmev_t); 32211102SGavin.Maltby@Sun.COM 32311102SGavin.Maltby@Sun.COM extern fmev_err_t fmev_timespec(fmev_t, struct timespec *); 32411102SGavin.Maltby@Sun.COM extern uint64_t fmev_time_sec(fmev_t); 32511102SGavin.Maltby@Sun.COM extern uint64_t fmev_time_nsec(fmev_t); 32611102SGavin.Maltby@Sun.COM extern struct tm *fmev_localtime(fmev_t, struct tm *); 32711102SGavin.Maltby@Sun.COM 32811102SGavin.Maltby@Sun.COM extern void fmev_hold(fmev_t); 32911102SGavin.Maltby@Sun.COM extern void fmev_rele(fmev_t); 33011102SGavin.Maltby@Sun.COM extern fmev_t fmev_dup(fmev_t); 33111102SGavin.Maltby@Sun.COM 332*12967Sgavin.maltby@oracle.com extern char *fmev_shdl_nvl2str(fmev_shdl_t, nvlist_t *); 333*12967Sgavin.maltby@oracle.com 334*12967Sgavin.maltby@oracle.com extern fmev_shdl_t fmev_ev2shdl(fmev_t); 335*12967Sgavin.maltby@oracle.com 33611102SGavin.Maltby@Sun.COM /* 33711102SGavin.Maltby@Sun.COM * The following will allocate and free memory based on the choices made 33811102SGavin.Maltby@Sun.COM * at fmev_shdl_init. 33911102SGavin.Maltby@Sun.COM */ 34011102SGavin.Maltby@Sun.COM void *fmev_shdl_alloc(fmev_shdl_t, size_t); 34111102SGavin.Maltby@Sun.COM void *fmev_shdl_zalloc(fmev_shdl_t, size_t); 34211102SGavin.Maltby@Sun.COM void fmev_shdl_free(fmev_shdl_t, void *, size_t); 343*12967Sgavin.maltby@oracle.com extern char *fmev_shdl_strdup(fmev_shdl_t, char *); 344*12967Sgavin.maltby@oracle.com extern void fmev_shdl_strfree(fmev_shdl_t, char *); 345*12967Sgavin.maltby@oracle.com 346*12967Sgavin.maltby@oracle.com /* 347*12967Sgavin.maltby@oracle.com * Part B - Raw Event Publication 348*12967Sgavin.maltby@oracle.com * ====== 349*12967Sgavin.maltby@oracle.com * 350*12967Sgavin.maltby@oracle.com * The following interfaces are private to the Solaris system and are 351*12967Sgavin.maltby@oracle.com * subject to change at any time without notice. Applications using 352*12967Sgavin.maltby@oracle.com * these interfaces will fail to run on future releases. The interfaces 353*12967Sgavin.maltby@oracle.com * should not be used for any purpose until they are publicly documented 354*12967Sgavin.maltby@oracle.com * for use outside of Sun. These interface are *certain* to change 355*12967Sgavin.maltby@oracle.com * incompatibly, as the current interface is very much purpose-built for 356*12967Sgavin.maltby@oracle.com * a limited application. 357*12967Sgavin.maltby@oracle.com * 358*12967Sgavin.maltby@oracle.com * The interfaces below allow a process to publish a "raw" event 359*12967Sgavin.maltby@oracle.com * which will be transmitted to the fault manager and post-processed 360*12967Sgavin.maltby@oracle.com * into a full FMA protocol event. The post-processing to be applied 361*12967Sgavin.maltby@oracle.com * is selected by a "ruleset" specified either implicitly or explicitly 362*12967Sgavin.maltby@oracle.com * at publication. A ruleset will take the raw event (comprising 363*12967Sgavin.maltby@oracle.com * class, subclass, priority, raw payload) and mark it up into a full 364*12967Sgavin.maltby@oracle.com * protocol event; it may also augment the payload through looking up 365*12967Sgavin.maltby@oracle.com * details that would have been costly to compute at publication time. 366*12967Sgavin.maltby@oracle.com * 367*12967Sgavin.maltby@oracle.com * In this first implementation event dispatch is synchronous and blocking, 368*12967Sgavin.maltby@oracle.com * and not guaranteed to be re-entrant. This limits the call sites 369*12967Sgavin.maltby@oracle.com * at which publication calls can be placed, and also means that careful 370*12967Sgavin.maltby@oracle.com * thought is required before sprinkling event publication code throughout 371*12967Sgavin.maltby@oracle.com * common system libraries. The dispatch mechanism amounts to some 372*12967Sgavin.maltby@oracle.com * nvlist chicanery followed by a sysevent_evc_publish. A future revision 373*12967Sgavin.maltby@oracle.com * will relax the context from which one may publish, and add more-powerful 374*12967Sgavin.maltby@oracle.com * publication interfaces. 375*12967Sgavin.maltby@oracle.com * 376*12967Sgavin.maltby@oracle.com * Some publication interfaces (those ending in _nvl) accept a preconstructed 377*12967Sgavin.maltby@oracle.com * nvlist as raw event payload. We require that such an nvlist be of type 378*12967Sgavin.maltby@oracle.com * NV_UNIQUE_NAME. The publication interfaces all call nvlist_free on any 379*12967Sgavin.maltby@oracle.com * nvlist that is passed for publication. 380*12967Sgavin.maltby@oracle.com * 381*12967Sgavin.maltby@oracle.com * Other publication interfaces allow you to build up the raw event payload 382*12967Sgavin.maltby@oracle.com * by specifying the members in a varargs list terminated by FMEV_ARG_TERM. 383*12967Sgavin.maltby@oracle.com * Again we require that payload member names are unique (that is, you cannot 384*12967Sgavin.maltby@oracle.com * have two members with the same name but different datatype). See 385*12967Sgavin.maltby@oracle.com * <sys/nvpair.h> for the data_type_t enumeration of types supported - but 386*12967Sgavin.maltby@oracle.com * note that DATA_TYPE_BOOLEAN is excluded (DATA_TYPE_BOOLEAN_VALUE is 387*12967Sgavin.maltby@oracle.com * supported). A single-valued (non-array type) member is specified with 3 388*12967Sgavin.maltby@oracle.com * consecutive varargs as: 389*12967Sgavin.maltby@oracle.com * 390*12967Sgavin.maltby@oracle.com * (char *)name, DATA_TYPE_foo, (type)value 391*12967Sgavin.maltby@oracle.com * 392*12967Sgavin.maltby@oracle.com * An array-valued member is specified with 4 consecutive varargs as: 393*12967Sgavin.maltby@oracle.com * 394*12967Sgavin.maltby@oracle.com * (char *)name, DATA_TYPE_foo_ARRAY, (int)nelem, (type *)arrayptr 395*12967Sgavin.maltby@oracle.com * 396*12967Sgavin.maltby@oracle.com * The varargs list that specifies the nvlist must begin with an 397*12967Sgavin.maltby@oracle.com * integer that specifies the number of members that follow. For example: 398*12967Sgavin.maltby@oracle.com * 399*12967Sgavin.maltby@oracle.com * uint32_t mode; 400*12967Sgavin.maltby@oracle.com * char *clientname; 401*12967Sgavin.maltby@oracle.com * uint32_t ins[NARGS]; 402*12967Sgavin.maltby@oracle.com * 403*12967Sgavin.maltby@oracle.com * fmev_publish("class", "subclass", FMEV_LOPRI, 404*12967Sgavin.maltby@oracle.com * 3, 405*12967Sgavin.maltby@oracle.com * "mode", DATA_TYPE_UINT32, mode, 406*12967Sgavin.maltby@oracle.com * "client", DATA_TYPE_STRING, clientname, 407*12967Sgavin.maltby@oracle.com * "ins", DATA_TYPE_UINT32_ARRAY, sizeof (ins) / sizeof (ins[0]), ins, 408*12967Sgavin.maltby@oracle.com * FMEV_ARG_TERM); 409*12967Sgavin.maltby@oracle.com * 410*12967Sgavin.maltby@oracle.com * The following tables summarize the capabilities of the various 411*12967Sgavin.maltby@oracle.com * publication interfaces. 412*12967Sgavin.maltby@oracle.com * 413*12967Sgavin.maltby@oracle.com * Detector 414*12967Sgavin.maltby@oracle.com * Interface Ruleset? File/Line Func 415*12967Sgavin.maltby@oracle.com * ---------------------------- -------- --------- ---- 416*12967Sgavin.maltby@oracle.com * fmev_publish_nvl default Yes No 417*12967Sgavin.maltby@oracle.com * fmev_publish_nvl (C99) default Yes Yes 418*12967Sgavin.maltby@oracle.com * fmev_rspublish_nvl chosen Yes No 419*12967Sgavin.maltby@oracle.com * fmev_rspublish_nvl (C99) chosen Yes Yes 420*12967Sgavin.maltby@oracle.com * fmev_publish default No No 421*12967Sgavin.maltby@oracle.com * fmev_publish (C99) default Yes Yes 422*12967Sgavin.maltby@oracle.com * fmev_rspublish chosen No No 423*12967Sgavin.maltby@oracle.com * fmev_rspublish (C99) chosen Yes Yes 424*12967Sgavin.maltby@oracle.com * 425*12967Sgavin.maltby@oracle.com * Summary: if not using C99 then try to use the _nvl variants as the 426*12967Sgavin.maltby@oracle.com * varargs variants will not include file, line or function in the 427*12967Sgavin.maltby@oracle.com * detector. 428*12967Sgavin.maltby@oracle.com */ 429*12967Sgavin.maltby@oracle.com 430*12967Sgavin.maltby@oracle.com /* 431*12967Sgavin.maltby@oracle.com * In publishing an event you must select a "ruleset" (or accept the 432*12967Sgavin.maltby@oracle.com * defaults). Rulesets are listed in the following header. 433*12967Sgavin.maltby@oracle.com */ 434*12967Sgavin.maltby@oracle.com #include <fm/libfmevent_ruleset.h> 435*12967Sgavin.maltby@oracle.com 436*12967Sgavin.maltby@oracle.com /* 437*12967Sgavin.maltby@oracle.com * In publishing an event we can specify a class and subclass (which 438*12967Sgavin.maltby@oracle.com * in post-processing combine in some way selected by the ruleset to 439*12967Sgavin.maltby@oracle.com * form a full event protocol class). The maximum class and subclass 440*12967Sgavin.maltby@oracle.com * string lengths are as follows. 441*12967Sgavin.maltby@oracle.com */ 442*12967Sgavin.maltby@oracle.com #define FMEV_PUB_MAXCLASSLEN 32 443*12967Sgavin.maltby@oracle.com #define FMEV_PUB_MAXSUBCLASSLEN 32 444*12967Sgavin.maltby@oracle.com 445*12967Sgavin.maltby@oracle.com /* 446*12967Sgavin.maltby@oracle.com * Events are either high-priority (try really hard not to lose) or 447*12967Sgavin.maltby@oracle.com * low-priority (can drop, throttle etc). Convert a fmev_pri_t to 448*12967Sgavin.maltby@oracle.com * a string with fmev_pri_string(). 449*12967Sgavin.maltby@oracle.com */ 450*12967Sgavin.maltby@oracle.com typedef enum fmev_pri { 451*12967Sgavin.maltby@oracle.com FMEV_LOPRI = 0x1000, 452*12967Sgavin.maltby@oracle.com FMEV_HIPRI 453*12967Sgavin.maltby@oracle.com } fmev_pri_t; 454*12967Sgavin.maltby@oracle.com 455*12967Sgavin.maltby@oracle.com extern const char *fmev_pri_string(fmev_pri_t); 456*12967Sgavin.maltby@oracle.com 457*12967Sgavin.maltby@oracle.com /* 458*12967Sgavin.maltby@oracle.com * The varargs event publication interfaces must terminate the list 459*12967Sgavin.maltby@oracle.com * of nvpair specifications with FMEV_ARG_TERM. This is to guard 460*12967Sgavin.maltby@oracle.com * against very easily-made mistakes in those arg lists. 461*12967Sgavin.maltby@oracle.com */ 462*12967Sgavin.maltby@oracle.com #define FMEV_ARG_TERM (void *)0xa4a3a2a1 463*12967Sgavin.maltby@oracle.com 464*12967Sgavin.maltby@oracle.com /* 465*12967Sgavin.maltby@oracle.com * The following are NOT for direct use. 466*12967Sgavin.maltby@oracle.com */ 467*12967Sgavin.maltby@oracle.com extern fmev_err_t _i_fmev_publish_nvl( 468*12967Sgavin.maltby@oracle.com const char *, const char *, int64_t, 469*12967Sgavin.maltby@oracle.com const char *, const char *, const char *, 470*12967Sgavin.maltby@oracle.com fmev_pri_t, nvlist_t *); 471*12967Sgavin.maltby@oracle.com 472*12967Sgavin.maltby@oracle.com extern fmev_err_t _i_fmev_publish( 473*12967Sgavin.maltby@oracle.com const char *, const char *, int64_t, 474*12967Sgavin.maltby@oracle.com const char *, const char *, const char *, 475*12967Sgavin.maltby@oracle.com fmev_pri_t, 476*12967Sgavin.maltby@oracle.com uint_t, ...); 477*12967Sgavin.maltby@oracle.com 478*12967Sgavin.maltby@oracle.com /* 479*12967Sgavin.maltby@oracle.com * Post-processing will always generate a "detector" payload member. In 480*12967Sgavin.maltby@oracle.com * the case of the _nvl publishing variants the detector information 481*12967Sgavin.maltby@oracle.com * includes file and line number, and - if your application is compiled 482*12967Sgavin.maltby@oracle.com * with C99 enabled - function name. 483*12967Sgavin.maltby@oracle.com */ 484*12967Sgavin.maltby@oracle.com #if __STDC_VERSION__ - 0 >= 199901L 485*12967Sgavin.maltby@oracle.com #define _FMEVFUNC __func__ 486*12967Sgavin.maltby@oracle.com #else 487*12967Sgavin.maltby@oracle.com #define _FMEVFUNC NULL 488*12967Sgavin.maltby@oracle.com #endif 489*12967Sgavin.maltby@oracle.com 490*12967Sgavin.maltby@oracle.com /* 491*12967Sgavin.maltby@oracle.com * All these definitions "return" an fmev_err_t. 492*12967Sgavin.maltby@oracle.com * 493*12967Sgavin.maltby@oracle.com * In the _nvl variants you pass a preconstructed event payload; otherwise 494*12967Sgavin.maltby@oracle.com * you include an integer indicating the number of payload 495*12967Sgavin.maltby@oracle.com * (name, type, value) tuples that follow, then all those tuples, finally 496*12967Sgavin.maltby@oracle.com * terminated by FMEV_ARG_TERM. 497*12967Sgavin.maltby@oracle.com * 498*12967Sgavin.maltby@oracle.com * In the rspublish variants you select a ruleset from 499*12967Sgavin.maltby@oracle.com * libfmevent_ruleset.h - just use the final suffix (as in 500*12967Sgavin.maltby@oracle.com * DEFAULT, EREPORT, ISV). 501*12967Sgavin.maltby@oracle.com * 502*12967Sgavin.maltby@oracle.com * The primary classification must not be NULL or the empty string. 503*12967Sgavin.maltby@oracle.com * 504*12967Sgavin.maltby@oracle.com * arg type Description 505*12967Sgavin.maltby@oracle.com * ------- --------------- ------------------------------------------- 506*12967Sgavin.maltby@oracle.com * ruleset const char * Ruleset; can be NULL (implies default ruleset) 507*12967Sgavin.maltby@oracle.com * cl1 const char * Primary classification string 508*12967Sgavin.maltby@oracle.com * cl2 const char * Secondary classification string 509*12967Sgavin.maltby@oracle.com * pri fmev_pri_t Priority 510*12967Sgavin.maltby@oracle.com * nvl nvlist_t * Preconstructed attributes; caller must free 511*12967Sgavin.maltby@oracle.com * ntuples int Number of tuples before FMEV_ARG_TERM 512*12967Sgavin.maltby@oracle.com * suffix - See above. 513*12967Sgavin.maltby@oracle.com */ 514*12967Sgavin.maltby@oracle.com 515*12967Sgavin.maltby@oracle.com /* 516*12967Sgavin.maltby@oracle.com * fmev_publish_nvl - Default ruleset implied; class/subclass, pri and an nvl 517*12967Sgavin.maltby@oracle.com */ 518*12967Sgavin.maltby@oracle.com #define fmev_publish_nvl(cl1, cl2, pri, nvl) \ 519*12967Sgavin.maltby@oracle.com _i_fmev_publish_nvl( \ 520*12967Sgavin.maltby@oracle.com __FILE__, _FMEVFUNC, __LINE__, \ 521*12967Sgavin.maltby@oracle.com FMEV_RULESET_DEFAULT, cl1, cl2, \ 522*12967Sgavin.maltby@oracle.com pri, nvl) 523*12967Sgavin.maltby@oracle.com 524*12967Sgavin.maltby@oracle.com /* 525*12967Sgavin.maltby@oracle.com * fmev_rspublish_nvl - As fmev_publish_nvl, but with a chosen ruleset. 526*12967Sgavin.maltby@oracle.com */ 527*12967Sgavin.maltby@oracle.com #define fmev_rspublish_nvl(ruleset, cl1, cl2, pri, nvl) \ 528*12967Sgavin.maltby@oracle.com _i_fmev_publish_nvl( \ 529*12967Sgavin.maltby@oracle.com __FILE__, _FMEVFUNC, __LINE__, \ 530*12967Sgavin.maltby@oracle.com ruleset, cl1, cl2, \ 531*12967Sgavin.maltby@oracle.com pri, nvl) 532*12967Sgavin.maltby@oracle.com 533*12967Sgavin.maltby@oracle.com #if __STDC_VERSION__ - 0 >= 199901L && !defined(__lint) 534*12967Sgavin.maltby@oracle.com 535*12967Sgavin.maltby@oracle.com /* 536*12967Sgavin.maltby@oracle.com * fmev_publish (C99 version) - Default ruleset; class/subclass, pri, nvpairs 537*12967Sgavin.maltby@oracle.com */ 538*12967Sgavin.maltby@oracle.com #define fmev_publish(cl1, cl2, pri, ntuples, ...) \ 539*12967Sgavin.maltby@oracle.com _i_fmev_publish( \ 540*12967Sgavin.maltby@oracle.com __FILE__, __func__, __LINE__, \ 541*12967Sgavin.maltby@oracle.com FMEV_RULESET_DEFAULT, cl1, cl2, \ 542*12967Sgavin.maltby@oracle.com pri, \ 543*12967Sgavin.maltby@oracle.com ntuples, __VA_ARGS__) 544*12967Sgavin.maltby@oracle.com 545*12967Sgavin.maltby@oracle.com 546*12967Sgavin.maltby@oracle.com /* 547*12967Sgavin.maltby@oracle.com * fmev_rspublish (C99 version) - As fmev_publish, but with a chosen ruleset. 548*12967Sgavin.maltby@oracle.com */ 549*12967Sgavin.maltby@oracle.com #define fmev_rspublish(ruleset, cl1, cl2, pri, ntuples, ...) \ 550*12967Sgavin.maltby@oracle.com _i_fmev_publish( \ 551*12967Sgavin.maltby@oracle.com __FILE__, __func__, __LINE__, \ 552*12967Sgavin.maltby@oracle.com ruleset, cl1, cl2, \ 553*12967Sgavin.maltby@oracle.com pri, \ 554*12967Sgavin.maltby@oracle.com ntuples, __VA_ARGS__) 555*12967Sgavin.maltby@oracle.com 556*12967Sgavin.maltby@oracle.com #else 557*12967Sgavin.maltby@oracle.com 558*12967Sgavin.maltby@oracle.com /* 559*12967Sgavin.maltby@oracle.com * fmev_publish (pre C99) 560*12967Sgavin.maltby@oracle.com */ 561*12967Sgavin.maltby@oracle.com extern fmev_err_t fmev_publish(const char *, const char *, 562*12967Sgavin.maltby@oracle.com fmev_pri_t, uint_t, ...); 563*12967Sgavin.maltby@oracle.com 564*12967Sgavin.maltby@oracle.com /* 565*12967Sgavin.maltby@oracle.com * fmev_rspublish (pre C99) 566*12967Sgavin.maltby@oracle.com */ 567*12967Sgavin.maltby@oracle.com extern fmev_err_t fmev_rspublish(const char *, const char *, const char *, 568*12967Sgavin.maltby@oracle.com fmev_pri_t, uint_t, ...); 569*12967Sgavin.maltby@oracle.com 570*12967Sgavin.maltby@oracle.com #endif /* __STDC_VERSION__ */ 57111102SGavin.Maltby@Sun.COM 57211102SGavin.Maltby@Sun.COM #ifdef __cplusplus 57311102SGavin.Maltby@Sun.COM } 57411102SGavin.Maltby@Sun.COM #endif 57511102SGavin.Maltby@Sun.COM 57611102SGavin.Maltby@Sun.COM #endif /* _LIBFMEVENT_H */ 577