xref: /titanic_50/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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 
43 /*
44  * The resource is represented by an fmd_asru_t structure and one or more
45  * fmd_asru_link_t structures. Each of the latter represents a separate
46  * unrepaired case (problem) involving the resource. There are separate
47  * reference counts for both the fmd_asru_t and fmd_asru_link_t structures,
48  * but only one lock is used (asru_lock) which protects both the parent
49  * fmd_asru_t and its associated fmd_asru_link_t structures. The FMD_ASRU_FAULTY
50  * flags in the fmd_asru_t represents the cumulative value of the associated
51  * FMD_ASRU_FAULTY flags in the fmd_asru_link_t structures (and therefore of
52  * all independant unrepaired problems that are affecting that resource).
53  */
54 typedef struct fmd_asru {
55 	struct fmd_asru *asru_next;	/* next asru on hash chain */
56 	char *asru_name;		/* string form of resource fmri (ro) */
57 	nvlist_t *asru_fmri;		/* nvlist form of resource fmri (ro) */
58 	char *asru_root;		/* directory for cache entry (ro) */
59 	char *asru_uuid;		/* uuid for asru cache entry (ro) */
60 	uint_t asru_uuidlen;		/* length of asru_uuid (not incl. \0) */
61 	pthread_mutex_t asru_lock;	/* lock protecting remaining members */
62 	pthread_cond_t asru_cv;		/* condition variable for asru_flags */
63 	uint_t asru_refs;		/* reference count */
64 	uint_t asru_flags;		/* flags (see below) */
65 	fmd_case_t *asru_case;		/* case associated with last change */
66 	nvlist_t *asru_event;		/* event associated with last change */
67 	fmd_list_t asru_list;		/* linked list next/prev pointers */
68 } fmd_asru_t;
69 
70 typedef struct fmd_asru_link {
71 	fmd_list_t al_list;		/* linked list next/prev pointers */
72 	struct fmd_asru *al_asru;		/* pointer back to parent */
73 	struct fmd_asru_link *al_asru_next;	/* next link on hash chain */
74 	struct fmd_asru_link *al_case_next;	/* next link on hash chain */
75 	struct fmd_asru_link *al_fru_next;	/* next link on hash chain */
76 	struct fmd_asru_link *al_label_next;	/* next link on hash chain */
77 	struct fmd_asru_link *al_rsrc_next;	/* next link on hash chain */
78 	char *al_uuid;			/* uuid for asru cache entry (ro) */
79 	uint_t al_uuidlen;		/* length of al_uuid (not incl. \0) */
80 	fmd_log_t *al_log;		/* persistent event log */
81 	char *al_asru_name;		/* string form of asru fmri (ro) */
82 	char *al_fru_name;		/* string form of fru fmri (ro) */
83 	char *al_rsrc_name;		/* string form of resource fmri (ro) */
84 	char *al_label;			/* label */
85 	char *al_case_uuid;		/* case uuid */
86 	nvlist_t *al_asru_fmri;		/* nvlist form of resource fmri (ro) */
87 	fmd_case_t *al_case;		/* case associated with last change */
88 	nvlist_t *al_event;		/* event associated with last change */
89 	uint_t al_refs;			/* reference count */
90 	uint_t al_flags;		/* flags (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 
101 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
102 
103 #define	FMD_ASRU_AL_HASH_NAME(a, off) \
104 	*(char **)((uint8_t *)a + off)
105 #define	FMD_ASRU_AL_HASH_NEXT(a, off) \
106 	*(fmd_asru_link_t **)((uint8_t *)a + off)
107 #define	FMD_ASRU_AL_HASH_NEXTP(a, off) \
108 	(fmd_asru_link_t **)((uint8_t *)a + off)
109 
110 typedef struct fmd_asru_hash {
111 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
112 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
113 	fmd_asru_link_t **ah_asru_hash;	/* hash bucket array for asrus */
114 	fmd_asru_link_t **ah_case_hash;	/* hash bucket array for frus */
115 	fmd_asru_link_t **ah_fru_hash;	/* hash bucket array for cases */
116 	fmd_asru_link_t **ah_label_hash;	/* label hash bucket array */
117 	fmd_asru_link_t **ah_rsrc_hash;	/* hash bucket array for rsrcs */
118 	uint_t ah_hashlen;		/* length of hash bucket array */
119 	char *ah_dirpath;		/* path of hash's log file directory */
120 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
121 	uint_t ah_al_count;		/* count of number of entries in hash */
122 	uint_t ah_count;		/* count of separate rsrcs in hash */
123 	int ah_error;			/* error from opening asru log */
124 } fmd_asru_hash_t;
125 
126 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
127 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
128 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
129 extern void fmd_asru_hash_replay(fmd_asru_hash_t *);
130 
131 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
132     void (*)(fmd_asru_t *, void *), void *);
133 extern void fmd_asru_al_hash_apply(fmd_asru_hash_t *,
134     void (*)(fmd_asru_link_t *, void *), void *);
135 extern void fmd_asru_hash_apply_by_asru(fmd_asru_hash_t *, char *,
136     void (*)(fmd_asru_link_t *, void *), void *);
137 extern void fmd_asru_hash_apply_by_label(fmd_asru_hash_t *, char *,
138     void (*)(fmd_asru_link_t *, void *), void *);
139 extern void fmd_asru_hash_apply_by_fru(fmd_asru_hash_t *, char *,
140     void (*)(fmd_asru_link_t *, void *), void *);
141 extern void fmd_asru_hash_apply_by_rsrc(fmd_asru_hash_t *, char *,
142     void (*)(fmd_asru_link_t *, void *), void *);
143 extern void fmd_asru_hash_apply_by_case(fmd_asru_hash_t *, fmd_case_t *,
144     void (*)(fmd_asru_link_t *, void *), void *);
145 
146 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
147 extern fmd_asru_t *fmd_asru_hash_lookup_nvl(fmd_asru_hash_t *, nvlist_t *);
148 extern fmd_asru_link_t *fmd_asru_hash_create_entry(fmd_asru_hash_t *,
149     fmd_case_t *, nvlist_t *);
150 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
151 extern void fmd_asru_hash_delete_case(fmd_asru_hash_t *, fmd_case_t *);
152 
153 extern void fmd_asru_clear_aged_rsrcs();
154 extern void fmd_asru_repair(fmd_asru_link_t *, void *);
155 extern int fmd_asru_setflags(fmd_asru_link_t *, uint_t);
156 extern int fmd_asru_clrflags(fmd_asru_link_t *, uint_t);
157 extern int fmd_asru_al_getstate(fmd_asru_link_t *);
158 extern int fmd_asru_getstate(fmd_asru_t *);
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _FMD_ASRU_H */
165