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