xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_case.h (revision 3299f39fdcbdab4be7a9c70daa3873f2b78a398d)
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 
26 #ifndef	_FMD_CASE_H
27 #define	_FMD_CASE_H
28 
29 #include <pthread.h>
30 #include <libnvpair.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <fmd_list.h>
37 #include <fmd_api.h>
38 #include <fmd_buf.h>
39 
40 struct fmd_module;			/* see <fmd_module.h> */
41 
42 typedef struct fmd_case_item {
43 	struct fmd_case_item *cit_next;	/* pointer to next element in list */
44 	fmd_event_t *cit_event;		/* pointer to held event */
45 } fmd_case_item_t;
46 
47 typedef struct fmd_case_susp {
48 	struct fmd_case_susp *cis_next;	/* pointer to next element in list */
49 	nvlist_t *cis_nvl;		/* nvpair representing fault event */
50 } fmd_case_susp_t;
51 
52 typedef struct fmd_case_impl {
53 	fmd_list_t ci_list;		/* linked list next/prev pointers */
54 	struct fmd_case_impl *ci_next;	/* next pointer for hash bucket chain */
55 	struct fmd_case_impl *ci_code_next;	/* ci_code hash bucket chain */
56 	char *ci_uuid;			/* uuid string for this case */
57 	uint_t ci_uuidlen;		/* length of ci_uuid (not incl. \0) */
58 	char *ci_code;			/* code associated with this case */
59 	size_t ci_codelen;		/* size of ci_code buffer in bytes */
60 	struct fmd_module *ci_mod;	/* module that owns this case */
61 	fmd_xprt_t *ci_xprt;		/* transport for this case (or NULL) */
62 	uint8_t ci_precanned;		/* precanned code from injection */
63 	nvlist_t *ci_diag_de;		/* diag side de fmri */
64 	uint8_t *ci_diag_asru;		/* is asru valid on diag side */
65 	uint8_t *ci_proxy_asru;		/* is asru valid on proxy side */
66 	void *ci_data;			/* data from fmd_case_setspecific() */
67 	pthread_mutex_t ci_lock;	/* lock for remainder of contents */
68 	uint_t ci_refs;			/* reference count */
69 	ushort_t ci_state;		/* case state (see below) */
70 	ushort_t ci_flags;		/* case flags (see below) */
71 	fmd_case_item_t *ci_items;	/* list of items in this case */
72 	uint_t ci_nitems;		/* number of ci_items */
73 	fmd_event_t *ci_principal;	/* principal event (if any) */
74 	fmd_case_susp_t *ci_suspects;	/* list of suspects in this case */
75 	uint_t ci_nsuspects;		/* number of ci_suspects */
76 	size_t ci_nvsz;			/* packed suspect nvlist array size */
77 	fmd_buf_hash_t ci_bufs;		/* hash of bufs associated with case */
78 	struct timeval ci_tv;		/* time of original diagnosis */
79 	int ci_tv_valid;		/* time of original diagnosis valid */
80 	int ci_injected;		/* was the fault injected */
81 } fmd_case_impl_t;
82 
83 #define	FMD_CASE_CURRENT	-1u	/* flag for current state */
84 
85 #define	FMD_CASE_UNSOLVED	0	/* case is not yet solved (waiting) */
86 #define	FMD_CASE_SOLVED		1	/* case is solved (suspects added) */
87 #define	FMD_CASE_CLOSE_WAIT	2	/* case is executing fmdo_close() */
88 #define	FMD_CASE_CLOSED		3	/* case is closed (reconfig done) */
89 #define	FMD_CASE_REPAIRED	4	/* case is repaired */
90 #define	FMD_CASE_RESOLVED	5	/* case is resolved (can be freed) */
91 
92 #define	FMD_CF_DIRTY		0x01	/* case is in need of checkpoint */
93 #define	FMD_CF_SOLVED		0x02	/* case has been solved */
94 #define	FMD_CF_ISOLATED		0x04	/* case has been isolated */
95 #define	FMD_CF_REPAIRED		0x08	/* case has been repaired */
96 #define	FMD_CF_RESOLVED		0x10	/* case has been resolved */
97 #define	FMD_CF_INVISIBLE	0x20	/* case should be invisible */
98 #define	FMD_CF_DELETING		0x40	/* case is about to be deleted */
99 #define	FMD_CF_RES_CMPL		0x80	/* transition to resolved is complete */
100 
101 /*
102  * ci_proxy_asru flags record if we created a new asru on the proxy side and
103  * if so whether it is derived from the received asru or received resource.
104  */
105 #define	FMD_PROXY_ASRU_NOT_NEEDED	0
106 #define	FMD_PROXY_ASRU_FROM_ASRU	1
107 #define	FMD_PROXY_ASRU_FROM_RSRC	2
108 
109 typedef struct fmd_case_hash {
110 	pthread_rwlock_t ch_lock;	/* lock protecting case hash */
111 	fmd_case_impl_t **ch_hash;	/* hash bucket array for cases */
112 	fmd_case_impl_t **ch_code_hash;	/* ci_code hash bucket array */
113 	uint_t ch_hashlen;		/* size of hash bucket array */
114 	uint_t ch_count;		/* number of cases in hash */
115 } fmd_case_hash_t;
116 
117 extern fmd_case_hash_t *fmd_case_hash_create(void);
118 extern void fmd_case_hash_destroy(fmd_case_hash_t *);
119 extern fmd_case_t *fmd_case_hash_lookup(fmd_case_hash_t *, const char *);
120 extern void fmd_case_hash_apply(fmd_case_hash_t *,
121     void (*)(fmd_case_t *, void *), void *);
122 
123 extern fmd_case_t *fmd_case_create(struct fmd_module *, const char *, void *);
124 extern fmd_case_t *fmd_case_recreate(struct fmd_module *,
125     struct fmd_xprt *, uint_t, const char *, const char *);
126 extern void fmd_case_destroy(fmd_case_t *, int);
127 extern void fmd_case_hold(fmd_case_t *);
128 extern void fmd_case_hold_locked(fmd_case_t *);
129 extern void fmd_case_rele(fmd_case_t *);
130 extern void fmd_case_rele_locked(fmd_case_t *);
131 extern void fmd_case_update(fmd_case_t *);
132 
133 extern int fmd_case_insert_principal(fmd_case_t *, fmd_event_t *);
134 extern int fmd_case_insert_event(fmd_case_t *, fmd_event_t *);
135 
136 extern void fmd_case_insert_suspect(fmd_case_t *, nvlist_t *);
137 extern void fmd_case_recreate_suspect(fmd_case_t *, nvlist_t *);
138 extern void fmd_case_reset_suspects(fmd_case_t *);
139 
140 extern nvlist_t *fmd_case_mkevent(fmd_case_t *, const char *);
141 extern void fmd_case_publish(fmd_case_t *, uint_t);
142 extern void fmd_case_transition(fmd_case_t *, uint_t, uint_t);
143 extern void fmd_case_transition_update(fmd_case_t *, uint_t, uint_t);
144 extern void fmd_case_setdirty(fmd_case_t *);
145 extern void fmd_case_clrdirty(fmd_case_t *);
146 extern void fmd_case_commit(fmd_case_t *);
147 extern void fmd_case_update(fmd_case_t *);
148 extern void fmd_case_delete(fmd_case_t *);
149 extern void fmd_case_discard(fmd_case_t *, boolean_t);
150 extern void fmd_case_settime(fmd_case_t *, time_t, suseconds_t);
151 extern void fmd_case_setcode(fmd_case_t *, char *);
152 extern void fmd_case_set_de_fmri(fmd_case_t *, nvlist_t *);
153 extern void fmd_case_set_injected(fmd_case_t *);
154 extern void fmd_case_update_status(fmd_case_t *, uint8_t *, uint8_t *,
155     uint8_t *);
156 extern void fmd_case_update_containees(fmd_case_t *);
157 extern void fmd_case_xprt_updated(fmd_case_t *);
158 extern void fmd_case_close_status(fmd_case_t *);
159 
160 extern int fmd_case_repair(fmd_case_t *);
161 extern int fmd_case_acquit(fmd_case_t *);
162 extern int fmd_case_contains(fmd_case_t *, fmd_event_t *);
163 extern int fmd_case_orphaned(fmd_case_t *);
164 extern void fmd_case_repair_replay(void);
165 extern void fmd_case_discard_resolved(fmd_case_t *, void *);
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _FMD_CASE_H */
172