xref: /onnv-gate/usr/src/cmd/fm/fmd/common/fmd_module.h (revision 12967:ab9ae749152f)
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
51717Swesolows  * Common Development and Distribution License (the "License").
61717Swesolows  * 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  */
211429Smws 
220Sstevel@tonic-gate /*
23*12967Sgavin.maltby@oracle.com  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_FMD_MODULE_H
270Sstevel@tonic-gate #define	_FMD_MODULE_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <fm/diagcode.h>
310Sstevel@tonic-gate #include <pthread.h>
320Sstevel@tonic-gate #include <setjmp.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include <fmd_conf.h>
390Sstevel@tonic-gate #include <fmd_list.h>
400Sstevel@tonic-gate #include <fmd_serd.h>
410Sstevel@tonic-gate #include <fmd_buf.h>
420Sstevel@tonic-gate #include <fmd_api.h>
431193Smws #include <fmd_eventq.h>
444198Seschrock #include <fmd_topo.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate struct fmd_module;			/* see below */
470Sstevel@tonic-gate struct fmd_thread;			/* see <fmd_thread.h> */
480Sstevel@tonic-gate struct fmd_idspace;			/* see <fmd_idspace.h> */
490Sstevel@tonic-gate struct fmd_ustat;			/* see <fmd_ustat.h> */
500Sstevel@tonic-gate struct fmd_ustat_snap;			/* see <fmd_ustat.h> */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate typedef struct fmd_modops {
530Sstevel@tonic-gate 	int (*mop_init)(struct fmd_module *);
540Sstevel@tonic-gate 	int (*mop_fini)(struct fmd_module *);
550Sstevel@tonic-gate 	void (*mop_dispatch)(struct fmd_module *, struct fmd_event *);
561193Smws 	int (*mop_transport)(struct fmd_module *,
571193Smws 	    fmd_xprt_t *, struct fmd_event *);
580Sstevel@tonic-gate } fmd_modops_t;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef struct fmd_modhash {
610Sstevel@tonic-gate 	pthread_rwlock_t mh_lock;	/* r/w lock to protect hash */
620Sstevel@tonic-gate 	struct fmd_module **mh_hash;	/* hash bucket array */
630Sstevel@tonic-gate 	uint_t mh_hashlen;		/* size of hash bucket array */
640Sstevel@tonic-gate 	uint_t mh_nelems;		/* number of modules in hash */
650Sstevel@tonic-gate } fmd_modhash_t;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * Statistics maintained by fmd itself on behalf of all modules for fmstat(1M).
690Sstevel@tonic-gate  * NOTE: FMD_TYPE_STRING statistics should not be used here.  If they are
700Sstevel@tonic-gate  * required in the future, the FMD_ADM_MODDSTAT service routine must change.
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate typedef struct fmd_modstat {
731193Smws 	fmd_eventqstat_t ms_evqstat;	/* stats for main module event queue */
740Sstevel@tonic-gate 	fmd_stat_t ms_loadtime;		/* hrtime at which module was loaded */
750Sstevel@tonic-gate 	fmd_stat_t ms_snaptime;		/* hrtime of recent stats snapshot */
760Sstevel@tonic-gate 	fmd_stat_t ms_accepted;		/* total events accepted by module */
770Sstevel@tonic-gate 	fmd_stat_t ms_debugdrop;	/* dropped debug messages */
780Sstevel@tonic-gate 	fmd_stat_t ms_memtotal;		/* total space allocated by module */
790Sstevel@tonic-gate 	fmd_stat_t ms_memlimit;		/* limit on space allocated by module */
800Sstevel@tonic-gate 	fmd_stat_t ms_buftotal;		/* total space consumed by buffers */
810Sstevel@tonic-gate 	fmd_stat_t ms_buflimit;		/* limit on space consumed by buffers */
820Sstevel@tonic-gate 	fmd_stat_t ms_thrtotal;		/* total number of auxiliary threads */
830Sstevel@tonic-gate 	fmd_stat_t ms_thrlimit;		/* limit on auxiliary threads */
84*12967Sgavin.maltby@oracle.com 	fmd_stat_t ms_doorthrtotal;	/* total number of doorserver threads */
85*12967Sgavin.maltby@oracle.com 	fmd_stat_t ms_doorthrlimit;	/* limit on doorserver threads */
860Sstevel@tonic-gate 	fmd_stat_t ms_caseopen;		/* cases currently open */
870Sstevel@tonic-gate 	fmd_stat_t ms_casesolved;	/* total cases solved by module */
880Sstevel@tonic-gate 	fmd_stat_t ms_caseclosed;	/* total cases closed by module */
890Sstevel@tonic-gate 	fmd_stat_t ms_ckpt_save;	/* save checkpoints for module */
900Sstevel@tonic-gate 	fmd_stat_t ms_ckpt_restore;	/* restore checkpoints for module */
910Sstevel@tonic-gate 	fmd_stat_t ms_ckpt_zeroed;	/* checkpoint was zeroed at startup */
920Sstevel@tonic-gate 	fmd_stat_t ms_ckpt_cnt;		/* number of checkpoints taken */
930Sstevel@tonic-gate 	fmd_stat_t ms_ckpt_time;	/* total checkpoint time */
941193Smws 	fmd_stat_t ms_xprtopen;		/* total number of open transports */
951193Smws 	fmd_stat_t ms_xprtlimit;	/* limit on number of open transports */
961193Smws 	fmd_stat_t ms_xprtqlimit;	/* limit on transport eventq length */
970Sstevel@tonic-gate } fmd_modstat_t;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate typedef struct fmd_module {
1000Sstevel@tonic-gate 	fmd_list_t mod_list;		/* linked list next/prev pointers */
1010Sstevel@tonic-gate 	pthread_mutex_t mod_lock;	/* lock for mod_cv/owner/flags/refs */
1020Sstevel@tonic-gate 	pthread_cond_t mod_cv;		/* condition variable for waiters */
1030Sstevel@tonic-gate 	pthread_t mod_owner;		/* tid of thread that set MOD_LOCK */
1040Sstevel@tonic-gate 	uint_t mod_refs;		/* module reference count */
1050Sstevel@tonic-gate 	uint_t mod_flags;		/* miscellaneous flags (see below) */
1060Sstevel@tonic-gate 	uint64_t mod_gen;		/* module checkpoint generation */
1070Sstevel@tonic-gate 	int mod_error;			/* error return from module thread */
1080Sstevel@tonic-gate 	jmp_buf mod_jmpbuf;		/* setjmp data for fmd_module_enter() */
1090Sstevel@tonic-gate 	fmd_modhash_t *mod_hash;	/* containing namespace (ro) */
1100Sstevel@tonic-gate 	struct fmd_module *mod_next;	/* next module in fmd_modhash chain */
1110Sstevel@tonic-gate 	char *mod_name;			/* basename of module (ro) */
1120Sstevel@tonic-gate 	char *mod_path;			/* full pathname of module file (ro) */
1130Sstevel@tonic-gate 	char *mod_ckpt;			/* pathname of checkpoint dir (ro) */
1140Sstevel@tonic-gate 	nvlist_t *mod_fmri;		/* fmri for this module */
1150Sstevel@tonic-gate 	const fmd_modops_t *mod_ops;	/* module class ops vector (ro) */
1160Sstevel@tonic-gate 	void *mod_data;			/* data private to module ops vector */
1170Sstevel@tonic-gate 	fmd_hdl_info_t *mod_info;	/* module info registered with handle */
1180Sstevel@tonic-gate 	void *mod_spec;			/* fmd_hdl_get/setspecific data value */
1190Sstevel@tonic-gate 	int mod_argc;			/* size of mod_argv formals array */
1200Sstevel@tonic-gate 	fmd_conf_formal_t *mod_argv; 	/* array of conf file formals */
1210Sstevel@tonic-gate 	fmd_conf_t *mod_conf;		/* configuration properties (ro) */
1220Sstevel@tonic-gate 	struct fm_dc_handle **mod_dictv; /* libdiagcode dictionaries */
1230Sstevel@tonic-gate 	int mod_dictc;			/* size of mod_dictv array */
1240Sstevel@tonic-gate 	size_t mod_codelen;		/* libdiagcode maximum string length */
1250Sstevel@tonic-gate 	struct fmd_eventq *mod_queue;	/* eventq associated with module (ro) */
1260Sstevel@tonic-gate 	struct fmd_ustat *mod_ustat;	/* collection of custom statistics */
1270Sstevel@tonic-gate 	pthread_mutex_t mod_stats_lock;	/* lock protecting mod_stats data */
1280Sstevel@tonic-gate 	fmd_modstat_t *mod_stats;	/* fmd built-in per-module statistics */
1290Sstevel@tonic-gate 	struct fmd_thread *mod_thread;	/* thread associated with module (ro) */
1300Sstevel@tonic-gate 	struct fmd_idspace *mod_threads;  /* idspace for alternate thread ids */
1310Sstevel@tonic-gate 	struct fmd_idspace *mod_timerids; /* idspace for timer identifiers */
1320Sstevel@tonic-gate 	fmd_list_t mod_cases;		/* list of cases owned by this module */
1330Sstevel@tonic-gate 	fmd_buf_hash_t mod_bufs;	/* hash of bufs owned by this module */
1340Sstevel@tonic-gate 	fmd_serd_hash_t mod_serds;	/* hash of serd engs owned by module */
1351193Smws 	fmd_list_t mod_transports;	/* list of transports owned by module */
1364198Seschrock 	fmd_list_t mod_topolist;	/* list of held topo handles */
1374198Seschrock 	fmd_topo_t *mod_topo_current;	/* current libtopo snapshot */
1387139Scy152378 	char *mod_vers;			/* a copy of module version string */
1397171Seschrock 	nv_alloc_t mod_nva_sleep;	/* module nvalloc routines (sleep) */
1407171Seschrock 	nv_alloc_t mod_nva_nosleep;	/* module nvalloc routines (nosleep) */
1410Sstevel@tonic-gate } fmd_module_t;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define	FMD_MOD_INIT	0x001		/* mod_ops->mop_init() has completed */
1440Sstevel@tonic-gate #define	FMD_MOD_FINI	0x002		/* mod_ops->mop_fini() has completed */
1450Sstevel@tonic-gate #define	FMD_MOD_QUIT	0x004		/* module has been requested to quit */
1460Sstevel@tonic-gate #define	FMD_MOD_FAIL	0x008		/* unrecoverable error has occurred */
1470Sstevel@tonic-gate #define	FMD_MOD_LOCK	0x010		/* lock bit for fmd_module_lock() */
1480Sstevel@tonic-gate #define	FMD_MOD_BUSY	0x020		/* module is busy executing a call */
1490Sstevel@tonic-gate #define	FMD_MOD_MDIRTY	0x040		/* module meta state needs checkpoint */
1500Sstevel@tonic-gate #define	FMD_MOD_CDIRTY	0x080		/* module case state needs checkpoint */
1510Sstevel@tonic-gate #define	FMD_MOD_STSUB	0x100		/* stats subscriber is waiting */
1520Sstevel@tonic-gate #define	FMD_MOD_STPUB	0x200		/* stats publisher is waiting */
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate typedef struct fmd_modtimer {
1550Sstevel@tonic-gate 	fmd_module_t *mt_mod;		/* module that installed this timer */
1560Sstevel@tonic-gate 	void *mt_arg;			/* module private timer argument */
1570Sstevel@tonic-gate 	id_t mt_id;			/* timer ID (or -1 if still pending) */
1580Sstevel@tonic-gate } fmd_modtimer_t;
1590Sstevel@tonic-gate 
1604198Seschrock typedef struct fmd_modtopo {
1614198Seschrock 	fmd_list_t mt_link;		/* link on module topo list */
1624198Seschrock 	fmd_topo_t *mt_topo;		/* topo handle */
1634198Seschrock } fmd_modtopo_t;
1644198Seschrock 
1650Sstevel@tonic-gate extern const fmd_modops_t fmd_bltin_ops; /* see fmd/common/fmd_builtin.c */
1660Sstevel@tonic-gate extern const fmd_modops_t fmd_rtld_ops;	/* see fmd/common/fmd_rtld.c */
1670Sstevel@tonic-gate extern const fmd_modops_t fmd_proc_ops;	/* see fmd/common/fmd_proc.c */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate extern fmd_module_t *fmd_module_create(const char *, const fmd_modops_t *);
1700Sstevel@tonic-gate extern void fmd_module_unload(fmd_module_t *);
1710Sstevel@tonic-gate extern void fmd_module_destroy(fmd_module_t *);
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate extern void fmd_module_dispatch(fmd_module_t *, fmd_event_t *);
1741193Smws extern int fmd_module_transport(fmd_module_t *, fmd_xprt_t *, fmd_event_t *);
1750Sstevel@tonic-gate extern void fmd_module_timeout(fmd_modtimer_t *, id_t, hrtime_t);
1760Sstevel@tonic-gate extern void fmd_module_gc(fmd_module_t *);
1770Sstevel@tonic-gate extern void fmd_module_trygc(fmd_module_t *);
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate extern int fmd_module_contains(fmd_module_t *, fmd_event_t *);
1800Sstevel@tonic-gate extern void fmd_module_setdirty(fmd_module_t *);
1810Sstevel@tonic-gate extern void fmd_module_setcdirty(fmd_module_t *);
1820Sstevel@tonic-gate extern void fmd_module_clrdirty(fmd_module_t *);
1830Sstevel@tonic-gate extern void fmd_module_commit(fmd_module_t *);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate extern void fmd_module_lock(fmd_module_t *);
1860Sstevel@tonic-gate extern void fmd_module_unlock(fmd_module_t *);
1870Sstevel@tonic-gate extern int fmd_module_trylock(fmd_module_t *);
1880Sstevel@tonic-gate extern int fmd_module_locked(fmd_module_t *);
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate extern void fmd_module_unregister(fmd_module_t *);
1910Sstevel@tonic-gate extern int fmd_module_enter(fmd_module_t *, void (*)(fmd_hdl_t *));
1920Sstevel@tonic-gate extern void fmd_module_exit(fmd_module_t *);
1931717Swesolows extern void fmd_module_abort(fmd_module_t *, int) __NORETURN;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate extern void fmd_module_hold(fmd_module_t *);
1960Sstevel@tonic-gate extern void fmd_module_rele(fmd_module_t *);
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate extern int fmd_module_dc_opendict(fmd_module_t *, const char *);
1990Sstevel@tonic-gate extern int fmd_module_dc_key2code(fmd_module_t *,
2000Sstevel@tonic-gate     char *const [], char *, size_t);
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate extern fmd_modhash_t *fmd_modhash_create(void);
2030Sstevel@tonic-gate extern void fmd_modhash_destroy(fmd_modhash_t *);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate extern fmd_module_t *fmd_modhash_load(fmd_modhash_t *,
2060Sstevel@tonic-gate     const char *, const fmd_modops_t *);
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate extern void fmd_modhash_loadall(fmd_modhash_t *,
2091429Smws     const fmd_conf_path_t *, const fmd_modops_t *, const char *);
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate extern fmd_module_t *fmd_modhash_lookup(fmd_modhash_t *, const char *);
2120Sstevel@tonic-gate extern int fmd_modhash_unload(fmd_modhash_t *, const char *);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate extern void fmd_modhash_apply(fmd_modhash_t *, void (*)(fmd_module_t *));
2150Sstevel@tonic-gate extern void fmd_modhash_tryapply(fmd_modhash_t *, void (*)(fmd_module_t *));
2160Sstevel@tonic-gate extern void fmd_modhash_dispatch(fmd_modhash_t *, fmd_event_t *);
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate extern void fmd_modstat_publish(fmd_module_t *);
2190Sstevel@tonic-gate extern int fmd_modstat_snapshot(fmd_module_t *, struct fmd_ustat_snap *);
2200Sstevel@tonic-gate 
2214198Seschrock extern struct topo_hdl *fmd_module_topo_hold(fmd_module_t *);
2224198Seschrock extern int fmd_module_topo_rele(fmd_module_t *, struct topo_hdl *);
2234198Seschrock 
2247171Seschrock extern nv_alloc_ops_t fmd_module_nva_ops_sleep;
2257171Seschrock extern nv_alloc_ops_t fmd_module_nva_ops_nosleep;
2267171Seschrock 
2270Sstevel@tonic-gate #ifdef	__cplusplus
2280Sstevel@tonic-gate }
2290Sstevel@tonic-gate #endif
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate #endif	/* _FMD_MODULE_H */
232