xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd_scheme.h (revision 25c6ff4b77fcddf4097ce78a8277275ca603b46c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*25c6ff4bSstephh  * Common Development and Distribution License (the "License").
6*25c6ff4bSstephh  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21d9638e54Smws 
227c478bd9Sstevel@tonic-gate /*
23*25c6ff4bSstephh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_FMD_SCHEME_H
287c478bd9Sstevel@tonic-gate #define	_FMD_SCHEME_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <libnvpair.h>
337c478bd9Sstevel@tonic-gate #include <pthread.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Scheme operations.  These function pointers are filled in when the scheme
417c478bd9Sstevel@tonic-gate  * is loaded.  New operations must be added here as well as to the default
427c478bd9Sstevel@tonic-gate  * operations declaration and initialization table in fmd_scheme.c.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_ops {
457c478bd9Sstevel@tonic-gate 	int (*sop_init)(void);
467c478bd9Sstevel@tonic-gate 	void (*sop_fini)(void);
477c478bd9Sstevel@tonic-gate 	ssize_t (*sop_nvl2str)(nvlist_t *, char *, size_t);
487c478bd9Sstevel@tonic-gate 	int (*sop_expand)(nvlist_t *);
497c478bd9Sstevel@tonic-gate 	int (*sop_present)(nvlist_t *);
50*25c6ff4bSstephh 	int (*sop_replaced)(nvlist_t *);
51*25c6ff4bSstephh 	int (*sop_service_state)(nvlist_t *);
527c478bd9Sstevel@tonic-gate 	int (*sop_unusable)(nvlist_t *);
537c478bd9Sstevel@tonic-gate 	int (*sop_contains)(nvlist_t *, nvlist_t *);
54d9638e54Smws 	nvlist_t *(*sop_translate)(nvlist_t *, nvlist_t *);
557c478bd9Sstevel@tonic-gate } fmd_scheme_ops_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_opd {
587c478bd9Sstevel@tonic-gate 	const char *opd_name;		/* symbol name of scheme function */
597c478bd9Sstevel@tonic-gate 	size_t opd_off;			/* offset within fmd_scheme_ops_t */
607c478bd9Sstevel@tonic-gate } fmd_scheme_opd_t;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct fmd_scheme {
637c478bd9Sstevel@tonic-gate 	struct fmd_scheme *sch_next;	/* next scheme on hash bucket chain */
647c478bd9Sstevel@tonic-gate 	char *sch_name;			/* name of this scheme (fmri prefix) */
657c478bd9Sstevel@tonic-gate 	void *sch_dlp;			/* libdl(3DL) shared library handle */
667c478bd9Sstevel@tonic-gate 	pthread_mutex_t sch_lock;	/* lock protecting cv, refs, loaded */
677c478bd9Sstevel@tonic-gate 	pthread_cond_t sch_cv;		/* condition variable for sch_loaded */
687c478bd9Sstevel@tonic-gate 	uint_t sch_refs;		/* scheme reference count */
697c478bd9Sstevel@tonic-gate 	uint_t sch_loaded;		/* scheme has been loaded */
707c478bd9Sstevel@tonic-gate 	pthread_mutex_t sch_opslock;	/* lock protecting non-init/fini ops */
717c478bd9Sstevel@tonic-gate 	fmd_scheme_ops_t sch_ops;	/* scheme function pointers */
727c478bd9Sstevel@tonic-gate } fmd_scheme_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_hash {
757c478bd9Sstevel@tonic-gate 	pthread_rwlock_t sch_rwlock;	/* rwlock protecting scheme hash */
767c478bd9Sstevel@tonic-gate 	fmd_scheme_t **sch_hash;	/* hash bucket array of schemes */
777c478bd9Sstevel@tonic-gate 	uint_t sch_hashlen;		/* length of hash bucket array */
787c478bd9Sstevel@tonic-gate 	char *sch_dirpath;		/* directory path for schemes */
797c478bd9Sstevel@tonic-gate } fmd_scheme_hash_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate extern fmd_scheme_hash_t *fmd_scheme_hash_create(const char *, const char *);
827c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_destroy(fmd_scheme_hash_t *);
837c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_trygc(fmd_scheme_hash_t *);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern fmd_scheme_t *fmd_scheme_hash_lookup(fmd_scheme_hash_t *, const char *);
867c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_release(fmd_scheme_hash_t *, fmd_scheme_t *);
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #endif	/* _FMD_SCHEME_H */
93