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#pragma ident	"%Z%%M%	%I%	%E% SMI"
30
31#include <libnvpair.h>
32#include <exacct.h>
33#include <regex.h>
34
35#ifdef	__cplusplus
36extern "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
51typedef struct fmd_log fmd_log_t;
52
53extern fmd_log_t *fmd_log_open(int, const char *, int *);
54extern void fmd_log_close(fmd_log_t *);
55extern const char *fmd_log_label(fmd_log_t *);
56
57extern const char *fmd_log_errmsg(fmd_log_t *, int);
58extern int fmd_log_errno(fmd_log_t *);
59
60typedef 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
71extern void fmd_log_header(fmd_log_t *, fmd_log_header_t *);
72
73typedef 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
84typedef int fmd_log_rec_f(fmd_log_t *, const fmd_log_record_t *, void *);
85typedef int fmd_log_err_f(fmd_log_t *, void *);
86
87extern int fmd_log_rewind(fmd_log_t *);
88extern int fmd_log_iter(fmd_log_t *, fmd_log_rec_f *, void *);
89extern 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
95typedef 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
100extern fmd_log_rec_f fmd_log_filter_class;	/* char *name of event class */
101extern fmd_log_rec_f fmd_log_filter_uuid;	/* char *uuid of list.suspect */
102extern fmd_log_rec_f fmd_log_filter_before;	/* struct timeval * latest */
103extern fmd_log_rec_f fmd_log_filter_after;	/* struct timeval * earliest */
104extern fmd_log_rec_f fmd_log_filter_nv;		/* char *namevalue in event */
105
106extern int fmd_log_filter(fmd_log_t *,
107    uint_t, fmd_log_filter_t *, const fmd_log_record_t *);
108
109typedef struct fmd_log_filter_nvarg {
110	char	*nvarg_name;
111	char	*nvarg_value;
112	regex_t	*nvarg_value_regex;
113} fmd_log_filter_nvarg_t;
114
115/*
116 * fmd_log_xiter() can be used to perform sophisticated iteration over an fmd
117 * log file such as that required by fmdump(1M).  The arguments are as follows:
118 *
119 * fmd_log_t *lp - log to use for iteration from fmd_log_open()
120 * uint_t iflags - FMD_LOG_XITER_* flags (see above)
121 * uint_t filtc - count of number of filters (or zero for no filtering)
122 * fmd_log_filter_t *filtv - array of 'filtc' filter structures
123 * fmd_log_rec_f *rfunc - function to invoke for each record in log
124 * fmd_log_err_f *efunc - function to invoke for any errors in log
125 * void *private - argument to pass to 'rfunc' and 'efunc' callbacks
126 * ulong_t *cntp - pointer to storage for record count (or NULL)
127 */
128extern int fmd_log_xiter(fmd_log_t *, uint_t, uint_t, fmd_log_filter_t *,
129    fmd_log_rec_f *, fmd_log_err_f *, void *, ulong_t *);
130
131#ifdef	__cplusplus
132}
133#endif
134
135#endif	/* _FMD_LOG_H */
136