xref: /freebsd/sys/contrib/openzfs/cmd/zed/agents/fmd_api.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
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 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  *
25  * Copyright (c) 2016, Intel Corporation.
26  */
27 
28 #ifndef	_FMD_API_H
29 #define	_FMD_API_H
30 
31 #include <sys/types.h>
32 #include <sys/time.h>
33 #include <time.h>
34 #include <libnvpair.h>
35 #include <stdarg.h>
36 #include <umem.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Fault Management Daemon Client Interfaces
44  */
45 
46 #define	FMD_API_VERSION		5
47 
48 typedef struct fmd_hdl fmd_hdl_t;
49 
50 typedef struct fmd_timer {
51 	timer_t		ft_tid;
52 	void		*ft_arg;
53 	fmd_hdl_t	*ft_hdl;
54 } fmd_timer_t;
55 
56 #define	id_t	fmd_timer_t *
57 
58 
59 typedef struct fmd_event {
60 	hrtime_t	ev_hrt;		/* event time used by SERD engines */
61 } fmd_event_t;
62 
63 typedef struct fmd_case {
64 	char		ci_uuid[48];	/* uuid string for this case */
65 	fmd_hdl_t	*ci_mod;	/* module that owns this case */
66 	void		*ci_data;	/* data from fmd_case_setspecific() */
67 	ushort_t	ci_state;	/* case state (see below) */
68 	ushort_t	ci_flags;	/* case flags (see below) */
69 	struct timeval	ci_tv;		/* time of original diagnosis */
70 	void		*ci_bufptr;	/* case data serialization buffer */
71 	size_t		ci_bufsiz;
72 } fmd_case_t;
73 
74 
75 #define	FMD_B_FALSE	0		/* false value for booleans as int */
76 #define	FMD_B_TRUE	1		/* true value for booleans as int */
77 
78 
79 #define	FMD_CASE_UNSOLVED	0	/* case is not yet solved (waiting) */
80 #define	FMD_CASE_SOLVED		1	/* case is solved (suspects added) */
81 #define	FMD_CASE_CLOSE_WAIT	2	/* case is executing fmdo_close() */
82 #define	FMD_CASE_CLOSED		3	/* case is closed (reconfig done) */
83 #define	FMD_CASE_REPAIRED	4	/* case is repaired */
84 #define	FMD_CASE_RESOLVED	5	/* case is resolved (can be freed) */
85 
86 #define	FMD_CF_DIRTY		0x01	/* case is in need of checkpoint */
87 #define	FMD_CF_SOLVED		0x02	/* case has been solved */
88 #define	FMD_CF_ISOLATED		0x04	/* case has been isolated */
89 #define	FMD_CF_REPAIRED		0x08	/* case has been repaired */
90 #define	FMD_CF_RESOLVED		0x10	/* case has been resolved */
91 
92 
93 #define	FMD_TYPE_BOOL	0		/* int */
94 #define	FMD_TYPE_INT32	1		/* int32_t */
95 #define	FMD_TYPE_UINT32	2		/* uint32_t */
96 #define	FMD_TYPE_INT64	3		/* int64_t */
97 #define	FMD_TYPE_UINT64	4		/* uint64_t */
98 #define	FMD_TYPE_TIME	5		/* uint64_t */
99 #define	FMD_TYPE_SIZE	6		/* uint64_t */
100 
101 typedef struct fmd_prop {
102 	const char *fmdp_name;		/* property name */
103 	uint_t fmdp_type;		/* property type (see above) */
104 	const char *fmdp_defv;		/* default value */
105 } fmd_prop_t;
106 
107 typedef struct fmd_stat {
108 	char fmds_name[32];		/* statistic name */
109 	uint_t fmds_type;		/* statistic type (see above) */
110 	char fmds_desc[64];		/* statistic description */
111 	union {
112 		int bool;		/* FMD_TYPE_BOOL */
113 		int32_t i32;		/* FMD_TYPE_INT32 */
114 		uint32_t ui32;		/* FMD_TYPE_UINT32 */
115 		int64_t i64;		/* FMD_TYPE_INT64 */
116 		uint64_t ui64;		/* FMD_TYPE_UINT64 */
117 	} fmds_value;
118 } fmd_stat_t;
119 
120 typedef struct fmd_hdl_ops {
121 	void (*fmdo_recv)(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);
122 	void (*fmdo_timeout)(fmd_hdl_t *, id_t, void *);
123 	void (*fmdo_close)(fmd_hdl_t *, fmd_case_t *);
124 	void (*fmdo_stats)(fmd_hdl_t *);
125 	void (*fmdo_gc)(fmd_hdl_t *);
126 } fmd_hdl_ops_t;
127 
128 #define	FMD_SEND_SUCCESS	0	/* fmdo_send queued event */
129 #define	FMD_SEND_FAILED		1	/* fmdo_send unrecoverable error */
130 #define	FMD_SEND_RETRY		2	/* fmdo_send requests retry */
131 
132 typedef struct fmd_hdl_info {
133 	const char *fmdi_desc;		/* fmd client description string */
134 	const char *fmdi_vers;		/* fmd client version string */
135 	const fmd_hdl_ops_t *fmdi_ops;	/* ops vector for client */
136 	const fmd_prop_t *fmdi_props;	/* array of configuration props */
137 } fmd_hdl_info_t;
138 
139 extern int fmd_hdl_register(fmd_hdl_t *, int, const fmd_hdl_info_t *);
140 extern void fmd_hdl_unregister(fmd_hdl_t *);
141 
142 extern void fmd_hdl_setspecific(fmd_hdl_t *, void *);
143 extern void *fmd_hdl_getspecific(fmd_hdl_t *);
144 
145 #define	FMD_SLEEP	UMEM_NOFAIL
146 
147 extern void *fmd_hdl_alloc(fmd_hdl_t *, size_t, int);
148 extern void *fmd_hdl_zalloc(fmd_hdl_t *, size_t, int);
149 extern void fmd_hdl_free(fmd_hdl_t *, void *, size_t);
150 
151 extern char *fmd_hdl_strdup(fmd_hdl_t *, const char *, int);
152 extern void fmd_hdl_strfree(fmd_hdl_t *, char *);
153 
154 extern void fmd_hdl_vdebug(fmd_hdl_t *, const char *, va_list);
155 extern void fmd_hdl_debug(fmd_hdl_t *, const char *, ...);
156 
157 extern int32_t fmd_prop_get_int32(fmd_hdl_t *, const char *);
158 extern int64_t fmd_prop_get_int64(fmd_hdl_t *, const char *);
159 
160 #define	FMD_STAT_NOALLOC	0x0	/* fmd should use caller's memory */
161 #define	FMD_STAT_ALLOC		0x1	/* fmd should allocate stats memory */
162 
163 extern fmd_stat_t *fmd_stat_create(fmd_hdl_t *, uint_t, uint_t, fmd_stat_t *);
164 extern void fmd_stat_destroy(fmd_hdl_t *, uint_t, fmd_stat_t *);
165 extern void fmd_stat_setstr(fmd_hdl_t *, fmd_stat_t *, const char *);
166 
167 extern fmd_case_t *fmd_case_open(fmd_hdl_t *, void *);
168 extern void fmd_case_reset(fmd_hdl_t *, fmd_case_t *);
169 extern void fmd_case_solve(fmd_hdl_t *, fmd_case_t *);
170 extern void fmd_case_close(fmd_hdl_t *, fmd_case_t *);
171 
172 extern const char *fmd_case_uuid(fmd_hdl_t *, fmd_case_t *);
173 extern fmd_case_t *fmd_case_uulookup(fmd_hdl_t *, const char *);
174 extern void fmd_case_uuclose(fmd_hdl_t *, const char *);
175 extern int fmd_case_uuclosed(fmd_hdl_t *, const char *);
176 extern int fmd_case_uuisresolved(fmd_hdl_t *, const char *);
177 extern void fmd_case_uuresolved(fmd_hdl_t *, const char *);
178 
179 extern int fmd_case_solved(fmd_hdl_t *, fmd_case_t *);
180 extern int fmd_case_closed(fmd_hdl_t *, fmd_case_t *);
181 
182 extern void fmd_case_add_ereport(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);
183 extern void fmd_case_add_serd(fmd_hdl_t *, fmd_case_t *, const char *);
184 extern void fmd_case_add_suspect(fmd_hdl_t *, fmd_case_t *, nvlist_t *);
185 
186 extern void fmd_case_setspecific(fmd_hdl_t *, fmd_case_t *, void *);
187 extern void *fmd_case_getspecific(fmd_hdl_t *, fmd_case_t *);
188 
189 extern fmd_case_t *fmd_case_next(fmd_hdl_t *, fmd_case_t *);
190 extern fmd_case_t *fmd_case_prev(fmd_hdl_t *, fmd_case_t *);
191 
192 extern void fmd_buf_create(fmd_hdl_t *, fmd_case_t *, const char *, size_t);
193 extern void fmd_buf_destroy(fmd_hdl_t *, fmd_case_t *, const char *);
194 extern void fmd_buf_read(fmd_hdl_t *, fmd_case_t *,
195     const char *, void *, size_t);
196 extern void fmd_buf_write(fmd_hdl_t *, fmd_case_t *,
197     const char *, const void *, size_t);
198 extern size_t fmd_buf_size(fmd_hdl_t *, fmd_case_t *, const char *);
199 
200 extern void fmd_serd_create(fmd_hdl_t *, const char *, uint_t, hrtime_t);
201 extern void fmd_serd_destroy(fmd_hdl_t *, const char *);
202 extern int fmd_serd_exists(fmd_hdl_t *, const char *);
203 extern void fmd_serd_reset(fmd_hdl_t *, const char *);
204 extern int fmd_serd_record(fmd_hdl_t *, const char *, fmd_event_t *);
205 extern int fmd_serd_fired(fmd_hdl_t *, const char *);
206 extern int fmd_serd_empty(fmd_hdl_t *, const char *);
207 
208 extern id_t fmd_timer_install(fmd_hdl_t *, void *, fmd_event_t *, hrtime_t);
209 extern void fmd_timer_remove(fmd_hdl_t *, id_t);
210 
211 extern nvlist_t *fmd_nvl_create_fault(fmd_hdl_t *,
212     const char *, uint8_t, nvlist_t *, nvlist_t *, nvlist_t *);
213 
214 extern int fmd_nvl_class_match(fmd_hdl_t *, nvlist_t *, const char *);
215 
216 #define	FMD_HAS_FAULT_FRU	0
217 #define	FMD_HAS_FAULT_ASRU	1
218 #define	FMD_HAS_FAULT_RESOURCE	2
219 
220 extern void fmd_repair_fru(fmd_hdl_t *, const char *);
221 extern int fmd_repair_asru(fmd_hdl_t *, const char *);
222 
223 extern nvlist_t *fmd_nvl_alloc(fmd_hdl_t *, int);
224 extern nvlist_t *fmd_nvl_dup(fmd_hdl_t *, nvlist_t *, int);
225 
226 /*
227  * ZED Specific Interfaces
228  */
229 
230 extern fmd_hdl_t *fmd_module_hdl(const char *);
231 extern boolean_t fmd_module_initialized(fmd_hdl_t *);
232 extern void fmd_module_recv(fmd_hdl_t *, nvlist_t *, const char *);
233 
234 /* ZFS FMA Retire Agent */
235 extern void _zfs_retire_init(fmd_hdl_t *);
236 extern void _zfs_retire_fini(fmd_hdl_t *);
237 
238 /* ZFS FMA Diagnosis Engine */
239 extern void _zfs_diagnosis_init(fmd_hdl_t *);
240 extern void _zfs_diagnosis_fini(fmd_hdl_t *);
241 
242 #ifdef	__cplusplus
243 }
244 #endif
245 
246 #endif	/* _FMD_API_H */
247