xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/fault.c (revision 7aec1d6e)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*7aec1d6eScindi 
237c478bd9Sstevel@tonic-gate /*
24*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <fmdump.h>
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
347c478bd9Sstevel@tonic-gate static int
357c478bd9Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate 	char buf[32], *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 
427c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%-15s.%4.4llu %-32s %s\n",
437c478bd9Sstevel@tonic-gate 	    fmdump_date(buf, sizeof (buf), rp),
447c478bd9Sstevel@tonic-gate 	    rp->rec_nsec / (NANOSEC / 10000), uuid, code);
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 	return (0);
477c478bd9Sstevel@tonic-gate }
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static int
507c478bd9Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	uint_t i, size = 0;
537c478bd9Sstevel@tonic-gate 	nvlist_t **nva;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
567c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	if (size != 0) {
597c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
607c478bd9Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
64*7aec1d6eScindi 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
65*7aec1d6eScindi 		nvlist_t *fru, *asru, *rsrc;
667c478bd9Sstevel@tonic-gate 		uint8_t pct = 0;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
697c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
727c478bd9Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
737c478bd9Sstevel@tonic-gate 
74*7aec1d6eScindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
75*7aec1d6eScindi 			aname = fmdump_nvl2str(asru);
76*7aec1d6eScindi 
77*7aec1d6eScindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
78*7aec1d6eScindi 			rname = fmdump_nvl2str(rsrc);
79*7aec1d6eScindi 
80*7aec1d6eScindi 		fmdump_printf(fp, "  %3u%%  %s\n\n",
81*7aec1d6eScindi 		    pct, class ? class : "-");
82*7aec1d6eScindi 
83*7aec1d6eScindi 		/*
84*7aec1d6eScindi 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
85*7aec1d6eScindi 		 * isn't defined in the event, display the ASRU FMRI instead.
86*7aec1d6eScindi 		 */
87*7aec1d6eScindi 		fmdump_printf(fp, "        Problem in: %s\n",
88*7aec1d6eScindi 		    rname ? rname : aname ? aname : "-");
89*7aec1d6eScindi 
90*7aec1d6eScindi 		fmdump_printf(fp, "           Affects: %s\n",
91*7aec1d6eScindi 		    aname ? aname : "-");
927c478bd9Sstevel@tonic-gate 
93*7aec1d6eScindi 		fmdump_printf(fp, "               FRU: %s\n\n",
94*7aec1d6eScindi 		    fname ? fname : "-");
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 		free(fname);
97*7aec1d6eScindi 		free(aname);
987c478bd9Sstevel@tonic-gate 		free(rname);
997c478bd9Sstevel@tonic-gate 	}
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	return (0);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate static int
1057c478bd9Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
1087c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
1097c478bd9Sstevel@tonic-gate 	uint_t i;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
1127c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
1157c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
1187c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
1197c478bd9Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
1207c478bd9Sstevel@tonic-gate 	}
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1237c478bd9Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
1247c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	return (0);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
1307c478bd9Sstevel@tonic-gate "fault", {
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1337c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
1347c478bd9Sstevel@tonic-gate }, {
1357c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1367c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
1377c478bd9Sstevel@tonic-gate }, {
1387c478bd9Sstevel@tonic-gate NULL,
1397c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
1407c478bd9Sstevel@tonic-gate } }
1417c478bd9Sstevel@tonic-gate };
142