xref: /onnv-gate/usr/src/cmd/fm/modules/common/disk-monitor/diskmon_conf.h (revision 4582:da3c7347dfa5)
1*4582Scth /*
2*4582Scth  * CDDL HEADER START
3*4582Scth  *
4*4582Scth  * The contents of this file are subject to the terms of the
5*4582Scth  * Common Development and Distribution License (the "License").
6*4582Scth  * You may not use this file except in compliance with the License.
7*4582Scth  *
8*4582Scth  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*4582Scth  * or http://www.opensolaris.org/os/licensing.
10*4582Scth  * See the License for the specific language governing permissions
11*4582Scth  * and limitations under the License.
12*4582Scth  *
13*4582Scth  * When distributing Covered Code, include this CDDL HEADER in each
14*4582Scth  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*4582Scth  * If applicable, add the following below this CDDL HEADER, with the
16*4582Scth  * fields enclosed by brackets "[]" replaced with your own identifying
17*4582Scth  * information: Portions Copyright [yyyy] [name of copyright owner]
18*4582Scth  *
19*4582Scth  * CDDL HEADER END
20*4582Scth  */
21*4582Scth 
22*4582Scth /*
23*4582Scth  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*4582Scth  * Use is subject to license terms.
25*4582Scth  */
26*4582Scth 
27*4582Scth #ifndef _DISKMOND_CONF_H
28*4582Scth #define	_DISKMOND_CONF_H
29*4582Scth 
30*4582Scth #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*4582Scth 
32*4582Scth /*
33*4582Scth  * Configuration File data
34*4582Scth  */
35*4582Scth 
36*4582Scth #ifdef __cplusplus
37*4582Scth extern "C" {
38*4582Scth #endif
39*4582Scth 
40*4582Scth #include <sys/types.h>
41*4582Scth #include <pthread.h>
42*4582Scth #include <libnvpair.h>
43*4582Scth #include <fm/fmd_api.h>
44*4582Scth #include "dm_types.h"
45*4582Scth #include "util.h"
46*4582Scth 
47*4582Scth #ifndef MIN
48*4582Scth #define	MIN(x, y) ((x) < (y) ? (x) : (y))
49*4582Scth #endif
50*4582Scth 
51*4582Scth #ifndef MAX
52*4582Scth #define	MAX(x, y) ((x) > (y) ? (x) : (y))
53*4582Scth #endif
54*4582Scth 
55*4582Scth #define	DEVICES_PREFIX "/devices"
56*4582Scth 
57*4582Scth #define	GLOBAL_PROP_LOG_LEVEL		"log-level"
58*4582Scth 
59*4582Scth /* Property names (and values) for the disk configuration file entity */
60*4582Scth #define	DISK_PROP_DEVPATH		"dev-path"
61*4582Scth #define	DISK_PROP_LOGNAME		"logical-path"
62*4582Scth #define	DISK_PROP_FRUACTION		"fru-update-action"
63*4582Scth #define	DISK_PROP_OTEMPACTION		"overtemp-action"
64*4582Scth #define	DISK_PROP_STFAILACTION		"selftest-fail-action"
65*4582Scth 
66*4582Scth /* Properties for the "ap" subentity */
67*4582Scth #define	DISK_AP_PROP_APID "path"
68*4582Scth 
69*4582Scth #define	DEVPATH_MINOR_SEPARATOR ':'
70*4582Scth 
71*4582Scth #define	DEFAULT_FAULT_POLLING_INTERVAL 3600	/* seconds */
72*4582Scth 
73*4582Scth #define	INDICATOR_FAULT_IDENTIFIER "FAULT"
74*4582Scth 
75*4582Scth typedef enum conf_err_e {
76*4582Scth 	E_NO_ERROR = 0,
77*4582Scth 	E_MULTIPLE_IND_LISTS_DEFINED,
78*4582Scth 	E_MULTIPLE_INDRULE_LISTS_DEFINED,
79*4582Scth 	E_INVALID_STATE_CHANGE,
80*4582Scth 	E_IND_MULTIPLY_DEFINED,
81*4582Scth 	E_IND_ACTION_REDUNDANT,
82*4582Scth 	E_IND_ACTION_CONFLICT,
83*4582Scth 	E_IND_MISSING_FAULT_ON,
84*4582Scth 	E_IND_MISSING_FAULT_OFF,
85*4582Scth 	E_INDRULE_REFERENCES_NONEXISTENT_IND_ACTION,
86*4582Scth 	E_DUPLICATE_STATE_TRANSITION
87*4582Scth } conf_err_t;
88*4582Scth 
89*4582Scth typedef enum {
90*4582Scth 	INDICATOR_UNKNOWN,
91*4582Scth 	INDICATOR_ON,
92*4582Scth 	INDICATOR_OFF
93*4582Scth } ind_state_t;
94*4582Scth 
95*4582Scth typedef enum {
96*4582Scth 	TS_NOT_RUNNING,
97*4582Scth 	TS_RUNNING,
98*4582Scth 	TS_EXIT_REQUESTED,
99*4582Scth 	TS_EXITED
100*4582Scth } thread_state_t;
101*4582Scth 
102*4582Scth typedef struct ind_action {
103*4582Scth 	ind_state_t		ind_state;
104*4582Scth 	char			*ind_name;
105*4582Scth 	struct ind_action	*next;
106*4582Scth } ind_action_t;
107*4582Scth 
108*4582Scth typedef struct state_transition {
109*4582Scth 	hotplug_state_t		begin;
110*4582Scth 	hotplug_state_t		end;
111*4582Scth } state_transition_t;
112*4582Scth 
113*4582Scth typedef struct indrule {
114*4582Scth 	state_transition_t	strans;
115*4582Scth 	ind_action_t 		*action_list;
116*4582Scth 	struct indrule 		*next;
117*4582Scth } indrule_t;
118*4582Scth 
119*4582Scth typedef struct indicator {
120*4582Scth 	ind_state_t		ind_state;
121*4582Scth 	char			*ind_name;
122*4582Scth 	char			*ind_instr_spec;
123*4582Scth 	struct indicator	*next;
124*4582Scth } indicator_t;
125*4582Scth 
126*4582Scth typedef struct diskmon {
127*4582Scth 	/*
128*4582Scth 	 * Static configuration data
129*4582Scth 	 */
130*4582Scth 	nvlist_t		*props;
131*4582Scth 	char			*location;	/* descriptive location */
132*4582Scth 	nvlist_t		*app_props;
133*4582Scth 	indicator_t		*ind_list;
134*4582Scth 	indrule_t		*indrule_list;
135*4582Scth 	/*
136*4582Scth 	 * Dynamic data
137*4582Scth 	 */
138*4582Scth 	hotplug_state_t		state;
139*4582Scth 
140*4582Scth 	/*
141*4582Scth 	 * Only one manager can be manipulating the
142*4582Scth 	 * state in the diskmon at one time (either the
143*4582Scth 	 * state-change manager or the fault-polling manager)
144*4582Scth 	 */
145*4582Scth 	pthread_mutex_t		manager_mutex;
146*4582Scth 
147*4582Scth 	/*
148*4582Scth 	 * Set to true only during initialization, and
149*4582Scth 	 * cleared the next time a fru update needs to
150*4582Scth 	 * occur, this flag enabled an optimization of
151*4582Scth 	 * NOT calling libtopo for a configuration update
152*4582Scth 	 * when the DE starts up.  This allows a HUGE
153*4582Scth 	 * savings (since only a single snapshot-- the
154*4582Scth 	 * initial snapshot) is used as the source of
155*4582Scth 	 * the FRU information.
156*4582Scth 	 */
157*4582Scth 	boolean_t		initial_configuration;
158*4582Scth 
159*4582Scth 	/* For the state-change manager: */
160*4582Scth 
161*4582Scth 	/*
162*4582Scth 	 * Current state of the fault indicator.
163*4582Scth 	 */
164*4582Scth 	pthread_mutex_t		fault_indicator_mutex;
165*4582Scth 	ind_state_t		fault_indicator_state;
166*4582Scth 
167*4582Scth 	/*
168*4582Scth 	 * Set to TRUE when a disk transitions to the CONFIGURED state
169*4582Scth 	 * and remains TRUE until the disk is physically removed.
170*4582Scth 	 */
171*4582Scth 	boolean_t		configured_yet;
172*4582Scth 
173*4582Scth 	/*
174*4582Scth 	 * The number of disk hotplug state transitions since the disk
175*4582Scth 	 * was inserted.
176*4582Scth 	 */
177*4582Scth 	uint_t			state_change_count;
178*4582Scth 
179*4582Scth 	/* Disk FRU (model, manufacturer, etc) information */
180*4582Scth 	pthread_mutex_t		fru_mutex;
181*4582Scth 	dm_fru_t		*frup;
182*4582Scth 
183*4582Scth 	struct diskmon		*next;
184*4582Scth } diskmon_t;
185*4582Scth 
186*4582Scth typedef struct cfgdata {
187*4582Scth 	nvlist_t 		*props;
188*4582Scth 	diskmon_t		*disk_list;
189*4582Scth } cfgdata_t;
190*4582Scth 
191*4582Scth typedef struct namevalpr {
192*4582Scth 	char 			*name;
193*4582Scth 	char 			*value;
194*4582Scth } namevalpr_t;
195*4582Scth 
196*4582Scth 
197*4582Scth extern indicator_t 	*new_indicator(ind_state_t lstate, char *namep,
198*4582Scth     char *actionp);
199*4582Scth extern void		link_indicator(indicator_t **first,
200*4582Scth     indicator_t *to_add);
201*4582Scth extern void		ind_free(indicator_t *indp);
202*4582Scth 
203*4582Scth extern ind_action_t 	*new_indaction(ind_state_t state, char *namep);
204*4582Scth extern void		link_indaction(ind_action_t **first,
205*4582Scth     ind_action_t *to_add);
206*4582Scth extern void		indaction_free(ind_action_t *lap);
207*4582Scth 
208*4582Scth extern indrule_t 	*new_indrule(state_transition_t *st,
209*4582Scth     ind_action_t *actionp);
210*4582Scth extern void		link_indrule(indrule_t **first, indrule_t *to_add);
211*4582Scth extern void		indrule_free(indrule_t *lrp);
212*4582Scth 
213*4582Scth extern diskmon_t	*new_diskmon(nvlist_t *app_props, indicator_t *indp,
214*4582Scth     indrule_t *indrp, nvlist_t *nvlp);
215*4582Scth extern void		diskmon_free(diskmon_t *dmp);
216*4582Scth 
217*4582Scth extern dm_fru_t 	*new_dmfru(char *manu, char *modl, char *firmrev,
218*4582Scth     char *serno, uint64_t capa);
219*4582Scth extern void		dmfru_free(dm_fru_t *frup);
220*4582Scth 
221*4582Scth extern nvlist_t 	*namevalpr_to_nvlist(namevalpr_t *nvprp);
222*4582Scth 
223*4582Scth extern conf_err_t	check_state_transition(hotplug_state_t s1,
224*4582Scth     hotplug_state_t s2);
225*4582Scth extern conf_err_t	check_inds(indicator_t *indp);
226*4582Scth extern conf_err_t	check_indactions(ind_action_t *indap);
227*4582Scth extern conf_err_t	check_indrules(indrule_t *indrp,
228*4582Scth     state_transition_t **offender);
229*4582Scth extern conf_err_t	check_consistent_ind_indrules(indicator_t *indp,
230*4582Scth     indrule_t *indrp, ind_action_t **offender);
231*4582Scth 
232*4582Scth extern void		cfgdata_add_diskmon(cfgdata_t *cfgp, diskmon_t *dmp);
233*4582Scth 
234*4582Scth extern void		conf_error_msg(conf_err_t err, char *buf, int buflen,
235*4582Scth     void *arg);
236*4582Scth 
237*4582Scth extern const char	*dm_prop_lookup(nvlist_t *props, const char *prop_name);
238*4582Scth extern int		dm_prop_lookup_int(nvlist_t *props,
239*4582Scth     const char *prop_name, int *value);
240*4582Scth 
241*4582Scth extern int		config_init(void);
242*4582Scth extern int		config_get(fmd_hdl_t *hdl, const fmd_prop_t *fmd_props);
243*4582Scth extern void		config_fini(void);
244*4582Scth 
245*4582Scth extern const char *hotplug_state_string(hotplug_state_t state);
246*4582Scth 
247*4582Scth extern nvlist_t	*dm_global_proplist(void);
248*4582Scth 
249*4582Scth #ifdef __cplusplus
250*4582Scth }
251*4582Scth #endif
252*4582Scth 
253*4582Scth #endif /* _DISKMOND_CONF_H */
254