annotate usr/src/lib/fm/topo/libtopo/common/mod.c @ 12979:ab9ae749152f

PSARC/2009/617 Software Events Notification Parameters CLI PSARC/2009/618 snmp-notify: SNMP Notification Daemon for Software Events PSARC/2009/619 smtp-notify: Email Notification Daemon for Software Events PSARC/2010/225 fmd for non-global Solaris zones PSARC/2010/226 Solaris Instance UUID PSARC/2010/227 nvlist_nvflag(3NVPAIR) PSARC/2010/228 libfmevent additions PSARC/2010/257 sysevent_evc_setpropnvl and sysevent_evc_getpropnvl PSARC/2010/265 FMRI and FMA Event Stabilty, 'ireport' category 1 event class, and the 'sw' FMRI scheme PSARC/2010/278 FMA/SMF integration: instance state transitions PSARC/2010/279 Modelling panics within FMA PSARC/2010/290 logadm.conf upgrade 6392476 fmdump needs to pretty-print 6393375 userland ereport/ireport event generation interfaces 6445732 Add email notification agent for FMA and software events 6804168 RFE: Allow an efficient means to monitor SMF services status changes 6866661 scf_values_destroy(3SCF) will segfault if is passed NULL 6884709 Add snmp notification agent for FMA and software events 6884712 Add private interface to tap into libfmd_msg macro expansion capabilities 6897919 fmd to run in a non-global zone 6897937 fmd use of non-private doors is not safe 6900081 add a UUID to Solaris kernel image for use in crashdump identification 6914884 model panic events as a defect diagnosis in FMA 6944862 fmd_case_open_uuid, fmd_case_uuisresolved, fmd_nvl_create_defect 6944866 log legacy sysevents in fmd 6944867 enumerate svc scheme in topo 6944868 software-diagnosis and software-response fmd modules 6944870 model SMF maintenance state as a defect diagnosis in FMA 6944876 savecore runs in foreground for systems with zfs root and dedicated dump 6965796 Implement notification parameters for SMF state transitions and FMA events 6968287 SUN-FM-MIB.mib needs to be updated to reflect Oracle information 6972331 logadm.conf upgrade PSARC/2010/290
author Gavin Maltby <gavin.maltby@oracle.com>
date Fri, 30 Jul 2010 17:04:17 +1000
parents be69f645ce17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
1 /*
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
2 * CDDL HEADER START
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
3 *
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
5 * Common Development and Distribution License (the "License").
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
6 * You may not use this file except in compliance with the License.
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
7 *
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
10 * See the License for the specific language governing permissions
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
11 * and limitations under the License.
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
12 *
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
18 *
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
19 * CDDL HEADER END
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
20 */
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
21
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
22 /*
12979
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
24 */
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
25
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
26 #include <limits.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
27 #include <strings.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
28 #include <unistd.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
29 #include <libnvpair.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
30 #include <fm/topo_mod.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
31 #include <sys/fm/protocol.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
32
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
33 #include <fcntl.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
34 #include <sys/types.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
35 #include <sys/stat.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
36 #include <sys/objfs.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
37 #include <sys/modctl.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
38 #include <libelf.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
39 #include <gelf.h>
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
40
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
41 #include <topo_method.h>
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
42 #include <topo_subr.h>
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
43 #include <mod.h>
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
44
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
45 static int mod_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
46 topo_instance_t, void *, void *);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
47 static void mod_release(topo_mod_t *, tnode_t *);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
48 static int mod_fmri_create_meth(topo_mod_t *, tnode_t *, topo_version_t,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
49 nvlist_t *, nvlist_t **);
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
50 static int mod_fmri_nvl2str(topo_mod_t *, tnode_t *, topo_version_t,
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
51 nvlist_t *, nvlist_t **);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
52
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
53 static const topo_method_t mod_methods[] = {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
54 { TOPO_METH_FMRI, TOPO_METH_FMRI_DESC, TOPO_METH_FMRI_VERSION,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
55 TOPO_STABILITY_INTERNAL, mod_fmri_create_meth },
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
56 { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
57 TOPO_STABILITY_INTERNAL, mod_fmri_nvl2str },
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
58 { NULL }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
59 };
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
60
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
61 static const topo_modops_t mod_modops =
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
62 { mod_enum, mod_release };
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
63 static const topo_modinfo_t mod_info =
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
64 { "mod", FM_FMRI_SCHEME_MOD, MOD_VERSION, &mod_modops };
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
65
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
66 int
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
67 mod_init(topo_mod_t *mod, topo_version_t version)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
68 {
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
69 if (getenv("TOPOMODDEBUG"))
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
70 topo_mod_setdebug(mod);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
71 topo_mod_dprintf(mod, "initializing mod builtin\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
72
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
73 if (version != MOD_VERSION)
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
74 return (topo_mod_seterrno(mod, EMOD_VER_NEW));
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
75
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
76 if (topo_mod_register(mod, &mod_info, TOPO_VERSION) != 0) {
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
77 topo_mod_dprintf(mod, "failed to register mod_info: "
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
78 "%s\n", topo_mod_errmsg(mod));
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
79 return (-1); /* mod errno already set */
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
80 }
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
81
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
82 return (0);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
83 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
84
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
85 void
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
86 mod_fini(topo_mod_t *mod)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
87 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
88 topo_mod_unregister(mod);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
89 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
90
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
91 /*ARGSUSED*/
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
92 static int
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
93 mod_enum(topo_mod_t *mod, tnode_t *pnode, const char *name,
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
94 topo_instance_t min, topo_instance_t max, void *notused1, void *notused2)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
95 {
12979
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
96 /*
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
97 * Methods are registered, but there is no enumeration. Should
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
98 * enumeration be added be sure to cater for global vs non-global
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
99 * zones.
ab9ae749152f PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents: 11050
diff changeset
100 */
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
101 (void) topo_method_register(mod, pnode, mod_methods);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
102 return (0);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
103 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
104
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
105 static void
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
106 mod_release(topo_mod_t *mod, tnode_t *node)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
107 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
108 topo_method_unregister_all(mod, node);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
109 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
110
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
111 static int
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
112 mod_binary_path_get(topo_mod_t *mp, const char *objpath)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
113 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
114 Elf *elf = NULL;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
115 Elf_Scn *scn = NULL;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
116 GElf_Ehdr ehdr;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
117 GElf_Shdr shdr;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
118 int fd;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
119
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
120 if ((fd = open(objpath, O_RDONLY)) < 0) {
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
121 topo_mod_dprintf(mp, "unable to open %s\n", objpath);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
122 return (-1);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
123 }
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
124
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
125 if (elf_version(EV_CURRENT) == EV_NONE) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
126 topo_mod_dprintf(mp, "Elf version out of whack\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
127 goto mbpg_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
128 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
129 if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
130 topo_mod_dprintf(mp, "elf_begin failed\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
131 goto mbpg_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
132 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
133 if ((gelf_getehdr(elf, &ehdr)) == NULL) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
134 topo_mod_dprintf(mp, "gelf_getehdr failed\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
135 goto mbpg_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
136 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
137 scn = elf_getscn(elf, 0); /* "seek" to start of sections */
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
138 while ((scn = elf_nextscn(elf, scn)) != NULL) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
139 const char *sh_name;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
140 if (gelf_getshdr(scn, &shdr) == NULL) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
141 topo_mod_dprintf(mp, "gelf_getshdr failed\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
142 goto mbpg_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
143 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
144 if (shdr.sh_type != SHT_PROGBITS)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
145 continue;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
146 sh_name = elf_strptr(elf,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
147 ehdr.e_shstrndx, (size_t)shdr.sh_name);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
148 if (strcmp(sh_name, ".filename") != 0)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
149 continue;
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
150 if (elf_getdata(scn, NULL) == NULL) {
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
151 topo_mod_dprintf(mp, "no filename data");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
152 break;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
153 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
154 break;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
155 }
11050
be69f645ce17 6894028 Some fm libraries are not lint clean
Robert Johnston <Robert.Johnston@Sun.COM>
parents: 10462
diff changeset
156 (void) elf_end(elf);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
157 (void) close(fd);
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
158 return (0);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
159
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
160 mbpg_bail:
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
161 if (elf != NULL)
11050
be69f645ce17 6894028 Some fm libraries are not lint clean
Robert Johnston <Robert.Johnston@Sun.COM>
parents: 10462
diff changeset
162 (void) elf_end(elf);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
163 if (fd >= 0)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
164 (void) close(fd);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
165 (void) topo_mod_seterrno(mp, EMOD_METHOD_INVAL);
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
166 return (-1);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
167 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
168
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
169 static int
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
170 mod_nvl_data(topo_mod_t *mp, nvlist_t *out, const char *path)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
171 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
172 struct modinfo mi;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
173 struct stat64 s;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
174 int id, e;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
175
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
176 if (stat64(path, &s) < 0) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
177 topo_mod_dprintf(mp,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
178 "No system object file for driver %s", path);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
179 return (topo_mod_seterrno(mp, EMOD_METHOD_INVAL));
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
180 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
181
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
182 id = OBJFS_MODID(s.st_ino);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
183 mi.mi_id = mi.mi_nextid = id;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
184 mi.mi_info = MI_INFO_ONE | MI_INFO_NOBASE;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
185 if (modctl(MODINFO, id, &mi) < 0) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
186 return (topo_mod_seterrno(mp, EMOD_METHOD_INVAL));
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
187 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
188 mi.mi_name[MODMAXNAMELEN - 1] = '\0';
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
189 mi.mi_msinfo[0].msi_linkinfo[MODMAXNAMELEN - 1] = '\0';
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
190 e = nvlist_add_string(out, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MOD);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
191 e |= nvlist_add_uint8(out, FM_VERSION, FM_MOD_SCHEME_VERSION);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
192 e |= nvlist_add_int32(out, FM_FMRI_MOD_ID, id);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
193 e |= nvlist_add_string(out, FM_FMRI_MOD_NAME, mi.mi_name);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
194 e |= nvlist_add_string(out,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
195 FM_FMRI_MOD_DESC, mi.mi_msinfo[0].msi_linkinfo);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
196 if (e != 0)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
197 return (topo_mod_seterrno(mp, EMOD_FMRI_NVL));
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
198
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
199 return (0);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
200 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
201
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
202 static nvlist_t *
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
203 mod_fmri_create(topo_mod_t *mp, const char *driver)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
204 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
205 nvlist_t *out = NULL;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
206 char objpath[PATH_MAX];
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
207
3062
46d280f5351d 6396916 verification of dtd file name is wrong
cindi
parents: 1414
diff changeset
208 if (topo_mod_nvalloc(mp, &out, NV_UNIQUE_NAME) != 0) {
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
209 (void) topo_mod_seterrno(mp, EMOD_FMRI_NVL);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
210 goto mfc_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
211 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
212
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
213 (void) snprintf(objpath, PATH_MAX, "%s/%s/object", OBJFS_ROOT, driver);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
214
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
215 /*
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
216 * Validate the module object ELF header if possible
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
217 */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
218 if (mod_binary_path_get(mp, objpath) < 0)
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
219 goto mfc_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
220
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
221 if (mod_nvl_data(mp, out, objpath) < 0) {
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
222 topo_mod_dprintf(mp, "failed to get modinfo for %s", driver);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
223 goto mfc_bail;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
224 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
225
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
226 return (out);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
227
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
228 mfc_bail:
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
229 nvlist_free(out);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
230 return (NULL);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
231 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
232
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
233 /*ARGSUSED*/
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
234 static int
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
235 mod_fmri_create_meth(topo_mod_t *mp, tnode_t *node, topo_version_t version,
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
236 nvlist_t *in, nvlist_t **out)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
237 {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
238 nvlist_t *args;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
239 nvlist_t *modnvl;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
240 char *driver;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
241
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
242 if (version > TOPO_METH_FMRI_VERSION)
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
243 return (topo_mod_seterrno(mp, EMOD_VER_NEW));
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
244
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
245 if (nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NVL, &args) != 0 ||
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
246 nvlist_lookup_string(args, "DRIVER", &driver) != 0) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
247 topo_mod_dprintf(mp, "no DRIVER string in method argument\n");
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
248 return (topo_mod_seterrno(mp, EMOD_METHOD_INVAL));
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
249 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
250
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
251 modnvl = mod_fmri_create(mp, driver);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
252 if (modnvl == NULL) {
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
253 *out = NULL;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
254 topo_mod_dprintf(mp, "failed to create contained mod FMRI\n");
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
255 return (-1);
1414
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
256 }
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
257 *out = modnvl;
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
258 return (0);
b4126407ac5b PSARC 2006/020 FMA for Athlon 64 and Opteron Processors
cindi
parents:
diff changeset
259 }
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
260
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
261 #define MAXINTSTR 11
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
262
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
263 static ssize_t
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
264 fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
265 {
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
266 nvlist_t *anvl = NULL;
10462
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
267 nvpair_t *apair;
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
268 uint8_t version;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
269 ssize_t size = 0;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
270 int32_t modid;
10462
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
271 char *modname = NULL, *aname, *aval;
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
272 char numbuf[MAXINTSTR];
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
273 int err;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
274
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
275 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
276 version > FM_MOD_SCHEME_VERSION)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
277 return (-1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
278
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
279 /* Get authority, if present */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
280 err = nvlist_lookup_nvlist(nvl, FM_FMRI_AUTHORITY, &anvl);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
281 if (err != 0 && err != ENOENT)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
282 return (-1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
283
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
284 /*
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
285 * For brevity, we only include the module name and id
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
286 * present in the FMRI in our output string. The FMRI
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
287 * also has data on the package containing the module.
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
288 */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
289
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
290 /* There must be a module name */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
291 err = nvlist_lookup_string(nvl, FM_FMRI_MOD_NAME, &modname);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
292 if (err != 0 || modname == NULL)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
293 return (-1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
294
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
295 /* There must be a module id */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
296 err = nvlist_lookup_int32(nvl, FM_FMRI_MOD_ID, &modid);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
297 if (err != 0)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
298 return (-1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
299
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
300 /* mod:// */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
301 topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_MOD, NULL, "://");
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
302
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
303 /* authority, if any */
10462
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
304 if (anvl != NULL) {
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
305 for (apair = nvlist_next_nvpair(anvl, NULL);
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
306 apair != NULL; apair = nvlist_next_nvpair(anvl, apair)) {
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
307 if (nvpair_type(apair) != DATA_TYPE_STRING ||
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
308 nvpair_value_string(apair, &aval) != 0)
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
309 continue;
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
310 aname = nvpair_name(apair);
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
311 topo_fmristr_build(&size, buf, buflen, ":", NULL, NULL);
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
312 topo_fmristr_build(&size, buf, buflen, "=",
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
313 aname, aval);
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
314 }
ec0e4f3134ef PSARC/2007/650 Product Serial Number for FMRI
Cheng Sean Ye <Sean.Ye@Sun.COM>
parents: 7197
diff changeset
315 }
3323
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
316
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
317 /* module parts */
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
318 topo_fmristr_build(&size, buf, buflen, modname,
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
319 "/" FM_FMRI_MOD_NAME "=", "/");
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
320
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
321 (void) snprintf(numbuf, MAXINTSTR, "%d", modid);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
322 topo_fmristr_build(&size, buf, buflen, numbuf, FM_FMRI_MOD_ID "=",
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
323 NULL);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
324
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
325 return (size);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
326 }
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
327
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
328 /*ARGSUSED*/
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
329 static int
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
330 mod_fmri_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
331 nvlist_t *nvl, nvlist_t **out)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
332 {
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
333 ssize_t len;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
334 char *name = NULL;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
335 nvlist_t *fmristr;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
336
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
337 if (version > TOPO_METH_NVL2STR_VERSION)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
338 return (topo_mod_seterrno(mod, EMOD_VER_NEW));
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
339
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
340 if ((len = fmri_nvl2str(nvl, NULL, 0)) == 0 ||
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
341 (name = topo_mod_alloc(mod, len + 1)) == NULL ||
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
342 fmri_nvl2str(nvl, name, len + 1) == 0) {
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
343 if (name != NULL)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
344 topo_mod_free(mod, name, len + 1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
345 return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
346 }
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
347
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
348 if (topo_mod_nvalloc(mod, &fmristr, NV_UNIQUE_NAME) != 0)
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
349 return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
350 if (nvlist_add_string(fmristr, "fmri-string", name) != 0) {
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
351 topo_mod_free(mod, name, len + 1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
352 nvlist_free(fmristr);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
353 return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
354 }
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
355 topo_mod_free(mod, name, len + 1);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
356 *out = fmristr;
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
357
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
358 return (0);
3cff27a475a5 PSARC 2006/679 Fault Event Extension
cindi
parents: 3062
diff changeset
359 }