xref: /freebsd/sys/contrib/openzfs/cmd/zed/agents/fmd_serd.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
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, Version 1.0 only
7  * (the "License").  You may not use this file except in compliance
8  * with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or https://opensource.org/licenses/CDDL-1.0.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 /*
24  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  *
27  * Copyright (c) 2016, Intel Corporation.
28  */
29 
30 #ifndef	_FMD_SERD_H
31 #define	_FMD_SERD_H
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <sys/list.h>
38 #include <sys/time.h>
39 
40 typedef struct fmd_serd_elem {
41 	list_node_t	se_list;	/* linked list forward/back pointers */
42 	hrtime_t	se_hrt;		/* upper bound on event hrtime */
43 } fmd_serd_elem_t;
44 
45 typedef struct fmd_serd_eng {
46 	char		*sg_name;	/* string name for this engine */
47 	struct fmd_serd_eng *sg_next;	/* next engine on hash chain */
48 	list_t		sg_list;	/* list of fmd_serd_elem_t's */
49 	uint_t		sg_count;	/* count of events in sg_list */
50 	uint_t		sg_flags;	/* engine flags (see below) */
51 	uint_t		sg_n;		/* engine N parameter (event count) */
52 	hrtime_t	sg_t;		/* engine T parameter (nanoseconds) */
53 } fmd_serd_eng_t;
54 
55 #define	FMD_SERD_FIRED	0x1		/* error rate has exceeded threshold */
56 #define	FMD_SERD_DIRTY	0x2		/* engine needs to be checkpointed */
57 
58 typedef void fmd_serd_eng_f(fmd_serd_eng_t *, void *);
59 
60 typedef struct fmd_serd_hash {
61 	fmd_serd_eng_t	**sh_hash;	/* hash bucket array for buffers */
62 	uint_t		sh_hashlen;	/* length of hash bucket array */
63 	uint_t		sh_count;	/* count of engines in hash */
64 } fmd_serd_hash_t;
65 
66 extern void fmd_serd_hash_create(fmd_serd_hash_t *);
67 extern void fmd_serd_hash_destroy(fmd_serd_hash_t *);
68 extern void fmd_serd_hash_apply(fmd_serd_hash_t *, fmd_serd_eng_f *, void *);
69 
70 extern fmd_serd_eng_t *fmd_serd_eng_insert(fmd_serd_hash_t *,
71     const char *, uint32_t, hrtime_t);
72 
73 extern fmd_serd_eng_t *fmd_serd_eng_lookup(fmd_serd_hash_t *, const char *);
74 extern void fmd_serd_eng_delete(fmd_serd_hash_t *, const char *);
75 
76 extern int fmd_serd_eng_record(fmd_serd_eng_t *, hrtime_t);
77 extern int fmd_serd_eng_fired(fmd_serd_eng_t *);
78 extern int fmd_serd_eng_empty(fmd_serd_eng_t *);
79 
80 extern void fmd_serd_eng_reset(fmd_serd_eng_t *);
81 extern void fmd_serd_eng_gc(fmd_serd_eng_t *, void *);
82 
83 #ifdef	__cplusplus
84 }
85 #endif
86 
87 #endif	/* _FMD_SERD_H */
88