xref: /onnv-gate/usr/src/lib/fm/libfmd_log/common/fmd_log.h (revision 6640:c92ca9b95b9c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6640Scth  * Common Development and Distribution License (the "License").
6*6640Scth  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6640Scth  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_FMD_LOG_H
270Sstevel@tonic-gate #define	_FMD_LOG_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <libnvpair.h>
320Sstevel@tonic-gate #include <exacct.h>
33*6640Scth #include <regex.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Fault Management Daemon Log File Interfaces
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * Note: The contents of this file are private to the implementation of the
430Sstevel@tonic-gate  * Solaris system and FMD subsystem and are subject to change at any time
440Sstevel@tonic-gate  * without notice.  Applications and drivers using these interfaces will fail
450Sstevel@tonic-gate  * to run on future releases.  These interfaces should not be used for any
460Sstevel@tonic-gate  * purpose until they are publicly documented for use outside of Sun.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate 
491052Sdilpreet #define	FMD_LOG_VERSION	2		/* library ABI interface version */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate typedef struct fmd_log fmd_log_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate extern fmd_log_t *fmd_log_open(int, const char *, int *);
540Sstevel@tonic-gate extern void fmd_log_close(fmd_log_t *);
550Sstevel@tonic-gate extern const char *fmd_log_label(fmd_log_t *);
560Sstevel@tonic-gate 
570Sstevel@tonic-gate extern const char *fmd_log_errmsg(fmd_log_t *, int);
580Sstevel@tonic-gate extern int fmd_log_errno(fmd_log_t *);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef struct fmd_log_header {
610Sstevel@tonic-gate 	const char *log_creator;	/* ea_get_creator(3EXACCT) string */
620Sstevel@tonic-gate 	const char *log_hostname;	/* ea_get_hostname(3EXACCT) string */
630Sstevel@tonic-gate 	const char *log_label;		/* fmd(1M) log file label */
640Sstevel@tonic-gate 	const char *log_version;	/* fmd(1M) log file version */
650Sstevel@tonic-gate 	const char *log_osrelease;	/* uname(1) -r value at creation time */
660Sstevel@tonic-gate 	const char *log_osversion;	/* uname(1) -v value at creation time */
670Sstevel@tonic-gate 	const char *log_platform;	/* uname(1) -i value at creation time */
681052Sdilpreet 	const char *log_uuid;		/* fmd(1M) log file uuid */
690Sstevel@tonic-gate } fmd_log_header_t;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate extern void fmd_log_header(fmd_log_t *, fmd_log_header_t *);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate typedef struct fmd_log_record {
740Sstevel@tonic-gate 	ea_object_t *rec_grp;		/* log file exacct record group */
750Sstevel@tonic-gate 	nvlist_t *rec_nvl;		/* protocol name-value pair list */
760Sstevel@tonic-gate 	const char *rec_class;		/* protocol event class */
770Sstevel@tonic-gate 	uint64_t rec_sec;		/* time-of-day seconds */
780Sstevel@tonic-gate 	uint64_t rec_nsec;		/* time-of-day nanoseconds */
790Sstevel@tonic-gate 	struct fmd_log_record *rec_xrefs; /* array of cross-references */
800Sstevel@tonic-gate 	uint32_t rec_nrefs;		/* size of rec_xrefs array */
810Sstevel@tonic-gate 	off64_t rec_off;		/* file offset (if requested) */
820Sstevel@tonic-gate } fmd_log_record_t;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate typedef int fmd_log_rec_f(fmd_log_t *, const fmd_log_record_t *, void *);
850Sstevel@tonic-gate typedef int fmd_log_err_f(fmd_log_t *, void *);
860Sstevel@tonic-gate 
870Sstevel@tonic-gate extern int fmd_log_rewind(fmd_log_t *);
880Sstevel@tonic-gate extern int fmd_log_iter(fmd_log_t *, fmd_log_rec_f *, void *);
890Sstevel@tonic-gate extern int fmd_log_seek(fmd_log_t *, off64_t);
900Sstevel@tonic-gate 
910Sstevel@tonic-gate #define	FMD_LOG_XITER_REFS	0x1	/* load event cross-references */
920Sstevel@tonic-gate #define	FMD_LOG_XITER_OFFS	0x2	/* compute rec_off for each record */
930Sstevel@tonic-gate #define	FMD_LOG_XITER_MASK	0x3	/* mask of all valid flag bits */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate typedef struct fmd_log_filter {
960Sstevel@tonic-gate 	fmd_log_rec_f *filt_func;	/* filter function (see below) */
970Sstevel@tonic-gate 	void *filt_arg;			/* filter argument (see below) */
980Sstevel@tonic-gate } fmd_log_filter_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate extern fmd_log_rec_f fmd_log_filter_class;	/* char *name of event class */
1010Sstevel@tonic-gate extern fmd_log_rec_f fmd_log_filter_uuid;	/* char *uuid of list.suspect */
1020Sstevel@tonic-gate extern fmd_log_rec_f fmd_log_filter_before;	/* struct timeval * latest */
1030Sstevel@tonic-gate extern fmd_log_rec_f fmd_log_filter_after;	/* struct timeval * earliest */
104*6640Scth extern fmd_log_rec_f fmd_log_filter_nv;		/* char *namevalue in event */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate extern int fmd_log_filter(fmd_log_t *,
1070Sstevel@tonic-gate     uint_t, fmd_log_filter_t *, const fmd_log_record_t *);
1080Sstevel@tonic-gate 
109*6640Scth typedef struct fmd_log_filter_nvarg {
110*6640Scth 	char	*nvarg_name;
111*6640Scth 	char	*nvarg_value;
112*6640Scth 	regex_t	*nvarg_value_regex;
113*6640Scth } fmd_log_filter_nvarg_t;
114*6640Scth 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * fmd_log_xiter() can be used to perform sophisticated iteration over an fmd
1170Sstevel@tonic-gate  * log file such as that required by fmdump(1M).  The arguments are as follows:
1180Sstevel@tonic-gate  *
1190Sstevel@tonic-gate  * fmd_log_t *lp - log to use for iteration from fmd_log_open()
1200Sstevel@tonic-gate  * uint_t iflags - FMD_LOG_XITER_* flags (see above)
1210Sstevel@tonic-gate  * uint_t filtc - count of number of filters (or zero for no filtering)
1220Sstevel@tonic-gate  * fmd_log_filter_t *filtv - array of 'filtc' filter structures
1230Sstevel@tonic-gate  * fmd_log_rec_f *rfunc - function to invoke for each record in log
1240Sstevel@tonic-gate  * fmd_log_err_f *efunc - function to invoke for any errors in log
1250Sstevel@tonic-gate  * void *private - argument to pass to 'rfunc' and 'efunc' callbacks
1260Sstevel@tonic-gate  * ulong_t *cntp - pointer to storage for record count (or NULL)
1270Sstevel@tonic-gate  */
1280Sstevel@tonic-gate extern int fmd_log_xiter(fmd_log_t *, uint_t, uint_t, fmd_log_filter_t *,
1290Sstevel@tonic-gate     fmd_log_rec_f *, fmd_log_err_f *, void *, ulong_t *);
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #ifdef	__cplusplus
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate #endif
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #endif	/* _FMD_LOG_H */
136