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