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