xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_FMD_ASRU_H
29 #define	_FMD_ASRU_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <sys/types.h>
34 #include <pthread.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #include <fmd_api.h>
41 #include <fmd_log.h>
42 
43 typedef struct fmd_asru {
44 	struct fmd_asru *asru_next;	/* next asru on hash chain */
45 	char *asru_name;		/* string form of resource fmri (ro) */
46 	nvlist_t *asru_fmri;		/* nvlist form of resource fmri (ro) */
47 	char *asru_root;		/* directory for cache entry (ro) */
48 	char *asru_uuid;		/* uuid for asru cache entry (ro) */
49 	uint_t asru_uuidlen;		/* length of asru_uuid (not incl. \0) */
50 	fmd_log_t *asru_log;		/* persistent event log */
51 	pthread_mutex_t asru_lock;	/* lock protecting remaining members */
52 	pthread_cond_t asru_cv;		/* condition variable for asru_flags */
53 	uint_t asru_refs;		/* reference count */
54 	uint_t asru_flags;		/* flags (see below) */
55 	fmd_case_t *asru_case;		/* case associated with last change */
56 	nvlist_t *asru_event;		/* event associated with last change */
57 } fmd_asru_t;
58 
59 #define	FMD_ASRU_FAULTY		0x01	/* asru has been diagnosed as faulty */
60 #define	FMD_ASRU_UNUSABLE	0x02	/* asru can not be used at present */
61 #define	FMD_ASRU_VALID		0x04	/* asru is initialized and valid */
62 #define	FMD_ASRU_INTERNAL	0x08	/* asru is managed by fmd itself */
63 #define	FMD_ASRU_INVISIBLE	0x10	/* asru is not visibly administered */
64 #define	FMD_ASRU_RECREATED	0x20	/* asru recreated by cache replay */
65 #define	FMD_ASRU_PRESENT	0x40	/* asru present at last R$ update */
66 
67 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
68 
69 typedef struct fmd_asru_hash {
70 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
71 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
72 	uint_t ah_hashlen;		/* length of hash bucket array */
73 	char *ah_dirpath;		/* path of hash's log file directory */
74 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
75 	uint_t ah_count;		/* count of number of entries in hash */
76 	int ah_error;			/* error from opening asru log */
77 } fmd_asru_hash_t;
78 
79 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
80 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
81 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
82 extern void fmd_asru_hash_replay(fmd_asru_hash_t *);
83 
84 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
85     void (*)(fmd_asru_t *, void *), void *);
86 
87 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
88 extern fmd_asru_t *fmd_asru_hash_lookup_nvl(fmd_asru_hash_t *, nvlist_t *, int);
89 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
90 extern int fmd_asru_hash_delete_name(fmd_asru_hash_t *, const char *);
91 
92 extern int fmd_asru_setflags(fmd_asru_t *, uint_t, fmd_case_t *, nvlist_t *);
93 extern int fmd_asru_clrflags(fmd_asru_t *, uint_t, fmd_case_t *, nvlist_t *);
94 extern int fmd_asru_getstate(fmd_asru_t *);
95 
96 #ifdef	__cplusplus
97 }
98 #endif
99 
100 #endif	/* _FMD_ASRU_H */
101