xref: /titanic_44/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 643e2e74e1c00e6b3d1896a6a67dbdb7308135c3)
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 } fmd_asru_link_t;
93 
94 #define	FMD_ASRU_FAULTY		0x01	/* asru has been diagnosed as faulty */
95 #define	FMD_ASRU_UNUSABLE	0x02	/* asru can not be used at present */
96 #define	FMD_ASRU_VALID		0x04	/* asru is initialized and valid */
97 #define	FMD_ASRU_INTERNAL	0x08	/* asru is managed by fmd itself */
98 #define	FMD_ASRU_INVISIBLE	0x10	/* asru is not visibly administered */
99 #define	FMD_ASRU_RECREATED	0x20	/* asru recreated by cache replay */
100 #define	FMD_ASRU_PRESENT	0x40	/* asru present at last R$ update */
101 
102 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
103 
104 #define	FMD_ASRU_AL_HASH_NAME(a, off) \
105 	*(char **)((uint8_t *)a + off)
106 #define	FMD_ASRU_AL_HASH_NEXT(a, off) \
107 	*(fmd_asru_link_t **)((uint8_t *)a + off)
108 #define	FMD_ASRU_AL_HASH_NEXTP(a, off) \
109 	(fmd_asru_link_t **)((uint8_t *)a + off)
110 
111 typedef struct fmd_asru_hash {
112 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
113 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
114 	fmd_asru_link_t **ah_asru_hash;	/* hash bucket array for asrus */
115 	fmd_asru_link_t **ah_case_hash;	/* hash bucket array for frus */
116 	fmd_asru_link_t **ah_fru_hash;	/* hash bucket array for cases */
117 	fmd_asru_link_t **ah_label_hash;	/* label hash bucket array */
118 	fmd_asru_link_t **ah_rsrc_hash;	/* hash bucket array for rsrcs */
119 	uint_t ah_hashlen;		/* length of hash bucket array */
120 	char *ah_dirpath;		/* path of hash's log file directory */
121 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
122 	uint_t ah_al_count;		/* count of number of entries in hash */
123 	uint_t ah_count;		/* count of separate rsrcs in hash */
124 	int ah_error;			/* error from opening asru log */
125 	fmd_topo_t *ah_topo;		/* topo handle */
126 } fmd_asru_hash_t;
127 
128 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
129 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
130 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
131 extern void fmd_asru_hash_replay(fmd_asru_hash_t *);
132 
133 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
134     void (*)(fmd_asru_t *, void *), void *);
135 extern void fmd_asru_al_hash_apply(fmd_asru_hash_t *,
136     void (*)(fmd_asru_link_t *, void *), void *);
137 extern void fmd_asru_hash_apply_by_asru(fmd_asru_hash_t *, char *,
138     void (*)(fmd_asru_link_t *, void *), void *);
139 extern void fmd_asru_hash_apply_by_label(fmd_asru_hash_t *, char *,
140     void (*)(fmd_asru_link_t *, void *), void *);
141 extern void fmd_asru_hash_apply_by_fru(fmd_asru_hash_t *, char *,
142     void (*)(fmd_asru_link_t *, void *), void *);
143 extern void fmd_asru_hash_apply_by_rsrc(fmd_asru_hash_t *, char *,
144     void (*)(fmd_asru_link_t *, void *), void *);
145 extern void fmd_asru_hash_apply_by_case(fmd_asru_hash_t *, fmd_case_t *,
146     void (*)(fmd_asru_link_t *, void *), void *);
147 
148 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
149 extern fmd_asru_t *fmd_asru_hash_lookup_nvl(fmd_asru_hash_t *, nvlist_t *);
150 extern fmd_asru_link_t *fmd_asru_hash_create_entry(fmd_asru_hash_t *,
151     fmd_case_t *, nvlist_t *);
152 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
153 extern void fmd_asru_hash_delete_case(fmd_asru_hash_t *, fmd_case_t *);
154 
155 extern void fmd_asru_clear_aged_rsrcs();
156 extern void fmd_asru_repair(fmd_asru_link_t *, void *);
157 extern int fmd_asru_setflags(fmd_asru_link_t *, uint_t);
158 extern int fmd_asru_clrflags(fmd_asru_link_t *, uint_t);
159 extern int fmd_asru_al_getstate(fmd_asru_link_t *);
160 extern int fmd_asru_getstate(fmd_asru_t *);
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _FMD_ASRU_H */
167