xref: /titanic_44/usr/src/cmd/fm/fmd/common/fmd_scheme.h (revision baf2c95cb7af3bdff76a3e6693e566e0b8b75bc4)
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_SCHEME_H
28 #define	_FMD_SCHEME_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <libnvpair.h>
33 #include <pthread.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Scheme operations.  These function pointers are filled in when the scheme
41  * is loaded.  New operations must be added here as well as to the default
42  * operations declaration and initialization table in fmd_scheme.c.
43  */
44 typedef struct fmd_scheme_ops {
45 	int (*sop_init)(void);
46 	void (*sop_fini)(void);
47 	ssize_t (*sop_nvl2str)(nvlist_t *, char *, size_t);
48 	int (*sop_expand)(nvlist_t *);
49 	int (*sop_present)(nvlist_t *);
50 	int (*sop_replaced)(nvlist_t *);
51 	int (*sop_service_state)(nvlist_t *);
52 	int (*sop_unusable)(nvlist_t *);
53 	int (*sop_contains)(nvlist_t *, nvlist_t *);
54 	nvlist_t *(*sop_translate)(nvlist_t *, nvlist_t *);
55 } fmd_scheme_ops_t;
56 
57 typedef struct fmd_scheme_opd {
58 	const char *opd_name;		/* symbol name of scheme function */
59 	size_t opd_off;			/* offset within fmd_scheme_ops_t */
60 } fmd_scheme_opd_t;
61 
62 typedef struct fmd_scheme {
63 	struct fmd_scheme *sch_next;	/* next scheme on hash bucket chain */
64 	char *sch_name;			/* name of this scheme (fmri prefix) */
65 	void *sch_dlp;			/* libdl(3DL) shared library handle */
66 	pthread_mutex_t sch_lock;	/* lock protecting cv, refs, loaded */
67 	pthread_cond_t sch_cv;		/* condition variable for sch_loaded */
68 	uint_t sch_refs;		/* scheme reference count */
69 	uint_t sch_loaded;		/* scheme has been loaded */
70 	pthread_mutex_t sch_opslock;	/* lock protecting non-init/fini ops */
71 	fmd_scheme_ops_t sch_ops;	/* scheme function pointers */
72 } fmd_scheme_t;
73 
74 typedef struct fmd_scheme_hash {
75 	pthread_rwlock_t sch_rwlock;	/* rwlock protecting scheme hash */
76 	fmd_scheme_t **sch_hash;	/* hash bucket array of schemes */
77 	uint_t sch_hashlen;		/* length of hash bucket array */
78 	char *sch_dirpath;		/* directory path for schemes */
79 } fmd_scheme_hash_t;
80 
81 extern fmd_scheme_hash_t *fmd_scheme_hash_create(const char *, const char *);
82 extern void fmd_scheme_hash_destroy(fmd_scheme_hash_t *);
83 extern void fmd_scheme_hash_trygc(fmd_scheme_hash_t *);
84 
85 extern fmd_scheme_t *fmd_scheme_hash_lookup(fmd_scheme_hash_t *, const char *);
86 extern void fmd_scheme_hash_release(fmd_scheme_hash_t *, fmd_scheme_t *);
87 
88 #ifdef	__cplusplus
89 }
90 #endif
91 
92 #endif	/* _FMD_SCHEME_H */
93