8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fm / schemes / svc / scheme.c
blob23ab16b6e3e62a082a4d687688b6b49b6209f38d
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <fm/fmd_fmri.h>
28 #include <fm/libtopo.h>
29 #include <fm/topo_mod.h>
30 #include <string.h>
31 #include <sys/fm/protocol.h>
33 int
34 fmd_fmri_init(void)
36 return (0);
39 void
40 fmd_fmri_fini(void)
44 ssize_t
45 fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
47 int err;
48 ssize_t len;
49 topo_hdl_t *thp;
50 char *str;
52 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
53 return (fmd_fmri_set_errno(EINVAL));
55 if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
56 fmd_fmri_topo_rele(thp);
57 return (fmd_fmri_set_errno(EINVAL));
60 if (buf != NULL)
61 len = snprintf(buf, buflen, "%s", str);
62 else
63 len = strlen(str);
65 topo_hdl_strfree(thp, str);
66 fmd_fmri_topo_rele(thp);
68 return (len);
71 /*ARGSUSED*/
72 int
73 fmd_fmri_present(nvlist_t *nvl)
75 uint8_t version;
76 int err, present;
77 topo_hdl_t *thp;
79 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
80 version > FM_SVC_SCHEME_VERSION)
81 return (fmd_fmri_set_errno(EINVAL));
83 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
84 return (fmd_fmri_set_errno(EINVAL));
85 present = topo_fmri_present(thp, nvl, &err);
86 fmd_fmri_topo_rele(thp);
88 return (present);
91 int
92 fmd_fmri_replaced(nvlist_t *nvl)
94 uint8_t version;
95 int err, replaced;
96 topo_hdl_t *thp;
98 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
99 version > FM_SVC_SCHEME_VERSION)
100 return (fmd_fmri_set_errno(EINVAL));
102 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
103 return (fmd_fmri_set_errno(EINVAL));
104 replaced = topo_fmri_replaced(thp, nvl, &err);
105 fmd_fmri_topo_rele(thp);
107 return (replaced);
111 fmd_fmri_service_state(nvlist_t *nvl)
113 uint8_t version;
114 int err, service_state;
115 topo_hdl_t *thp;
117 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
118 version > FM_DEV_SCHEME_VERSION)
119 return (fmd_fmri_set_errno(EINVAL));
121 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
122 return (fmd_fmri_set_errno(EINVAL));
123 err = 0;
124 service_state = topo_fmri_service_state(thp, nvl, &err);
125 fmd_fmri_topo_rele(thp);
127 if (err != 0)
128 return (FMD_SERVICE_STATE_UNKNOWN);
129 else
130 return (service_state);
133 /*ARGSUSED*/
135 fmd_fmri_unusable(nvlist_t *nvl)
137 uint8_t version;
138 int err, unusable;
139 topo_hdl_t *thp;
141 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
142 version > FM_SVC_SCHEME_VERSION)
143 return (fmd_fmri_set_errno(EINVAL));
145 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
146 return (fmd_fmri_set_errno(EINVAL));
147 unusable = topo_fmri_unusable(thp, nvl, &err);
148 fmd_fmri_topo_rele(thp);
150 return (unusable == 1 ? 1 : 0);