xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_scheme.h (revision 2a8bcb4e)
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 #include <libnvpair.h>
317c478bd9Sstevel@tonic-gate #include <pthread.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Scheme operations.  These function pointers are filled in when the scheme
397c478bd9Sstevel@tonic-gate  * is loaded.  New operations must be added here as well as to the default
407c478bd9Sstevel@tonic-gate  * operations declaration and initialization table in fmd_scheme.c.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_ops {
437c478bd9Sstevel@tonic-gate 	int (*sop_init)(void);
447c478bd9Sstevel@tonic-gate 	void (*sop_fini)(void);
457c478bd9Sstevel@tonic-gate 	ssize_t (*sop_nvl2str)(nvlist_t *, char *, size_t);
467c478bd9Sstevel@tonic-gate 	int (*sop_expand)(nvlist_t *);
477c478bd9Sstevel@tonic-gate 	int (*sop_present)(nvlist_t *);
48*25c6ff4bSstephh 	int (*sop_replaced)(nvlist_t *);
49*25c6ff4bSstephh 	int (*sop_service_state)(nvlist_t *);
507c478bd9Sstevel@tonic-gate 	int (*sop_unusable)(nvlist_t *);
517c478bd9Sstevel@tonic-gate 	int (*sop_contains)(nvlist_t *, nvlist_t *);
52d9638e54Smws 	nvlist_t *(*sop_translate)(nvlist_t *, nvlist_t *);
537c478bd9Sstevel@tonic-gate } fmd_scheme_ops_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_opd {
567c478bd9Sstevel@tonic-gate 	const char *opd_name;		/* symbol name of scheme function */
577c478bd9Sstevel@tonic-gate 	size_t opd_off;			/* offset within fmd_scheme_ops_t */
587c478bd9Sstevel@tonic-gate } fmd_scheme_opd_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef struct fmd_scheme {
617c478bd9Sstevel@tonic-gate 	struct fmd_scheme *sch_next;	/* next scheme on hash bucket chain */
627c478bd9Sstevel@tonic-gate 	char *sch_name;			/* name of this scheme (fmri prefix) */
637c478bd9Sstevel@tonic-gate 	void *sch_dlp;			/* libdl(3DL) shared library handle */
647c478bd9Sstevel@tonic-gate 	pthread_mutex_t sch_lock;	/* lock protecting cv, refs, loaded */
657c478bd9Sstevel@tonic-gate 	pthread_cond_t sch_cv;		/* condition variable for sch_loaded */
667c478bd9Sstevel@tonic-gate 	uint_t sch_refs;		/* scheme reference count */
677c478bd9Sstevel@tonic-gate 	uint_t sch_loaded;		/* scheme has been loaded */
687c478bd9Sstevel@tonic-gate 	pthread_mutex_t sch_opslock;	/* lock protecting non-init/fini ops */
697c478bd9Sstevel@tonic-gate 	fmd_scheme_ops_t sch_ops;	/* scheme function pointers */
707c478bd9Sstevel@tonic-gate } fmd_scheme_t;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate typedef struct fmd_scheme_hash {
737c478bd9Sstevel@tonic-gate 	pthread_rwlock_t sch_rwlock;	/* rwlock protecting scheme hash */
747c478bd9Sstevel@tonic-gate 	fmd_scheme_t **sch_hash;	/* hash bucket array of schemes */
757c478bd9Sstevel@tonic-gate 	uint_t sch_hashlen;		/* length of hash bucket array */
767c478bd9Sstevel@tonic-gate 	char *sch_dirpath;		/* directory path for schemes */
777c478bd9Sstevel@tonic-gate } fmd_scheme_hash_t;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate extern fmd_scheme_hash_t *fmd_scheme_hash_create(const char *, const char *);
807c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_destroy(fmd_scheme_hash_t *);
817c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_trygc(fmd_scheme_hash_t *);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate extern fmd_scheme_t *fmd_scheme_hash_lookup(fmd_scheme_hash_t *, const char *);
847c478bd9Sstevel@tonic-gate extern void fmd_scheme_hash_release(fmd_scheme_hash_t *, fmd_scheme_t *);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #endif	/* _FMD_SCHEME_H */
91