Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
static topo_hdl_t *
set_open_errno(topo_hdl_t *thp, int *errp, int err)
{
	if (thp != NULL) {
		topo_close(thp);
	}
	if (errp != NULL)
		*errp = err;
	return (NULL);
}
Exemplo n.º 3
0
int
fmtopo_exit(topo_hdl_t *thp, char *uuid, int err)
{
	if (uuid != NULL)
		topo_hdl_strfree(thp, uuid);

	if (thp != NULL) {
		topo_snap_release(thp);
		topo_close(thp);
	}

	if (pargs) {
		int i;
		for (i = 0; i < pcnt; ++i)
			free(pargs[i]);
		free(pargs);
	}

	return (err);
}
Exemplo n.º 4
0
void
fmd_destroy(fmd_t *dp)
{
	fmd_module_t *mp;
	fmd_case_t *cp;
	int core;

	(void) fmd_conf_getprop(fmd.d_conf, "core", &core);

	fmd_rpc_fini();
	fmd_dr_fini();

	if (dp->d_xprt_ids != NULL)
		fmd_xprt_suspend_all();

	/*
	 * Unload the self-diagnosis module first.  This ensures that it does
	 * not get confused as we start unloading other modules, etc.  We must
	 * hold the dispq lock as a writer while doing so since it uses d_self.
	 */
	if (dp->d_self != NULL) {
		fmd_module_t *self;

		(void) pthread_rwlock_wrlock(&dp->d_disp->dq_lock);
		self = dp->d_self;
		dp->d_self = NULL;
		(void) pthread_rwlock_unlock(&dp->d_disp->dq_lock);

		fmd_module_unload(self);
		fmd_module_rele(self);
	}

	/*
	 * Unload modules in reverse order *except* for the root module, which
	 * is first in the list.  This allows it to keep its thread and trace.
	 */
	for (mp = fmd_list_prev(&dp->d_mod_list); mp != dp->d_rmod; ) {
		fmd_module_unload(mp);
		mp = fmd_list_prev(mp);
	}

	if (dp->d_mod_hash != NULL) {
		fmd_modhash_destroy(dp->d_mod_hash);
		dp->d_mod_hash = NULL;
	}

	/*
	 * Close both log files now that modules are no longer active.  We must
	 * set these pointers to NULL in case any subsequent errors occur.
	 */
	if (dp->d_errlog != NULL) {
		fmd_log_rele(dp->d_errlog);
		dp->d_errlog = NULL;
	}

	if (dp->d_fltlog != NULL) {
		fmd_log_rele(dp->d_fltlog);
		dp->d_fltlog = NULL;
	}

	/*
	 * Now destroy the resource cache: each ASRU contains a case reference,
	 * which may in turn contain a pointer to a referenced owning module.
	 */
	if (dp->d_asrus != NULL) {
		fmd_asru_hash_destroy(dp->d_asrus);
		dp->d_asrus = NULL;
	}

	/*
	 * Now that all data structures that refer to modules are torn down,
	 * no modules should be remaining on the module list except for d_rmod.
	 * If we trip one of these assertions, we're missing a rele somewhere.
	 */
	ASSERT(fmd_list_prev(&dp->d_mod_list) == dp->d_rmod);
	ASSERT(fmd_list_next(&dp->d_mod_list) == dp->d_rmod);

	/*
	 * Now destroy the root module.  We clear its thread key first so any
	 * calls to fmd_trace() inside of the module code will be ignored.
	 */
	(void) pthread_setspecific(dp->d_key, NULL);
	fmd_module_lock(dp->d_rmod);

	while ((cp = fmd_list_next(&dp->d_rmod->mod_cases)) != NULL)
		fmd_case_discard(cp);

	fmd_module_unlock(dp->d_rmod);
	fmd_free(dp->d_rmod->mod_stats, sizeof (fmd_modstat_t));
	dp->d_rmod->mod_stats = NULL;

	(void) pthread_mutex_lock(&dp->d_rmod->mod_lock);
	dp->d_rmod->mod_flags |= FMD_MOD_FINI;
	(void) pthread_mutex_unlock(&dp->d_rmod->mod_lock);

	fmd_module_rele(dp->d_rmod);
	ASSERT(fmd_list_next(&dp->d_mod_list) == NULL);

	/*
	 * Now destroy the remaining global data structures.  If 'core' was
	 * set to true, force a core dump so we can check for memory leaks.
	 */
	if (dp->d_cases != NULL)
		fmd_case_hash_destroy(dp->d_cases);
	if (dp->d_disp != NULL)
		fmd_dispq_destroy(dp->d_disp);
	if (dp->d_timers != NULL)
		fmd_timerq_destroy(dp->d_timers);
	if (dp->d_schemes != NULL)
		fmd_scheme_hash_destroy(dp->d_schemes);
	if (dp->d_xprt_ids != NULL)
		fmd_idspace_destroy(dp->d_xprt_ids);

	if (dp->d_errstats != NULL) {
		fmd_free(dp->d_errstats,
		    sizeof (fmd_stat_t) * (EFMD_END - EFMD_UNKNOWN));
	}

	if (dp->d_conf != NULL)
		fmd_conf_close(dp->d_conf);

	if (dp->d_topo != NULL)
		topo_close(dp->d_topo);

	nvlist_free(dp->d_auth);
	(void) nv_alloc_fini(&dp->d_nva);
	dp->d_clockops->fto_fini(dp->d_clockptr);

	(void) pthread_key_delete(dp->d_key);
	bzero(dp, sizeof (fmd_t));

	if (core)
		fmd_panic("forcing core dump at user request\n");
}
Exemplo n.º 5
0
/*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);
}