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