cmd_branch_t * cmd_branch_create(fmd_hdl_t *hdl, nvlist_t *asru) { cmd_branch_t *branch; const char *b_unum; if ((b_unum = cmd_fmri_get_unum(asru)) == NULL) { CMD_STAT_BUMP(bad_mem_asru); return (NULL); } fmd_hdl_debug(hdl, "branch_create: creating new branch %s\n", b_unum); CMD_STAT_BUMP(branch_creat); branch = fmd_hdl_zalloc(hdl, sizeof (cmd_branch_t), FMD_SLEEP); branch->branch_nodetype = CMD_NT_BRANCH; branch->branch_version = CMD_BRANCH_VERSION; cmd_bufname(branch->branch_bufname, sizeof (branch->branch_bufname), "branch_%s", b_unum); cmd_fmri_init(hdl, &branch->branch_asru, asru, "branch_asru_%s", b_unum); (void) nvlist_lookup_string(branch->branch_asru_nvl, FM_FMRI_MEM_UNUM, (char **)&branch->branch_unum); cmd_list_append(&cmd.cmd_branches, branch); cmd_branch_dirty(hdl, branch); return (branch); }
void cmd_branch_add_dimm(fmd_hdl_t *hdl, cmd_branch_t *branch, cmd_dimm_t *dimm) { cmd_branch_memb_t *bm; if (dimm == NULL) return; fmd_hdl_debug(hdl, "Attaching dimm %s to branch %s\n", dimm->dimm_unum, branch->branch_unum); bm = fmd_hdl_zalloc(hdl, sizeof (cmd_branch_memb_t), FMD_SLEEP); bm->dimm = dimm; cmd_list_append(&branch->branch_dimms, bm); }
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); }
cmd_dimm_t * cmd_dimm_create(fmd_hdl_t *hdl, nvlist_t *asru) { cmd_dimm_t *dimm; const char *unum; nvlist_t *fmri; size_t nserids = 0; char **serids = NULL; if (!fmd_nvl_fmri_present(hdl, asru)) { fmd_hdl_debug(hdl, "dimm_lookup: discarding old ereport\n"); return (NULL); } if ((unum = cmd_fmri_get_unum(asru)) == NULL) { CMD_STAT_BUMP(bad_mem_asru); return (NULL); } #ifdef sun4v if (nvlist_lookup_string_array(asru, FM_FMRI_HC_SERIAL_ID, &serids, &nserids) != 0) { fmd_hdl_debug(hdl, "sun4v mem: FMRI does not" " have serial_ids\n"); CMD_STAT_BUMP(bad_mem_asru); return (NULL); } #endif fmri = cmd_mem_fmri_create(unum, serids, nserids); if (fmd_nvl_fmri_expand(hdl, fmri) < 0) { CMD_STAT_BUMP(bad_mem_asru); nvlist_free(fmri); return (NULL); } fmd_hdl_debug(hdl, "dimm_create: creating new DIMM %s\n", unum); CMD_STAT_BUMP(dimm_creat); dimm = fmd_hdl_zalloc(hdl, sizeof (cmd_dimm_t), FMD_SLEEP); dimm->dimm_nodetype = CMD_NT_DIMM; dimm->dimm_version = CMD_DIMM_VERSION; cmd_bufname(dimm->dimm_bufname, sizeof (dimm->dimm_bufname), "dimm_%s", unum); cmd_fmri_init(hdl, &dimm->dimm_asru, fmri, "dimm_asru_%s", unum); nvlist_free(fmri); (void) nvlist_lookup_string(dimm->dimm_asru_nvl, FM_FMRI_MEM_UNUM, (char **)&dimm->dimm_unum); dimm_attach_to_bank(hdl, dimm); cmd_mem_retirestat_create(hdl, &dimm->dimm_retstat, dimm->dimm_unum, 0, CMD_DIMM_STAT_PREFIX); cmd_list_append(&cmd.cmd_dimms, dimm); cmd_dimm_dirty(hdl, dimm); return (dimm); }