Пример #1
0
/*
 * Teardown any transport infrastructure after all connections are closed.
 * Return 0 for success, or nonzero for failure.
 */
int
etm_xport_fini(fmd_hdl_t *hdl, etm_xport_hdl_t tlhdl)
{
	exs_hdl_t *hp = (exs_hdl_t *)tlhdl;
	exs_hdl_t *xp, **ppx;

	(void) pthread_mutex_lock(&List_lock);

	ppx = &Exh_head;

	for (xp = *ppx; xp; xp = xp->h_next) {
		if (xp != hp)
			ppx = &xp->h_next;
		else
			break;
	}

	if (xp != hp) {
		(void) pthread_mutex_unlock(&List_lock);
		fmd_hdl_abort(hdl, "xport - fini failed, tlhdl %p not on list",
		    (void *)hp);
	}

	*ppx = hp->h_next;
	hp->h_next = NULL;

	if (hp->h_tid != EXS_TID_FREE) {
		hp->h_quit = 1;
		fmd_thr_signal(hdl, hp->h_tid);
		fmd_thr_destroy(hdl, hp->h_tid);
	}

	if (hp->h_server.c_sd != EXS_SD_FREE)
		(void) close(hp->h_server.c_sd);

	if (hp->h_client.c_sd != EXS_SD_FREE)
		(void) close(hp->h_client.c_sd);

	fmd_hdl_strfree(hdl, hp->h_endpt_id);
	fmd_hdl_free(hdl, hp, sizeof (exs_hdl_t));

	if (Exh_head == NULL) {
		/* Undo one-time initializations */
		exs_filter_fini(hdl);

		/* Destroy the accept/listen thread */
		if (Acc_tid != EXS_TID_FREE) {
			Acc_quit = 1;
			fmd_thr_signal(hdl, Acc_tid);
			fmd_thr_destroy(hdl, Acc_tid);
		}

		if (Acc.c_sd != EXS_SD_FREE)
			EXS_CLOSE_CLR(Acc);
	}

	(void) pthread_mutex_unlock(&List_lock);

	return (0);
}
Пример #2
0
void
_fmd_init(fmd_hdl_t *hdl)
{
	sp_monitor_t *smp;
	int error;
	char *msg;

	if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0)
		return;

	smp = fmd_hdl_zalloc(hdl, sizeof (sp_monitor_t), FMD_SLEEP);
	fmd_hdl_setspecific(hdl, smp);

	if ((smp->sm_hdl = ipmi_open(&error, &msg, IPMI_TRANSPORT_BMC, NULL))
	    == NULL) {
		/*
		 * If /dev/ipmi0 doesn't exist on the system, then unload the
		 * module without doing anything.
		 */
		if (error != EIPMI_BMC_OPEN_FAILED)
			fmd_hdl_abort(hdl, "failed to initialize IPMI "
			    "connection: %s\n", msg);
		fmd_hdl_debug(hdl, "failed to load: no IPMI connection "
		    "present");
		fmd_hdl_free(hdl, smp, sizeof (sp_monitor_t));
		fmd_hdl_unregister(hdl);
		return;
	}

	/*
	 * Attempt an initial uptime() call.  If the IPMI command is
	 * unrecognized, then this is an unsupported platform and the module
	 * should be unloaded.  Any other error is treated is transient failure.
	 */
	if ((error = ipmi_sunoem_uptime(smp->sm_hdl, &smp->sm_seconds,
	    &smp->sm_generation)) != 0 &&
	    ipmi_errno(smp->sm_hdl) == EIPMI_INVALID_COMMAND) {
		fmd_hdl_debug(hdl, "failed to load: uptime command "
		    "not supported");
		ipmi_close(smp->sm_hdl);
		fmd_hdl_free(hdl, smp, sizeof (sp_monitor_t));
		fmd_hdl_unregister(hdl);
		return;
	}

	smp->sm_interval = fmd_prop_get_int64(hdl, "interval");

	if (error == 0)
		fmd_hdl_debug(hdl, "successfully loaded, uptime = %u seconds "
		    "(generation %u)", smp->sm_seconds, smp->sm_generation);
	else
		fmd_hdl_debug(hdl, "successfully loaded, but uptime call "
		    "failed: %s", ipmi_errmsg(smp->sm_hdl));

	/*
	 * Setup the recurring timer.
	 */
	(void) fmd_timer_install(hdl, NULL, NULL, 0);
}
Пример #3
0
static void
send_fma_cap_to_ilom(fmd_hdl_t *hdl, uint32_t fma_cap)
{
    int error;
    char *msg;
    ipmi_handle_t *ipmi_hdl;
    ipmi_cmd_t cmd;
    uint8_t oem_data[OEM_DATA_LENGTH];

    if ((ipmi_hdl = ipmi_open(&error, &msg, IPMI_TRANSPORT_BMC, NULL))
            == NULL) {
        /*
         * If /dev/ipmi0 doesn't exist on the system, then return
         * without doing anything.
         */
        if (error != EIPMI_BMC_OPEN_FAILED)
            fmd_hdl_abort(hdl, "Failed to initialize IPMI "
                          "connection: %s\n", msg);
        fmd_hdl_debug(hdl, "Failed: no IPMI connection present");
        return;
    }

    /*
     * Check if it's Sun ILOM
     */
    if (check_sunoem(ipmi_hdl) != 0) {
        fmd_hdl_debug(hdl, "Service Processor does not run "
                      "Sun ILOM");
        ipmi_close(ipmi_hdl);
        return;
    }

    oem_data[0] = CORE_TUNNEL_SUBCMD_HOSTFMACAP;
    oem_data[1] = VERSION;
    oem_data[2] = fma_cap;

    cmd.ic_netfn = IPMI_NETFN_OEM;
    cmd.ic_lun = 0;
    cmd.ic_cmd = CMD_SUNOEM_CORE_TUNNEL;
    cmd.ic_dlen = OEM_DATA_LENGTH;
    cmd.ic_data = oem_data;

    if (ipmi_send(ipmi_hdl, &cmd) == NULL) {
        fmd_hdl_debug(hdl, "Failed to send Solaris FMA "
                      "capability to ilom: %s", ipmi_errmsg(ipmi_hdl));
    }

    ipmi_close(ipmi_hdl);
}
Пример #4
0
static cmd_branch_t *
branch_wrapv0(fmd_hdl_t *hdl, cmd_branch_pers_t *pers, size_t psz)
{
	cmd_branch_t *branch;

	if (psz != sizeof (cmd_branch_pers_t)) {
		fmd_hdl_abort(hdl, "size of state doesn't match size of "
		    "version 0 state (%u bytes).\n",
		    sizeof (cmd_branch_pers_t));
	}

	branch = fmd_hdl_zalloc(hdl, sizeof (cmd_branch_t), FMD_SLEEP);
	bcopy(pers, branch, sizeof (cmd_branch_pers_t));
	fmd_hdl_free(hdl, pers, psz);
	return (branch);
}
Пример #5
0
void
cmd_branch_remove_dimm(fmd_hdl_t *hdl, cmd_branch_t *branch, cmd_dimm_t *dimm)
{
	cmd_branch_memb_t *bm;

	fmd_hdl_debug(hdl, "Detaching dimm %s from branch %s\n",
	    dimm->dimm_unum, branch->branch_unum);

	for (bm = cmd_list_next(&branch->branch_dimms); bm != NULL;
	    bm = cmd_list_next(bm)) {
		if (bm->dimm == dimm) {
			cmd_list_delete(&branch->branch_dimms, bm);
			fmd_hdl_free(hdl, bm, sizeof (cmd_branch_memb_t));
			return;
		}
	}

	fmd_hdl_abort(hdl,
	    "Attempt to disconnect dimm from non-parent branch\n");
}
Пример #6
0
void *
cmd_branch_restore(fmd_hdl_t *hdl, fmd_case_t *cp, cmd_case_ptr_t *ptr)
{
	cmd_branch_t *branch;
	size_t branchsz;


	for (branch = cmd_list_next(&cmd.cmd_branches); branch != NULL;
	    branch = cmd_list_next(branch)) {
		if (strcmp(branch->branch_bufname, ptr->ptr_name) == 0)
			break;
	}

	if (branch == NULL) {
		fmd_hdl_debug(hdl, "restoring branch from %s\n", ptr->ptr_name);

		if ((branchsz = fmd_buf_size(hdl, NULL, ptr->ptr_name)) == 0) {
			fmd_hdl_abort(hdl, "branch referenced by case %s does "
			    "not exist in saved state\n",
			    fmd_case_uuid(hdl, cp));
		} else if (branchsz > CMD_BRANCH_MAXSIZE ||
		    branchsz < CMD_BRANCH_MINSIZE) {
			fmd_hdl_abort(hdl,
			    "branch buffer referenced by case %s "
			    "is out of bounds (is %u bytes, max %u, min %u)\n",
			    fmd_case_uuid(hdl, cp), branchsz,
			    CMD_BRANCH_MAXSIZE, CMD_BRANCH_MINSIZE);
		}

		if ((branch = cmd_buf_read(hdl, NULL, ptr->ptr_name,
		    branchsz)) == NULL) {
			fmd_hdl_abort(hdl, "failed to read branch buf %s",
			    ptr->ptr_name);
		}

		fmd_hdl_debug(hdl, "found %d in version field\n",
		    branch->branch_version);

		switch (branch->branch_version) {
		case CMD_BRANCH_VERSION_0:
			branch = branch_wrapv0(hdl,
			    (cmd_branch_pers_t *)branch, branchsz);
			break;
		default:
			fmd_hdl_abort(hdl, "unknown version (found %d) "
			    "for branch state referenced by case %s.\n",
			    branch->branch_version, fmd_case_uuid(hdl,
			    cp));
			break;
		}

		cmd_fmri_restore(hdl, &branch->branch_asru);

		if ((errno = nvlist_lookup_string(branch->branch_asru_nvl,
		    FM_FMRI_MEM_UNUM, (char **)&branch->branch_unum)) != 0)
			fmd_hdl_abort(hdl, "failed to retrieve unum from asru");


		cmd_list_append(&cmd.cmd_branches, branch);
	}

	switch (ptr->ptr_subtype) {
	case CMD_PTR_BRANCH_CASE:
		cmd_mem_case_restore(hdl, &branch->branch_case, cp, "branch",
		    branch->branch_unum);
		break;
	default:
		fmd_hdl_abort(hdl, "invalid %s subtype %d\n",
		    ptr->ptr_name, ptr->ptr_subtype);
	}

	return (branch);
}