xref: /illumos-gate/usr/src/cmd/fm/schemes/hc/scheme.c (revision 3ee87bca47e74aa2719352485b80973ca6e079b7)
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 <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 (fmd_fmri_set_errno(EINVAL));
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 	return (present);
95 }
96 
97 int
98 fmd_fmri_replaced(nvlist_t *nvl)
99 {
100 	int err, replaced;
101 	topo_hdl_t *thp;
102 	nvlist_t **hcprs;
103 	char *nm;
104 	uint_t hcnprs;
105 
106 	err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
107 	err |= nvlist_lookup_string(hcprs[0], FM_FMRI_HC_NAME, &nm);
108 	if (err != 0)
109 		return (fmd_fmri_set_errno(EINVAL));
110 
111 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
112 		return (fmd_fmri_set_errno(EINVAL));
113 	replaced = topo_fmri_replaced(thp, nvl, &err);
114 	fmd_fmri_topo_rele(thp);
115 
116 	return (replaced);
117 }
118 
119 /*
120  * fmd_fmri_unusable() is called by fmadm to determine if a faulty ASRU
121  * is usable.  In general we don't expect to get ASRUs in this scheme,
122  * so it's unlikely this routine will get called.  In case it does,
123  * though, we just return false by default, as we have no real way to
124  * find the component or determine the component's usability.
125  */
126 /*ARGSUSED*/
127 int
128 fmd_fmri_unusable(nvlist_t *nvl)
129 {
130 	return (0);
131 }
132