Print this page
patch tsoome-feedback
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fm/schemes/hc/scheme.c
+++ new/usr/src/cmd/fm/schemes/hc/scheme.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #include <strings.h>
26 26 #include <fm/fmd_fmri.h>
27 27 #include <fm/libtopo.h>
28 28 #include <fm/topo_mod.h>
29 29
30 30 int
31 31 fmd_fmri_init(void)
32 32 {
33 33 return (0);
34 34 }
35 35
36 36 void
37 37 fmd_fmri_fini(void)
38 38 {
39 39 }
40 40
41 41 ssize_t
42 42 fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
43 43 {
44 44 int err;
45 45 uint8_t version;
46 46 ssize_t len;
47 47 topo_hdl_t *thp;
48 48 char *str;
49 49
50 50 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
51 51 version > FM_HC_SCHEME_VERSION)
52 52 return (fmd_fmri_set_errno(EINVAL));
53 53
54 54 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
55 55 return (fmd_fmri_set_errno(EINVAL));
56 56 if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
57 57 fmd_fmri_topo_rele(thp);
58 58 return (fmd_fmri_set_errno(EINVAL));
59 59 }
60 60
61 61 if (buf != NULL)
62 62 len = snprintf(buf, buflen, "%s", str);
63 63 else
64 64 len = strlen(str);
65 65
66 66 topo_hdl_strfree(thp, str);
67 67 fmd_fmri_topo_rele(thp);
68 68
69 69 return (len);
70 70 }
71 71
72 72 int
73 73 fmd_fmri_present(nvlist_t *nvl)
74 74 {
75 75 int err, present;
76 76 topo_hdl_t *thp;
77 77 nvlist_t **hcprs;
78 78 char *nm;
79 79 uint_t hcnprs;
80 80
81 81 err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
82 82 if (err != 0)
83 83 return (fmd_fmri_set_errno(EINVAL));
84 84 err = nvlist_lookup_string(hcprs[0], FM_FMRI_HC_NAME, &nm);
85 85 if (err != 0)
86 86 return (fmd_fmri_set_errno(EINVAL));
87 87
88 88 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
89 89 return (fmd_fmri_set_errno(EINVAL));
90 90 present = topo_fmri_present(thp, nvl, &err);
91 91 fmd_fmri_topo_rele(thp);
92 92
93 93 return (present);
94 94 }
95 95
96 96 int
97 97 fmd_fmri_replaced(nvlist_t *nvl)
98 98 {
99 99 int err, replaced;
100 100 topo_hdl_t *thp;
101 101 nvlist_t **hcprs;
102 102 char *nm;
103 103 uint_t hcnprs;
104 104
105 105 err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
106 106 if (err != 0)
107 107 return (fmd_fmri_set_errno(EINVAL));
108 108 err = nvlist_lookup_string(hcprs[0], FM_FMRI_HC_NAME, &nm);
109 109 if (err != 0)
110 110 return (fmd_fmri_set_errno(EINVAL));
111 111
112 112 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
113 113 return (fmd_fmri_set_errno(EINVAL));
114 114 replaced = topo_fmri_replaced(thp, nvl, &err);
115 115 fmd_fmri_topo_rele(thp);
116 116
117 117 return (replaced);
118 118 }
119 119
120 120 int
121 121 fmd_fmri_unusable(nvlist_t *nvl)
122 122 {
123 123 int err, unusable;
124 124 topo_hdl_t *thp;
125 125 nvlist_t **hcprs;
126 126 char *nm;
127 127 uint_t hcnprs;
128 128
129 129 if (nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST,
130 130 &hcprs, &hcnprs) != 0 ||
131 131 nvlist_lookup_string(hcprs[0], FM_FMRI_HC_NAME, &nm) != 0)
132 132 return (0);
133 133
134 134 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
135 135 return (fmd_fmri_set_errno(EINVAL));
136 136 unusable = topo_fmri_unusable(thp, nvl, &err);
137 137 fmd_fmri_topo_rele(thp);
138 138
139 139 return (unusable == 1 ? 1 : 0);
140 140 }
141 141
142 142 static int
143 143 auth_compare(nvlist_t *nvl1, nvlist_t *nvl2)
144 144 {
145 145 const char *names[] = {
146 146 FM_FMRI_AUTH_PRODUCT,
147 147 FM_FMRI_AUTH_PRODUCT_SN,
148 148 FM_FMRI_AUTH_CHASSIS,
149 149 FM_FMRI_AUTH_SERVER,
150 150 FM_FMRI_AUTH_DOMAIN,
151 151 FM_FMRI_AUTH_HOST,
152 152 NULL
153 153 };
154 154 const char **namep;
155 155 nvlist_t *auth1 = NULL, *auth2 = NULL;
156 156
157 157 (void) nvlist_lookup_nvlist(nvl1, FM_FMRI_AUTHORITY, &auth1);
158 158 (void) nvlist_lookup_nvlist(nvl2, FM_FMRI_AUTHORITY, &auth2);
159 159 if (auth1 == NULL && auth2 == NULL)
160 160 return (0);
161 161 if (auth1 == NULL || auth2 == NULL)
162 162 return (1);
163 163
164 164 for (namep = names; *namep != NULL; namep++) {
165 165 char *val1 = NULL, *val2 = NULL;
166 166
167 167 (void) nvlist_lookup_string(auth1, *namep, &val1);
168 168 (void) nvlist_lookup_string(auth2, *namep, &val2);
169 169 if (val1 == NULL && val2 == NULL)
170 170 continue;
171 171 if (val1 == NULL || val2 == NULL || strcmp(val1, val2) != 0)
172 172 return (1);
173 173 }
174 174
175 175 return (0);
176 176 }
177 177
178 178 static int
179 179 hclist_contains(nvlist_t **erhcl, uint_t erhclsz, nvlist_t **eehcl,
180 180 uint_t eehclsz)
181 181 {
182 182 uint_t i;
183 183 char *erval, *eeval;
184 184
185 185 if (erhclsz > eehclsz || erhcl == NULL || eehcl == NULL)
186 186 return (0);
187 187
188 188 for (i = 0; i < erhclsz; i++) {
189 189 (void) nvlist_lookup_string(erhcl[i], FM_FMRI_HC_NAME,
190 190 &erval);
191 191 (void) nvlist_lookup_string(eehcl[i], FM_FMRI_HC_NAME,
192 192 &eeval);
193 193 if (strcmp(erval, eeval) != 0)
194 194 return (0);
195 195 (void) nvlist_lookup_string(erhcl[i], FM_FMRI_HC_ID,
196 196 &erval);
197 197 (void) nvlist_lookup_string(eehcl[i], FM_FMRI_HC_ID,
198 198 &eeval);
199 199 if (strcmp(erval, eeval) != 0)
200 200 return (0);
201 201 }
202 202
203 203 return (1);
204 204 }
205 205
206 206 static int
207 207 fru_compare(nvlist_t *r1, nvlist_t *r2)
208 208 {
209 209 topo_hdl_t *thp;
210 210 nvlist_t *f1 = NULL, *f2 = NULL;
211 211 nvlist_t **h1 = NULL, **h2 = NULL;
212 212 uint_t h1sz, h2sz;
213 213 int err, rc = 1;
214 214
215 215 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
216 216 return (fmd_fmri_set_errno(EINVAL));
217 217
218 218 (void) topo_fmri_fru(thp, r1, &f1, &err);
219 219 (void) topo_fmri_fru(thp, r2, &f2, &err);
↓ open down ↓ |
219 lines elided |
↑ open up ↑ |
220 220 if (f1 != NULL && f2 != NULL) {
221 221 (void) nvlist_lookup_nvlist_array(f1, FM_FMRI_HC_LIST, &h1,
222 222 &h1sz);
223 223 (void) nvlist_lookup_nvlist_array(f2, FM_FMRI_HC_LIST, &h2,
224 224 &h2sz);
225 225 if (h1sz == h2sz && hclist_contains(h1, h1sz, h2, h2sz) == 1)
226 226 rc = 0;
227 227 }
228 228
229 229 fmd_fmri_topo_rele(thp);
230 - if (f1 != NULL)
231 - nvlist_free(f1);
232 - if (f2 != NULL)
233 - nvlist_free(f2);
230 + nvlist_free(f1);
231 + nvlist_free(f2);
234 232 return (rc);
235 233 }
236 234
237 235 int
238 236 fmd_fmri_contains(nvlist_t *er, nvlist_t *ee)
239 237 {
240 238 nvlist_t **erhcl, **eehcl;
241 239 uint_t erhclsz, eehclsz;
242 240 nvlist_t *hcsp;
243 241 uint64_t eroff, eeoff;
244 242
245 243 if (nvlist_lookup_nvlist_array(er, FM_FMRI_HC_LIST, &erhcl,
246 244 &erhclsz) != 0 || nvlist_lookup_nvlist_array(ee,
247 245 FM_FMRI_HC_LIST, &eehcl, &eehclsz) != 0)
248 246 return (fmd_fmri_set_errno(EINVAL));
249 247
250 248 /*
251 249 * Check ee is further down the hc tree than er; er and ee have
252 250 * the same auth and are on the same fru.
253 251 */
254 252 if (hclist_contains(erhcl, erhclsz, eehcl, eehclsz) == 0 ||
255 253 auth_compare(er, ee) != 0 || fru_compare(er, ee) != 0)
256 254 return (0);
257 255
258 256 /*
259 257 * return true if er is parent of ee, or er is not a page
260 258 */
261 259 if (erhclsz < eehclsz || nvlist_lookup_nvlist(er,
262 260 FM_FMRI_HC_SPECIFIC, &hcsp) != 0 || (nvlist_lookup_uint64(hcsp,
263 261 FM_FMRI_HC_SPECIFIC_OFFSET, &eroff) != 0 &&
264 262 nvlist_lookup_uint64(hcsp, "asru-" FM_FMRI_HC_SPECIFIC_OFFSET,
265 263 &eroff) != 0))
266 264 return (1);
267 265
268 266 /*
269 267 * special case for page fmri: return true if ee is the same page
270 268 */
271 269 if (nvlist_lookup_nvlist(ee, FM_FMRI_HC_SPECIFIC, &hcsp) == 0 &&
272 270 (nvlist_lookup_uint64(hcsp, FM_FMRI_HC_SPECIFIC_OFFSET,
273 271 &eeoff) == 0 || nvlist_lookup_uint64(hcsp, "asru-"
274 272 FM_FMRI_HC_SPECIFIC_OFFSET, &eeoff) == 0) && eroff == eeoff)
275 273 return (1);
276 274
277 275 return (0);
278 276 }
279 277
280 278 int
281 279 fmd_fmri_service_state(nvlist_t *nvl)
282 280 {
283 281 uint8_t version;
284 282 int err, service_state;
285 283 topo_hdl_t *thp;
286 284
287 285 if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
288 286 version > FM_DEV_SCHEME_VERSION)
289 287 return (fmd_fmri_set_errno(EINVAL));
290 288
291 289 if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
292 290 return (fmd_fmri_set_errno(EINVAL));
293 291 err = 0;
294 292 service_state = topo_fmri_service_state(thp, nvl, &err);
295 293 fmd_fmri_topo_rele(thp);
296 294
297 295 if (err != 0)
298 296 return (FMD_SERVICE_STATE_UNKNOWN);
299 297 else
300 298 return (service_state);
301 299 }
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX