xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd.h (revision 35f59e50e9ef37e6f1bd3b018289d678d5551cab)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_FMD_H
27 #define	_FMD_H
28 
29 #include <libnvpair.h>
30 #include <pthread.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <fmd_list.h>
37 #include <fmd_time.h>
38 #include <fmd_api.h>
39 
40 struct fmd_conf;			/* see <fmd_conf.h> */
41 struct fmd_dispq;			/* see <fmd_dispq.h> */
42 struct fmd_timerq;			/* see <fmd_timerq.h> */
43 struct fmd_asru_hash;			/* see <fmd_asru.h> */
44 struct fmd_scheme_hash;			/* see <fmd_fmri.h> */
45 struct fmd_case_hash;			/* see <fmd_case.h> */
46 struct fmd_modhash;			/* see <fmd_module.h> */
47 struct fmd_module;			/* see <fmd_module.h> */
48 struct fmd_log;				/* see <fmd_log.h> */
49 struct fmd_idspace;			/* see <fmd_idspace.h> */
50 struct topo_hdl;			/* see <fm/libtopo.h> */
51 
52 typedef struct fmd_statistics {
53 	fmd_stat_t ds_log_replayed;	/* number of events replayed from log */
54 	fmd_stat_t ds_log_partials;	/* number of events partially commit */
55 	fmd_stat_t ds_err_enospc;	/* number of events w/ ENOSPC errlog */
56 	fmd_stat_t ds_flt_enospc;	/* number of events w/ ENOSPC fltlog */
57 	fmd_stat_t ds_oth_enospc;	/* number of events w/ ENOSPC others */
58 	fmd_stat_t ds_dr_gen;		/* dynamic reconfiguration generation */
59 	fmd_stat_t ds_topo_gen;		/* topology snapshot generation */
60 	fmd_stat_t ds_topo_drgen;	/* topology DR generation */
61 } fmd_statistics_t;
62 
63 typedef struct fmd {
64 	const char *d_version;		/* version string for fmd (see fmd.c) */
65 	const char *d_pname;		/* basename to use for messages */
66 	pid_t d_pid;			/* process-ID of current daemon */
67 	pthread_key_t d_key;		/* key for fmd's thread-specific data */
68 	volatile int d_signal;		/* signal indicating we should quit */
69 	volatile int d_running;		/* flag set when fmd_run() succeeds */
70 	volatile int d_loaded;		/* flag set when all modules loaded */
71 	volatile int d_booted;		/* flag set when fmd_run() completes */
72 
73 	uint_t d_fmd_debug;		/* mask of fmd active debugging modes */
74 	uint_t d_fmd_dbout;		/* fmd debug output sinks (see below) */
75 	uint_t d_hdl_debug;		/* bool indicating if hdl debug is on */
76 	uint_t d_hdl_dbout;		/* hdl debug output sinks (see below) */
77 
78 	char *volatile d_panicstr;	/* pointer to formatted panic message */
79 	pthread_t d_panictid;		/* tid of thread forcing a panic */
80 	uint_t d_panicrefs;		/* number of attempts to panic */
81 
82 	pthread_mutex_t d_xprt_lock;	/* transport suspend lock */
83 	uint_t d_xprt_suspend;		/* transport suspend count  */
84 	uint_t d_xprt_ttl;		/* transport default time-to-live */
85 	struct fmd_idspace *d_xprt_ids;	/* transport id hash */
86 
87 	const fmd_timeops_t *d_clockops; /* system clock ops vector */
88 	void *d_clockptr;		/* system clock private data */
89 
90 	pthread_mutex_t d_thr_lock;	/* lock for d_thr_list */
91 	fmd_list_t d_thr_list;		/* list of all fmd_thread_t's */
92 	void (*d_thr_trace)();		/* thread trace buffer function */
93 	int d_thr_sig;			/* cached copy of client.thrsig */
94 
95 	pthread_mutex_t d_mod_lock;	/* lock for d_mod_list */
96 	fmd_list_t d_mod_list;		/* list of modules in load order */
97 	struct fmd_modhash *d_mod_hash;	/* hash of modules by base name */
98 	fmd_event_t *d_mod_event;	/* boot event for module quiesce */
99 
100 	uint_t d_alloc_msecs;		/* initial delay time for alloc retry */
101 	uint_t d_alloc_tries;		/* max # times to retry an allocation */
102 	uint_t d_str_buckets;		/* def # of buckets for string hashes */
103 
104 	const char *d_rootdir;		/* root directory path */
105 	const char *d_platform;		/* platform name (uname -i) */
106 	const char *d_machine;		/* machine class name (uname -m) */
107 	const char *d_isaname;		/* processor ISA name (uname -p) */
108 
109 	void *d_sysev_hdl;		/* legacy sysevent handle */
110 	nv_alloc_t d_nva;		/* libnvpair allocator handle */
111 	nvlist_t *d_auth;		/* FMRI authority nvlist */
112 	pthread_mutex_t d_topo_lock;	/* lock for topo hdl */
113 	fmd_list_t d_topo_list;		/* list of all topology snapshots */
114 
115 	struct fmd_conf *d_conf;	/* global configuration properties */
116 	uint_t d_fg;			/* cached value of "fg" property */
117 
118 	fmd_statistics_t *d_stats;	/* root module statistics collection */
119 	pthread_mutex_t d_stats_lock;	/* root module statistics lock */
120 
121 	struct fmd_module *d_rmod;	/* root module for fmd's main thread */
122 	struct fmd_module *d_self;	/* self module for fmd's diagnosis */
123 
124 	pthread_mutex_t d_err_lock;	/* lock for stderr and error stats */
125 	fmd_stat_t *d_errstats;		/* program-wide error statistics */
126 
127 	struct fmd_timerq *d_timers;	/* timer queue for module timers */
128 	struct fmd_dispq *d_disp;	/* dispatch queue for incoming events */
129 	struct fmd_scheme_hash *d_schemes; /* hash of fmri scheme modules */
130 	struct fmd_asru_hash *d_asrus;	/* hash of cached asru objects */
131 	struct fmd_case_hash *d_cases;	/* hash of active cases */
132 
133 	pthread_rwlock_t d_log_lock;	/* log pointer lock (r=use, w=rotate) */
134 	struct fmd_log *d_errlog;	/* log file for error events */
135 	struct fmd_log *d_fltlog;	/* log file for fault events */
136 
137 	pthread_rwlock_t d_hvilog_lock;	/* log pointer lock (r=use, w=rotate) */
138 	struct fmd_log *d_hvilog;	/* log file for hi value info events */
139 
140 	pthread_rwlock_t d_ilog_lock;	/* log pointer lock (r=use, w=rotate) */
141 	struct fmd_log *d_ilog;		/* log file for info events */
142 
143 	pthread_cond_t d_fmd_cv;	/* sync startup with rpc */
144 	pthread_mutex_t d_fmd_lock;	/* sync startup with rpc */
145 } fmd_t;
146 
147 /*
148  * Exit status values used for the few places within fmd where we exit(2) or
149  * return from main().  fmd only exits if a fatal error occurs during startup;
150  * if anything else happens errors are reported and we just keep trucking.
151  */
152 #define	FMD_EXIT_SUCCESS	0	/* successful execution of daemon */
153 #define	FMD_EXIT_ERROR		1	/* failed to initialize daemon */
154 #define	FMD_EXIT_USAGE		2	/* syntax error on command-line */
155 
156 /*
157  * Values associated with fmd's client.error property, stored as a uint32_t.
158  * By default, we unload bad clients; other values are for use by developers.
159  */
160 #define	FMD_CERROR_UNLOAD	0	/* unload module on error (default) */
161 #define	FMD_CERROR_STOP		1	/* stop fmd for debugger attach */
162 #define	FMD_CERROR_ABORT	2	/* abort fmd and generate core dump */
163 
164 /*
165  * Values associated with any *dbout (debug output sink) property, stored as
166  * a uint32_t.  Currently we permit syslog output and stderr output.
167  */
168 #define	FMD_DBOUT_SYSLOG	0x1	/* output to syslog(LOG_DEBUG) */
169 #define	FMD_DBOUT_STDERR	0x2	/* output to stderr */
170 
171 extern const char _fmd_version[];
172 extern fmd_t fmd;
173 
174 extern void fmd_door_server(void *);
175 extern void fmd_create(fmd_t *, const char *, const char *, const char *);
176 extern void fmd_destroy(fmd_t *);
177 extern void fmd_run(fmd_t *, int);
178 extern void fmd_help(fmd_t *);
179 
180 #ifdef	__cplusplus
181 }
182 #endif
183 
184 #endif	/* _FMD_H */
185