xref: /titanic_41/usr/src/cmd/fm/fmdump/common/fault.c (revision 55553f719b521a0bb4deab6efc944cd30c1a56aa)
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 2008 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], str[32];
37 	char *class = NULL, *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 	(void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class);
43 	if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) {
44 		(void) snprintf(str, sizeof (str), "%s %s", code, "Repaired");
45 		code = str;
46 	}
47 
48 	fmdump_printf(fp, "%-20s %-32s %s\n",
49 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
50 
51 	return (0);
52 }
53 
54 static int
55 flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
56 {
57 	uint_t i, size = 0;
58 	nvlist_t **nva;
59 
60 	(void) flt_short(lp, rp, fp);
61 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
62 
63 	if (size != 0) {
64 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
65 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
66 	}
67 
68 	for (i = 0; i < size; i++) {
69 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
70 		char *loc = NULL;
71 		nvlist_t *fru, *asru, *rsrc;
72 		uint8_t pct = 0;
73 
74 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
75 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
76 
77 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
78 			fname = fmdump_nvl2str(fru);
79 
80 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
81 			aname = fmdump_nvl2str(asru);
82 
83 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
84 			rname = fmdump_nvl2str(rsrc);
85 
86 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
87 		    == 0) {
88 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
89 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
90 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
91 		}
92 
93 
94 		fmdump_printf(fp, "  %3u%%  %s\n\n",
95 		    pct, class ? class : "-");
96 
97 		/*
98 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
99 		 * isn't defined in the event, display the ASRU FMRI instead.
100 		 */
101 		fmdump_printf(fp, "        Problem in: %s\n",
102 		    rname ? rname : aname ? aname : "-");
103 
104 		fmdump_printf(fp, "           Affects: %s\n",
105 		    aname ? aname : "-");
106 
107 		fmdump_printf(fp, "               FRU: %s\n",
108 		    fname ? fname : "-");
109 
110 		fmdump_printf(fp, "          Location: %s\n\n",
111 		    loc ? loc : "-");
112 
113 		free(fname);
114 		free(aname);
115 		free(rname);
116 	}
117 
118 	return (0);
119 }
120 
121 static int
122 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
123 {
124 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
125 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
126 	uint_t i;
127 
128 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
129 	(void) flt_short(lp, rp, fp);
130 
131 	if (rp->rec_nrefs != 0)
132 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
133 
134 	for (i = 0; i < rp->rec_nrefs; i++) {
135 		fmdump_printf(fp, "  ");
136 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
137 	}
138 
139 	fmdump_printf(fp, "\n");
140 	nvlist_print(fp, rp->rec_nvl);
141 	fmdump_printf(fp, "\n");
142 
143 	return (0);
144 }
145 
146 const fmdump_ops_t fmdump_flt_ops = {
147 "fault", {
148 {
149 "TIME                 UUID                                 SUNW-MSG-ID",
150 (fmd_log_rec_f *)flt_short
151 }, {
152 "TIME                 UUID                                 SUNW-MSG-ID",
153 (fmd_log_rec_f *)flt_verb1
154 }, {
155 NULL,
156 (fmd_log_rec_f *)flt_verb2
157 } }
158 };
159