xref: /titanic_44/usr/src/cmd/fm/fmd/common/fmd.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
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
50eb822a1Scindi  * Common Development and Distribution License (the "License").
60eb822a1Scindi  * 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 /*
23f6e214c7SGavin Maltby  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_FMD_H
277c478bd9Sstevel@tonic-gate #define	_FMD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <libnvpair.h>
307c478bd9Sstevel@tonic-gate #include <pthread.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <fmd_list.h>
377c478bd9Sstevel@tonic-gate #include <fmd_time.h>
387c478bd9Sstevel@tonic-gate #include <fmd_api.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate struct fmd_conf;			/* see <fmd_conf.h> */
417c478bd9Sstevel@tonic-gate struct fmd_dispq;			/* see <fmd_dispq.h> */
427c478bd9Sstevel@tonic-gate struct fmd_timerq;			/* see <fmd_timerq.h> */
437c478bd9Sstevel@tonic-gate struct fmd_asru_hash;			/* see <fmd_asru.h> */
447c478bd9Sstevel@tonic-gate struct fmd_scheme_hash;			/* see <fmd_fmri.h> */
457c478bd9Sstevel@tonic-gate struct fmd_case_hash;			/* see <fmd_case.h> */
467c478bd9Sstevel@tonic-gate struct fmd_modhash;			/* see <fmd_module.h> */
477c478bd9Sstevel@tonic-gate struct fmd_module;			/* see <fmd_module.h> */
487c478bd9Sstevel@tonic-gate struct fmd_log;				/* see <fmd_log.h> */
49d9638e54Smws struct fmd_idspace;			/* see <fmd_idspace.h> */
507aec1d6eScindi struct topo_hdl;			/* see <fm/libtopo.h> */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef struct fmd_statistics {
537c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_log_replayed;	/* number of events replayed from log */
547c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_log_partials;	/* number of events partially commit */
557c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_err_enospc;	/* number of events w/ ENOSPC errlog */
567c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_flt_enospc;	/* number of events w/ ENOSPC fltlog */
577c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_oth_enospc;	/* number of events w/ ENOSPC others */
587c478bd9Sstevel@tonic-gate 	fmd_stat_t ds_dr_gen;		/* dynamic reconfiguration generation */
590eb822a1Scindi 	fmd_stat_t ds_topo_gen;		/* topology snapshot generation */
600eb822a1Scindi 	fmd_stat_t ds_topo_drgen;	/* topology DR generation */
617c478bd9Sstevel@tonic-gate } fmd_statistics_t;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef struct fmd {
647c478bd9Sstevel@tonic-gate 	const char *d_version;		/* version string for fmd (see fmd.c) */
657c478bd9Sstevel@tonic-gate 	const char *d_pname;		/* basename to use for messages */
667c478bd9Sstevel@tonic-gate 	pid_t d_pid;			/* process-ID of current daemon */
677c478bd9Sstevel@tonic-gate 	pthread_key_t d_key;		/* key for fmd's thread-specific data */
687c478bd9Sstevel@tonic-gate 	volatile int d_signal;		/* signal indicating we should quit */
697c478bd9Sstevel@tonic-gate 	volatile int d_running;		/* flag set when fmd_run() succeeds */
70*35f59e50SStephen Hanson 	volatile int d_loaded;		/* flag set when all modules loaded */
71d9638e54Smws 	volatile int d_booted;		/* flag set when fmd_run() completes */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	uint_t d_fmd_debug;		/* mask of fmd active debugging modes */
747c478bd9Sstevel@tonic-gate 	uint_t d_fmd_dbout;		/* fmd debug output sinks (see below) */
757c478bd9Sstevel@tonic-gate 	uint_t d_hdl_debug;		/* bool indicating if hdl debug is on */
767c478bd9Sstevel@tonic-gate 	uint_t d_hdl_dbout;		/* hdl debug output sinks (see below) */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	char *volatile d_panicstr;	/* pointer to formatted panic message */
797c478bd9Sstevel@tonic-gate 	pthread_t d_panictid;		/* tid of thread forcing a panic */
807c478bd9Sstevel@tonic-gate 	uint_t d_panicrefs;		/* number of attempts to panic */
817c478bd9Sstevel@tonic-gate 
82d9638e54Smws 	pthread_mutex_t d_xprt_lock;	/* transport suspend lock */
83d9638e54Smws 	uint_t d_xprt_suspend;		/* transport suspend count  */
84d9638e54Smws 	uint_t d_xprt_ttl;		/* transport default time-to-live */
85d9638e54Smws 	struct fmd_idspace *d_xprt_ids;	/* transport id hash */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	const fmd_timeops_t *d_clockops; /* system clock ops vector */
887c478bd9Sstevel@tonic-gate 	void *d_clockptr;		/* system clock private data */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	pthread_mutex_t d_thr_lock;	/* lock for d_thr_list */
917c478bd9Sstevel@tonic-gate 	fmd_list_t d_thr_list;		/* list of all fmd_thread_t's */
927c478bd9Sstevel@tonic-gate 	void (*d_thr_trace)();		/* thread trace buffer function */
937c478bd9Sstevel@tonic-gate 	int d_thr_sig;			/* cached copy of client.thrsig */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	pthread_mutex_t d_mod_lock;	/* lock for d_mod_list */
967c478bd9Sstevel@tonic-gate 	fmd_list_t d_mod_list;		/* list of modules in load order */
977c478bd9Sstevel@tonic-gate 	struct fmd_modhash *d_mod_hash;	/* hash of modules by base name */
98d9638e54Smws 	fmd_event_t *d_mod_event;	/* boot event for module quiesce */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	uint_t d_alloc_msecs;		/* initial delay time for alloc retry */
1017c478bd9Sstevel@tonic-gate 	uint_t d_alloc_tries;		/* max # times to retry an allocation */
1027c478bd9Sstevel@tonic-gate 	uint_t d_str_buckets;		/* def # of buckets for string hashes */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	const char *d_rootdir;		/* root directory path */
1057c478bd9Sstevel@tonic-gate 	const char *d_platform;		/* platform name (uname -i) */
1067c478bd9Sstevel@tonic-gate 	const char *d_machine;		/* machine class name (uname -m) */
1077c478bd9Sstevel@tonic-gate 	const char *d_isaname;		/* processor ISA name (uname -p) */
1087c478bd9Sstevel@tonic-gate 
1099af3851aSeschrock 	void *d_sysev_hdl;		/* legacy sysevent handle */
1107c478bd9Sstevel@tonic-gate 	nv_alloc_t d_nva;		/* libnvpair allocator handle */
1117c478bd9Sstevel@tonic-gate 	nvlist_t *d_auth;		/* FMRI authority nvlist */
1120eb822a1Scindi 	pthread_mutex_t d_topo_lock;	/* lock for topo hdl */
1130eb822a1Scindi 	fmd_list_t d_topo_list;		/* list of all topology snapshots */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	struct fmd_conf *d_conf;	/* global configuration properties */
1167c478bd9Sstevel@tonic-gate 	uint_t d_fg;			/* cached value of "fg" property */
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	fmd_statistics_t *d_stats;	/* root module statistics collection */
1197c478bd9Sstevel@tonic-gate 	pthread_mutex_t d_stats_lock;	/* root module statistics lock */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	struct fmd_module *d_rmod;	/* root module for fmd's main thread */
1227c478bd9Sstevel@tonic-gate 	struct fmd_module *d_self;	/* self module for fmd's diagnosis */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	pthread_mutex_t d_err_lock;	/* lock for stderr and error stats */
1257c478bd9Sstevel@tonic-gate 	fmd_stat_t *d_errstats;		/* program-wide error statistics */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	struct fmd_timerq *d_timers;	/* timer queue for module timers */
1287c478bd9Sstevel@tonic-gate 	struct fmd_dispq *d_disp;	/* dispatch queue for incoming events */
1297c478bd9Sstevel@tonic-gate 	struct fmd_scheme_hash *d_schemes; /* hash of fmri scheme modules */
1307c478bd9Sstevel@tonic-gate 	struct fmd_asru_hash *d_asrus;	/* hash of cached asru objects */
1317c478bd9Sstevel@tonic-gate 	struct fmd_case_hash *d_cases;	/* hash of active cases */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	pthread_rwlock_t d_log_lock;	/* log pointer lock (r=use, w=rotate) */
1347c478bd9Sstevel@tonic-gate 	struct fmd_log *d_errlog;	/* log file for error events */
1357c478bd9Sstevel@tonic-gate 	struct fmd_log *d_fltlog;	/* log file for fault events */
136f6e214c7SGavin Maltby 
137f6e214c7SGavin Maltby 	pthread_rwlock_t d_hvilog_lock;	/* log pointer lock (r=use, w=rotate) */
138f6e214c7SGavin Maltby 	struct fmd_log *d_hvilog;	/* log file for hi value info events */
139f6e214c7SGavin Maltby 
140f6e214c7SGavin Maltby 	pthread_rwlock_t d_ilog_lock;	/* log pointer lock (r=use, w=rotate) */
141f6e214c7SGavin Maltby 	struct fmd_log *d_ilog;		/* log file for info events */
142f6e214c7SGavin Maltby 
14393136fe2Sstephh 	pthread_cond_t d_fmd_cv;	/* sync startup with rpc */
14493136fe2Sstephh 	pthread_mutex_t d_fmd_lock;	/* sync startup with rpc */
1457c478bd9Sstevel@tonic-gate } fmd_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * Exit status values used for the few places within fmd where we exit(2) or
1497c478bd9Sstevel@tonic-gate  * return from main().  fmd only exits if a fatal error occurs during startup;
1507c478bd9Sstevel@tonic-gate  * if anything else happens errors are reported and we just keep trucking.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate #define	FMD_EXIT_SUCCESS	0	/* successful execution of daemon */
1537c478bd9Sstevel@tonic-gate #define	FMD_EXIT_ERROR		1	/* failed to initialize daemon */
1547c478bd9Sstevel@tonic-gate #define	FMD_EXIT_USAGE		2	/* syntax error on command-line */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * Values associated with fmd's client.error property, stored as a uint32_t.
1587c478bd9Sstevel@tonic-gate  * By default, we unload bad clients; other values are for use by developers.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	FMD_CERROR_UNLOAD	0	/* unload module on error (default) */
1617c478bd9Sstevel@tonic-gate #define	FMD_CERROR_STOP		1	/* stop fmd for debugger attach */
1627c478bd9Sstevel@tonic-gate #define	FMD_CERROR_ABORT	2	/* abort fmd and generate core dump */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * Values associated with any *dbout (debug output sink) property, stored as
1667c478bd9Sstevel@tonic-gate  * a uint32_t.  Currently we permit syslog output and stderr output.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate #define	FMD_DBOUT_SYSLOG	0x1	/* output to syslog(LOG_DEBUG) */
1697c478bd9Sstevel@tonic-gate #define	FMD_DBOUT_STDERR	0x2	/* output to stderr */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate extern const char _fmd_version[];
1727c478bd9Sstevel@tonic-gate extern fmd_t fmd;
1737c478bd9Sstevel@tonic-gate 
174d9638e54Smws extern void fmd_door_server(void *);
1757c478bd9Sstevel@tonic-gate extern void fmd_create(fmd_t *, const char *, const char *, const char *);
1767c478bd9Sstevel@tonic-gate extern void fmd_destroy(fmd_t *);
1777c478bd9Sstevel@tonic-gate extern void fmd_run(fmd_t *, int);
1787c478bd9Sstevel@tonic-gate extern void fmd_help(fmd_t *);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate #endif
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #endif	/* _FMD_H */
185