xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/fault.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <fmdump.h>
30*7c478bd9Sstevel@tonic-gate #include <stdio.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
33*7c478bd9Sstevel@tonic-gate static int
34*7c478bd9Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
35*7c478bd9Sstevel@tonic-gate {
36*7c478bd9Sstevel@tonic-gate 	char buf[32], *uuid = "-", *code = "-";
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
39*7c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%-15s.%4.4llu %-32s %s\n",
42*7c478bd9Sstevel@tonic-gate 	    fmdump_date(buf, sizeof (buf), rp),
43*7c478bd9Sstevel@tonic-gate 	    rp->rec_nsec / (NANOSEC / 10000), uuid, code);
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 	return (0);
46*7c478bd9Sstevel@tonic-gate }
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate static int
49*7c478bd9Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate 	uint_t i, size = 0;
52*7c478bd9Sstevel@tonic-gate 	nvlist_t **nva;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
55*7c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 	if (size != 0) {
58*7c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
59*7c478bd9Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
60*7c478bd9Sstevel@tonic-gate 	}
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
63*7c478bd9Sstevel@tonic-gate 		char *class = NULL, *rname = NULL, *fname = NULL;
64*7c478bd9Sstevel@tonic-gate 		nvlist_t *fru, *rsc;
65*7c478bd9Sstevel@tonic-gate 		uint8_t pct = 0;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
68*7c478bd9Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
71*7c478bd9Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsc) == 0)
74*7c478bd9Sstevel@tonic-gate 			rname = fmdump_nvl2str(rsc);
75*7c478bd9Sstevel@tonic-gate 		else if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &rsc) == 0)
76*7c478bd9Sstevel@tonic-gate 			rname = fmdump_nvl2str(rsc);
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "  %3u%%  %s\n"
79*7c478bd9Sstevel@tonic-gate 		    "         FRU: %s\n        rsrc: %s\n\n",
80*7c478bd9Sstevel@tonic-gate 		    pct, class ? class : "-",
81*7c478bd9Sstevel@tonic-gate 		    fname ? fname : "-", rname ? rname : "-");
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 		free(fname);
84*7c478bd9Sstevel@tonic-gate 		free(rname);
85*7c478bd9Sstevel@tonic-gate 	}
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 	return (0);
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate static int
91*7c478bd9Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
94*7c478bd9Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
95*7c478bd9Sstevel@tonic-gate 	uint_t i;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
98*7c478bd9Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
101*7c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
104*7c478bd9Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
105*7c478bd9Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
106*7c478bd9Sstevel@tonic-gate 	}
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
109*7c478bd9Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
110*7c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	return (0);
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
116*7c478bd9Sstevel@tonic-gate "fault", {
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
119*7c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
120*7c478bd9Sstevel@tonic-gate }, {
121*7c478bd9Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
122*7c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
123*7c478bd9Sstevel@tonic-gate }, {
124*7c478bd9Sstevel@tonic-gate NULL,
125*7c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
126*7c478bd9Sstevel@tonic-gate } }
127*7c478bd9Sstevel@tonic-gate };
128