149b225e1SGavin Maltby /* 249b225e1SGavin Maltby * CDDL HEADER START 349b225e1SGavin Maltby * 449b225e1SGavin Maltby * 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. 749b225e1SGavin Maltby * 849b225e1SGavin Maltby * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 949b225e1SGavin Maltby * or http://www.opensolaris.org/os/licensing. 1049b225e1SGavin Maltby * See the License for the specific language governing permissions 1149b225e1SGavin Maltby * and limitations under the License. 1249b225e1SGavin Maltby * 1349b225e1SGavin Maltby * When distributing Covered Code, include this CDDL HEADER in each 1449b225e1SGavin Maltby * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1549b225e1SGavin Maltby * If applicable, add the following below this CDDL HEADER, with the 1649b225e1SGavin Maltby * fields enclosed by brackets "[]" replaced with your own identifying 1749b225e1SGavin Maltby * information: Portions Copyright [yyyy] [name of copyright owner] 1849b225e1SGavin Maltby * 1949b225e1SGavin Maltby * CDDL HEADER END 2049b225e1SGavin Maltby */ 2149b225e1SGavin Maltby 2249b225e1SGavin Maltby /* 23f6e214c7SGavin Maltby * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2449b225e1SGavin Maltby */ 2549b225e1SGavin Maltby 2649b225e1SGavin Maltby #ifndef _LIBFMEVENT_H 2749b225e1SGavin Maltby #define _LIBFMEVENT_H 2849b225e1SGavin Maltby 2949b225e1SGavin Maltby /* 3049b225e1SGavin Maltby * FMA event library. 3149b225e1SGavin Maltby * 3249b225e1SGavin Maltby * A. Protocol event subscription interfaces (Committed). 33f6e214c7SGavin Maltby * B. Raw event publication interfaces (Consolidation Private). 3449b225e1SGavin Maltby */ 3549b225e1SGavin Maltby 3649b225e1SGavin Maltby #ifdef __cplusplus 3749b225e1SGavin Maltby extern "C" { 3849b225e1SGavin Maltby #endif 3949b225e1SGavin Maltby 4049b225e1SGavin Maltby #include <sys/types.h> 4149b225e1SGavin Maltby #include <libnvpair.h> 4249b225e1SGavin Maltby #include <stdlib.h> 4349b225e1SGavin Maltby #include <door.h> 4449b225e1SGavin Maltby #include <sys/time.h> 4549b225e1SGavin Maltby #include <sys/fm/protocol.h> 4649b225e1SGavin Maltby 4749b225e1SGavin Maltby /* 4849b225e1SGavin Maltby * Library ABI interface version. Quote the version you are using 4949b225e1SGavin Maltby * to fmev_shdl_init. Only interfaces introduced in or prior to the 5049b225e1SGavin Maltby * quoted version will be available. Once introduced an interface 5149b225e1SGavin Maltby * only ever changes compatibly. 52f6e214c7SGavin Maltby * 53f6e214c7SGavin Maltby * Introduced in 54f6e214c7SGavin Maltby * API Function LIBFMEVENT_VERSION_* 55f6e214c7SGavin Maltby * ----------------------- -------------------- 56f6e214c7SGavin Maltby * fmev_attr_list; 1 57f6e214c7SGavin Maltby * fmev_class; 1 58f6e214c7SGavin Maltby * fmev_dup; 1 59f6e214c7SGavin Maltby * fmev_ev2shdl 2 60f6e214c7SGavin Maltby * fmev_hold; 1 61f6e214c7SGavin Maltby * fmev_localtime; 1 62f6e214c7SGavin Maltby * fmev_rele; 1 63f6e214c7SGavin Maltby * fmev_shdl_alloc; 1 64f6e214c7SGavin Maltby * fmev_shdl_init; 1 65f6e214c7SGavin Maltby * fmev_shdl_fini; 1 66f6e214c7SGavin Maltby * fmev_shdl_free; 1 67f6e214c7SGavin Maltby * fmev_shdl_getauthority 2 68f6e214c7SGavin Maltby * fmev_shdl_nvl2str 2 69f6e214c7SGavin Maltby * fmev_shdl_strdup 2 70f6e214c7SGavin Maltby * fmev_shdl_strfree 2 71f6e214c7SGavin Maltby * fmev_shdl_subscribe; 1 72f6e214c7SGavin Maltby * fmev_shdl_unsubscribe; 1 73f6e214c7SGavin Maltby * fmev_shdl_zalloc; 1 74f6e214c7SGavin Maltby * fmev_shdlctl_serialize; 1 75f6e214c7SGavin Maltby * fmev_shdlctl_sigmask; 1 76f6e214c7SGavin Maltby * fmev_shdlctl_thrattr; 1 77f6e214c7SGavin Maltby * fmev_shdlctl_thrcreate; 1 78f6e214c7SGavin Maltby * fmev_shdlctl_thrsetup; 1 79f6e214c7SGavin Maltby * fmev_strerror; 1 80f6e214c7SGavin Maltby * fmev_timespec; 1 81f6e214c7SGavin Maltby * fmev_time_nsec; 1 82f6e214c7SGavin Maltby * fmev_time_sec; 1 8349b225e1SGavin Maltby */ 84f6e214c7SGavin Maltby 8549b225e1SGavin Maltby #define LIBFMEVENT_VERSION_1 1 86f6e214c7SGavin Maltby #define LIBFMEVENT_VERSION_2 2 8749b225e1SGavin Maltby 88f6e214c7SGavin Maltby #define LIBFMEVENT_VERSION_LATEST LIBFMEVENT_VERSION_2 8949b225e1SGavin Maltby 9049b225e1SGavin Maltby /* 9149b225e1SGavin Maltby * Success and error return values. The descriptive comment for each 9249b225e1SGavin Maltby * FMEVERR_* becomes the string that is returned by fmev_strerror for that 9349b225e1SGavin Maltby * error type. 9449b225e1SGavin Maltby */ 9549b225e1SGavin Maltby typedef enum { 9649b225e1SGavin Maltby FMEV_SUCCESS = 0, 9749b225e1SGavin Maltby FMEV_OK = FMEV_SUCCESS, /* alias for FMEV_SUCCESS */ 9849b225e1SGavin Maltby FMEVERR_UNKNOWN = 0xe000, /* Error details unknown */ 9949b225e1SGavin Maltby FMEVERR_VERSION_MISMATCH, /* Library ABI version incompatible with caller */ 10049b225e1SGavin Maltby FMEVERR_API, /* Library API usage violation */ 10149b225e1SGavin Maltby FMEVERR_ALLOC, /* Failed to allocate additional resources */ 10249b225e1SGavin Maltby FMEVERR_MALFORMED_EVENT, /* Event contents are inconsistent or corrupt */ 10349b225e1SGavin Maltby FMEVERR_OVERFLOW, /* Operation would overflow result type */ 10449b225e1SGavin Maltby FMEVERR_INTERNAL, /* Internal library error */ 10549b225e1SGavin Maltby FMEVERR_NOPRIV, /* Insufficient permissions or privilege */ 10649b225e1SGavin Maltby FMEVERR_BUSY, /* Resource is busy */ 10749b225e1SGavin Maltby FMEVERR_DUPLICATE, /* Duplicate request */ 10849b225e1SGavin Maltby FMEVERR_BADCLASS, /* Bad event class or class pattern */ 10949b225e1SGavin Maltby FMEVERR_NOMATCH, /* No match to criteria provided */ 11049b225e1SGavin Maltby FMEVERR_MAX_SUBSCRIBERS, /* Exceeds maximum subscribers per handle */ 111f6e214c7SGavin Maltby FMEVERR_INVALIDARG, /* Argument is invalid */ 112f6e214c7SGavin Maltby FMEVERR_STRING2BIG, /* String argument exceeds maximum length */ 113f6e214c7SGavin Maltby FMEVERR_VARARGS_MALFORMED, /* Varargs list bad or incorrectly terminated */ 114f6e214c7SGavin Maltby FMEVERR_VARARGS_TOOLONG, /* Varargs list exceeds maximum length */ 115f6e214c7SGavin Maltby FMEVERR_BADRULESET, /* Ruleset selected for publication is bad */ 116f6e214c7SGavin Maltby FMEVERR_BADPRI, /* Priority selected for publication is bad */ 117f6e214c7SGavin Maltby FMEVERR_TRANSPORT, /* Error in underlying event transport implementation */ 118f6e214c7SGavin Maltby FMEVERR_NVLIST /* nvlist argument is not of type NV_UNIQUE_NAME */ 11949b225e1SGavin Maltby } fmev_err_t; 12049b225e1SGavin Maltby 12149b225e1SGavin Maltby /* 12249b225e1SGavin Maltby * Some interfaces return an fmev_err_t - FMEV_SUCCESS on success, otherwise 12349b225e1SGavin Maltby * failure of the indicated type. You can use fmev_strerror to render an 12449b225e1SGavin Maltby * fmev_err_t into a string. 12549b225e1SGavin Maltby * 12649b225e1SGavin Maltby * Other interfaces do not return an fmev_err_t directly. For example 12749b225e1SGavin Maltby * where we return a pointer an error is indicated by a NULL return. 12849b225e1SGavin Maltby * In these cases you can retrieve the fmev_err_t describing the reason 12949b225e1SGavin Maltby * for the failure using fmev_errno or get a string with 13049b225e1SGavin Maltby * fmev_strerr(fmev_errno). Note that fmev_errno is per-thread and holds 13149b225e1SGavin Maltby * the error value for any error that occured during the last libfmevent 13249b225e1SGavin Maltby * API call made by the current thread. Use fmev_errno as you would 13349b225e1SGavin Maltby * regular errno, but you should not assign to fmev_errno. 13449b225e1SGavin Maltby */ 13549b225e1SGavin Maltby extern const fmev_err_t *__fmev_errno(void); /* do not use this directly */ 13649b225e1SGavin Maltby #define fmev_errno (*(__fmev_errno())) 13749b225e1SGavin Maltby extern const char *fmev_strerror(fmev_err_t); 13849b225e1SGavin Maltby 13949b225e1SGavin Maltby /* 14049b225e1SGavin Maltby * Part A - Protocol Event Subscription 14149b225e1SGavin Maltby * ====== 14249b225e1SGavin Maltby * 14349b225e1SGavin Maltby * Subscribe to FMA protocol events published by the fault management 14449b225e1SGavin Maltby * daemon, receiving a callback for each matching event. 14549b225e1SGavin Maltby * 146*bbf21555SRichard Lowe * This is a Committed interface (see attributes(7) for a definition). 14749b225e1SGavin Maltby */ 14849b225e1SGavin Maltby 14949b225e1SGavin Maltby /* 15049b225e1SGavin Maltby * Opaque subscription handle and event types. 15149b225e1SGavin Maltby */ 15249b225e1SGavin Maltby typedef struct fmev_shdl *fmev_shdl_t; 15349b225e1SGavin Maltby typedef struct fmev *fmev_t; 15449b225e1SGavin Maltby 15549b225e1SGavin Maltby /* 15649b225e1SGavin Maltby * Subscription callback function type for fmev_shdl_subscribe. 15749b225e1SGavin Maltby */ 15849b225e1SGavin Maltby typedef void fmev_cbfunc_t(fmev_t, const char *, nvlist_t *, void *); 15949b225e1SGavin Maltby 16049b225e1SGavin Maltby /* 16149b225e1SGavin Maltby * Initialize a new handle using fmev_shdl_init and quoting interface 16249b225e1SGavin Maltby * version number along with alloc, zalloc and free function pointers (all 16349b225e1SGavin Maltby * NULL to use the defaults. 16449b225e1SGavin Maltby * 16549b225e1SGavin Maltby * Close the handle and release resources with fmev_shdl_fini. 16649b225e1SGavin Maltby */ 16749b225e1SGavin Maltby 16849b225e1SGavin Maltby extern fmev_shdl_t fmev_shdl_init(uint32_t, 16949b225e1SGavin Maltby void *(*)(size_t), /* alloc */ 17049b225e1SGavin Maltby void *(*)(size_t), /* zalloc */ 17149b225e1SGavin Maltby void (*)(void *, size_t)); /* free */ 17249b225e1SGavin Maltby 17349b225e1SGavin Maltby extern fmev_err_t fmev_shdl_fini(fmev_shdl_t); 17449b225e1SGavin Maltby 17549b225e1SGavin Maltby /* 17649b225e1SGavin Maltby * Having created a handle you may optionally configure various properties 17749b225e1SGavin Maltby * for this handle using fmev_shdlctl_*. In most cases accepting the defaults 17849b225e1SGavin Maltby * (that are obtained through fmev_shdl_init alone) will provide adequate 17949b225e1SGavin Maltby * semantics - the controls below are provided for applications 18049b225e1SGavin Maltby * that require fine-grained control over event delivery semantics and, in 18149b225e1SGavin Maltby * particular, the service threads used to perform delivery callbacks. 18249b225e1SGavin Maltby * 18349b225e1SGavin Maltby * These controls may only be applied to a subscription handle 18449b225e1SGavin Maltby * that has no current subscriptions in place. You therefore cannot 18549b225e1SGavin Maltby * change the properties once subscriptions are established, and the 18649b225e1SGavin Maltby * handle properties apply uniformly to all subscriptions on that handle. 18749b225e1SGavin Maltby * If you require different properties per subscription then use multiple 18849b225e1SGavin Maltby * handles. 18949b225e1SGavin Maltby * 19049b225e1SGavin Maltby * fmev_shdlctl_serialize() will serialize all callbacks arising from all 19149b225e1SGavin Maltby * subscriptions on a handle. Event deliveries are normally single-threaded 19249b225e1SGavin Maltby * on a per-subscribtion bases, that is a call to fmev_shdl_subscribe 19349b225e1SGavin Maltby * will have deliveries arising from that subscription delivered 19449b225e1SGavin Maltby * in a serialized fashion on a single thread dedicated to the subscription. 19549b225e1SGavin Maltby * If multiple subscriptions are established then each has a dedicated 19649b225e1SGavin Maltby * delivery thread - fmev_shdlctl_serialize arranges that only one of these 19749b225e1SGavin Maltby * threads services a callback at any one time. 19849b225e1SGavin Maltby * 19949b225e1SGavin Maltby * fmev_shdlctl_thrattr() allows you to provide thread attributes for use 20049b225e1SGavin Maltby * in pthread_create() when server threads are created. The attributes 20149b225e1SGavin Maltby * are not copied - the pthread_attr_t object passed must exist for 20249b225e1SGavin Maltby * the duration of all subscriptions on the handle. These attributes only 20349b225e1SGavin Maltby * apply if fmev_shdlctl_thrcreate() is not in use on this handle. 20449b225e1SGavin Maltby * 20549b225e1SGavin Maltby * fmev_shdlctl_sigmask() allows you to provide a sigset_t signal mask 20649b225e1SGavin Maltby * of signals to block in server threads. The pthread_sigmask is set 20749b225e1SGavin Maltby * to this immediately before pthread_create, and restored immediately 20849b225e1SGavin Maltby * after pthread_create. This mask only applies if fmev_shdlctl_thrcreate() 20949b225e1SGavin Maltby * is not in use on this handle. 21049b225e1SGavin Maltby * 21149b225e1SGavin Maltby * fmev_shdlctl_thrsetup() allows you to install a custom door server thread 21249b225e1SGavin Maltby * setup function - see door_xcreate(3C). This will be used with the 21349b225e1SGavin Maltby * default thread creation semantics or with any custom thread creation 21449b225e1SGavin Maltby * function appointed with fmev_shdlctl_thrcreate(). 21549b225e1SGavin Maltby * 21649b225e1SGavin Maltby * fmev_shdlctl_thrcreate() allows you to install a custom door server thread 21749b225e1SGavin Maltby * creation function - see door_xcreate(3C). This option excludes 21849b225e1SGavin Maltby * fmev_shdlctl_{thrattr,sigmask} but the remaining options 21949b225e1SGavin Maltby * of fmev_shdlctl_{serialize,thrsetup} are still available. 22049b225e1SGavin Maltby */ 22149b225e1SGavin Maltby 22249b225e1SGavin Maltby extern fmev_err_t fmev_shdlctl_serialize(fmev_shdl_t); 22349b225e1SGavin Maltby extern fmev_err_t fmev_shdlctl_thrattr(fmev_shdl_t, pthread_attr_t *); 22449b225e1SGavin Maltby extern fmev_err_t fmev_shdlctl_sigmask(fmev_shdl_t, sigset_t *); 22549b225e1SGavin Maltby extern fmev_err_t fmev_shdlctl_thrsetup(fmev_shdl_t, 22649b225e1SGavin Maltby door_xcreate_thrsetup_func_t *, void *); 22749b225e1SGavin Maltby extern fmev_err_t fmev_shdlctl_thrcreate(fmev_shdl_t, 22849b225e1SGavin Maltby door_xcreate_server_func_t *, void *); 22949b225e1SGavin Maltby 23049b225e1SGavin Maltby /* 23149b225e1SGavin Maltby * Specify subscription choices on a handle using fmev_shdl_subscribe as 23249b225e1SGavin Maltby * many times as needed to describe the full event set. The event class 23349b225e1SGavin Maltby * pattern can be wildcarded using simple '*' wildcarding. When an event 23449b225e1SGavin Maltby * matching a subscription is received a callback is performed to the 23549b225e1SGavin Maltby * nominated function passing a fmev_t handle on the event and the 23649b225e1SGavin Maltby * requested cookie argument. 23749b225e1SGavin Maltby * 23849b225e1SGavin Maltby * See the fault management event protocol specification for a description 23949b225e1SGavin Maltby * of event classes. 24049b225e1SGavin Maltby * 24149b225e1SGavin Maltby * Drop a subscription using fmev_shdl_unsubscribe (which must match an 24249b225e1SGavin Maltby * earlier subscription). 24349b225e1SGavin Maltby */ 24449b225e1SGavin Maltby 24549b225e1SGavin Maltby #define FMEV_MAX_CLASS 64 /* Longest class string for subscription */ 24649b225e1SGavin Maltby 24749b225e1SGavin Maltby extern fmev_err_t fmev_shdl_subscribe(fmev_shdl_t, const char *, fmev_cbfunc_t, 24849b225e1SGavin Maltby void *); 24949b225e1SGavin Maltby extern fmev_err_t fmev_shdl_unsubscribe(fmev_shdl_t, const char *); 25049b225e1SGavin Maltby 251f6e214c7SGavin Maltby /* 252f6e214c7SGavin Maltby * Retrieve an authority nvlist for the fault manager that is forwarding 253f6e214c7SGavin Maltby * events to us. This may be NULL if the fault manager has not yet 254f6e214c7SGavin Maltby * started up and made the information available. The caller is 255f6e214c7SGavin Maltby * responsible for freeing the nvlist returned. 256f6e214c7SGavin Maltby */ 257f6e214c7SGavin Maltby extern fmev_err_t fmev_shdl_getauthority(fmev_shdl_t, nvlist_t **); 258f6e214c7SGavin Maltby 25949b225e1SGavin Maltby /* 26049b225e1SGavin Maltby * Event access. In the common case that the event is processed to 26149b225e1SGavin Maltby * completion in the context of the event callback you need only 26249b225e1SGavin Maltby * use fmev_attr_list to access the nvlist of event attributes, 26349b225e1SGavin Maltby * with no responsibility for freeing the event or the nvlist; for 26449b225e1SGavin Maltby * convenience, fmev_class and fmev_timestamp can both be used to 26549b225e1SGavin Maltby * look inside an event without having to work with the attribute list (and 26649b225e1SGavin Maltby * the callback receives the class as an argument). 26749b225e1SGavin Maltby * 26849b225e1SGavin Maltby * See libnvpair(3LIB) for interfaces to access an nvlist_t. 26949b225e1SGavin Maltby * 27049b225e1SGavin Maltby * The remaining interfaces apply in the case that event handling will 27149b225e1SGavin Maltby * continue beyond the context of the event callback in which it is received. 27249b225e1SGavin Maltby * 27349b225e1SGavin Maltby * The fmev_t handle received in a callback is reference-counted; 27449b225e1SGavin Maltby * the initial reference count on entry to the callback is 1, and the 27549b225e1SGavin Maltby * count is always decremented when the callback completes. To continue 27649b225e1SGavin Maltby * to operate on a received event outside of the context of the callback 27749b225e1SGavin Maltby * in which it is first received, take an fmev_hold during the callback 27849b225e1SGavin Maltby * and later fmev_rele to release your hold (and free the event if the count 27949b225e1SGavin Maltby * drops to 0). 28049b225e1SGavin Maltby * 28149b225e1SGavin Maltby * To access attributes of an event use fmev_attr_list to receive 28249b225e1SGavin Maltby * an nvlist_t pointer valid for the same lifetime as the event itself (i.e., 28349b225e1SGavin Maltby * until its reference count drops to zero). 28449b225e1SGavin Maltby * 28549b225e1SGavin Maltby * If changes are made to a received fmev_t (discouraged) then all who 28649b225e1SGavin Maltby * have a hold on the event share the change. To obtain an independent 28749b225e1SGavin Maltby * copy of an fmev_t, with a reference count of 1, use fmev_dup. When 28849b225e1SGavin Maltby * finished with the copy decrement the reference count 28949b225e1SGavin Maltby * using fmev_rele - the event will be freed if the count reaches 0. 29049b225e1SGavin Maltby * 29149b225e1SGavin Maltby * For convenience you can retrieve the class of an event using fmev_class 29249b225e1SGavin Maltby * (it's also available as an argument to a callback, and within the 29349b225e1SGavin Maltby * event attribute list). The string returned by fmev_class is valid for 29449b225e1SGavin Maltby * the same lifetime as the event itself. 29549b225e1SGavin Maltby * 29649b225e1SGavin Maltby * The time at which a protocol event was generated is available via 29749b225e1SGavin Maltby * fmev_timespec; tv_sec has seconds since the epoch, and tv_nsec nanoseconds 29849b225e1SGavin Maltby * past that second. This can fail with FMEVERR_OVERFLOW if the seconds 29949b225e1SGavin Maltby * value does not fit within a time_t; you can retrieve the 64-bit second 30049b225e1SGavin Maltby * and nanosecond values with fmev_time_sec and fmev_time_nsec. 301f6e214c7SGavin Maltby * 302f6e214c7SGavin Maltby * An FMRI in an event payload is typically in nvlist form, i.e 303f6e214c7SGavin Maltby * DATA_TYPE_NVLIST. That form is useful for extracting individual 304f6e214c7SGavin Maltby * component fields, but that requires knowledge of the FMRI scheme and 305f6e214c7SGavin Maltby * Public commitment thereof. FMRIs are typically Private, but in some 306f6e214c7SGavin Maltby * cases they can be descriptive such as in listing the ASRU(s) affected 307f6e214c7SGavin Maltby * by a fault; so we offer an API member which will blindly render any 308f6e214c7SGavin Maltby * FMRI in its string form. Use fmev_shdl_nvl2str to format an nvlist_t 309f6e214c7SGavin Maltby * as a string (if it is recognized as an FMRI); the caller is responsible 310f6e214c7SGavin Maltby * for freeing the returned string using fmev_shdl_strfree. If 311f6e214c7SGavin Maltby * fmev_shdl_nvl2str fails it will return NULL with fmev_errno set - 312f6e214c7SGavin Maltby * FMEVERR_INVALIDARG if the nvlist_t does not appear to be a valid/known FMRI, 313f6e214c7SGavin Maltby * FMEVERR_ALLOC if an allocation for memory for the string failed. 314f6e214c7SGavin Maltby * 315f6e214c7SGavin Maltby * fmev_ev2shdl will return the fmev_shdl_t with which a received fmev_t 316f6e214c7SGavin Maltby * is associated. It should only be used in an event delivery callback 317f6e214c7SGavin Maltby * context and for the event received in that callback. 31849b225e1SGavin Maltby */ 31949b225e1SGavin Maltby 32049b225e1SGavin Maltby extern nvlist_t *fmev_attr_list(fmev_t); 32149b225e1SGavin Maltby extern const char *fmev_class(fmev_t); 32249b225e1SGavin Maltby 32349b225e1SGavin Maltby extern fmev_err_t fmev_timespec(fmev_t, struct timespec *); 32449b225e1SGavin Maltby extern uint64_t fmev_time_sec(fmev_t); 32549b225e1SGavin Maltby extern uint64_t fmev_time_nsec(fmev_t); 32649b225e1SGavin Maltby extern struct tm *fmev_localtime(fmev_t, struct tm *); 32749b225e1SGavin Maltby 32849b225e1SGavin Maltby extern void fmev_hold(fmev_t); 32949b225e1SGavin Maltby extern void fmev_rele(fmev_t); 33049b225e1SGavin Maltby extern fmev_t fmev_dup(fmev_t); 33149b225e1SGavin Maltby 332f6e214c7SGavin Maltby extern char *fmev_shdl_nvl2str(fmev_shdl_t, nvlist_t *); 333f6e214c7SGavin Maltby 334f6e214c7SGavin Maltby extern fmev_shdl_t fmev_ev2shdl(fmev_t); 335f6e214c7SGavin Maltby 33649b225e1SGavin Maltby /* 33749b225e1SGavin Maltby * The following will allocate and free memory based on the choices made 33849b225e1SGavin Maltby * at fmev_shdl_init. 33949b225e1SGavin Maltby */ 34049b225e1SGavin Maltby void *fmev_shdl_alloc(fmev_shdl_t, size_t); 34149b225e1SGavin Maltby void *fmev_shdl_zalloc(fmev_shdl_t, size_t); 34249b225e1SGavin Maltby void fmev_shdl_free(fmev_shdl_t, void *, size_t); 343f6e214c7SGavin Maltby extern char *fmev_shdl_strdup(fmev_shdl_t, char *); 344f6e214c7SGavin Maltby extern void fmev_shdl_strfree(fmev_shdl_t, char *); 345f6e214c7SGavin Maltby 346f6e214c7SGavin Maltby /* 347f6e214c7SGavin Maltby * Part B - Raw Event Publication 348f6e214c7SGavin Maltby * ====== 349f6e214c7SGavin Maltby * 350f6e214c7SGavin Maltby * The following interfaces are private to the Solaris system and are 351f6e214c7SGavin Maltby * subject to change at any time without notice. Applications using 352f6e214c7SGavin Maltby * these interfaces will fail to run on future releases. The interfaces 353f6e214c7SGavin Maltby * should not be used for any purpose until they are publicly documented 354f6e214c7SGavin Maltby * for use outside of Sun. These interface are *certain* to change 355f6e214c7SGavin Maltby * incompatibly, as the current interface is very much purpose-built for 356f6e214c7SGavin Maltby * a limited application. 357f6e214c7SGavin Maltby * 358f6e214c7SGavin Maltby * The interfaces below allow a process to publish a "raw" event 359f6e214c7SGavin Maltby * which will be transmitted to the fault manager and post-processed 360f6e214c7SGavin Maltby * into a full FMA protocol event. The post-processing to be applied 361f6e214c7SGavin Maltby * is selected by a "ruleset" specified either implicitly or explicitly 362f6e214c7SGavin Maltby * at publication. A ruleset will take the raw event (comprising 363f6e214c7SGavin Maltby * class, subclass, priority, raw payload) and mark it up into a full 364f6e214c7SGavin Maltby * protocol event; it may also augment the payload through looking up 365f6e214c7SGavin Maltby * details that would have been costly to compute at publication time. 366f6e214c7SGavin Maltby * 367f6e214c7SGavin Maltby * In this first implementation event dispatch is synchronous and blocking, 368f6e214c7SGavin Maltby * and not guaranteed to be re-entrant. This limits the call sites 369f6e214c7SGavin Maltby * at which publication calls can be placed, and also means that careful 370f6e214c7SGavin Maltby * thought is required before sprinkling event publication code throughout 371f6e214c7SGavin Maltby * common system libraries. The dispatch mechanism amounts to some 372f6e214c7SGavin Maltby * nvlist chicanery followed by a sysevent_evc_publish. A future revision 373f6e214c7SGavin Maltby * will relax the context from which one may publish, and add more-powerful 374f6e214c7SGavin Maltby * publication interfaces. 375f6e214c7SGavin Maltby * 376f6e214c7SGavin Maltby * Some publication interfaces (those ending in _nvl) accept a preconstructed 377f6e214c7SGavin Maltby * nvlist as raw event payload. We require that such an nvlist be of type 378f6e214c7SGavin Maltby * NV_UNIQUE_NAME. The publication interfaces all call nvlist_free on any 379f6e214c7SGavin Maltby * nvlist that is passed for publication. 380f6e214c7SGavin Maltby * 381f6e214c7SGavin Maltby * Other publication interfaces allow you to build up the raw event payload 382f6e214c7SGavin Maltby * by specifying the members in a varargs list terminated by FMEV_ARG_TERM. 383f6e214c7SGavin Maltby * Again we require that payload member names are unique (that is, you cannot 384f6e214c7SGavin Maltby * have two members with the same name but different datatype). See 385f6e214c7SGavin Maltby * <sys/nvpair.h> for the data_type_t enumeration of types supported - but 386f6e214c7SGavin Maltby * note that DATA_TYPE_BOOLEAN is excluded (DATA_TYPE_BOOLEAN_VALUE is 387f6e214c7SGavin Maltby * supported). A single-valued (non-array type) member is specified with 3 388f6e214c7SGavin Maltby * consecutive varargs as: 389f6e214c7SGavin Maltby * 390f6e214c7SGavin Maltby * (char *)name, DATA_TYPE_foo, (type)value 391f6e214c7SGavin Maltby * 392f6e214c7SGavin Maltby * An array-valued member is specified with 4 consecutive varargs as: 393f6e214c7SGavin Maltby * 394f6e214c7SGavin Maltby * (char *)name, DATA_TYPE_foo_ARRAY, (int)nelem, (type *)arrayptr 395f6e214c7SGavin Maltby * 396f6e214c7SGavin Maltby * The varargs list that specifies the nvlist must begin with an 397f6e214c7SGavin Maltby * integer that specifies the number of members that follow. For example: 398f6e214c7SGavin Maltby * 399f6e214c7SGavin Maltby * uint32_t mode; 400f6e214c7SGavin Maltby * char *clientname; 401f6e214c7SGavin Maltby * uint32_t ins[NARGS]; 402f6e214c7SGavin Maltby * 403f6e214c7SGavin Maltby * fmev_publish("class", "subclass", FMEV_LOPRI, 404f6e214c7SGavin Maltby * 3, 405f6e214c7SGavin Maltby * "mode", DATA_TYPE_UINT32, mode, 406f6e214c7SGavin Maltby * "client", DATA_TYPE_STRING, clientname, 407f6e214c7SGavin Maltby * "ins", DATA_TYPE_UINT32_ARRAY, sizeof (ins) / sizeof (ins[0]), ins, 408f6e214c7SGavin Maltby * FMEV_ARG_TERM); 409f6e214c7SGavin Maltby * 410f6e214c7SGavin Maltby * The following tables summarize the capabilities of the various 411f6e214c7SGavin Maltby * publication interfaces. 412f6e214c7SGavin Maltby * 413f6e214c7SGavin Maltby * Detector 414f6e214c7SGavin Maltby * Interface Ruleset? File/Line Func 415f6e214c7SGavin Maltby * ---------------------------- -------- --------- ---- 416f6e214c7SGavin Maltby * fmev_publish_nvl default Yes No 417f6e214c7SGavin Maltby * fmev_publish_nvl (C99) default Yes Yes 418f6e214c7SGavin Maltby * fmev_rspublish_nvl chosen Yes No 419f6e214c7SGavin Maltby * fmev_rspublish_nvl (C99) chosen Yes Yes 420f6e214c7SGavin Maltby * fmev_publish default No No 421f6e214c7SGavin Maltby * fmev_publish (C99) default Yes Yes 422f6e214c7SGavin Maltby * fmev_rspublish chosen No No 423f6e214c7SGavin Maltby * fmev_rspublish (C99) chosen Yes Yes 424f6e214c7SGavin Maltby * 425f6e214c7SGavin Maltby * Summary: if not using C99 then try to use the _nvl variants as the 426f6e214c7SGavin Maltby * varargs variants will not include file, line or function in the 427f6e214c7SGavin Maltby * detector. 428f6e214c7SGavin Maltby */ 429f6e214c7SGavin Maltby 430f6e214c7SGavin Maltby /* 431f6e214c7SGavin Maltby * In publishing an event you must select a "ruleset" (or accept the 432f6e214c7SGavin Maltby * defaults). Rulesets are listed in the following header. 433f6e214c7SGavin Maltby */ 434f6e214c7SGavin Maltby #include <fm/libfmevent_ruleset.h> 435f6e214c7SGavin Maltby 436f6e214c7SGavin Maltby /* 437f6e214c7SGavin Maltby * In publishing an event we can specify a class and subclass (which 438f6e214c7SGavin Maltby * in post-processing combine in some way selected by the ruleset to 439f6e214c7SGavin Maltby * form a full event protocol class). The maximum class and subclass 440f6e214c7SGavin Maltby * string lengths are as follows. 441f6e214c7SGavin Maltby */ 442f6e214c7SGavin Maltby #define FMEV_PUB_MAXCLASSLEN 32 443f6e214c7SGavin Maltby #define FMEV_PUB_MAXSUBCLASSLEN 32 444f6e214c7SGavin Maltby 445f6e214c7SGavin Maltby /* 446f6e214c7SGavin Maltby * Events are either high-priority (try really hard not to lose) or 447f6e214c7SGavin Maltby * low-priority (can drop, throttle etc). Convert a fmev_pri_t to 448f6e214c7SGavin Maltby * a string with fmev_pri_string(). 449f6e214c7SGavin Maltby */ 450f6e214c7SGavin Maltby typedef enum fmev_pri { 451f6e214c7SGavin Maltby FMEV_LOPRI = 0x1000, 452f6e214c7SGavin Maltby FMEV_HIPRI 453f6e214c7SGavin Maltby } fmev_pri_t; 454f6e214c7SGavin Maltby 455f6e214c7SGavin Maltby extern const char *fmev_pri_string(fmev_pri_t); 456f6e214c7SGavin Maltby 457f6e214c7SGavin Maltby /* 458f6e214c7SGavin Maltby * The varargs event publication interfaces must terminate the list 459f6e214c7SGavin Maltby * of nvpair specifications with FMEV_ARG_TERM. This is to guard 460f6e214c7SGavin Maltby * against very easily-made mistakes in those arg lists. 461f6e214c7SGavin Maltby */ 462f6e214c7SGavin Maltby #define FMEV_ARG_TERM (void *)0xa4a3a2a1 463f6e214c7SGavin Maltby 464f6e214c7SGavin Maltby /* 465f6e214c7SGavin Maltby * The following are NOT for direct use. 466f6e214c7SGavin Maltby */ 467f6e214c7SGavin Maltby extern fmev_err_t _i_fmev_publish_nvl( 468f6e214c7SGavin Maltby const char *, const char *, int64_t, 469f6e214c7SGavin Maltby const char *, const char *, const char *, 470f6e214c7SGavin Maltby fmev_pri_t, nvlist_t *); 471f6e214c7SGavin Maltby 472f6e214c7SGavin Maltby extern fmev_err_t _i_fmev_publish( 473f6e214c7SGavin Maltby const char *, const char *, int64_t, 474f6e214c7SGavin Maltby const char *, const char *, const char *, 475f6e214c7SGavin Maltby fmev_pri_t, 476f6e214c7SGavin Maltby uint_t, ...); 477f6e214c7SGavin Maltby 478f6e214c7SGavin Maltby /* 479f6e214c7SGavin Maltby * Post-processing will always generate a "detector" payload member. In 480f6e214c7SGavin Maltby * the case of the _nvl publishing variants the detector information 481f6e214c7SGavin Maltby * includes file and line number, and - if your application is compiled 482f6e214c7SGavin Maltby * with C99 enabled - function name. 483f6e214c7SGavin Maltby */ 484f6e214c7SGavin Maltby #if __STDC_VERSION__ - 0 >= 199901L 485f6e214c7SGavin Maltby #define _FMEVFUNC __func__ 486f6e214c7SGavin Maltby #else 487f6e214c7SGavin Maltby #define _FMEVFUNC NULL 488f6e214c7SGavin Maltby #endif 489f6e214c7SGavin Maltby 490f6e214c7SGavin Maltby /* 491f6e214c7SGavin Maltby * All these definitions "return" an fmev_err_t. 492f6e214c7SGavin Maltby * 493f6e214c7SGavin Maltby * In the _nvl variants you pass a preconstructed event payload; otherwise 494f6e214c7SGavin Maltby * you include an integer indicating the number of payload 495f6e214c7SGavin Maltby * (name, type, value) tuples that follow, then all those tuples, finally 496f6e214c7SGavin Maltby * terminated by FMEV_ARG_TERM. 497f6e214c7SGavin Maltby * 498f6e214c7SGavin Maltby * In the rspublish variants you select a ruleset from 499f6e214c7SGavin Maltby * libfmevent_ruleset.h - just use the final suffix (as in 500f6e214c7SGavin Maltby * DEFAULT, EREPORT, ISV). 501f6e214c7SGavin Maltby * 502f6e214c7SGavin Maltby * The primary classification must not be NULL or the empty string. 503f6e214c7SGavin Maltby * 504f6e214c7SGavin Maltby * arg type Description 505f6e214c7SGavin Maltby * ------- --------------- ------------------------------------------- 506f6e214c7SGavin Maltby * ruleset const char * Ruleset; can be NULL (implies default ruleset) 507f6e214c7SGavin Maltby * cl1 const char * Primary classification string 508f6e214c7SGavin Maltby * cl2 const char * Secondary classification string 509f6e214c7SGavin Maltby * pri fmev_pri_t Priority 510f6e214c7SGavin Maltby * nvl nvlist_t * Preconstructed attributes; caller must free 511f6e214c7SGavin Maltby * ntuples int Number of tuples before FMEV_ARG_TERM 512f6e214c7SGavin Maltby * suffix - See above. 513f6e214c7SGavin Maltby */ 514f6e214c7SGavin Maltby 515f6e214c7SGavin Maltby /* 516f6e214c7SGavin Maltby * fmev_publish_nvl - Default ruleset implied; class/subclass, pri and an nvl 517f6e214c7SGavin Maltby */ 518f6e214c7SGavin Maltby #define fmev_publish_nvl(cl1, cl2, pri, nvl) \ 519f6e214c7SGavin Maltby _i_fmev_publish_nvl( \ 520f6e214c7SGavin Maltby __FILE__, _FMEVFUNC, __LINE__, \ 521f6e214c7SGavin Maltby FMEV_RULESET_DEFAULT, cl1, cl2, \ 522f6e214c7SGavin Maltby pri, nvl) 523f6e214c7SGavin Maltby 524f6e214c7SGavin Maltby /* 525f6e214c7SGavin Maltby * fmev_rspublish_nvl - As fmev_publish_nvl, but with a chosen ruleset. 526f6e214c7SGavin Maltby */ 527f6e214c7SGavin Maltby #define fmev_rspublish_nvl(ruleset, cl1, cl2, pri, nvl) \ 528f6e214c7SGavin Maltby _i_fmev_publish_nvl( \ 529f6e214c7SGavin Maltby __FILE__, _FMEVFUNC, __LINE__, \ 530f6e214c7SGavin Maltby ruleset, cl1, cl2, \ 531f6e214c7SGavin Maltby pri, nvl) 532f6e214c7SGavin Maltby 533f6e214c7SGavin Maltby #if __STDC_VERSION__ - 0 >= 199901L && !defined(__lint) 534f6e214c7SGavin Maltby 535f6e214c7SGavin Maltby /* 536f6e214c7SGavin Maltby * fmev_publish (C99 version) - Default ruleset; class/subclass, pri, nvpairs 537f6e214c7SGavin Maltby */ 538f6e214c7SGavin Maltby #define fmev_publish(cl1, cl2, pri, ntuples, ...) \ 539f6e214c7SGavin Maltby _i_fmev_publish( \ 540f6e214c7SGavin Maltby __FILE__, __func__, __LINE__, \ 541f6e214c7SGavin Maltby FMEV_RULESET_DEFAULT, cl1, cl2, \ 542f6e214c7SGavin Maltby pri, \ 543f6e214c7SGavin Maltby ntuples, __VA_ARGS__) 544f6e214c7SGavin Maltby 545f6e214c7SGavin Maltby 546f6e214c7SGavin Maltby /* 547f6e214c7SGavin Maltby * fmev_rspublish (C99 version) - As fmev_publish, but with a chosen ruleset. 548f6e214c7SGavin Maltby */ 549f6e214c7SGavin Maltby #define fmev_rspublish(ruleset, cl1, cl2, pri, ntuples, ...) \ 550f6e214c7SGavin Maltby _i_fmev_publish( \ 551f6e214c7SGavin Maltby __FILE__, __func__, __LINE__, \ 552f6e214c7SGavin Maltby ruleset, cl1, cl2, \ 553f6e214c7SGavin Maltby pri, \ 554f6e214c7SGavin Maltby ntuples, __VA_ARGS__) 555f6e214c7SGavin Maltby 556f6e214c7SGavin Maltby #else 557f6e214c7SGavin Maltby 558f6e214c7SGavin Maltby /* 559f6e214c7SGavin Maltby * fmev_publish (pre C99) 560f6e214c7SGavin Maltby */ 561f6e214c7SGavin Maltby extern fmev_err_t fmev_publish(const char *, const char *, 562f6e214c7SGavin Maltby fmev_pri_t, uint_t, ...); 563f6e214c7SGavin Maltby 564f6e214c7SGavin Maltby /* 565f6e214c7SGavin Maltby * fmev_rspublish (pre C99) 566f6e214c7SGavin Maltby */ 567f6e214c7SGavin Maltby extern fmev_err_t fmev_rspublish(const char *, const char *, const char *, 568f6e214c7SGavin Maltby fmev_pri_t, uint_t, ...); 569f6e214c7SGavin Maltby 570f6e214c7SGavin Maltby #endif /* __STDC_VERSION__ */ 57149b225e1SGavin Maltby 57249b225e1SGavin Maltby #ifdef __cplusplus 57349b225e1SGavin Maltby } 57449b225e1SGavin Maltby #endif 57549b225e1SGavin Maltby 57649b225e1SGavin Maltby #endif /* _LIBFMEVENT_H */ 577