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