xref: /titanic_41/usr/src/cmd/fm/fmd/common/fmd_case.h (revision c138f478d2bc94e73ab8f6a084e323bec25e62f5)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_FMD_CASE_H
29 #define	_FMD_CASE_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <pthread.h>
34 #include <libnvpair.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #include <fmd_list.h>
41 #include <fmd_api.h>
42 #include <fmd_buf.h>
43 
44 struct fmd_module;			/* see <fmd_module.h> */
45 
46 typedef struct fmd_case_item {
47 	struct fmd_case_item *cit_next;	/* pointer to next element in list */
48 	fmd_event_t *cit_event;		/* pointer to held event */
49 } fmd_case_item_t;
50 
51 typedef struct fmd_case_susp {
52 	struct fmd_case_susp *cis_next;	/* pointer to next element in list */
53 	nvlist_t *cis_nvl;		/* nvpair representing fault event */
54 } fmd_case_susp_t;
55 
56 typedef struct fmd_case_impl {
57 	fmd_list_t ci_list;		/* linked list next/prev pointers */
58 	struct fmd_case_impl *ci_next;	/* next pointer for hash bucket chain */
59 	char *ci_uuid;			/* uuid string for this case */
60 	uint_t ci_uuidlen;		/* length of ci_uuid (not incl. \0) */
61 	char *ci_code;			/* code associated with this case */
62 	size_t ci_codelen;		/* size of ci_code buffer in bytes */
63 	struct fmd_module *ci_mod;	/* module that owns this case */
64 	fmd_xprt_t *ci_xprt;		/* transport for this case (or NULL) */
65 	void *ci_data;			/* data from fmd_case_setspecific() */
66 	pthread_mutex_t ci_lock;	/* lock for remainder of contents */
67 	uint_t ci_refs;			/* reference count */
68 	ushort_t ci_state;		/* case state (see below) */
69 	ushort_t ci_flags;		/* case flags (see below) */
70 	fmd_case_item_t *ci_items;	/* list of items in this case */
71 	uint_t ci_nitems;		/* number of ci_items */
72 	fmd_event_t *ci_principal;	/* principal event (if any) */
73 	fmd_case_susp_t *ci_suspects;	/* list of suspects in this case */
74 	uint_t ci_nsuspects;		/* number of ci_suspects */
75 	size_t ci_nvsz;			/* packed suspect nvlist array size */
76 	fmd_buf_hash_t ci_bufs;		/* hash of bufs associated with case */
77 } fmd_case_impl_t;
78 
79 #define	FMD_CASE_CURRENT	-1u	/* flag for current state */
80 
81 #define	FMD_CASE_UNSOLVED	0	/* case is not yet solved (waiting) */
82 #define	FMD_CASE_SOLVED		1	/* case is solved (suspects added) */
83 #define	FMD_CASE_CLOSE_WAIT	2	/* case is executing fmdo_close() */
84 #define	FMD_CASE_CLOSED		3	/* case is closed (reconfig done) */
85 #define	FMD_CASE_REPAIRED	4	/* case is repaired (can be freed) */
86 
87 #define	FMD_CF_DIRTY		0x1	/* case is in need of checkpoint */
88 #define	FMD_CF_SOLVED		0x2	/* case has been solved */
89 #define	FMD_CF_ISOLATED		0x4	/* case has been isolated */
90 #define	FMD_CF_REPAIRED		0x8	/* case has been repaired */
91 
92 typedef struct fmd_case_hash {
93 	pthread_rwlock_t ch_lock;	/* lock protecting case hash */
94 	fmd_case_impl_t **ch_hash;	/* hash bucket array for cases */
95 	uint_t ch_hashlen;		/* size of hash bucket array */
96 	uint_t ch_count;		/* number of cases in hash */
97 } fmd_case_hash_t;
98 
99 extern fmd_case_hash_t *fmd_case_hash_create(void);
100 extern void fmd_case_hash_destroy(fmd_case_hash_t *);
101 extern fmd_case_t *fmd_case_hash_lookup(fmd_case_hash_t *, const char *);
102 extern void fmd_case_hash_apply(fmd_case_hash_t *,
103     void (*)(fmd_case_t *, void *), void *);
104 
105 extern fmd_case_t *fmd_case_create(struct fmd_module *, void *);
106 extern fmd_case_t *fmd_case_recreate(struct fmd_module *,
107     struct fmd_xprt *, uint_t, const char *, const char *);
108 extern void fmd_case_destroy(fmd_case_t *, int);
109 extern void fmd_case_hold(fmd_case_t *);
110 extern void fmd_case_hold_locked(fmd_case_t *);
111 extern void fmd_case_rele(fmd_case_t *);
112 
113 extern void fmd_case_insert_principal(fmd_case_t *, fmd_event_t *);
114 extern void fmd_case_insert_event(fmd_case_t *, fmd_event_t *);
115 extern void fmd_case_insert_suspect(fmd_case_t *, nvlist_t *);
116 extern void fmd_case_recreate_suspect(fmd_case_t *, nvlist_t *);
117 extern void fmd_case_reset_suspects(fmd_case_t *);
118 
119 extern nvlist_t *fmd_case_mkevent(fmd_case_t *, const char *);
120 extern void fmd_case_publish(fmd_case_t *, uint_t);
121 extern void fmd_case_transition(fmd_case_t *, uint_t, uint_t);
122 extern void fmd_case_setdirty(fmd_case_t *);
123 extern void fmd_case_clrdirty(fmd_case_t *);
124 extern void fmd_case_commit(fmd_case_t *);
125 extern void fmd_case_update(fmd_case_t *);
126 extern void fmd_case_delete(fmd_case_t *);
127 extern void fmd_case_discard(fmd_case_t *);
128 
129 extern int fmd_case_repair(fmd_case_t *);
130 extern int fmd_case_contains(fmd_case_t *, fmd_event_t *);
131 extern int fmd_case_orphaned(fmd_case_t *);
132 
133 #ifdef	__cplusplus
134 }
135 #endif
136 
137 #endif	/* _FMD_CASE_H */
138