xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 5750ef5c2584f7399d9b98bfd513c0ca9f79f66e)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_ASRU_H
28 #define	_FMD_ASRU_H
29 
30 #include <sys/types.h>
31 #include <pthread.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <fmd_api.h>
38 #include <fmd_log.h>
39 #include <fmd_list.h>
40 #include <fmd_topo.h>
41 
42 /*
43  * The resource is represented by an fmd_asru_t structure and one or more
44  * fmd_asru_link_t structures. Each of the latter represents a separate
45  * unrepaired case (problem) involving the resource. There are separate
46  * reference counts for both the fmd_asru_t and fmd_asru_link_t structures,
47  * but only one lock is used (asru_lock) which protects both the parent
48  * fmd_asru_t and its associated fmd_asru_link_t structures. The FMD_ASRU_FAULTY
49  * flags in the fmd_asru_t represents the cumulative value of the associated
50  * FMD_ASRU_FAULTY flags in the fmd_asru_link_t structures (and therefore of
51  * all independant unrepaired problems that are affecting that resource).
52  */
53 typedef struct fmd_asru {
54 	struct fmd_asru *asru_next;	/* next asru on hash chain */
55 	char *asru_name;		/* string form of resource fmri (ro) */
56 	nvlist_t *asru_fmri;		/* nvlist form of resource fmri (ro) */
57 	char *asru_root;		/* directory for cache entry (ro) */
58 	char *asru_uuid;		/* uuid for asru cache entry (ro) */
59 	uint_t asru_uuidlen;		/* length of asru_uuid (not incl. \0) */
60 	pthread_mutex_t asru_lock;	/* lock protecting remaining members */
61 	pthread_cond_t asru_cv;		/* condition variable for asru_flags */
62 	uint_t asru_refs;		/* reference count */
63 	uint_t asru_flags;		/* flags (see below) */
64 	fmd_case_t *asru_case;		/* case associated with last change */
65 	nvlist_t *asru_event;		/* event associated with last change */
66 	fmd_list_t asru_list;		/* linked list next/prev pointers */
67 } fmd_asru_t;
68 
69 typedef struct fmd_asru_link {
70 	fmd_list_t al_list;		/* linked list next/prev pointers */
71 	struct fmd_asru *al_asru;		/* pointer back to parent */
72 	struct fmd_asru_link *al_asru_next;	/* next link on hash chain */
73 	struct fmd_asru_link *al_case_next;	/* next link on hash chain */
74 	struct fmd_asru_link *al_fru_next;	/* next link on hash chain */
75 	struct fmd_asru_link *al_label_next;	/* next link on hash chain */
76 	struct fmd_asru_link *al_rsrc_next;	/* next link on hash chain */
77 	char *al_uuid;			/* uuid for asru cache entry (ro) */
78 	uint_t al_uuidlen;		/* length of al_uuid (not incl. \0) */
79 	fmd_log_t *al_log;		/* persistent event log */
80 	char *al_asru_name;		/* string form of asru fmri (ro) */
81 	char *al_fru_name;		/* string form of fru fmri (ro) */
82 	char *al_rsrc_name;		/* string form of resource fmri (ro) */
83 	char *al_label;			/* label */
84 	char *al_case_uuid;		/* case uuid */
85 	nvlist_t *al_asru_fmri;		/* nvlist form of resource fmri (ro) */
86 	fmd_case_t *al_case;		/* case associated with last change */
87 	nvlist_t *al_event;		/* event associated with last change */
88 	uint_t al_refs;			/* reference count */
89 	uint_t al_flags;		/* flags (see below) */
90 	uint8_t al_reason;		/* repair reason (see below) */
91 } fmd_asru_link_t;
92 
93 #define	FMD_ASRU_FAULTY		0x01	/* asru has been diagnosed as faulty */
94 #define	FMD_ASRU_UNUSABLE	0x02	/* asru can not be used at present */
95 #define	FMD_ASRU_VALID		0x04	/* asru is initialized and valid */
96 #define	FMD_ASRU_INTERNAL	0x08	/* asru is managed by fmd itself */
97 #define	FMD_ASRU_INVISIBLE	0x10	/* asru is not visibly administered */
98 #define	FMD_ASRU_RECREATED	0x20	/* asru recreated by cache replay */
99 #define	FMD_ASRU_PRESENT	0x40	/* asru present at last R$ update */
100 #define	FMD_ASRU_DEGRADED	0x80	/* asru service is degraded */
101 #define	FMD_ASRU_PROXY		0x100	/* asru on proxy */
102 #define	FMD_ASRU_PROXY_WITH_ASRU 0x200	/* asru accessible locally on proxy */
103 #define	FMD_ASRU_PROXY_EXTERNAL	0x400	/* proxy over external transport */
104 #define	FMD_ASRU_PROXY_RDONLY	0x800	/* proxy over readonly transport */
105 
106 /*
107  * Note the following are defined in order of increasing precedence and
108  * this should not be changed
109  */
110 #define	FMD_ASRU_REMOVED	0	/* asru removed */
111 #define	FMD_ASRU_ACQUITTED	1	/* asru acquitted */
112 #define	FMD_ASRU_REPAIRED	2	/* asru repaired */
113 #define	FMD_ASRU_REPLACED	3	/* asru replaced */
114 
115 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
116 
117 #define	FMD_ASRU_AL_HASH_NAME(a, off) \
118 	*(char **)((uint8_t *)a + off)
119 #define	FMD_ASRU_AL_HASH_NEXT(a, off) \
120 	*(fmd_asru_link_t **)((uint8_t *)a + off)
121 #define	FMD_ASRU_AL_HASH_NEXTP(a, off) \
122 	(fmd_asru_link_t **)((uint8_t *)a + off)
123 
124 typedef struct fmd_asru_hash {
125 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
126 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
127 	fmd_asru_link_t **ah_asru_hash;	/* hash bucket array for asrus */
128 	fmd_asru_link_t **ah_case_hash;	/* hash bucket array for frus */
129 	fmd_asru_link_t **ah_fru_hash;	/* hash bucket array for cases */
130 	fmd_asru_link_t **ah_label_hash;	/* label hash bucket array */
131 	fmd_asru_link_t **ah_rsrc_hash;	/* hash bucket array for rsrcs */
132 	uint_t ah_hashlen;		/* length of hash bucket array */
133 	char *ah_dirpath;		/* path of hash's log file directory */
134 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
135 	uint_t ah_al_count;		/* count of number of entries in hash */
136 	uint_t ah_count;		/* count of separate rsrcs in hash */
137 	int ah_error;			/* error from opening asru log */
138 	fmd_topo_t *ah_topo;		/* topo handle */
139 } fmd_asru_hash_t;
140 
141 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
142 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
143 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
144 extern void fmd_asru_hash_replay(fmd_asru_hash_t *);
145 
146 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
147     void (*)(fmd_asru_t *, void *), void *);
148 extern void fmd_asru_al_hash_apply(fmd_asru_hash_t *,
149     void (*)(fmd_asru_link_t *, void *), void *);
150 extern void fmd_asru_hash_apply_by_asru(fmd_asru_hash_t *, const char *,
151     void (*)(fmd_asru_link_t *, void *), void *);
152 extern void fmd_asru_hash_apply_by_label(fmd_asru_hash_t *, const char *,
153     void (*)(fmd_asru_link_t *, void *), void *);
154 extern void fmd_asru_hash_apply_by_fru(fmd_asru_hash_t *, const char *,
155     void (*)(fmd_asru_link_t *, void *), void *);
156 extern void fmd_asru_hash_apply_by_rsrc(fmd_asru_hash_t *, const char *,
157     void (*)(fmd_asru_link_t *, void *), void *);
158 extern void fmd_asru_hash_apply_by_case(fmd_asru_hash_t *, fmd_case_t *,
159     void (*)(fmd_asru_link_t *, void *), void *);
160 
161 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
162 extern fmd_asru_link_t *fmd_asru_hash_create_entry(fmd_asru_hash_t *,
163     fmd_case_t *, nvlist_t *);
164 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
165 extern void fmd_asru_hash_delete_case(fmd_asru_hash_t *, fmd_case_t *);
166 
167 extern void fmd_asru_clear_aged_rsrcs();
168 
169 /*
170  * flags used in fara_bywhat field in fmd_asru_rep_arg_t
171  */
172 #define	FARA_ALL	0
173 #define	FARA_BY_CASE	1
174 #define	FARA_BY_ASRU	2
175 #define	FARA_BY_FRU	3
176 #define	FARA_BY_RSRC	4
177 #define	FARA_BY_LABEL	5
178 
179 /*
180  * Return values for fmd_asru_repaired. May return "ok" or "not replaced".
181  * If no fault is found we will get default value of "not found".
182  */
183 #define	FARA_OK 0
184 #define	FARA_ERR_RSRCNOTF 1
185 #define	FARA_ERR_RSRCNOTR 2
186 
187 /*
188  * The following structures are used to pass arguments to the corresponding
189  * function when walking the resource cache by case etc.
190  */
191 typedef struct {
192 	uint8_t fara_reason;	/* repaired, acquit, replaced, removed */
193 	uint8_t fara_bywhat;	/* whether doing a walk by case, asru, etc */
194 	int *fara_rval;		/* for return success or failure */
195 	char *fara_uuid;	/* uuid can be passed in for comparison */
196 } fmd_asru_rep_arg_t;
197 extern void fmd_asru_repaired(fmd_asru_link_t *, void *);
198 extern void fmd_asru_flush(fmd_asru_link_t *, void *);
199 
200 typedef struct {
201 	int	*faus_countp;
202 	int	faus_maxcount;
203 	uint8_t *faus_ba;		/* received status for each suspect */
204 	uint8_t *faus_proxy_asru;	/* asru on proxy for each suspect? */
205 	uint8_t *faus_diag_asru;	/* asru on diag for each suspect? */
206 	boolean_t	faus_is_proxy;	/* are we on the proxy side? */
207 } fmd_asru_update_status_t;
208 extern void fmd_asru_update_status(fmd_asru_link_t *alp, void *arg);
209 
210 typedef struct {
211 	int	*fasp_countp;
212 	int	fasp_maxcount;
213 	uint8_t *fasp_proxy_asru;	/* asru on proxy for each suspect? */
214 	int	fasp_proxy_external;	/* is this an external transport? */
215 	int	fasp_proxy_rdonly;	/* is this a rdonly transport? */
216 } fmd_asru_set_on_proxy_t;
217 extern void fmd_asru_set_on_proxy(fmd_asru_link_t *alp, void *arg);
218 
219 extern void fmd_asru_update_containees(fmd_asru_link_t *alp, void *arg);
220 
221 typedef struct {
222 	int	*facs_countp;
223 	int	facs_maxcount;
224 } fmd_asru_close_status_t;
225 extern void fmd_asru_close_status(fmd_asru_link_t *alp, void *arg);
226 
227 extern int fmd_asru_setflags(fmd_asru_link_t *, uint_t);
228 extern int fmd_asru_clrflags(fmd_asru_link_t *, uint_t, uint8_t);
229 extern void fmd_asru_log_resolved(fmd_asru_link_t *, void *);
230 extern int fmd_asru_al_getstate(fmd_asru_link_t *);
231 extern int fmd_asru_getstate(fmd_asru_t *);
232 extern void fmd_asru_check_if_aged(fmd_asru_link_t *, void *);
233 void fmd_asru_most_recent(fmd_asru_link_t *, void *);
234 
235 #ifdef	__cplusplus
236 }
237 #endif
238 
239 #endif	/* _FMD_ASRU_H */
240