xref: /titanic_50/usr/src/cmd/fm/schemes/svc/scheme.c (revision 95efa359b507db290a2484b8f615822b1e06096f)
1*95efa359SEric Schrock /*
2*95efa359SEric Schrock  * CDDL HEADER START
3*95efa359SEric Schrock  *
4*95efa359SEric Schrock  * The contents of this file are subject to the terms of the
5*95efa359SEric Schrock  * Common Development and Distribution License (the "License").
6*95efa359SEric Schrock  * You may not use this file except in compliance with the License.
7*95efa359SEric Schrock  *
8*95efa359SEric Schrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*95efa359SEric Schrock  * or http://www.opensolaris.org/os/licensing.
10*95efa359SEric Schrock  * See the License for the specific language governing permissions
11*95efa359SEric Schrock  * and limitations under the License.
12*95efa359SEric Schrock  *
13*95efa359SEric Schrock  * When distributing Covered Code, include this CDDL HEADER in each
14*95efa359SEric Schrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*95efa359SEric Schrock  * If applicable, add the following below this CDDL HEADER, with the
16*95efa359SEric Schrock  * fields enclosed by brackets "[]" replaced with your own identifying
17*95efa359SEric Schrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18*95efa359SEric Schrock  *
19*95efa359SEric Schrock  * CDDL HEADER END
20*95efa359SEric Schrock  */
21*95efa359SEric Schrock 
22*95efa359SEric Schrock /*
23*95efa359SEric Schrock  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*95efa359SEric Schrock  * Use is subject to license terms.
25*95efa359SEric Schrock  */
26*95efa359SEric Schrock 
27*95efa359SEric Schrock #include <fm/fmd_fmri.h>
28*95efa359SEric Schrock #include <fm/libtopo.h>
29*95efa359SEric Schrock #include <fm/topo_mod.h>
30*95efa359SEric Schrock #include <string.h>
31*95efa359SEric Schrock #include <sys/fm/protocol.h>
32*95efa359SEric Schrock 
33*95efa359SEric Schrock int
fmd_fmri_init(void)34*95efa359SEric Schrock fmd_fmri_init(void)
35*95efa359SEric Schrock {
36*95efa359SEric Schrock 	return (0);
37*95efa359SEric Schrock }
38*95efa359SEric Schrock 
39*95efa359SEric Schrock void
fmd_fmri_fini(void)40*95efa359SEric Schrock fmd_fmri_fini(void)
41*95efa359SEric Schrock {
42*95efa359SEric Schrock }
43*95efa359SEric Schrock 
44*95efa359SEric Schrock ssize_t
fmd_fmri_nvl2str(nvlist_t * nvl,char * buf,size_t buflen)45*95efa359SEric Schrock fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
46*95efa359SEric Schrock {
47*95efa359SEric Schrock 	int err;
48*95efa359SEric Schrock 	ssize_t len;
49*95efa359SEric Schrock 	topo_hdl_t *thp;
50*95efa359SEric Schrock 	char *str;
51*95efa359SEric Schrock 
52*95efa359SEric Schrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
53*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
54*95efa359SEric Schrock 
55*95efa359SEric Schrock 	if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
56*95efa359SEric Schrock 		fmd_fmri_topo_rele(thp);
57*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
58*95efa359SEric Schrock 	}
59*95efa359SEric Schrock 
60*95efa359SEric Schrock 	if (buf != NULL)
61*95efa359SEric Schrock 		len = snprintf(buf, buflen, "%s", str);
62*95efa359SEric Schrock 	else
63*95efa359SEric Schrock 		len = strlen(str);
64*95efa359SEric Schrock 
65*95efa359SEric Schrock 	topo_hdl_strfree(thp, str);
66*95efa359SEric Schrock 	fmd_fmri_topo_rele(thp);
67*95efa359SEric Schrock 
68*95efa359SEric Schrock 	return (len);
69*95efa359SEric Schrock }
70*95efa359SEric Schrock 
71*95efa359SEric Schrock /*ARGSUSED*/
72*95efa359SEric Schrock int
fmd_fmri_present(nvlist_t * nvl)73*95efa359SEric Schrock fmd_fmri_present(nvlist_t *nvl)
74*95efa359SEric Schrock {
75*95efa359SEric Schrock 	uint8_t version;
76*95efa359SEric Schrock 	int err, present;
77*95efa359SEric Schrock 	topo_hdl_t *thp;
78*95efa359SEric Schrock 
79*95efa359SEric Schrock 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
80*95efa359SEric Schrock 	    version > FM_SVC_SCHEME_VERSION)
81*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
82*95efa359SEric Schrock 
83*95efa359SEric Schrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
84*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
85*95efa359SEric Schrock 	present = topo_fmri_present(thp, nvl, &err);
86*95efa359SEric Schrock 	fmd_fmri_topo_rele(thp);
87*95efa359SEric Schrock 
88*95efa359SEric Schrock 	return (present);
89*95efa359SEric Schrock }
90*95efa359SEric Schrock 
91*95efa359SEric Schrock int
fmd_fmri_replaced(nvlist_t * nvl)92*95efa359SEric Schrock fmd_fmri_replaced(nvlist_t *nvl)
93*95efa359SEric Schrock {
94*95efa359SEric Schrock 	uint8_t version;
95*95efa359SEric Schrock 	int err, replaced;
96*95efa359SEric Schrock 	topo_hdl_t *thp;
97*95efa359SEric Schrock 
98*95efa359SEric Schrock 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
99*95efa359SEric Schrock 	    version > FM_SVC_SCHEME_VERSION)
100*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
101*95efa359SEric Schrock 
102*95efa359SEric Schrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
103*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
104*95efa359SEric Schrock 	replaced = topo_fmri_replaced(thp, nvl, &err);
105*95efa359SEric Schrock 	fmd_fmri_topo_rele(thp);
106*95efa359SEric Schrock 
107*95efa359SEric Schrock 	return (replaced);
108*95efa359SEric Schrock }
109*95efa359SEric Schrock 
110*95efa359SEric Schrock int
fmd_fmri_service_state(nvlist_t * nvl)111*95efa359SEric Schrock fmd_fmri_service_state(nvlist_t *nvl)
112*95efa359SEric Schrock {
113*95efa359SEric Schrock 	uint8_t version;
114*95efa359SEric Schrock 	int err, service_state;
115*95efa359SEric Schrock 	topo_hdl_t *thp;
116*95efa359SEric Schrock 
117*95efa359SEric Schrock 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
118*95efa359SEric Schrock 	    version > FM_DEV_SCHEME_VERSION)
119*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
120*95efa359SEric Schrock 
121*95efa359SEric Schrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
122*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
123*95efa359SEric Schrock 	err = 0;
124*95efa359SEric Schrock 	service_state = topo_fmri_service_state(thp, nvl, &err);
125*95efa359SEric Schrock 	fmd_fmri_topo_rele(thp);
126*95efa359SEric Schrock 
127*95efa359SEric Schrock 	if (err != 0)
128*95efa359SEric Schrock 		return (FMD_SERVICE_STATE_UNKNOWN);
129*95efa359SEric Schrock 	else
130*95efa359SEric Schrock 		return (service_state);
131*95efa359SEric Schrock }
132*95efa359SEric Schrock 
133*95efa359SEric Schrock /*ARGSUSED*/
134*95efa359SEric Schrock int
fmd_fmri_unusable(nvlist_t * nvl)135*95efa359SEric Schrock fmd_fmri_unusable(nvlist_t *nvl)
136*95efa359SEric Schrock {
137*95efa359SEric Schrock 	uint8_t version;
138*95efa359SEric Schrock 	int err, unusable;
139*95efa359SEric Schrock 	topo_hdl_t *thp;
140*95efa359SEric Schrock 
141*95efa359SEric Schrock 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
142*95efa359SEric Schrock 	    version > FM_SVC_SCHEME_VERSION)
143*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
144*95efa359SEric Schrock 
145*95efa359SEric Schrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
146*95efa359SEric Schrock 		return (fmd_fmri_set_errno(EINVAL));
147*95efa359SEric Schrock 	unusable = topo_fmri_unusable(thp, nvl, &err);
148*95efa359SEric Schrock 	fmd_fmri_topo_rele(thp);
149*95efa359SEric Schrock 
150*95efa359SEric Schrock 	return (unusable == 1 ? 1 : 0);
151*95efa359SEric Schrock }
152