xref: /titanic_44/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 62a24de03df1f2399ceda704cb3874dabc98bbbd)
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 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <pthread.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <fmd_api.h>
40 #include <fmd_log.h>
41 #include <fmd_list.h>
42 #include <fmd_topo.h>
43 
44 /*
45  * The resource is represented by an fmd_asru_t structure and one or more
46  * fmd_asru_link_t structures. Each of the latter represents a separate
47  * unrepaired case (problem) involving the resource. There are separate
48  * reference counts for both the fmd_asru_t and fmd_asru_link_t structures,
49  * but only one lock is used (asru_lock) which protects both the parent
50  * fmd_asru_t and its associated fmd_asru_link_t structures. The FMD_ASRU_FAULTY
51  * flags in the fmd_asru_t represents the cumulative value of the associated
52  * FMD_ASRU_FAULTY flags in the fmd_asru_link_t structures (and therefore of
53  * all independant unrepaired problems that are affecting that resource).
54  */
55 typedef struct fmd_asru {
56 	struct fmd_asru *asru_next;	/* next asru on hash chain */
57 	char *asru_name;		/* string form of resource fmri (ro) */
58 	nvlist_t *asru_fmri;		/* nvlist form of resource fmri (ro) */
59 	char *asru_root;		/* directory for cache entry (ro) */
60 	char *asru_uuid;		/* uuid for asru cache entry (ro) */
61 	uint_t asru_uuidlen;		/* length of asru_uuid (not incl. \0) */
62 	pthread_mutex_t asru_lock;	/* lock protecting remaining members */
63 	pthread_cond_t asru_cv;		/* condition variable for asru_flags */
64 	uint_t asru_refs;		/* reference count */
65 	uint_t asru_flags;		/* flags (see below) */
66 	fmd_case_t *asru_case;		/* case associated with last change */
67 	nvlist_t *asru_event;		/* event associated with last change */
68 	fmd_list_t asru_list;		/* linked list next/prev pointers */
69 } fmd_asru_t;
70 
71 typedef struct fmd_asru_link {
72 	fmd_list_t al_list;		/* linked list next/prev pointers */
73 	struct fmd_asru *al_asru;		/* pointer back to parent */
74 	struct fmd_asru_link *al_asru_next;	/* next link on hash chain */
75 	struct fmd_asru_link *al_case_next;	/* next link on hash chain */
76 	struct fmd_asru_link *al_fru_next;	/* next link on hash chain */
77 	struct fmd_asru_link *al_label_next;	/* next link on hash chain */
78 	struct fmd_asru_link *al_rsrc_next;	/* next link on hash chain */
79 	char *al_uuid;			/* uuid for asru cache entry (ro) */
80 	uint_t al_uuidlen;		/* length of al_uuid (not incl. \0) */
81 	fmd_log_t *al_log;		/* persistent event log */
82 	char *al_asru_name;		/* string form of asru fmri (ro) */
83 	char *al_fru_name;		/* string form of fru fmri (ro) */
84 	char *al_rsrc_name;		/* string form of resource fmri (ro) */
85 	char *al_label;			/* label */
86 	char *al_case_uuid;		/* case uuid */
87 	nvlist_t *al_asru_fmri;		/* nvlist form of resource fmri (ro) */
88 	fmd_case_t *al_case;		/* case associated with last change */
89 	nvlist_t *al_event;		/* event associated with last change */
90 	uint_t al_refs;			/* reference count */
91 	uint_t al_flags;		/* flags (see below) */
92 	uint8_t al_reason;		/* repair reason (see below) */
93 } fmd_asru_link_t;
94 
95 #define	FMD_ASRU_FAULTY		0x01	/* asru has been diagnosed as faulty */
96 #define	FMD_ASRU_UNUSABLE	0x02	/* asru can not be used at present */
97 #define	FMD_ASRU_VALID		0x04	/* asru is initialized and valid */
98 #define	FMD_ASRU_INTERNAL	0x08	/* asru is managed by fmd itself */
99 #define	FMD_ASRU_INVISIBLE	0x10	/* asru is not visibly administered */
100 #define	FMD_ASRU_RECREATED	0x20	/* asru recreated by cache replay */
101 #define	FMD_ASRU_PRESENT	0x40	/* asru present at last R$ update */
102 #define	FMD_ASRU_DEGRADED	0x80	/* asru service is degraded */
103 
104 /*
105  * Note the following are defined in order of increasing precedence and
106  * this should not be changed
107  */
108 #define	FMD_ASRU_ACQUITTED	1	/* asru acquitted */
109 #define	FMD_ASRU_REPAIRED	2	/* asru repaired */
110 #define	FMD_ASRU_REPLACED	3	/* asru replaced */
111 
112 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
113 
114 #define	FMD_ASRU_AL_HASH_NAME(a, off) \
115 	*(char **)((uint8_t *)a + off)
116 #define	FMD_ASRU_AL_HASH_NEXT(a, off) \
117 	*(fmd_asru_link_t **)((uint8_t *)a + off)
118 #define	FMD_ASRU_AL_HASH_NEXTP(a, off) \
119 	(fmd_asru_link_t **)((uint8_t *)a + off)
120 
121 typedef struct fmd_asru_hash {
122 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
123 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
124 	fmd_asru_link_t **ah_asru_hash;	/* hash bucket array for asrus */
125 	fmd_asru_link_t **ah_case_hash;	/* hash bucket array for frus */
126 	fmd_asru_link_t **ah_fru_hash;	/* hash bucket array for cases */
127 	fmd_asru_link_t **ah_label_hash;	/* label hash bucket array */
128 	fmd_asru_link_t **ah_rsrc_hash;	/* hash bucket array for rsrcs */
129 	uint_t ah_hashlen;		/* length of hash bucket array */
130 	char *ah_dirpath;		/* path of hash's log file directory */
131 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
132 	uint_t ah_al_count;		/* count of number of entries in hash */
133 	uint_t ah_count;		/* count of separate rsrcs in hash */
134 	int ah_error;			/* error from opening asru log */
135 	fmd_topo_t *ah_topo;		/* topo handle */
136 } fmd_asru_hash_t;
137 
138 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
139 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
140 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
141 extern void fmd_asru_hash_replay(fmd_asru_hash_t *);
142 
143 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
144     void (*)(fmd_asru_t *, void *), void *);
145 extern void fmd_asru_al_hash_apply(fmd_asru_hash_t *,
146     void (*)(fmd_asru_link_t *, void *), void *);
147 extern void fmd_asru_hash_apply_by_asru(fmd_asru_hash_t *, char *,
148     void (*)(fmd_asru_link_t *, void *), void *);
149 extern void fmd_asru_hash_apply_by_label(fmd_asru_hash_t *, char *,
150     void (*)(fmd_asru_link_t *, void *), void *);
151 extern void fmd_asru_hash_apply_by_fru(fmd_asru_hash_t *, char *,
152     void (*)(fmd_asru_link_t *, void *), void *);
153 extern void fmd_asru_hash_apply_by_rsrc(fmd_asru_hash_t *, char *,
154     void (*)(fmd_asru_link_t *, void *), void *);
155 extern void fmd_asru_hash_apply_by_case(fmd_asru_hash_t *, fmd_case_t *,
156     void (*)(fmd_asru_link_t *, void *), void *);
157 
158 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
159 extern fmd_asru_link_t *fmd_asru_hash_create_entry(fmd_asru_hash_t *,
160     fmd_case_t *, nvlist_t *);
161 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
162 extern void fmd_asru_hash_delete_case(fmd_asru_hash_t *, fmd_case_t *);
163 
164 extern void fmd_asru_clear_aged_rsrcs();
165 extern void fmd_asru_repaired(fmd_asru_link_t *, void *);
166 extern void fmd_asru_acquit(fmd_asru_link_t *, void *);
167 extern void fmd_asru_replaced(fmd_asru_link_t *, void *);
168 extern void fmd_asru_removed(fmd_asru_link_t *);
169 extern int fmd_asru_setflags(fmd_asru_link_t *, uint_t);
170 extern int fmd_asru_clrflags(fmd_asru_link_t *, uint_t, uint8_t);
171 extern int fmd_asru_al_getstate(fmd_asru_link_t *);
172 extern int fmd_asru_getstate(fmd_asru_t *);
173 
174 #ifdef	__cplusplus
175 }
176 #endif
177 
178 #endif	/* _FMD_ASRU_H */
179