xref: /illumos-gate/usr/src/lib/fm/libfmd_log/common/fmd_log.h (revision 6918308b4f7a98b1ab7146af715a679a95b03288)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_LOG_H
28 #define	_FMD_LOG_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <libnvpair.h>
33 #include <exacct.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Fault Management Daemon Log File Interfaces
41  *
42  * Note: The contents of this file are private to the implementation of the
43  * Solaris system and FMD subsystem and are subject to change at any time
44  * without notice.  Applications and drivers using these interfaces will fail
45  * to run on future releases.  These interfaces should not be used for any
46  * purpose until they are publicly documented for use outside of Sun.
47  */
48 
49 #define	FMD_LOG_VERSION	2		/* library ABI interface version */
50 
51 typedef struct fmd_log fmd_log_t;
52 
53 extern fmd_log_t *fmd_log_open(int, const char *, int *);
54 extern void fmd_log_close(fmd_log_t *);
55 extern const char *fmd_log_label(fmd_log_t *);
56 
57 extern const char *fmd_log_errmsg(fmd_log_t *, int);
58 extern int fmd_log_errno(fmd_log_t *);
59 
60 typedef struct fmd_log_header {
61 	const char *log_creator;	/* ea_get_creator(3EXACCT) string */
62 	const char *log_hostname;	/* ea_get_hostname(3EXACCT) string */
63 	const char *log_label;		/* fmd(1M) log file label */
64 	const char *log_version;	/* fmd(1M) log file version */
65 	const char *log_osrelease;	/* uname(1) -r value at creation time */
66 	const char *log_osversion;	/* uname(1) -v value at creation time */
67 	const char *log_platform;	/* uname(1) -i value at creation time */
68 	const char *log_uuid;		/* fmd(1M) log file uuid */
69 } fmd_log_header_t;
70 
71 extern void fmd_log_header(fmd_log_t *, fmd_log_header_t *);
72 
73 typedef struct fmd_log_record {
74 	ea_object_t *rec_grp;		/* log file exacct record group */
75 	nvlist_t *rec_nvl;		/* protocol name-value pair list */
76 	const char *rec_class;		/* protocol event class */
77 	uint64_t rec_sec;		/* time-of-day seconds */
78 	uint64_t rec_nsec;		/* time-of-day nanoseconds */
79 	struct fmd_log_record *rec_xrefs; /* array of cross-references */
80 	uint32_t rec_nrefs;		/* size of rec_xrefs array */
81 	off64_t rec_off;		/* file offset (if requested) */
82 } fmd_log_record_t;
83 
84 typedef int fmd_log_rec_f(fmd_log_t *, const fmd_log_record_t *, void *);
85 typedef int fmd_log_err_f(fmd_log_t *, void *);
86 
87 extern int fmd_log_rewind(fmd_log_t *);
88 extern int fmd_log_iter(fmd_log_t *, fmd_log_rec_f *, void *);
89 extern int fmd_log_seek(fmd_log_t *, off64_t);
90 
91 #define	FMD_LOG_XITER_REFS	0x1	/* load event cross-references */
92 #define	FMD_LOG_XITER_OFFS	0x2	/* compute rec_off for each record */
93 #define	FMD_LOG_XITER_MASK	0x3	/* mask of all valid flag bits */
94 
95 typedef struct fmd_log_filter {
96 	fmd_log_rec_f *filt_func;	/* filter function (see below) */
97 	void *filt_arg;			/* filter argument (see below) */
98 } fmd_log_filter_t;
99 
100 extern fmd_log_rec_f fmd_log_filter_class;	/* char *name of event class */
101 extern fmd_log_rec_f fmd_log_filter_uuid;	/* char *uuid of list.suspect */
102 extern fmd_log_rec_f fmd_log_filter_before;	/* struct timeval * latest */
103 extern fmd_log_rec_f fmd_log_filter_after;	/* struct timeval * earliest */
104 
105 extern int fmd_log_filter(fmd_log_t *,
106     uint_t, fmd_log_filter_t *, const fmd_log_record_t *);
107 
108 /*
109  * fmd_log_xiter() can be used to perform sophisticated iteration over an fmd
110  * log file such as that required by fmdump(1M).  The arguments are as follows:
111  *
112  * fmd_log_t *lp - log to use for iteration from fmd_log_open()
113  * uint_t iflags - FMD_LOG_XITER_* flags (see above)
114  * uint_t filtc - count of number of filters (or zero for no filtering)
115  * fmd_log_filter_t *filtv - array of 'filtc' filter structures
116  * fmd_log_rec_f *rfunc - function to invoke for each record in log
117  * fmd_log_err_f *efunc - function to invoke for any errors in log
118  * void *private - argument to pass to 'rfunc' and 'efunc' callbacks
119  * ulong_t *cntp - pointer to storage for record count (or NULL)
120  */
121 extern int fmd_log_xiter(fmd_log_t *, uint_t, uint_t, fmd_log_filter_t *,
122     fmd_log_rec_f *, fmd_log_err_f *, void *, ulong_t *);
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _FMD_LOG_H */
129