xref: /titanic_44/usr/src/cmd/fm/fmdump/common/fault.c (revision 39c23413b8df94a95f67b34cfd4a4dfc3fd0b48d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <fmdump.h>
30 #include <stdio.h>
31 #include <strings.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 		char *loc = NULL;
66 		nvlist_t *fru, *asru, *rsrc;
67 		uint8_t pct = 0;
68 
69 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
70 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
71 
72 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
73 			fname = fmdump_nvl2str(fru);
74 
75 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
76 			aname = fmdump_nvl2str(asru);
77 
78 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
79 			rname = fmdump_nvl2str(rsrc);
80 
81 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
82 		    == 0) {
83 			if (strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
84 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
85 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
86 		}
87 
88 
89 		fmdump_printf(fp, "  %3u%%  %s\n\n",
90 		    pct, class ? class : "-");
91 
92 		/*
93 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
94 		 * isn't defined in the event, display the ASRU FMRI instead.
95 		 */
96 		fmdump_printf(fp, "        Problem in: %s\n",
97 		    rname ? rname : aname ? aname : "-");
98 
99 		fmdump_printf(fp, "           Affects: %s\n",
100 		    aname ? aname : "-");
101 
102 		fmdump_printf(fp, "               FRU: %s\n",
103 		    fname ? fname : "-");
104 
105 		fmdump_printf(fp, "          Location: %s\n\n",
106 		    loc ? loc : "-");
107 
108 		free(fname);
109 		free(aname);
110 		free(rname);
111 	}
112 
113 	return (0);
114 }
115 
116 static int
117 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
118 {
119 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
120 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
121 	uint_t i;
122 
123 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
124 	(void) flt_short(lp, rp, fp);
125 
126 	if (rp->rec_nrefs != 0)
127 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
128 
129 	for (i = 0; i < rp->rec_nrefs; i++) {
130 		fmdump_printf(fp, "  ");
131 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
132 	}
133 
134 	fmdump_printf(fp, "\n");
135 	nvlist_print(fp, rp->rec_nvl);
136 	fmdump_printf(fp, "\n");
137 
138 	return (0);
139 }
140 
141 const fmdump_ops_t fmdump_flt_ops = {
142 "fault", {
143 {
144 "TIME                 UUID                                 SUNW-MSG-ID",
145 (fmd_log_rec_f *)flt_short
146 }, {
147 "TIME                 UUID                                 SUNW-MSG-ID",
148 (fmd_log_rec_f *)flt_verb1
149 }, {
150 NULL,
151 (fmd_log_rec_f *)flt_verb2
152 } }
153 };
154