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