xref: /titanic_41/usr/src/cmd/fm/fmdump/common/fault.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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  * Copyright 2004 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 
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, "%-15s.%4.4llu %-32s %s\n",
42 	    fmdump_date(buf, sizeof (buf), rp),
43 	    rp->rec_nsec / (NANOSEC / 10000), uuid, code);
44 
45 	return (0);
46 }
47 
48 static int
49 flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
50 {
51 	uint_t i, size = 0;
52 	nvlist_t **nva;
53 
54 	(void) flt_short(lp, rp, fp);
55 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
56 
57 	if (size != 0) {
58 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
59 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
60 	}
61 
62 	for (i = 0; i < size; i++) {
63 		char *class = NULL, *rname = NULL, *fname = NULL;
64 		nvlist_t *fru, *rsc;
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_RESOURCE, &rsc) == 0)
74 			rname = fmdump_nvl2str(rsc);
75 		else if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &rsc) == 0)
76 			rname = fmdump_nvl2str(rsc);
77 
78 		fmdump_printf(fp, "  %3u%%  %s\n"
79 		    "         FRU: %s\n        rsrc: %s\n\n",
80 		    pct, class ? class : "-",
81 		    fname ? fname : "-", rname ? rname : "-");
82 
83 		free(fname);
84 		free(rname);
85 	}
86 
87 	return (0);
88 }
89 
90 static int
91 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
92 {
93 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
94 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
95 	uint_t i;
96 
97 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
98 	(void) flt_short(lp, rp, fp);
99 
100 	if (rp->rec_nrefs != 0)
101 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
102 
103 	for (i = 0; i < rp->rec_nrefs; i++) {
104 		fmdump_printf(fp, "  ");
105 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
106 	}
107 
108 	fmdump_printf(fp, "\n");
109 	nvlist_print(fp, rp->rec_nvl);
110 	fmdump_printf(fp, "\n");
111 
112 	return (0);
113 }
114 
115 const fmdump_ops_t fmdump_flt_ops = {
116 "fault", {
117 {
118 "TIME                 UUID                                 SUNW-MSG-ID",
119 (fmd_log_rec_f *)flt_short
120 }, {
121 "TIME                 UUID                                 SUNW-MSG-ID",
122 (fmd_log_rec_f *)flt_verb1
123 }, {
124 NULL,
125 (fmd_log_rec_f *)flt_verb2
126 } }
127 };
128