xref: /titanic_51/usr/src/lib/fm/libfmevent/common/libfmevent.h (revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa)
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 /*
23*f6e214c7SGavin 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).
33*f6e214c7SGavin 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.
52*f6e214c7SGavin Maltby  *
53*f6e214c7SGavin Maltby  *				Introduced in
54*f6e214c7SGavin Maltby  *	API Function		LIBFMEVENT_VERSION_*
55*f6e214c7SGavin Maltby  *	-----------------------	--------------------
56*f6e214c7SGavin Maltby  *	fmev_attr_list;		1
57*f6e214c7SGavin Maltby  *	fmev_class;		1
58*f6e214c7SGavin Maltby  *	fmev_dup;		1
59*f6e214c7SGavin Maltby  *	fmev_ev2shdl		2
60*f6e214c7SGavin Maltby  *	fmev_hold;		1
61*f6e214c7SGavin Maltby  *	fmev_localtime;		1
62*f6e214c7SGavin Maltby  *	fmev_rele;		1
63*f6e214c7SGavin Maltby  *	fmev_shdl_alloc;	1
64*f6e214c7SGavin Maltby  *	fmev_shdl_init;		1
65*f6e214c7SGavin Maltby  *	fmev_shdl_fini;		1
66*f6e214c7SGavin Maltby  *	fmev_shdl_free;		1
67*f6e214c7SGavin Maltby  *	fmev_shdl_getauthority	2
68*f6e214c7SGavin Maltby  *	fmev_shdl_nvl2str	2
69*f6e214c7SGavin Maltby  *	fmev_shdl_strdup	2
70*f6e214c7SGavin Maltby  *	fmev_shdl_strfree	2
71*f6e214c7SGavin Maltby  *	fmev_shdl_subscribe;	1
72*f6e214c7SGavin Maltby  *	fmev_shdl_unsubscribe;	1
73*f6e214c7SGavin Maltby  *	fmev_shdl_zalloc;	1
74*f6e214c7SGavin Maltby  *	fmev_shdlctl_serialize;	1
75*f6e214c7SGavin Maltby  *	fmev_shdlctl_sigmask;	1
76*f6e214c7SGavin Maltby  *	fmev_shdlctl_thrattr;	1
77*f6e214c7SGavin Maltby  *	fmev_shdlctl_thrcreate;	1
78*f6e214c7SGavin Maltby  *	fmev_shdlctl_thrsetup;	1
79*f6e214c7SGavin Maltby  *	fmev_strerror;		1
80*f6e214c7SGavin Maltby  *	fmev_timespec;		1
81*f6e214c7SGavin Maltby  *	fmev_time_nsec;		1
82*f6e214c7SGavin Maltby  *	fmev_time_sec;		1
8349b225e1SGavin Maltby  */
8449b225e1SGavin Maltby 
85*f6e214c7SGavin Maltby #define	LIBFMEVENT_VERSION_1	1
86*f6e214c7SGavin Maltby #define	LIBFMEVENT_VERSION_2	2
87*f6e214c7SGavin Maltby 
88*f6e214c7SGavin 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 */
111*f6e214c7SGavin Maltby     FMEVERR_INVALIDARG, /* Argument is invalid */
112*f6e214c7SGavin Maltby     FMEVERR_STRING2BIG, /* String argument exceeds maximum length */
113*f6e214c7SGavin Maltby     FMEVERR_VARARGS_MALFORMED, /* Varargs list bad or incorrectly terminated */
114*f6e214c7SGavin Maltby     FMEVERR_VARARGS_TOOLONG, /* Varargs list exceeds maximum length */
115*f6e214c7SGavin Maltby     FMEVERR_BADRULESET, /* Ruleset selected for publication is bad */
116*f6e214c7SGavin Maltby     FMEVERR_BADPRI, /* Priority selected for publication is bad */
117*f6e214c7SGavin Maltby     FMEVERR_TRANSPORT, /* Error in underlying event transport implementation */
118*f6e214c7SGavin 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  *
14649b225e1SGavin Maltby  * This is a Committed interface (see attributes(5) 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 
25149b225e1SGavin Maltby /*
252*f6e214c7SGavin Maltby  * Retrieve an authority nvlist for the fault manager that is forwarding
253*f6e214c7SGavin Maltby  * events to us.  This may be NULL if the fault manager has not yet
254*f6e214c7SGavin Maltby  * started up and made the information available.  The caller is
255*f6e214c7SGavin Maltby  * responsible for freeing the nvlist returned.
256*f6e214c7SGavin Maltby  */
257*f6e214c7SGavin Maltby extern fmev_err_t fmev_shdl_getauthority(fmev_shdl_t, nvlist_t **);
258*f6e214c7SGavin Maltby 
259*f6e214c7SGavin 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.
301*f6e214c7SGavin Maltby  *
302*f6e214c7SGavin Maltby  * An FMRI in an event payload is typically in nvlist form, i.e
303*f6e214c7SGavin Maltby  * DATA_TYPE_NVLIST.  That form is useful for extracting individual
304*f6e214c7SGavin Maltby  * component fields, but that requires knowledge of the FMRI scheme and
305*f6e214c7SGavin Maltby  * Public commitment thereof.  FMRIs are typically Private, but in some
306*f6e214c7SGavin Maltby  * cases they can be descriptive such as in listing the ASRU(s) affected
307*f6e214c7SGavin Maltby  * by a fault; so we offer an API member which will blindly render any
308*f6e214c7SGavin Maltby  * FMRI in its string form.  Use fmev_shdl_nvl2str to format an nvlist_t
309*f6e214c7SGavin Maltby  * as a string (if it is recognized as an FMRI); the caller is responsible
310*f6e214c7SGavin Maltby  * for freeing the returned string using fmev_shdl_strfree.  If
311*f6e214c7SGavin Maltby  * fmev_shdl_nvl2str fails it will return NULL with fmev_errno set -
312*f6e214c7SGavin Maltby  * FMEVERR_INVALIDARG if the nvlist_t does not appear to be a valid/known FMRI,
313*f6e214c7SGavin Maltby  * FMEVERR_ALLOC if an allocation for memory for the string failed.
314*f6e214c7SGavin Maltby  *
315*f6e214c7SGavin Maltby  * fmev_ev2shdl will return the fmev_shdl_t with which a received fmev_t
316*f6e214c7SGavin Maltby  * is associated.  It should only be used in an event delivery callback
317*f6e214c7SGavin 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 
332*f6e214c7SGavin Maltby extern char *fmev_shdl_nvl2str(fmev_shdl_t, nvlist_t *);
333*f6e214c7SGavin Maltby 
334*f6e214c7SGavin Maltby extern fmev_shdl_t fmev_ev2shdl(fmev_t);
335*f6e214c7SGavin 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);
343*f6e214c7SGavin Maltby extern char *fmev_shdl_strdup(fmev_shdl_t, char *);
344*f6e214c7SGavin Maltby extern void fmev_shdl_strfree(fmev_shdl_t, char *);
345*f6e214c7SGavin Maltby 
346*f6e214c7SGavin Maltby /*
347*f6e214c7SGavin Maltby  * Part B - Raw Event Publication
348*f6e214c7SGavin Maltby  * ======
349*f6e214c7SGavin Maltby  *
350*f6e214c7SGavin Maltby  * The following interfaces are private to the Solaris system and are
351*f6e214c7SGavin Maltby  * subject to change at any time without notice.  Applications using
352*f6e214c7SGavin Maltby  * these interfaces will fail to run on future releases.  The interfaces
353*f6e214c7SGavin Maltby  * should not be used for any purpose until they are publicly documented
354*f6e214c7SGavin Maltby  * for use outside of Sun.  These interface are *certain* to change
355*f6e214c7SGavin Maltby  * incompatibly, as the current interface is very much purpose-built for
356*f6e214c7SGavin Maltby  * a limited application.
357*f6e214c7SGavin Maltby  *
358*f6e214c7SGavin Maltby  * The interfaces below allow a process to publish a "raw" event
359*f6e214c7SGavin Maltby  * which will be transmitted to the fault manager and post-processed
360*f6e214c7SGavin Maltby  * into a full FMA protocol event.  The post-processing to be applied
361*f6e214c7SGavin Maltby  * is selected by a "ruleset" specified either implicitly or explicitly
362*f6e214c7SGavin Maltby  * at publication.  A ruleset will take the raw event (comprising
363*f6e214c7SGavin Maltby  * class, subclass, priority, raw payload) and mark it up into a full
364*f6e214c7SGavin Maltby  * protocol event; it may also augment the payload through looking up
365*f6e214c7SGavin Maltby  * details that would have been costly to compute at publication time.
366*f6e214c7SGavin Maltby  *
367*f6e214c7SGavin Maltby  * In this first implementation event dispatch is synchronous and blocking,
368*f6e214c7SGavin Maltby  * and not guaranteed to be re-entrant.  This limits the call sites
369*f6e214c7SGavin Maltby  * at which publication calls can be placed, and also means that careful
370*f6e214c7SGavin Maltby  * thought is required before sprinkling event publication code throughout
371*f6e214c7SGavin Maltby  * common system libraries.  The dispatch mechanism amounts to some
372*f6e214c7SGavin Maltby  * nvlist chicanery followed by a sysevent_evc_publish.  A future revision
373*f6e214c7SGavin Maltby  * will relax the context from which one may publish, and add more-powerful
374*f6e214c7SGavin Maltby  * publication interfaces.
375*f6e214c7SGavin Maltby  *
376*f6e214c7SGavin Maltby  * Some publication interfaces (those ending in _nvl) accept a preconstructed
377*f6e214c7SGavin Maltby  * nvlist as raw event payload.  We require that such an nvlist be of type
378*f6e214c7SGavin Maltby  * NV_UNIQUE_NAME.  The publication interfaces all call nvlist_free on any
379*f6e214c7SGavin Maltby  * nvlist that is passed for publication.
380*f6e214c7SGavin Maltby  *
381*f6e214c7SGavin Maltby  * Other publication interfaces allow you to build up the raw event payload
382*f6e214c7SGavin Maltby  * by specifying the members in a varargs list terminated by FMEV_ARG_TERM.
383*f6e214c7SGavin Maltby  * Again we require that payload member names are unique (that is, you cannot
384*f6e214c7SGavin Maltby  * have two members with the same name but different datatype).  See
385*f6e214c7SGavin Maltby  * <sys/nvpair.h> for the data_type_t enumeration of types supported - but
386*f6e214c7SGavin Maltby  * note that DATA_TYPE_BOOLEAN is excluded (DATA_TYPE_BOOLEAN_VALUE is
387*f6e214c7SGavin Maltby  * supported).  A single-valued (non-array type) member is specified with 3
388*f6e214c7SGavin Maltby  * consecutive varargs as:
389*f6e214c7SGavin Maltby  *
390*f6e214c7SGavin Maltby  *	(char *)name, DATA_TYPE_foo, (type)value
391*f6e214c7SGavin Maltby  *
392*f6e214c7SGavin Maltby  * An array-valued member is specified with 4 consecutive varargs as:
393*f6e214c7SGavin Maltby  *
394*f6e214c7SGavin Maltby  *	(char *)name, DATA_TYPE_foo_ARRAY, (int)nelem, (type *)arrayptr
395*f6e214c7SGavin Maltby  *
396*f6e214c7SGavin Maltby  * The varargs list that specifies the nvlist must begin with an
397*f6e214c7SGavin Maltby  * integer that specifies the number of members that follow.  For example:
398*f6e214c7SGavin Maltby  *
399*f6e214c7SGavin Maltby  * uint32_t mode;
400*f6e214c7SGavin Maltby  * char *clientname;
401*f6e214c7SGavin Maltby  * uint32_t ins[NARGS];
402*f6e214c7SGavin Maltby  *
403*f6e214c7SGavin Maltby  * fmev_publish("class", "subclass", FMEV_LOPRI,
404*f6e214c7SGavin Maltby  *	3,
405*f6e214c7SGavin Maltby  *	"mode", DATA_TYPE_UINT32, mode,
406*f6e214c7SGavin Maltby  *	"client", DATA_TYPE_STRING, clientname,
407*f6e214c7SGavin Maltby  *	"ins", DATA_TYPE_UINT32_ARRAY, sizeof (ins) / sizeof (ins[0]), ins,
408*f6e214c7SGavin Maltby  *	FMEV_ARG_TERM);
409*f6e214c7SGavin Maltby  *
410*f6e214c7SGavin Maltby  * The following tables summarize the capabilities of the various
411*f6e214c7SGavin Maltby  * publication interfaces.
412*f6e214c7SGavin Maltby  *
413*f6e214c7SGavin Maltby  *					     Detector
414*f6e214c7SGavin Maltby  * Interface			Ruleset? File/Line Func
415*f6e214c7SGavin Maltby  * ---------------------------- -------- --------- ----
416*f6e214c7SGavin Maltby  * fmev_publish_nvl		default	 Yes	   No
417*f6e214c7SGavin Maltby  * fmev_publish_nvl (C99)	default  Yes	   Yes
418*f6e214c7SGavin Maltby  * fmev_rspublish_nvl		chosen	 Yes	   No
419*f6e214c7SGavin Maltby  * fmev_rspublish_nvl (C99)	chosen	 Yes	   Yes
420*f6e214c7SGavin Maltby  * fmev_publish			default	 No	   No
421*f6e214c7SGavin Maltby  * fmev_publish (C99)		default	 Yes	   Yes
422*f6e214c7SGavin Maltby  * fmev_rspublish		chosen	 No	   No
423*f6e214c7SGavin Maltby  * fmev_rspublish (C99)		chosen	 Yes	   Yes
424*f6e214c7SGavin Maltby  *
425*f6e214c7SGavin Maltby  * Summary: if not using C99 then try to use the _nvl variants as the
426*f6e214c7SGavin Maltby  * varargs variants will not include file, line or function in the
427*f6e214c7SGavin Maltby  * detector.
428*f6e214c7SGavin Maltby  */
429*f6e214c7SGavin Maltby 
430*f6e214c7SGavin Maltby /*
431*f6e214c7SGavin Maltby  * In publishing an event you must select a "ruleset" (or accept the
432*f6e214c7SGavin Maltby  * defaults).  Rulesets are listed in the following header.
433*f6e214c7SGavin Maltby  */
434*f6e214c7SGavin Maltby #include <fm/libfmevent_ruleset.h>
435*f6e214c7SGavin Maltby 
436*f6e214c7SGavin Maltby /*
437*f6e214c7SGavin Maltby  * In publishing an event we can specify a class and subclass (which
438*f6e214c7SGavin Maltby  * in post-processing combine in some way selected by the ruleset to
439*f6e214c7SGavin Maltby  * form a full event protocol class).  The maximum class and subclass
440*f6e214c7SGavin Maltby  * string lengths are as follows.
441*f6e214c7SGavin Maltby  */
442*f6e214c7SGavin Maltby #define	FMEV_PUB_MAXCLASSLEN	32
443*f6e214c7SGavin Maltby #define	FMEV_PUB_MAXSUBCLASSLEN	32
444*f6e214c7SGavin Maltby 
445*f6e214c7SGavin Maltby /*
446*f6e214c7SGavin Maltby  * Events are either high-priority (try really hard not to lose) or
447*f6e214c7SGavin Maltby  * low-priority (can drop, throttle etc).  Convert a fmev_pri_t to
448*f6e214c7SGavin Maltby  * a string with fmev_pri_string().
449*f6e214c7SGavin Maltby  */
450*f6e214c7SGavin Maltby typedef enum fmev_pri {
451*f6e214c7SGavin Maltby 	FMEV_LOPRI = 0x1000,
452*f6e214c7SGavin Maltby 	FMEV_HIPRI
453*f6e214c7SGavin Maltby } fmev_pri_t;
454*f6e214c7SGavin Maltby 
455*f6e214c7SGavin Maltby extern const char *fmev_pri_string(fmev_pri_t);
456*f6e214c7SGavin Maltby 
457*f6e214c7SGavin Maltby /*
458*f6e214c7SGavin Maltby  * The varargs event publication interfaces must terminate the list
459*f6e214c7SGavin Maltby  * of nvpair specifications with FMEV_ARG_TERM.  This is to guard
460*f6e214c7SGavin Maltby  * against very easily-made mistakes in those arg lists.
461*f6e214c7SGavin Maltby  */
462*f6e214c7SGavin Maltby #define	FMEV_ARG_TERM	(void *)0xa4a3a2a1
463*f6e214c7SGavin Maltby 
464*f6e214c7SGavin Maltby /*
465*f6e214c7SGavin Maltby  * The following are NOT for direct use.
466*f6e214c7SGavin Maltby  */
467*f6e214c7SGavin Maltby extern fmev_err_t _i_fmev_publish_nvl(
468*f6e214c7SGavin Maltby     const char *, const char *, int64_t,
469*f6e214c7SGavin Maltby     const char *, const char *, const char *,
470*f6e214c7SGavin Maltby     fmev_pri_t, nvlist_t *);
471*f6e214c7SGavin Maltby 
472*f6e214c7SGavin Maltby extern fmev_err_t _i_fmev_publish(
473*f6e214c7SGavin Maltby     const char *, const char *, int64_t,
474*f6e214c7SGavin Maltby     const char *, const char *, const char *,
475*f6e214c7SGavin Maltby     fmev_pri_t,
476*f6e214c7SGavin Maltby     uint_t, ...);
477*f6e214c7SGavin Maltby 
478*f6e214c7SGavin Maltby /*
479*f6e214c7SGavin Maltby  * Post-processing will always generate a "detector" payload member.  In
480*f6e214c7SGavin Maltby  * the case of the _nvl publishing variants the detector information
481*f6e214c7SGavin Maltby  * includes file and line number, and - if your application is compiled
482*f6e214c7SGavin Maltby  * with C99 enabled - function name.
483*f6e214c7SGavin Maltby  */
484*f6e214c7SGavin Maltby #if __STDC_VERSION__ - 0 >= 199901L
485*f6e214c7SGavin Maltby #define	_FMEVFUNC	__func__
486*f6e214c7SGavin Maltby #else
487*f6e214c7SGavin Maltby #define	_FMEVFUNC	NULL
488*f6e214c7SGavin Maltby #endif
489*f6e214c7SGavin Maltby 
490*f6e214c7SGavin Maltby /*
491*f6e214c7SGavin Maltby  * All these definitions "return" an fmev_err_t.
492*f6e214c7SGavin Maltby  *
493*f6e214c7SGavin Maltby  * In the _nvl variants you pass a preconstructed event payload; otherwise
494*f6e214c7SGavin Maltby  * you include an integer indicating the number of payload
495*f6e214c7SGavin Maltby  * (name, type, value) tuples that follow, then all those tuples, finally
496*f6e214c7SGavin Maltby  * terminated by FMEV_ARG_TERM.
497*f6e214c7SGavin Maltby  *
498*f6e214c7SGavin Maltby  * In the rspublish variants you select a ruleset from
499*f6e214c7SGavin Maltby  * libfmevent_ruleset.h - just use the final suffix (as in
500*f6e214c7SGavin Maltby  * DEFAULT, EREPORT, ISV).
501*f6e214c7SGavin Maltby  *
502*f6e214c7SGavin Maltby  * The primary classification must not be NULL or the empty string.
503*f6e214c7SGavin Maltby  *
504*f6e214c7SGavin Maltby  *	arg	type		Description
505*f6e214c7SGavin Maltby  *	------- --------------- -------------------------------------------
506*f6e214c7SGavin Maltby  *	ruleset	const char *	Ruleset; can be NULL (implies default ruleset)
507*f6e214c7SGavin Maltby  *	cl1	const char *	Primary classification string
508*f6e214c7SGavin Maltby  *	cl2	const char *	Secondary classification string
509*f6e214c7SGavin Maltby  *	pri	fmev_pri_t	Priority
510*f6e214c7SGavin Maltby  *	nvl	nvlist_t *	Preconstructed attributes; caller must free
511*f6e214c7SGavin Maltby  *	ntuples	int		Number of tuples before FMEV_ARG_TERM
512*f6e214c7SGavin Maltby  *	suffix	-		See above.
513*f6e214c7SGavin Maltby  */
514*f6e214c7SGavin Maltby 
515*f6e214c7SGavin Maltby /*
516*f6e214c7SGavin Maltby  * fmev_publish_nvl - Default ruleset implied; class/subclass, pri and an nvl
517*f6e214c7SGavin Maltby  */
518*f6e214c7SGavin Maltby #define	fmev_publish_nvl(cl1, cl2, pri, nvl) \
519*f6e214c7SGavin Maltby 	_i_fmev_publish_nvl( \
520*f6e214c7SGavin Maltby 	    __FILE__, _FMEVFUNC, __LINE__, \
521*f6e214c7SGavin Maltby 	    FMEV_RULESET_DEFAULT, cl1, cl2, \
522*f6e214c7SGavin Maltby 	    pri, nvl)
523*f6e214c7SGavin Maltby 
524*f6e214c7SGavin Maltby /*
525*f6e214c7SGavin Maltby  * fmev_rspublish_nvl - As fmev_publish_nvl, but with a chosen ruleset.
526*f6e214c7SGavin Maltby  */
527*f6e214c7SGavin Maltby #define	fmev_rspublish_nvl(ruleset, cl1, cl2, pri, nvl) \
528*f6e214c7SGavin Maltby 	_i_fmev_publish_nvl( \
529*f6e214c7SGavin Maltby 	    __FILE__, _FMEVFUNC, __LINE__, \
530*f6e214c7SGavin Maltby 	    ruleset, cl1, cl2, \
531*f6e214c7SGavin Maltby 	    pri, nvl)
532*f6e214c7SGavin Maltby 
533*f6e214c7SGavin Maltby #if __STDC_VERSION__ - 0 >= 199901L && !defined(__lint)
534*f6e214c7SGavin Maltby 
535*f6e214c7SGavin Maltby /*
536*f6e214c7SGavin Maltby  * fmev_publish (C99 version) - Default ruleset; class/subclass, pri, nvpairs
537*f6e214c7SGavin Maltby  */
538*f6e214c7SGavin Maltby #define	fmev_publish(cl1, cl2, pri, ntuples, ...) \
539*f6e214c7SGavin Maltby 	_i_fmev_publish( \
540*f6e214c7SGavin Maltby 	    __FILE__, __func__, __LINE__, \
541*f6e214c7SGavin Maltby 	    FMEV_RULESET_DEFAULT, cl1, cl2, \
542*f6e214c7SGavin Maltby 	    pri, \
543*f6e214c7SGavin Maltby 	    ntuples, __VA_ARGS__)
544*f6e214c7SGavin Maltby 
545*f6e214c7SGavin Maltby 
546*f6e214c7SGavin Maltby /*
547*f6e214c7SGavin Maltby  * fmev_rspublish (C99 version) - As fmev_publish, but with a chosen ruleset.
548*f6e214c7SGavin Maltby  */
549*f6e214c7SGavin Maltby #define	fmev_rspublish(ruleset, cl1, cl2, pri, ntuples, ...) \
550*f6e214c7SGavin Maltby 	_i_fmev_publish( \
551*f6e214c7SGavin Maltby 	    __FILE__, __func__, __LINE__, \
552*f6e214c7SGavin Maltby 	    ruleset, cl1, cl2, \
553*f6e214c7SGavin Maltby 	    pri, \
554*f6e214c7SGavin Maltby 	    ntuples, __VA_ARGS__)
555*f6e214c7SGavin Maltby 
556*f6e214c7SGavin Maltby #else
557*f6e214c7SGavin Maltby 
558*f6e214c7SGavin Maltby /*
559*f6e214c7SGavin Maltby  * fmev_publish (pre C99)
560*f6e214c7SGavin Maltby  */
561*f6e214c7SGavin Maltby extern fmev_err_t fmev_publish(const char *, const char *,
562*f6e214c7SGavin Maltby     fmev_pri_t, uint_t, ...);
563*f6e214c7SGavin Maltby 
564*f6e214c7SGavin Maltby /*
565*f6e214c7SGavin Maltby  * fmev_rspublish (pre C99)
566*f6e214c7SGavin Maltby  */
567*f6e214c7SGavin Maltby extern fmev_err_t fmev_rspublish(const char *, const char *, const char *,
568*f6e214c7SGavin Maltby     fmev_pri_t, uint_t, ...);
569*f6e214c7SGavin Maltby 
570*f6e214c7SGavin Maltby #endif /* __STDC_VERSION__ */
57149b225e1SGavin Maltby 
57249b225e1SGavin Maltby #ifdef __cplusplus
57349b225e1SGavin Maltby }
57449b225e1SGavin Maltby #endif
57549b225e1SGavin Maltby 
57649b225e1SGavin Maltby #endif /* _LIBFMEVENT_H */
577