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