xref: /titanic_52/usr/src/cmd/fm/fmdump/common/fault.c (revision 0bb073995ac5a95bd35f2dd790df1ea3d8c2d507)
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 	if (class != NULL && strcmp(class, FM_LIST_RESOLVED_CLASS) == 0) {
48 		(void) snprintf(str, sizeof (str), "%s %s", code, "Resolved");
49 		code = str;
50 	}
51 
52 	if (class != NULL && strcmp(class, FM_LIST_UPDATED_CLASS) == 0) {
53 		(void) snprintf(str, sizeof (str), "%s %s", code, "Updated");
54 		code = str;
55 	}
56 
57 	fmdump_printf(fp, "%-20s %-32s %s\n",
58 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
59 
60 	return (0);
61 }
62 
63 static int
64 flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
65 {
66 	uint_t i, size = 0;
67 	nvlist_t **nva;
68 	uint8_t *ba;
69 
70 	(void) flt_short(lp, rp, fp);
71 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
72 
73 	if (size != 0) {
74 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
75 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
76 		(void) nvlist_lookup_uint8_array(rp->rec_nvl,
77 		    FM_SUSPECT_FAULT_STATUS, &ba, &size);
78 	}
79 
80 	for (i = 0; i < size; i++) {
81 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
82 		char *loc = NULL;
83 		nvlist_t *fru, *asru, *rsrc;
84 		uint8_t pct = 0;
85 
86 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
87 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
88 
89 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
90 			fname = fmdump_nvl2str(fru);
91 
92 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
93 			aname = fmdump_nvl2str(asru);
94 
95 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
96 			rname = fmdump_nvl2str(rsrc);
97 
98 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
99 		    == 0) {
100 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
101 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
102 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
103 		}
104 
105 
106 		fmdump_printf(fp, "  %3u%%  %s",
107 		    pct, class ? class : "-");
108 
109 		if (ba[i] & FM_SUSPECT_FAULTY)
110 			fmdump_printf(fp, "\n\n");
111 		else if (ba[i] & FM_SUSPECT_NOT_PRESENT)
112 			fmdump_printf(fp, "\tRemoved\n\n");
113 		else if (ba[i] & FM_SUSPECT_REPLACED)
114 			fmdump_printf(fp, "\tReplaced\n\n");
115 		else if (ba[i] & FM_SUSPECT_REPAIRED)
116 			fmdump_printf(fp, "\tRepair Attempted\n\n");
117 		else if (ba[i] & FM_SUSPECT_ACQUITTED)
118 			fmdump_printf(fp, "\tAcquitted\n\n");
119 		else
120 			fmdump_printf(fp, "\n\n");
121 
122 		fmdump_printf(fp, "        Problem in: %s\n",
123 		    rname ? rname : "-");
124 
125 		fmdump_printf(fp, "           Affects: %s\n",
126 		    aname ? aname : "-");
127 
128 		fmdump_printf(fp, "               FRU: %s\n",
129 		    fname ? fname : "-");
130 
131 		fmdump_printf(fp, "          Location: %s\n\n",
132 		    loc ? loc : "-");
133 
134 		free(fname);
135 		free(aname);
136 		free(rname);
137 	}
138 
139 	return (0);
140 }
141 
142 static int
143 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
144 {
145 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
146 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
147 	uint_t i;
148 
149 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
150 	(void) flt_short(lp, rp, fp);
151 
152 	if (rp->rec_nrefs != 0)
153 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
154 
155 	for (i = 0; i < rp->rec_nrefs; i++) {
156 		fmdump_printf(fp, "  ");
157 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
158 	}
159 
160 	fmdump_printf(fp, "\n");
161 	nvlist_print(fp, rp->rec_nvl);
162 	fmdump_printf(fp, "\n");
163 
164 	return (0);
165 }
166 
167 const fmdump_ops_t fmdump_flt_ops = {
168 "fault", {
169 {
170 "TIME                 UUID                                 SUNW-MSG-ID",
171 (fmd_log_rec_f *)flt_short
172 }, {
173 "TIME                 UUID                                 SUNW-MSG-ID",
174 (fmd_log_rec_f *)flt_verb1
175 }, {
176 NULL,
177 (fmd_log_rec_f *)flt_verb2
178 } }
179 };
180