xref: /onnv-gate/usr/src/cmd/fm/fmd/common/fmd_scheme.h (revision 7275:1157db66a604)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7275Sstephh  * Common Development and Distribution License (the "License").
6*7275Sstephh  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211193Smws 
220Sstevel@tonic-gate /*
23*7275Sstephh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_FMD_SCHEME_H
280Sstevel@tonic-gate #define	_FMD_SCHEME_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <libnvpair.h>
330Sstevel@tonic-gate #include <pthread.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Scheme operations.  These function pointers are filled in when the scheme
410Sstevel@tonic-gate  * is loaded.  New operations must be added here as well as to the default
420Sstevel@tonic-gate  * operations declaration and initialization table in fmd_scheme.c.
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate typedef struct fmd_scheme_ops {
450Sstevel@tonic-gate 	int (*sop_init)(void);
460Sstevel@tonic-gate 	void (*sop_fini)(void);
470Sstevel@tonic-gate 	ssize_t (*sop_nvl2str)(nvlist_t *, char *, size_t);
480Sstevel@tonic-gate 	int (*sop_expand)(nvlist_t *);
490Sstevel@tonic-gate 	int (*sop_present)(nvlist_t *);
50*7275Sstephh 	int (*sop_replaced)(nvlist_t *);
51*7275Sstephh 	int (*sop_service_state)(nvlist_t *);
520Sstevel@tonic-gate 	int (*sop_unusable)(nvlist_t *);
530Sstevel@tonic-gate 	int (*sop_contains)(nvlist_t *, nvlist_t *);
541193Smws 	nvlist_t *(*sop_translate)(nvlist_t *, nvlist_t *);
550Sstevel@tonic-gate } fmd_scheme_ops_t;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate typedef struct fmd_scheme_opd {
580Sstevel@tonic-gate 	const char *opd_name;		/* symbol name of scheme function */
590Sstevel@tonic-gate 	size_t opd_off;			/* offset within fmd_scheme_ops_t */
600Sstevel@tonic-gate } fmd_scheme_opd_t;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate typedef struct fmd_scheme {
630Sstevel@tonic-gate 	struct fmd_scheme *sch_next;	/* next scheme on hash bucket chain */
640Sstevel@tonic-gate 	char *sch_name;			/* name of this scheme (fmri prefix) */
650Sstevel@tonic-gate 	void *sch_dlp;			/* libdl(3DL) shared library handle */
660Sstevel@tonic-gate 	pthread_mutex_t sch_lock;	/* lock protecting cv, refs, loaded */
670Sstevel@tonic-gate 	pthread_cond_t sch_cv;		/* condition variable for sch_loaded */
680Sstevel@tonic-gate 	uint_t sch_refs;		/* scheme reference count */
690Sstevel@tonic-gate 	uint_t sch_loaded;		/* scheme has been loaded */
700Sstevel@tonic-gate 	pthread_mutex_t sch_opslock;	/* lock protecting non-init/fini ops */
710Sstevel@tonic-gate 	fmd_scheme_ops_t sch_ops;	/* scheme function pointers */
720Sstevel@tonic-gate } fmd_scheme_t;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate typedef struct fmd_scheme_hash {
750Sstevel@tonic-gate 	pthread_rwlock_t sch_rwlock;	/* rwlock protecting scheme hash */
760Sstevel@tonic-gate 	fmd_scheme_t **sch_hash;	/* hash bucket array of schemes */
770Sstevel@tonic-gate 	uint_t sch_hashlen;		/* length of hash bucket array */
780Sstevel@tonic-gate 	char *sch_dirpath;		/* directory path for schemes */
790Sstevel@tonic-gate } fmd_scheme_hash_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate extern fmd_scheme_hash_t *fmd_scheme_hash_create(const char *, const char *);
820Sstevel@tonic-gate extern void fmd_scheme_hash_destroy(fmd_scheme_hash_t *);
830Sstevel@tonic-gate extern void fmd_scheme_hash_trygc(fmd_scheme_hash_t *);
840Sstevel@tonic-gate 
850Sstevel@tonic-gate extern fmd_scheme_t *fmd_scheme_hash_lookup(fmd_scheme_hash_t *, const char *);
860Sstevel@tonic-gate extern void fmd_scheme_hash_release(fmd_scheme_hash_t *, fmd_scheme_t *);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #ifdef	__cplusplus
890Sstevel@tonic-gate }
900Sstevel@tonic-gate #endif
910Sstevel@tonic-gate 
920Sstevel@tonic-gate #endif	/* _FMD_SCHEME_H */
93