xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd_asru.h (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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  * Copyright 2004 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 
42 typedef struct fmd_asru {
43 	struct fmd_asru *asru_next;	/* next asru on hash chain */
44 	char *asru_name;		/* string form of resource fmri (ro) */
45 	nvlist_t *asru_fmri;		/* nvlist form of resource fmri (ro) */
46 	char *asru_root;		/* directory for cache entry (ro) */
47 	char *asru_uuid;		/* uuid for asru cache entry (ro) */
48 	uint_t asru_uuidlen;		/* length of asru_uuid (not incl. \0) */
49 	fmd_log_t *asru_log;		/* persistent event log */
50 	pthread_mutex_t asru_lock;	/* lock protecting remaining members */
51 	pthread_cond_t asru_cv;		/* condition variable for asru_flags */
52 	uint_t asru_refs;		/* reference count */
53 	uint_t asru_flags;		/* flags (see below) */
54 	char *asru_case;		/* case uuid from last change */
55 } fmd_asru_t;
56 
57 #define	FMD_ASRU_FAULTY		0x01	/* asru has been diagnosed as faulty */
58 #define	FMD_ASRU_UNUSABLE	0x02	/* asru can not be used at present */
59 #define	FMD_ASRU_VALID		0x04	/* asru is initialized and valid */
60 #define	FMD_ASRU_INTERNAL	0x08	/* asru is managed by fmd itself */
61 #define	FMD_ASRU_INVISIBLE	0x10	/* asru is not visibly administered */
62 
63 #define	FMD_ASRU_STATE	(FMD_ASRU_FAULTY | FMD_ASRU_UNUSABLE)
64 
65 typedef struct fmd_asru_hash {
66 	pthread_rwlock_t ah_lock;	/* r/w lock protecting hash contents */
67 	fmd_asru_t **ah_hash;		/* hash bucket array for asrus */
68 	uint_t ah_hashlen;		/* length of hash bucket array */
69 	char *ah_dirpath;		/* path of hash's log file directory */
70 	uint64_t ah_lifetime;		/* max lifetime of log if not present */
71 	uint_t ah_count;		/* count of number of entries in hash */
72 	int ah_error;			/* error from opening asru log */
73 } fmd_asru_hash_t;
74 
75 extern fmd_asru_hash_t *fmd_asru_hash_create(const char *, const char *);
76 extern void fmd_asru_hash_destroy(fmd_asru_hash_t *);
77 extern void fmd_asru_hash_refresh(fmd_asru_hash_t *);
78 
79 extern void fmd_asru_hash_apply(fmd_asru_hash_t *,
80     void (*)(fmd_asru_t *, void *), void *);
81 
82 extern fmd_asru_t *fmd_asru_hash_lookup_name(fmd_asru_hash_t *, const char *);
83 extern fmd_asru_t *fmd_asru_hash_lookup_nvl(fmd_asru_hash_t *, nvlist_t *, int);
84 extern void fmd_asru_hash_release(fmd_asru_hash_t *, fmd_asru_t *);
85 extern int fmd_asru_hash_delete_name(fmd_asru_hash_t *, const char *);
86 
87 extern int fmd_asru_setflags(fmd_asru_t *, uint_t, const char *, nvlist_t *);
88 extern int fmd_asru_clrflags(fmd_asru_t *, uint_t, const char *, nvlist_t *);
89 extern int fmd_asru_getstate(fmd_asru_t *);
90 extern char *fmd_asru_getcase(fmd_asru_t *, char *, size_t);
91 
92 #ifdef	__cplusplus
93 }
94 #endif
95 
96 #endif	/* _FMD_ASRU_H */
97