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 580ab886dSwesolows * Common Development and Distribution License (the "License"). 680ab886dSwesolows * 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 */ 210b9e3e76Smws 227c478bd9Sstevel@tonic-gate /* 23*f6e214c7SGavin Maltby * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _FMD_MODULE_H 277c478bd9Sstevel@tonic-gate #define _FMD_MODULE_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <fm/diagcode.h> 317c478bd9Sstevel@tonic-gate #include <pthread.h> 327c478bd9Sstevel@tonic-gate #include <setjmp.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include <fmd_conf.h> 397c478bd9Sstevel@tonic-gate #include <fmd_list.h> 407c478bd9Sstevel@tonic-gate #include <fmd_serd.h> 417c478bd9Sstevel@tonic-gate #include <fmd_buf.h> 427c478bd9Sstevel@tonic-gate #include <fmd_api.h> 43d9638e54Smws #include <fmd_eventq.h> 4424db4641Seschrock #include <fmd_topo.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate struct fmd_module; /* see below */ 477c478bd9Sstevel@tonic-gate struct fmd_thread; /* see <fmd_thread.h> */ 487c478bd9Sstevel@tonic-gate struct fmd_idspace; /* see <fmd_idspace.h> */ 497c478bd9Sstevel@tonic-gate struct fmd_ustat; /* see <fmd_ustat.h> */ 507c478bd9Sstevel@tonic-gate struct fmd_ustat_snap; /* see <fmd_ustat.h> */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate typedef struct fmd_modops { 537c478bd9Sstevel@tonic-gate int (*mop_init)(struct fmd_module *); 547c478bd9Sstevel@tonic-gate int (*mop_fini)(struct fmd_module *); 557c478bd9Sstevel@tonic-gate void (*mop_dispatch)(struct fmd_module *, struct fmd_event *); 56d9638e54Smws int (*mop_transport)(struct fmd_module *, 57d9638e54Smws fmd_xprt_t *, struct fmd_event *); 587c478bd9Sstevel@tonic-gate } fmd_modops_t; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate typedef struct fmd_modhash { 617c478bd9Sstevel@tonic-gate pthread_rwlock_t mh_lock; /* r/w lock to protect hash */ 627c478bd9Sstevel@tonic-gate struct fmd_module **mh_hash; /* hash bucket array */ 637c478bd9Sstevel@tonic-gate uint_t mh_hashlen; /* size of hash bucket array */ 647c478bd9Sstevel@tonic-gate uint_t mh_nelems; /* number of modules in hash */ 657c478bd9Sstevel@tonic-gate } fmd_modhash_t; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Statistics maintained by fmd itself on behalf of all modules for fmstat(1M). 697c478bd9Sstevel@tonic-gate * NOTE: FMD_TYPE_STRING statistics should not be used here. If they are 707c478bd9Sstevel@tonic-gate * required in the future, the FMD_ADM_MODDSTAT service routine must change. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate typedef struct fmd_modstat { 73d9638e54Smws fmd_eventqstat_t ms_evqstat; /* stats for main module event queue */ 747c478bd9Sstevel@tonic-gate fmd_stat_t ms_loadtime; /* hrtime at which module was loaded */ 757c478bd9Sstevel@tonic-gate fmd_stat_t ms_snaptime; /* hrtime of recent stats snapshot */ 767c478bd9Sstevel@tonic-gate fmd_stat_t ms_accepted; /* total events accepted by module */ 777c478bd9Sstevel@tonic-gate fmd_stat_t ms_debugdrop; /* dropped debug messages */ 787c478bd9Sstevel@tonic-gate fmd_stat_t ms_memtotal; /* total space allocated by module */ 797c478bd9Sstevel@tonic-gate fmd_stat_t ms_memlimit; /* limit on space allocated by module */ 807c478bd9Sstevel@tonic-gate fmd_stat_t ms_buftotal; /* total space consumed by buffers */ 817c478bd9Sstevel@tonic-gate fmd_stat_t ms_buflimit; /* limit on space consumed by buffers */ 827c478bd9Sstevel@tonic-gate fmd_stat_t ms_thrtotal; /* total number of auxiliary threads */ 837c478bd9Sstevel@tonic-gate fmd_stat_t ms_thrlimit; /* limit on auxiliary threads */ 84*f6e214c7SGavin Maltby fmd_stat_t ms_doorthrtotal; /* total number of doorserver threads */ 85*f6e214c7SGavin Maltby fmd_stat_t ms_doorthrlimit; /* limit on doorserver threads */ 867c478bd9Sstevel@tonic-gate fmd_stat_t ms_caseopen; /* cases currently open */ 877c478bd9Sstevel@tonic-gate fmd_stat_t ms_casesolved; /* total cases solved by module */ 887c478bd9Sstevel@tonic-gate fmd_stat_t ms_caseclosed; /* total cases closed by module */ 897c478bd9Sstevel@tonic-gate fmd_stat_t ms_ckpt_save; /* save checkpoints for module */ 907c478bd9Sstevel@tonic-gate fmd_stat_t ms_ckpt_restore; /* restore checkpoints for module */ 917c478bd9Sstevel@tonic-gate fmd_stat_t ms_ckpt_zeroed; /* checkpoint was zeroed at startup */ 927c478bd9Sstevel@tonic-gate fmd_stat_t ms_ckpt_cnt; /* number of checkpoints taken */ 937c478bd9Sstevel@tonic-gate fmd_stat_t ms_ckpt_time; /* total checkpoint time */ 94d9638e54Smws fmd_stat_t ms_xprtopen; /* total number of open transports */ 95d9638e54Smws fmd_stat_t ms_xprtlimit; /* limit on number of open transports */ 96d9638e54Smws fmd_stat_t ms_xprtqlimit; /* limit on transport eventq length */ 977c478bd9Sstevel@tonic-gate } fmd_modstat_t; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate typedef struct fmd_module { 1007c478bd9Sstevel@tonic-gate fmd_list_t mod_list; /* linked list next/prev pointers */ 1017c478bd9Sstevel@tonic-gate pthread_mutex_t mod_lock; /* lock for mod_cv/owner/flags/refs */ 1027c478bd9Sstevel@tonic-gate pthread_cond_t mod_cv; /* condition variable for waiters */ 1037c478bd9Sstevel@tonic-gate pthread_t mod_owner; /* tid of thread that set MOD_LOCK */ 1047c478bd9Sstevel@tonic-gate uint_t mod_refs; /* module reference count */ 1057c478bd9Sstevel@tonic-gate uint_t mod_flags; /* miscellaneous flags (see below) */ 1067c478bd9Sstevel@tonic-gate uint64_t mod_gen; /* module checkpoint generation */ 1077c478bd9Sstevel@tonic-gate int mod_error; /* error return from module thread */ 1087c478bd9Sstevel@tonic-gate jmp_buf mod_jmpbuf; /* setjmp data for fmd_module_enter() */ 1097c478bd9Sstevel@tonic-gate fmd_modhash_t *mod_hash; /* containing namespace (ro) */ 1107c478bd9Sstevel@tonic-gate struct fmd_module *mod_next; /* next module in fmd_modhash chain */ 1117c478bd9Sstevel@tonic-gate char *mod_name; /* basename of module (ro) */ 1127c478bd9Sstevel@tonic-gate char *mod_path; /* full pathname of module file (ro) */ 1137c478bd9Sstevel@tonic-gate char *mod_ckpt; /* pathname of checkpoint dir (ro) */ 1147c478bd9Sstevel@tonic-gate nvlist_t *mod_fmri; /* fmri for this module */ 1157c478bd9Sstevel@tonic-gate const fmd_modops_t *mod_ops; /* module class ops vector (ro) */ 1167c478bd9Sstevel@tonic-gate void *mod_data; /* data private to module ops vector */ 1177c478bd9Sstevel@tonic-gate fmd_hdl_info_t *mod_info; /* module info registered with handle */ 1187c478bd9Sstevel@tonic-gate void *mod_spec; /* fmd_hdl_get/setspecific data value */ 1197c478bd9Sstevel@tonic-gate int mod_argc; /* size of mod_argv formals array */ 1207c478bd9Sstevel@tonic-gate fmd_conf_formal_t *mod_argv; /* array of conf file formals */ 1217c478bd9Sstevel@tonic-gate fmd_conf_t *mod_conf; /* configuration properties (ro) */ 1227c478bd9Sstevel@tonic-gate struct fm_dc_handle **mod_dictv; /* libdiagcode dictionaries */ 1237c478bd9Sstevel@tonic-gate int mod_dictc; /* size of mod_dictv array */ 1247c478bd9Sstevel@tonic-gate size_t mod_codelen; /* libdiagcode maximum string length */ 1257c478bd9Sstevel@tonic-gate struct fmd_eventq *mod_queue; /* eventq associated with module (ro) */ 1267c478bd9Sstevel@tonic-gate struct fmd_ustat *mod_ustat; /* collection of custom statistics */ 1277c478bd9Sstevel@tonic-gate pthread_mutex_t mod_stats_lock; /* lock protecting mod_stats data */ 1287c478bd9Sstevel@tonic-gate fmd_modstat_t *mod_stats; /* fmd built-in per-module statistics */ 1297c478bd9Sstevel@tonic-gate struct fmd_thread *mod_thread; /* thread associated with module (ro) */ 1307c478bd9Sstevel@tonic-gate struct fmd_idspace *mod_threads; /* idspace for alternate thread ids */ 1317c478bd9Sstevel@tonic-gate struct fmd_idspace *mod_timerids; /* idspace for timer identifiers */ 1327c478bd9Sstevel@tonic-gate fmd_list_t mod_cases; /* list of cases owned by this module */ 1337c478bd9Sstevel@tonic-gate fmd_buf_hash_t mod_bufs; /* hash of bufs owned by this module */ 1347c478bd9Sstevel@tonic-gate fmd_serd_hash_t mod_serds; /* hash of serd engs owned by module */ 135d9638e54Smws fmd_list_t mod_transports; /* list of transports owned by module */ 13624db4641Seschrock fmd_list_t mod_topolist; /* list of held topo handles */ 13724db4641Seschrock fmd_topo_t *mod_topo_current; /* current libtopo snapshot */ 13819e1255fScy152378 char *mod_vers; /* a copy of module version string */ 1399af3851aSeschrock nv_alloc_t mod_nva_sleep; /* module nvalloc routines (sleep) */ 1409af3851aSeschrock nv_alloc_t mod_nva_nosleep; /* module nvalloc routines (nosleep) */ 1417c478bd9Sstevel@tonic-gate } fmd_module_t; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #define FMD_MOD_INIT 0x001 /* mod_ops->mop_init() has completed */ 1447c478bd9Sstevel@tonic-gate #define FMD_MOD_FINI 0x002 /* mod_ops->mop_fini() has completed */ 1457c478bd9Sstevel@tonic-gate #define FMD_MOD_QUIT 0x004 /* module has been requested to quit */ 1467c478bd9Sstevel@tonic-gate #define FMD_MOD_FAIL 0x008 /* unrecoverable error has occurred */ 1477c478bd9Sstevel@tonic-gate #define FMD_MOD_LOCK 0x010 /* lock bit for fmd_module_lock() */ 1487c478bd9Sstevel@tonic-gate #define FMD_MOD_BUSY 0x020 /* module is busy executing a call */ 1497c478bd9Sstevel@tonic-gate #define FMD_MOD_MDIRTY 0x040 /* module meta state needs checkpoint */ 1507c478bd9Sstevel@tonic-gate #define FMD_MOD_CDIRTY 0x080 /* module case state needs checkpoint */ 1517c478bd9Sstevel@tonic-gate #define FMD_MOD_STSUB 0x100 /* stats subscriber is waiting */ 1527c478bd9Sstevel@tonic-gate #define FMD_MOD_STPUB 0x200 /* stats publisher is waiting */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate typedef struct fmd_modtimer { 1557c478bd9Sstevel@tonic-gate fmd_module_t *mt_mod; /* module that installed this timer */ 1567c478bd9Sstevel@tonic-gate void *mt_arg; /* module private timer argument */ 1577c478bd9Sstevel@tonic-gate id_t mt_id; /* timer ID (or -1 if still pending) */ 1587c478bd9Sstevel@tonic-gate } fmd_modtimer_t; 1597c478bd9Sstevel@tonic-gate 16024db4641Seschrock typedef struct fmd_modtopo { 16124db4641Seschrock fmd_list_t mt_link; /* link on module topo list */ 16224db4641Seschrock fmd_topo_t *mt_topo; /* topo handle */ 16324db4641Seschrock } fmd_modtopo_t; 16424db4641Seschrock 1657c478bd9Sstevel@tonic-gate extern const fmd_modops_t fmd_bltin_ops; /* see fmd/common/fmd_builtin.c */ 1667c478bd9Sstevel@tonic-gate extern const fmd_modops_t fmd_rtld_ops; /* see fmd/common/fmd_rtld.c */ 1677c478bd9Sstevel@tonic-gate extern const fmd_modops_t fmd_proc_ops; /* see fmd/common/fmd_proc.c */ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate extern fmd_module_t *fmd_module_create(const char *, const fmd_modops_t *); 1707c478bd9Sstevel@tonic-gate extern void fmd_module_unload(fmd_module_t *); 1717c478bd9Sstevel@tonic-gate extern void fmd_module_destroy(fmd_module_t *); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate extern void fmd_module_dispatch(fmd_module_t *, fmd_event_t *); 174d9638e54Smws extern int fmd_module_transport(fmd_module_t *, fmd_xprt_t *, fmd_event_t *); 1757c478bd9Sstevel@tonic-gate extern void fmd_module_timeout(fmd_modtimer_t *, id_t, hrtime_t); 1767c478bd9Sstevel@tonic-gate extern void fmd_module_gc(fmd_module_t *); 1777c478bd9Sstevel@tonic-gate extern void fmd_module_trygc(fmd_module_t *); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate extern int fmd_module_contains(fmd_module_t *, fmd_event_t *); 1807c478bd9Sstevel@tonic-gate extern void fmd_module_setdirty(fmd_module_t *); 1817c478bd9Sstevel@tonic-gate extern void fmd_module_setcdirty(fmd_module_t *); 1827c478bd9Sstevel@tonic-gate extern void fmd_module_clrdirty(fmd_module_t *); 1837c478bd9Sstevel@tonic-gate extern void fmd_module_commit(fmd_module_t *); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate extern void fmd_module_lock(fmd_module_t *); 1867c478bd9Sstevel@tonic-gate extern void fmd_module_unlock(fmd_module_t *); 1877c478bd9Sstevel@tonic-gate extern int fmd_module_trylock(fmd_module_t *); 1887c478bd9Sstevel@tonic-gate extern int fmd_module_locked(fmd_module_t *); 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate extern void fmd_module_unregister(fmd_module_t *); 1917c478bd9Sstevel@tonic-gate extern int fmd_module_enter(fmd_module_t *, void (*)(fmd_hdl_t *)); 1927c478bd9Sstevel@tonic-gate extern void fmd_module_exit(fmd_module_t *); 19380ab886dSwesolows extern void fmd_module_abort(fmd_module_t *, int) __NORETURN; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate extern void fmd_module_hold(fmd_module_t *); 1967c478bd9Sstevel@tonic-gate extern void fmd_module_rele(fmd_module_t *); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate extern int fmd_module_dc_opendict(fmd_module_t *, const char *); 1997c478bd9Sstevel@tonic-gate extern int fmd_module_dc_key2code(fmd_module_t *, 2007c478bd9Sstevel@tonic-gate char *const [], char *, size_t); 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate extern fmd_modhash_t *fmd_modhash_create(void); 2037c478bd9Sstevel@tonic-gate extern void fmd_modhash_destroy(fmd_modhash_t *); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate extern fmd_module_t *fmd_modhash_load(fmd_modhash_t *, 2067c478bd9Sstevel@tonic-gate const char *, const fmd_modops_t *); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate extern void fmd_modhash_loadall(fmd_modhash_t *, 2090b9e3e76Smws const fmd_conf_path_t *, const fmd_modops_t *, const char *); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate extern fmd_module_t *fmd_modhash_lookup(fmd_modhash_t *, const char *); 2127c478bd9Sstevel@tonic-gate extern int fmd_modhash_unload(fmd_modhash_t *, const char *); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate extern void fmd_modhash_apply(fmd_modhash_t *, void (*)(fmd_module_t *)); 2157c478bd9Sstevel@tonic-gate extern void fmd_modhash_tryapply(fmd_modhash_t *, void (*)(fmd_module_t *)); 2167c478bd9Sstevel@tonic-gate extern void fmd_modhash_dispatch(fmd_modhash_t *, fmd_event_t *); 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate extern void fmd_modstat_publish(fmd_module_t *); 2197c478bd9Sstevel@tonic-gate extern int fmd_modstat_snapshot(fmd_module_t *, struct fmd_ustat_snap *); 2207c478bd9Sstevel@tonic-gate 22124db4641Seschrock extern struct topo_hdl *fmd_module_topo_hold(fmd_module_t *); 22224db4641Seschrock extern int fmd_module_topo_rele(fmd_module_t *, struct topo_hdl *); 22324db4641Seschrock 2249af3851aSeschrock extern nv_alloc_ops_t fmd_module_nva_ops_sleep; 2259af3851aSeschrock extern nv_alloc_ops_t fmd_module_nva_ops_nosleep; 2269af3851aSeschrock 2277c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate #endif 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate #endif /* _FMD_MODULE_H */ 232