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