/*ARGSUSED*/ struct topo_hdl * fmd_fmri_topology(int version) { int err; if (g_thp == NULL) { if ((g_thp = topo_open(TOPO_VERSION, "/", &err)) == NULL) { (void) fprintf(stderr, "topo_open failed: %s\n", topo_strerror(err)); exit(1); } } return (g_thp); }
int update_configuration_from_topo(diskmon_t *diskp) { int err; topo_hdl_t *thp; topo_walk_t *twp; char *uuid; if ((thp = topo_open(TOPO_VERSION, NULL, &err)) == NULL) { return (TOPO_OPEN_ERROR); } if ((uuid = topo_snap_hold(thp, NULL, &err)) == NULL) { topo_close(thp); return (TOPO_SNAP_ERROR); } if ((twp = topo_walk_init(thp, FM_FMRI_SCHEME_HC, gather_topo_cfg, diskp, &err)) == NULL) { topo_snap_release(thp); topo_hdl_strfree(thp, uuid); topo_close(thp); return (err ? TOPO_WALK_INIT_ERROR : TOPO_SUCCESS); } topo_hdl_strfree(thp, uuid); if (topo_walk_step(twp, TOPO_WALK_CHILD) == TOPO_WALK_ERR) { topo_walk_fini(twp); topo_snap_release(thp); topo_close(thp); return (TOPO_WALK_ERROR); } topo_walk_fini(twp); topo_snap_release(thp); topo_close(thp); return (TOPO_SUCCESS); }
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; }
int main(int argc, char *argv[]) { topo_hdl_t *thp = NULL; char *uuid = NULL; int c, err = 0; g_pname = argv[0]; while (optind < argc) { while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { case 'b': opt_b++; break; case 'C': (void) atexit(abort); break; case 'd': opt_d++; break; case 'e': opt_e++; break; case 'm': opt_m = optarg; break; case 'P': pcnt++; break; case 'p': opt_p++; break; case 'V': opt_V++; break; case 'R': opt_R = optarg; break; case 's': opt_s = optarg; break; case 'S': opt_S++; break; case 't': opt_t++; break; case 'x': opt_x++; break; default: return (usage(stderr)); } } if (optind < argc) { if (g_fmri != NULL) { (void) fprintf(stderr, "%s: illegal argument " "-- %s\n", g_pname, argv[optind]); return (FMTOPO_EXIT_USAGE); } else { g_fmri = argv[optind++]; } } } if (pcnt > 0) get_pargs(argc, argv); if ((thp = topo_open(TOPO_VERSION, opt_R, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to open topology tree: %s\n", g_pname, topo_strerror(err)); return (fmtopo_exit(thp, uuid, FMTOPO_EXIT_ERROR)); } if (opt_d) topo_debug_set(thp, "module", "stderr"); if ((uuid = topo_snap_hold(thp, NULL, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to snapshot topology: %s\n", g_pname, topo_strerror(err)); return (fmtopo_exit(thp, uuid, FMTOPO_EXIT_ERROR)); } else if (err != 0) { (void) fprintf(stderr, "%s: topology snapshot incomplete\n", g_pname); } if (opt_x) { if (opt_b) { (void) fprintf(stderr, "%s: -b and -x cannot be specified together\n", g_pname); return (fmtopo_exit(thp, uuid, FMTOPO_EXIT_USAGE)); } err = 0; if (topo_xml_print(thp, stdout, opt_s, &err) < 0) (void) fprintf(stderr, "%s: failed to print xml " "formatted topology:%s", g_pname, topo_strerror(err)); return (fmtopo_exit(thp, uuid, err ? FMTOPO_EXIT_ERROR : FMTOPO_EXIT_SUCCESS)); } if (opt_t || walk_topo(thp, uuid) < 0) { if (g_fmri != NULL) /* * Try getting some useful information */ print_fmri(thp, uuid); return (fmtopo_exit(thp, uuid, FMTOPO_EXIT_ERROR)); } return (fmtopo_exit(thp, uuid, FMTOPO_EXIT_SUCCESS)); }
/*ARGSUSED*/ int do_prominfo(int opt_v, char *progname, int opt_l, int opt_p) { smbios_hdl_t *shp; smbios_system_t sys; smbios_bios_t bios; smbios_ipmi_t ipmi; smbios_info_t info; topo_hdl_t *thp; char *uuid; const char *s; id_t id; int err; if ((shp = smbios_open(NULL, SMB_VERSION, 0, &err)) == NULL) { (void) fprintf(stderr, gettext("%s: failed to open SMBIOS: %s\n"), progname, smbios_errmsg(err)); return (1); } if ((id = smbios_info_system(shp, &sys)) != SMB_ERR && smbios_info_common(shp, id, &info) != SMB_ERR) { (void) printf(gettext("System Configuration: %s %s\n"), info.smbi_manufacturer, info.smbi_product); } else { (void) fprintf(stderr, gettext("%s: failed to get system info: %s\n"), progname, smbios_errmsg(smbios_errno(shp))); } if (smbios_info_bios(shp, &bios) != SMB_ERR) { (void) printf(gettext("BIOS Configuration: %s %s %s\n"), bios.smbb_vendor, bios.smbb_version, bios.smbb_reldate); } else { (void) fprintf(stderr, gettext("%s: failed to get bios info: %s\n"), progname, smbios_errmsg(smbios_errno(shp))); } if (smbios_info_ipmi(shp, &ipmi) != SMB_ERR) { if ((s = smbios_ipmi_type_desc(ipmi.smbip_type)) == NULL) s = gettext("Unknown"); (void) printf(gettext("BMC Configuration: IPMI %u.%u (%s)\n"), ipmi.smbip_vers.smbv_major, ipmi.smbip_vers.smbv_minor, s); } /* * Silently swallow all libtopo and libpcidb related errors. */ uuid = NULL; if ((thp = topo_open(TOPO_VERSION, NULL, &err)) != NULL) { if ((uuid = topo_snap_hold(thp, NULL, &err)) == NULL) { topo_close(thp); thp = NULL; } } prt_php = pcidb_open(PCIDB_VERSION); (void) printf(gettext( "\n==== Processor Sockets ====================================\n")); (void) printf(gettext("\n%-32s %s"), "Version", "Location Tag"); (void) printf(gettext( "\n-------------------------------- --------------------------\n")); (void) smbios_iter(shp, do_procs, NULL); (void) printf(gettext( "\n==== Memory Device Sockets ================================\n")); (void) printf(gettext("\n%-11s %-6s %-3s %-19s %s"), "Type", "Status", "Set", "Device Locator", "Bank Locator"); (void) printf(gettext( "\n----------- ------ --- ------------------- ----------------\n")); (void) smbios_iter(shp, do_memdevs, NULL); (void) printf(gettext( "\n==== On-Board Devices =====================================\n")); (void) smbios_iter(shp, do_obdevs, NULL); (void) printf(gettext( "\n==== Upgradeable Slots ====================================\n")); (void) printf(gettext("\n%-3s %-9s %-16s %s"), "ID", "Status", "Type", "Description"); (void) printf(gettext( "\n--- --------- ---------------- ----------------------------\n")); (void) smbios_iter(shp, do_slots, thp); smbios_close(shp); topo_hdl_strfree(thp, uuid); if (thp != NULL) { topo_snap_release(thp); topo_close(thp); } pcidb_close(prt_php); return (0); }