xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/fault.c (revision 627351e3)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59dd0f810Scindi  * Common Development and Distribution License (the "License").
69dd0f810Scindi  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*627351e3Scy  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <fmdump.h>
297c478bd9Sstevel@tonic-gate #include <stdio.h>
309dd0f810Scindi #include <strings.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*ARGSUSED*/
337c478bd9Sstevel@tonic-gate static int
347c478bd9Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
357c478bd9Sstevel@tonic-gate {
36*627351e3Scy 	char buf[32], str[32];
37*627351e3Scy 	char *class = NULL, *uuid = "-", *code = "-";
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
407c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
417c478bd9Sstevel@tonic-gate 
42*627351e3Scy 	(void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class);
43*627351e3Scy 	if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) {
44*627351e3Scy 		(void) snprintf(str, sizeof (str), "%s %s", code, "Repaired");
45*627351e3Scy 		code = str;
46*627351e3Scy 	}
47*627351e3Scy 
4847911a7dScy 	fmdump_printf(fp, "%-20s %-32s %s\n",
4947911a7dScy 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	return (0);
527c478bd9Sstevel@tonic-gate }
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static int
557c478bd9Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	uint_t i, size = 0;
587c478bd9Sstevel@tonic-gate 	nvlist_t **nva;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
617c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	if (size != 0) {
647c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
657c478bd9Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
667c478bd9Sstevel@tonic-gate 	}
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
697aec1d6eScindi 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
709dd0f810Scindi 		char *loc = NULL;
717aec1d6eScindi 		nvlist_t *fru, *asru, *rsrc;
727c478bd9Sstevel@tonic-gate 		uint8_t pct = 0;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
757c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
787c478bd9Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
797c478bd9Sstevel@tonic-gate 
807aec1d6eScindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
817aec1d6eScindi 			aname = fmdump_nvl2str(asru);
827aec1d6eScindi 
837aec1d6eScindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
847aec1d6eScindi 			rname = fmdump_nvl2str(rsrc);
857aec1d6eScindi 
869dd0f810Scindi 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
879dd0f810Scindi 		    == 0) {
88ef884685Srb 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
899dd0f810Scindi 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
909dd0f810Scindi 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
919dd0f810Scindi 		}
929dd0f810Scindi 
939dd0f810Scindi 
947aec1d6eScindi 		fmdump_printf(fp, "  %3u%%  %s\n\n",
957aec1d6eScindi 		    pct, class ? class : "-");
967aec1d6eScindi 
977aec1d6eScindi 		/*
987aec1d6eScindi 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
997aec1d6eScindi 		 * isn't defined in the event, display the ASRU FMRI instead.
1007aec1d6eScindi 		 */
1017aec1d6eScindi 		fmdump_printf(fp, "        Problem in: %s\n",
1027aec1d6eScindi 		    rname ? rname : aname ? aname : "-");
1037aec1d6eScindi 
1047aec1d6eScindi 		fmdump_printf(fp, "           Affects: %s\n",
1057aec1d6eScindi 		    aname ? aname : "-");
1067c478bd9Sstevel@tonic-gate 
1079dd0f810Scindi 		fmdump_printf(fp, "               FRU: %s\n",
1087aec1d6eScindi 		    fname ? fname : "-");
1097c478bd9Sstevel@tonic-gate 
1109dd0f810Scindi 		fmdump_printf(fp, "          Location: %s\n\n",
1119dd0f810Scindi 		    loc ? loc : "-");
1129dd0f810Scindi 
1137c478bd9Sstevel@tonic-gate 		free(fname);
1147aec1d6eScindi 		free(aname);
1157c478bd9Sstevel@tonic-gate 		free(rname);
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	return (0);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate static int
1227c478bd9Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
1257c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
1267c478bd9Sstevel@tonic-gate 	uint_t i;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
1297c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
1327c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
1357c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
1367c478bd9Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
1377c478bd9Sstevel@tonic-gate 	}
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1407c478bd9Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
1417c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	return (0);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
1477c478bd9Sstevel@tonic-gate "fault", {
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1507c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
1517c478bd9Sstevel@tonic-gate }, {
1527c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1537c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
1547c478bd9Sstevel@tonic-gate }, {
1557c478bd9Sstevel@tonic-gate NULL,
1567c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
1577c478bd9Sstevel@tonic-gate } }
1587c478bd9Sstevel@tonic-gate };
159