xref: /titanic_52/usr/src/cmd/fm/schemes/hc/scheme.c (revision bd0f52d78d701efcad2c460df61b45677d041c35)
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 <strings.h>
29 #include <fm/fmd_fmri.h>
30 #include <fm/libtopo.h>
31 #include <fm/topo_mod.h>
32 
33 int
34 fmd_fmri_init(void)
35 {
36 	return (0);
37 }
38 
39 void
40 fmd_fmri_fini(void)
41 {
42 }
43 
44 ssize_t
45 fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
46 {
47 	int err;
48 	uint8_t version;
49 	ssize_t len;
50 	topo_hdl_t *thp;
51 	char *str;
52 
53 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
54 	    version > FM_HC_SCHEME_VERSION)
55 		return (fmd_fmri_set_errno(EINVAL));
56 
57 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
58 		return (fmd_fmri_set_errno(EINVAL));
59 	if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
60 		fmd_fmri_topo_rele(thp);
61 		return (fmd_fmri_set_errno(EINVAL));
62 	}
63 
64 	if (buf != NULL)
65 		len = snprintf(buf, buflen, "%s", str);
66 	else
67 		len = strlen(str);
68 
69 	topo_hdl_strfree(thp, str);
70 	fmd_fmri_topo_rele(thp);
71 
72 	return (len);
73 }
74 
75 int
76 fmd_fmri_present(nvlist_t *nvl)
77 {
78 	int err, present;
79 	topo_hdl_t *thp;
80 	nvlist_t **hcprs;
81 	char *nm;
82 	uint_t hcnprs;
83 
84 	err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
85 	err |= nvlist_lookup_string(hcprs[0], FM_FMRI_HC_NAME, &nm);
86 	if (err != 0)
87 		return (0);
88 
89 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
90 		return (fmd_fmri_set_errno(EINVAL));
91 	present = topo_fmri_present(thp, nvl, &err);
92 	fmd_fmri_topo_rele(thp);
93 
94 	if (err != 0)
95 		return (present);
96 	else
97 		return (1);
98 }
99 
100 /*
101  * fmd_fmri_unusable() is called by fmadm to determine if a faulty ASRU
102  * is usable.  In general we don't expect to get ASRUs in this scheme,
103  * so it's unlikely this routine will get called.  In case it does,
104  * though, we just return false by default, as we have no real way to
105  * find the component or determine the component's usability.
106  */
107 /*ARGSUSED*/
108 int
109 fmd_fmri_unusable(nvlist_t *nvl)
110 {
111 	return (0);
112 }
113