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