10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53323Scindi  * Common Development and Distribution License (the "License").
63323Scindi  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211414Scindi 
220Sstevel@tonic-gate /*
23*3530Srb144127  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <fmdump.h>
300Sstevel@tonic-gate #include <stdio.h>
313323Scindi #include <strings.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*ARGSUSED*/
340Sstevel@tonic-gate static int
350Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
360Sstevel@tonic-gate {
370Sstevel@tonic-gate 	char buf[32], *uuid = "-", *code = "-";
380Sstevel@tonic-gate 
390Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
400Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
410Sstevel@tonic-gate 
420Sstevel@tonic-gate 	fmdump_printf(fp, "%-15s.%4.4llu %-32s %s\n",
430Sstevel@tonic-gate 	    fmdump_date(buf, sizeof (buf), rp),
440Sstevel@tonic-gate 	    rp->rec_nsec / (NANOSEC / 10000), uuid, code);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 	return (0);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate 
490Sstevel@tonic-gate static int
500Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	uint_t i, size = 0;
530Sstevel@tonic-gate 	nvlist_t **nva;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
560Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	if (size != 0) {
590Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
600Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
610Sstevel@tonic-gate 	}
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
641414Scindi 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
653323Scindi 		char *loc = NULL;
661414Scindi 		nvlist_t *fru, *asru, *rsrc;
670Sstevel@tonic-gate 		uint8_t pct = 0;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
700Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
730Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
740Sstevel@tonic-gate 
751414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
761414Scindi 			aname = fmdump_nvl2str(asru);
771414Scindi 
781414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
791414Scindi 			rname = fmdump_nvl2str(rsrc);
801414Scindi 
813323Scindi 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
823323Scindi 		    == 0) {
83*3530Srb144127 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
843323Scindi 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
853323Scindi 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
863323Scindi 		}
873323Scindi 
883323Scindi 
891414Scindi 		fmdump_printf(fp, "  %3u%%  %s\n\n",
901414Scindi 		    pct, class ? class : "-");
910Sstevel@tonic-gate 
921414Scindi 		/*
931414Scindi 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
941414Scindi 		 * isn't defined in the event, display the ASRU FMRI instead.
951414Scindi 		 */
961414Scindi 		fmdump_printf(fp, "        Problem in: %s\n",
971414Scindi 		    rname ? rname : aname ? aname : "-");
981414Scindi 
991414Scindi 		fmdump_printf(fp, "           Affects: %s\n",
1001414Scindi 		    aname ? aname : "-");
1011414Scindi 
1023323Scindi 		fmdump_printf(fp, "               FRU: %s\n",
1031414Scindi 		    fname ? fname : "-");
1040Sstevel@tonic-gate 
1053323Scindi 		fmdump_printf(fp, "          Location: %s\n\n",
1063323Scindi 		    loc ? loc : "-");
1073323Scindi 
1080Sstevel@tonic-gate 		free(fname);
1091414Scindi 		free(aname);
1100Sstevel@tonic-gate 		free(rname);
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	return (0);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate static int
1170Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
1200Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
1210Sstevel@tonic-gate 	uint_t i;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
1240Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
1270Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
1300Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
1310Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
1320Sstevel@tonic-gate 	}
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1350Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
1360Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	return (0);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
1420Sstevel@tonic-gate "fault", {
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1450Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
1460Sstevel@tonic-gate }, {
1470Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1480Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
1490Sstevel@tonic-gate }, {
1500Sstevel@tonic-gate NULL,
1510Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
1520Sstevel@tonic-gate } }
1530Sstevel@tonic-gate };
154