xref: /titanic_51/usr/src/cmd/fm/fmdump/common/fault.c (revision c498d9365aa68b789215f4f356a9935f70b0fb3b)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <fmdump.h>
29 #include <stdio.h>
30 #include <strings.h>
31 
32 /*ARGSUSED*/
33 static int
34 flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
35 {
36 	char buf[32], *uuid = "-", *code = "-";
37 
38 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
39 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
40 
41 	fmdump_printf(fp, "%-20s %-32s %s\n",
42 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
43 
44 	return (0);
45 }
46 
47 static int
48 flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
49 {
50 	uint_t i, size = 0;
51 	nvlist_t **nva;
52 
53 	(void) flt_short(lp, rp, fp);
54 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
55 
56 	if (size != 0) {
57 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
58 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
59 	}
60 
61 	for (i = 0; i < size; i++) {
62 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
63 		char *loc = NULL;
64 		nvlist_t *fru, *asru, *rsrc;
65 		uint8_t pct = 0;
66 
67 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
68 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
69 
70 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
71 			fname = fmdump_nvl2str(fru);
72 
73 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
74 			aname = fmdump_nvl2str(asru);
75 
76 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
77 			rname = fmdump_nvl2str(rsrc);
78 
79 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
80 		    == 0) {
81 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
82 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
83 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
84 		}
85 
86 
87 		fmdump_printf(fp, "  %3u%%  %s\n\n",
88 		    pct, class ? class : "-");
89 
90 		/*
91 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
92 		 * isn't defined in the event, display the ASRU FMRI instead.
93 		 */
94 		fmdump_printf(fp, "        Problem in: %s\n",
95 		    rname ? rname : aname ? aname : "-");
96 
97 		fmdump_printf(fp, "           Affects: %s\n",
98 		    aname ? aname : "-");
99 
100 		fmdump_printf(fp, "               FRU: %s\n",
101 		    fname ? fname : "-");
102 
103 		fmdump_printf(fp, "          Location: %s\n\n",
104 		    loc ? loc : "-");
105 
106 		free(fname);
107 		free(aname);
108 		free(rname);
109 	}
110 
111 	return (0);
112 }
113 
114 static int
115 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
116 {
117 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
118 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
119 	uint_t i;
120 
121 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
122 	(void) flt_short(lp, rp, fp);
123 
124 	if (rp->rec_nrefs != 0)
125 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
126 
127 	for (i = 0; i < rp->rec_nrefs; i++) {
128 		fmdump_printf(fp, "  ");
129 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
130 	}
131 
132 	fmdump_printf(fp, "\n");
133 	nvlist_print(fp, rp->rec_nvl);
134 	fmdump_printf(fp, "\n");
135 
136 	return (0);
137 }
138 
139 const fmdump_ops_t fmdump_flt_ops = {
140 "fault", {
141 {
142 "TIME                 UUID                                 SUNW-MSG-ID",
143 (fmd_log_rec_f *)flt_short
144 }, {
145 "TIME                 UUID                                 SUNW-MSG-ID",
146 (fmd_log_rec_f *)flt_verb1
147 }, {
148 NULL,
149 (fmd_log_rec_f *)flt_verb2
150 } }
151 };
152