xref: /titanic_41/usr/src/cmd/fm/fmd/common/fmd_api.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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_API_H
28 #define	_FMD_API_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <libnvpair.h>
34 #include <stdarg.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Fault Management Daemon Client Interfaces
42  *
43  * Note: The contents of this file are private to the implementation of the
44  * Solaris system and FMD subsystem and are subject to change at any time
45  * without notice.  Applications and drivers using these interfaces will fail
46  * to run on future releases.  These interfaces should not be used for any
47  * purpose until they are publicly documented for use outside of Sun.
48  */
49 
50 #define	FMD_API_VERSION_1	1
51 #define	FMD_API_VERSION_2	2
52 
53 #define	FMD_API_VERSION		FMD_API_VERSION_2
54 
55 typedef struct fmd_hdl fmd_hdl_t;
56 typedef struct fmd_event fmd_event_t;
57 typedef struct fmd_case fmd_case_t;
58 
59 #define	FMD_B_FALSE	0		/* false value for booleans as int */
60 #define	FMD_B_TRUE	1		/* true value for booleans as int */
61 
62 #ifndef	MIN
63 #define	MIN(x, y) ((x) < (y) ? (x) : (y))
64 #endif
65 
66 #ifndef	MAX
67 #define	MAX(x, y) ((x) > (y) ? (x) : (y))
68 #endif
69 
70 #define	FMD_TYPE_BOOL	0		/* int */
71 #define	FMD_TYPE_INT32	1		/* int32_t */
72 #define	FMD_TYPE_UINT32	2		/* uint32_t */
73 #define	FMD_TYPE_INT64	3		/* int64_t */
74 #define	FMD_TYPE_UINT64	4		/* uint64_t */
75 #define	FMD_TYPE_STRING	5		/* const char* */
76 #define	FMD_TYPE_TIME	6		/* uint64_t */
77 #define	FMD_TYPE_SIZE	7		/* uint64_t */
78 
79 typedef struct fmd_prop {
80 	const char *fmdp_name;		/* property name */
81 	uint_t fmdp_type;		/* property type (see above) */
82 	const char *fmdp_defv;		/* default value */
83 } fmd_prop_t;
84 
85 typedef struct fmd_stat {
86 	char fmds_name[32];		/* statistic name */
87 	uint_t fmds_type;		/* statistic type (see above) */
88 	char fmds_desc[64];		/* statistic description */
89 	union {
90 		int bool;		/* FMD_TYPE_BOOL */
91 		int32_t i32;		/* FMD_TYPE_INT32 */
92 		uint32_t ui32;		/* FMD_TYPE_UINT32 */
93 		int64_t i64;		/* FMD_TYPE_INT64 */
94 		uint64_t ui64;		/* FMD_TYPE_UINT64, TIME, SIZE */
95 		char *str;		/* FMD_TYPE_STRING */
96 	} fmds_value;
97 } fmd_stat_t;
98 
99 typedef struct fmd_hdl_ops {
100 	void (*fmdo_recv)(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);
101 	void (*fmdo_timeout)(fmd_hdl_t *, id_t, void *);
102 	void (*fmdo_close)(fmd_hdl_t *, fmd_case_t *);
103 	void (*fmdo_stats)(fmd_hdl_t *);
104 	void (*fmdo_gc)(fmd_hdl_t *);
105 } fmd_hdl_ops_t;
106 
107 typedef struct fmd_hdl_info {
108 	const char *fmdi_desc;		/* fmd client description string */
109 	const char *fmdi_vers;		/* fmd client version string */
110 	const fmd_hdl_ops_t *fmdi_ops;	/* ops vector for client */
111 	const fmd_prop_t *fmdi_props;	/* array of configuration props */
112 } fmd_hdl_info_t;
113 
114 extern void _fmd_init(fmd_hdl_t *);
115 extern void _fmd_fini(fmd_hdl_t *);
116 
117 extern int fmd_hdl_register(fmd_hdl_t *, int, const fmd_hdl_info_t *);
118 extern void fmd_hdl_unregister(fmd_hdl_t *);
119 
120 extern void fmd_hdl_subscribe(fmd_hdl_t *, const char *);
121 extern void fmd_hdl_unsubscribe(fmd_hdl_t *, const char *);
122 
123 extern void fmd_hdl_setspecific(fmd_hdl_t *, void *);
124 extern void *fmd_hdl_getspecific(fmd_hdl_t *);
125 
126 extern void fmd_hdl_opendict(fmd_hdl_t *, const char *);
127 
128 #define	FMD_NOSLEEP		0x0	/* do not sleep or retry on failure */
129 #define	FMD_SLEEP		0x1	/* sleep or retry if alloc fails */
130 
131 extern void *fmd_hdl_alloc(fmd_hdl_t *, size_t, int);
132 extern void *fmd_hdl_zalloc(fmd_hdl_t *, size_t, int);
133 extern void fmd_hdl_free(fmd_hdl_t *, void *, size_t);
134 
135 extern char *fmd_hdl_strdup(fmd_hdl_t *, const char *, int);
136 extern void fmd_hdl_strfree(fmd_hdl_t *, char *);
137 
138 extern void fmd_hdl_vabort(fmd_hdl_t *, const char *, va_list);
139 extern void fmd_hdl_abort(fmd_hdl_t *, const char *, ...);
140 
141 extern void fmd_hdl_verror(fmd_hdl_t *, const char *, va_list);
142 extern void fmd_hdl_error(fmd_hdl_t *, const char *, ...);
143 
144 extern void fmd_hdl_vdebug(fmd_hdl_t *, const char *, va_list);
145 extern void fmd_hdl_debug(fmd_hdl_t *, const char *, ...);
146 
147 extern int32_t fmd_prop_get_int32(fmd_hdl_t *, const char *);
148 extern int64_t fmd_prop_get_int64(fmd_hdl_t *, const char *);
149 extern char *fmd_prop_get_string(fmd_hdl_t *, const char *);
150 extern void fmd_prop_free_string(fmd_hdl_t *, char *);
151 
152 #define	FMD_STAT_NOALLOC	0x0	/* fmd should use caller's memory */
153 #define	FMD_STAT_ALLOC		0x1	/* fmd should allocate stats memory */
154 
155 extern fmd_stat_t *fmd_stat_create(fmd_hdl_t *, uint_t, uint_t, fmd_stat_t *);
156 extern void fmd_stat_destroy(fmd_hdl_t *, uint_t, fmd_stat_t *);
157 extern void fmd_stat_setstr(fmd_hdl_t *, fmd_stat_t *, const char *);
158 
159 extern fmd_case_t *fmd_case_open(fmd_hdl_t *, void *);
160 extern void fmd_case_reset(fmd_hdl_t *, fmd_case_t *);
161 extern void fmd_case_solve(fmd_hdl_t *, fmd_case_t *);
162 extern void fmd_case_convict(fmd_hdl_t *, fmd_case_t *, nvlist_t *);
163 extern void fmd_case_close(fmd_hdl_t *, fmd_case_t *);
164 
165 extern const char *fmd_case_uuid(fmd_hdl_t *, fmd_case_t *);
166 extern fmd_case_t *fmd_case_uulookup(fmd_hdl_t *, const char *);
167 extern void fmd_case_uuconvict(fmd_hdl_t *, const char *, nvlist_t *);
168 extern void fmd_case_uuclose(fmd_hdl_t *, const char *);
169 extern int fmd_case_uuclosed(fmd_hdl_t *, const char *);
170 
171 extern int fmd_case_solved(fmd_hdl_t *, fmd_case_t *);
172 extern int fmd_case_closed(fmd_hdl_t *, fmd_case_t *);
173 
174 extern void fmd_case_add_ereport(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);
175 extern void fmd_case_add_serd(fmd_hdl_t *, fmd_case_t *, const char *);
176 extern void fmd_case_add_suspect(fmd_hdl_t *, fmd_case_t *, nvlist_t *);
177 
178 extern void fmd_case_setspecific(fmd_hdl_t *, fmd_case_t *, void *);
179 extern void *fmd_case_getspecific(fmd_hdl_t *, fmd_case_t *);
180 
181 extern void fmd_case_setprincipal(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);
182 extern fmd_event_t *fmd_case_getprincipal(fmd_hdl_t *, fmd_case_t *);
183 
184 extern fmd_case_t *fmd_case_next(fmd_hdl_t *, fmd_case_t *);
185 extern fmd_case_t *fmd_case_prev(fmd_hdl_t *, fmd_case_t *);
186 
187 extern void fmd_buf_create(fmd_hdl_t *, fmd_case_t *, const char *, size_t);
188 extern void fmd_buf_destroy(fmd_hdl_t *, fmd_case_t *, const char *);
189 extern void fmd_buf_read(fmd_hdl_t *, fmd_case_t *,
190     const char *, void *, size_t);
191 extern void fmd_buf_write(fmd_hdl_t *, fmd_case_t *,
192     const char *, const void *, size_t);
193 extern size_t fmd_buf_size(fmd_hdl_t *, fmd_case_t *, const char *);
194 
195 extern void fmd_serd_create(fmd_hdl_t *, const char *, uint_t, hrtime_t);
196 extern void fmd_serd_destroy(fmd_hdl_t *, const char *);
197 extern int fmd_serd_exists(fmd_hdl_t *, const char *);
198 extern void fmd_serd_reset(fmd_hdl_t *, const char *);
199 extern int fmd_serd_record(fmd_hdl_t *, const char *, fmd_event_t *);
200 extern int fmd_serd_fired(fmd_hdl_t *, const char *);
201 extern int fmd_serd_empty(fmd_hdl_t *, const char *);
202 
203 extern pthread_t fmd_thr_create(fmd_hdl_t *, void (*)(void *), void *);
204 extern void fmd_thr_destroy(fmd_hdl_t *, pthread_t);
205 extern void fmd_thr_signal(fmd_hdl_t *, pthread_t);
206 
207 extern id_t fmd_timer_install(fmd_hdl_t *, void *, fmd_event_t *, hrtime_t);
208 extern void fmd_timer_remove(fmd_hdl_t *, id_t);
209 
210 extern nvlist_t *fmd_nvl_create_fault(fmd_hdl_t *,
211     const char *, uint8_t, nvlist_t *, nvlist_t *, nvlist_t *);
212 
213 extern int fmd_nvl_class_match(fmd_hdl_t *, nvlist_t *, const char *);
214 extern int fmd_nvl_fmri_expand(fmd_hdl_t *, nvlist_t *);
215 extern int fmd_nvl_fmri_present(fmd_hdl_t *, nvlist_t *);
216 extern int fmd_nvl_fmri_unusable(fmd_hdl_t *, nvlist_t *);
217 extern int fmd_nvl_fmri_contains(fmd_hdl_t *, nvlist_t *, nvlist_t *);
218 
219 #ifdef	__cplusplus
220 }
221 #endif
222 
223 #endif	/* _FMD_API_H */
224