bool_t fmd_adm_serdreset_1_svc(char *mname, char *sname, int *rvp, struct svc_req *req) { fmd_module_t *mp; fmd_serd_eng_t *sgp; int err = 0; if (fmd_rpc_deny(req)) { *rvp = FMD_ADM_ERR_PERM; return (TRUE); } if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, mname)) == NULL) { *rvp = FMD_ADM_ERR_MODSRCH; return (TRUE); } fmd_module_lock(mp); if ((sgp = fmd_serd_eng_lookup(&mp->mod_serds, sname)) != NULL) { if (fmd_serd_eng_fired(sgp)) { err = FMD_ADM_ERR_SERDFIRED; } else { fmd_serd_eng_reset(sgp); fmd_module_setdirty(mp); } } else err = FMD_ADM_ERR_SERDSRCH; fmd_module_unlock(mp); fmd_module_rele(mp); *rvp = err; return (TRUE); }
bool_t fmd_adm_modreset_1_svc(char *name, int *rvp, struct svc_req *req) { fmd_module_t *mp = NULL; int err = 0; if (fmd_rpc_deny(req)) err = FMD_ADM_ERR_PERM; else if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) err = FMD_ADM_ERR_MODSRCH; else if (mp == fmd.d_self) err = FMD_ADM_ERR_MODBUSY; else if (fmd_modhash_unload(fmd.d_mod_hash, name) != 0) err = FMD_ADM_ERR_MODSRCH; if (err == 0) fmd_ckpt_delete(mp); /* erase any saved checkpoints */ if (err == 0 && fmd_modhash_load(fmd.d_mod_hash, mp->mod_path, mp->mod_ops) == NULL) { if (errno == EFMD_MOD_INIT) err = FMD_ADM_ERR_MODINIT; else err = FMD_ADM_ERR_MODLOAD; } if (mp != NULL) fmd_module_rele(mp); *rvp = err; return (TRUE); }
bool_t fmd_adm_serdinfo_1_svc(char *mname, char *sname, struct fmd_rpc_serdinfo *rvp, struct svc_req *req) { fmd_module_t *mp; fmd_serd_eng_t *sgp; bzero(rvp, sizeof (struct fmd_rpc_serdinfo)); if (fmd_rpc_deny(req)) { rvp->rsi_err = FMD_ADM_ERR_PERM; return (TRUE); } if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, mname)) == NULL) { rvp->rsi_err = FMD_ADM_ERR_MODSRCH; return (TRUE); } fmd_module_lock(mp); if ((sgp = fmd_serd_eng_lookup(&mp->mod_serds, sname)) != NULL) { fmd_adm_serdinfo_record(sgp, rvp); } else rvp->rsi_err = FMD_ADM_ERR_SERDSRCH; fmd_module_unlock(mp); fmd_module_rele(mp); return (TRUE); }
bool_t fmd_adm_modcstat_1_svc(char *name, struct fmd_rpc_modstat *rms, struct svc_req *req) { fmd_ustat_snap_t snap; fmd_module_t *mp; rms->rms_buf.rms_buf_val = NULL; rms->rms_buf.rms_buf_len = 0; rms->rms_err = 0; if (fmd_rpc_deny(req)) { rms->rms_err = FMD_ADM_ERR_PERM; return (TRUE); } if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) { rms->rms_err = FMD_ADM_ERR_MODSRCH; return (TRUE); } if (fmd_modstat_snapshot(mp, &snap) == 0) { rms->rms_buf.rms_buf_val = snap.uss_buf; rms->rms_buf.rms_buf_len = snap.uss_len; } else if (errno == EFMD_HDL_ABORT) { rms->rms_err = FMD_ADM_ERR_MODFAIL; } else rms->rms_err = FMD_ADM_ERR_NOMEM; fmd_module_rele(mp); return (TRUE); }
bool_t fmd_adm_moddstat_1_svc(char *name, struct fmd_rpc_modstat *rms, struct svc_req *req) { fmd_module_t *mp; rms->rms_buf.rms_buf_val = NULL; rms->rms_buf.rms_buf_len = 0; rms->rms_err = 0; if (fmd_rpc_deny(req)) { rms->rms_err = FMD_ADM_ERR_PERM; return (TRUE); } if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) { rms->rms_err = FMD_ADM_ERR_MODSRCH; return (TRUE); } rms->rms_buf.rms_buf_val = malloc(sizeof (fmd_modstat_t)); rms->rms_buf.rms_buf_len = sizeof (fmd_modstat_t) / sizeof (fmd_stat_t); if (rms->rms_buf.rms_buf_val == NULL) { rms->rms_err = FMD_ADM_ERR_NOMEM; rms->rms_buf.rms_buf_len = 0; fmd_module_rele(mp); return (TRUE); } /* * Note: the bcopy() here is valid only if no FMD_TYPE_STRING stats * are present in mp->mod_stats. We don't use any for the daemon- * maintained stats and provide this function in order to reduce the * overhead of the fmstat(1M) default view, where these minimal stats * must be retrieved for all of the active modules. */ (void) pthread_mutex_lock(&mp->mod_stats_lock); if (mp->mod_stats != NULL) { mp->mod_stats->ms_snaptime.fmds_value.ui64 = gethrtime(); bcopy(mp->mod_stats, rms->rms_buf.rms_buf_val, sizeof (fmd_modstat_t)); } else { free(rms->rms_buf.rms_buf_val); rms->rms_buf.rms_buf_val = NULL; rms->rms_buf.rms_buf_len = 0; rms->rms_err = FMD_ADM_ERR_MODFAIL; } (void) pthread_mutex_unlock(&mp->mod_stats_lock); fmd_module_rele(mp); return (TRUE); }
bool_t fmd_adm_serdlist_1_svc(char *name, struct fmd_rpc_serdlist *rvp, struct svc_req *req) { fmd_module_t *mp; void *p; rvp->rsl_buf.rsl_buf_len = 0; rvp->rsl_buf.rsl_buf_val = NULL; rvp->rsl_len = 0; rvp->rsl_cnt = 0; rvp->rsl_err = 0; if (fmd_rpc_deny(req)) { rvp->rsl_err = FMD_ADM_ERR_PERM; return (TRUE); } if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) { rvp->rsl_err = FMD_ADM_ERR_MODSRCH; return (TRUE); } fmd_module_lock(mp); /* In the first pass, collect the overall length of the buffer. */ fmd_serd_hash_apply(&mp->mod_serds, fmd_adm_serdlist_measure, rvp); if (rvp->rsl_len == 0) { fmd_module_unlock(mp); fmd_module_rele(mp); return (TRUE); } p = malloc(rvp->rsl_len); if (p) { rvp->rsl_buf.rsl_buf_val = p; rvp->rsl_buf.rsl_buf_len = rvp->rsl_len; bzero(rvp->rsl_buf.rsl_buf_val, rvp->rsl_buf.rsl_buf_len); rvp->rsl_len = 0; /* In the second pass, populate the buffer with data. */ fmd_serd_hash_apply(&mp->mod_serds, fmd_adm_serdlist_record, rvp); } else { rvp->rsl_err = FMD_ADM_ERR_NOMEM; } fmd_module_unlock(mp); fmd_module_rele(mp); return (TRUE); }
bool_t fmd_adm_modgc_1_svc(char *name, int *rvp, struct svc_req *req) { fmd_module_t *mp; int err = 0; if (fmd_rpc_deny(req)) err = FMD_ADM_ERR_PERM; else if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) err = FMD_ADM_ERR_MODSRCH; else { fmd_module_gc(mp); fmd_module_rele(mp); } *rvp = err; return (TRUE); }
bool_t fmd_adm_modunload_1_svc(char *name, int *rvp, struct svc_req *req) { fmd_module_t *mp = NULL; int err = 0; if (fmd_rpc_deny(req)) err = FMD_ADM_ERR_PERM; else if ((mp = fmd_modhash_lookup(fmd.d_mod_hash, name)) == NULL) err = FMD_ADM_ERR_MODSRCH; else if (mp == fmd.d_self) err = FMD_ADM_ERR_MODBUSY; else if (fmd_modhash_unload(fmd.d_mod_hash, name) != 0) err = FMD_ADM_ERR_MODSRCH; if (mp != NULL) fmd_module_rele(mp); *rvp = err; return (TRUE); }
void fmd_run(fmd_t *dp, int pfd) { char *nodc_key[] = { FMD_FLT_NODC, NULL }; char nodc_str[128]; struct sigaction act; int status = FMD_EXIT_SUCCESS; const char *name; fmd_conf_path_t *pap; fmd_event_t *e; int dbout, err; /* * Cache all the current debug property settings in d_fmd_debug, * d_fmd_dbout, d_hdl_debug, and d_hdl_dbout. If a given debug mask * is non-zero and the corresponding dbout mask is zero, set dbout * to a sensible default value based on whether we have daemonized. */ (void) fmd_conf_getprop(dp->d_conf, "dbout", &dbout); if (dp->d_fmd_debug != 0 && dbout == 0) dp->d_fmd_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; else dp->d_fmd_dbout = dbout; (void) fmd_conf_getprop(dp->d_conf, "client.debug", &dp->d_hdl_debug); (void) fmd_conf_getprop(dp->d_conf, "client.dbout", &dbout); if (dp->d_hdl_debug != 0 && dbout == 0) dp->d_hdl_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; else dp->d_hdl_dbout = dbout; /* * Initialize remaining major program data structures such as the * clock, dispatch queues, log files, module hash collections, etc. * This work is done here rather than in fmd_create() to permit the -o * command-line option to modify properties after fmd_create() is done. */ name = dp->d_rootdir != NULL && *dp->d_rootdir != '\0' ? dp->d_rootdir : NULL; if ((dp->d_topo = topo_open(TOPO_VERSION, name, &err)) == NULL) { fmd_error(EFMD_EXIT, "failed to initialize " "topology library: %s\n", topo_strerror(err)); } dp->d_clockptr = dp->d_clockops->fto_init(); dp->d_xprt_ids = fmd_idspace_create("xprt_ids", 1, INT_MAX); fmd_xprt_suspend_all(); (void) door_server_create(fmd_door); fmd_dr_init(); dp->d_rmod->mod_timerids = fmd_idspace_create(dp->d_pname, 1, 16); dp->d_timers = fmd_timerq_create(); dp->d_disp = fmd_dispq_create(); dp->d_cases = fmd_case_hash_create(); /* * The root module's mod_queue is created with limit zero, making it * act like /dev/null; anything inserted here is simply ignored. */ dp->d_rmod->mod_queue = fmd_eventq_create(dp->d_rmod, &dp->d_rmod->mod_stats->ms_evqstat, &dp->d_rmod->mod_stats_lock, 0); /* * Once our subsystems that use signals have been set up, install the * signal handler for the fmd_thr_signal() API. Verify that the signal * being used for this purpose doesn't conflict with something else. */ (void) fmd_conf_getprop(dp->d_conf, "client.thrsig", &dp->d_thr_sig); if (sigaction(dp->d_thr_sig, NULL, &act) != 0) { fmd_error(EFMD_EXIT, "invalid signal selected for " "client.thrsig property: %d\n", dp->d_thr_sig); } if (act.sa_handler != SIG_IGN && act.sa_handler != SIG_DFL) { fmd_error(EFMD_EXIT, "signal selected for client.thrsig " "property is already in use: %d\n", dp->d_thr_sig); } act.sa_handler = fmd_signal; act.sa_flags = 0; (void) sigemptyset(&act.sa_mask); (void) sigaction(dp->d_thr_sig, &act, NULL); (void) fmd_conf_getprop(dp->d_conf, "schemedir", &name); dp->d_schemes = fmd_scheme_hash_create(dp->d_rootdir, name); (void) fmd_conf_getprop(dp->d_conf, "log.rsrc", &name); dp->d_asrus = fmd_asru_hash_create(dp->d_rootdir, name); (void) fmd_conf_getprop(dp->d_conf, "log.error", &name); dp->d_errlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_ERROR); (void) fmd_conf_getprop(dp->d_conf, "log.fault", &name); dp->d_fltlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_FAULT); if (dp->d_asrus == NULL || dp->d_errlog == NULL || dp->d_fltlog == NULL) fmd_error(EFMD_EXIT, "failed to initialize log files\n"); /* * Before loading modules, create an empty control event which will act * as a global barrier for module event processing. Each module we * load successfully will insert it at their head of their event queue, * and then pause inside of fmd_ctl_rele() after dequeuing the event. * This module barrier is required for two reasons: * * (a) During module loading, the restoration of case checkpoints may * result in a list.* event being recreated for which the intended * subscriber has not yet loaded depending on the load order. Such * events could then result in spurious "no subscriber" errors. * * (b) During errlog replay, a sequence of errors from a long time ago * may be replayed, and the module may attempt to install relative * timers associated with one or more of these events. If errlog * replay were "racing" with active module threads, an event E1 * that resulted in a relative timer T at time E1 + N nsec could * fire prior to an event E2 being enqueued, even if the relative * time ordering was E1 < E2 < E1 + N, causing mis-diagnosis. */ dp->d_mod_event = e = fmd_event_create(FMD_EVT_CTL, FMD_HRT_NOW, NULL, fmd_ctl_init(NULL)); fmd_event_hold(e); /* * Once all data structures are initialized, we load all of our modules * in order according to class in order to load up any subscriptions. * Once built-in modules are loaded, we detach from our waiting parent. */ dp->d_mod_hash = fmd_modhash_create(); if (fmd_builtin_loadall(dp->d_mod_hash) != 0 && !dp->d_fg) fmd_error(EFMD_EXIT, "failed to initialize fault manager\n"); (void) fmd_conf_getprop(dp->d_conf, "self.name", &name); dp->d_self = fmd_modhash_lookup(dp->d_mod_hash, name); if (dp->d_self != NULL && fmd_module_dc_key2code(dp->d_self, nodc_key, nodc_str, sizeof (nodc_str)) == 0) (void) fmd_conf_setprop(dp->d_conf, "nodiagcode", nodc_str); fmd_rpc_init(); dp->d_running = 1; /* we are now officially an active fmd */ /* * Now that we're running, if a pipe fd was specified, write an exit * status to it to indicate that our parent process can safely detach. * Then proceed to loading the remaining non-built-in modules. */ if (pfd >= 0) (void) write(pfd, &status, sizeof (status)); /* * Before loading all modules, repopulate the ASRU cache from its * persistent repository on disk. Then during module loading, the * restoration of checkpoint files will reparent any active cases. */ fmd_asru_hash_refresh(dp->d_asrus); (void) fmd_conf_getprop(dp->d_conf, "plugin.path", &pap); fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_rtld_ops, ".so"); (void) fmd_conf_getprop(dp->d_conf, "agent.path", &pap); fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_proc_ops, NULL); /* * With all modules loaded, replay fault events from the ASRU cache for * any ASRUs that must be retired, replay error events from the errlog * that did not finish processing the last time ran, and then release * the global module barrier by executing a final rele on d_mod_event. */ fmd_asru_hash_replay(dp->d_asrus); (void) pthread_rwlock_rdlock(&dp->d_log_lock); fmd_log_replay(dp->d_errlog, (fmd_log_f *)fmd_err_replay, dp); fmd_log_update(dp->d_errlog); (void) pthread_rwlock_unlock(&dp->d_log_lock); dp->d_mod_event = NULL; fmd_event_rele(e); /* * Finally, awaken any threads associated with receiving events from * open transports and tell them to proceed with fmd_xprt_recv(). */ fmd_xprt_resume_all(); fmd_gc(dp, 0, 0); dp->d_booted = 1; }