author | Robert Johnston <Robert.Johnston@Sun.COM> |
Tue, 01 Sep 2009 13:28:49 -0700 | |
changeset 10438 | dac6771300a8 |
parent 8526 | 8159d305568c |
child 10462 | ec0e4f3134ef |
permissions | -rw-r--r-- |
1414 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
3062 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
1414 | 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 |
/* |
|
8526
8159d305568c
PSARC 2008/753 Reflecting Fan/Power Supply Diagnosis in Solaris
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7585
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
1414 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* Topology Nodes |
|
28 |
* |
|
29 |
* Topology nodes, tnode_t, are data structures containing per-FMRI |
|
30 |
* information and are linked together to form the topology tree. |
|
31 |
* Nodes are created during the enumeration process of topo_snap_hold() |
|
32 |
* and destroyed during topo_snap_rele(). For the most part, tnode_t data |
|
33 |
* is read-only and no lock protection is required. Nodes are |
|
34 |
* held in place during tree walk functions. Tree walk functions |
|
35 |
* may access node data safely without locks. The exception to this rule |
|
36 |
* is data associated with node properties (topo_prop.c). Properties |
|
37 |
* may change at anytime and are protected by a per-property locking |
|
38 |
* strategy. |
|
39 |
* |
|
4087 | 40 |
* Enumerator plugin modules may also safely access topology nodes within their |
41 |
* scope of operation: the parent node passed into the enumeration op or those |
|
42 |
* nodes created by the enumerator. Enumeration occurs only during |
|
43 |
* topo_snap_hold() where a per-topo_hdl_t lock prevents multi-threaded access |
|
44 |
* to the topology trees. |
|
1414 | 45 |
* |
4087 | 46 |
* Enumerator method operation functions may safely access and change topology |
47 |
* node property data, and contruct or destroy child nodes for the node |
|
48 |
* on which the operation applies. The method may also be called to destroy |
|
49 |
* the node for which the method operation is called. This permits |
|
50 |
* dynamic topology tree snapshots and partial enumerations for branches that |
|
51 |
* may not be needed right away. |
|
1414 | 52 |
* |
53 |
* Node Interfaces |
|
54 |
* |
|
4087 | 55 |
* Nodes are created when an enumerator calls topo_node_bind(). Prior to |
56 |
* calling topo_node_bind(), the enumerator should have reserved a range of |
|
1414 | 57 |
* node instances with topo_node_range_create(). topo_node_range_create() |
58 |
* does not allocate any node resources but creates the infrastruture |
|
59 |
* required for a fully populated topology level. This allows enumerators |
|
60 |
* reading from a <scheme>-topology.xml file to parse the file for a range |
|
61 |
* of resources before confirming the existence of a resource via a helper |
|
62 |
* plugin. Only when the resource has been confirmed to exist should |
|
63 |
* the node be bound. |
|
64 |
* |
|
4087 | 65 |
* Node range and node linkage and unlinkage is performed during enumeration and |
66 |
* method operations when it is safe to change node hash lists. Nodes and node |
|
67 |
* ranges are deallocated when all references to the node have been released: |
|
1414 | 68 |
* last walk completes and topo_snap_rele() is called. |
69 |
* |
|
70 |
* Node Hash/Ranges |
|
71 |
* |
|
72 |
* Each parent node may have one or more ranges of child nodes. Each range |
|
4087 | 73 |
* is uniquely named and serves as a hash list of like sibling nodes with |
1414 | 74 |
* different instance numbers. A parent may have more than one node hash |
75 |
* (child range). If that is the case, the hash lists are strung together to |
|
76 |
* form sibling relationships between ranges. Hash/Ranges are sparsely |
|
77 |
* populated with only nodes that have represented resources in the system. |
|
4087 | 78 |
* |
79 |
* _________________ |
|
80 |
* | | |
|
81 |
* | tnode_t | ----------------------------- |
|
82 |
* | tn_phash ---> | topo_nodehash_t | |
|
83 |
* | (children)| | th_nodearr (instances)| |
|
84 |
* ----------------- | ------------------- | |
|
85 |
* | ---| 0 | 1 | ...| N | | |
|
86 |
* | | ------------------- | ------------------- |
|
87 |
* | | th_list (siblings) ----->| topo_nodehash_t | |
|
88 |
* | | | ------------------- |
|
89 |
* ---|------------------------- |
|
90 |
* | |
|
91 |
* v |
|
92 |
* ----------- |
|
93 |
* | tnode_t | |
|
94 |
* ----------- |
|
7243 | 95 |
* |
96 |
* Facility Nodes |
|
97 |
* |
|
98 |
* Facility nodes are always leaf nodes in the topology and represent a FMRI |
|
99 |
* sensor or indicator facility for the path to which it is connected. |
|
100 |
* Facility nodes are bound to the topology with topo_node_facbind() and |
|
101 |
* unbound with topo_node_unbind(). |
|
1414 | 102 |
*/ |
103 |
||
104 |
#include <assert.h> |
|
105 |
#include <pthread.h> |
|
106 |
#include <strings.h> |
|
3062 | 107 |
#include <sys/fm/protocol.h> |
1414 | 108 |
#include <topo_alloc.h> |
3062 | 109 |
#include <topo_error.h> |
7243 | 110 |
#include <topo_list.h> |
3062 | 111 |
#include <topo_method.h> |
112 |
#include <topo_subr.h> |
|
1414 | 113 |
#include <topo_tree.h> |
3062 | 114 |
|
115 |
static topo_pgroup_info_t protocol_pgroup = { |
|
116 |
TOPO_PGROUP_PROTOCOL, |
|
117 |
TOPO_STABILITY_PRIVATE, |
|
118 |
TOPO_STABILITY_PRIVATE, |
|
119 |
1 |
|
120 |
}; |
|
121 |
||
122 |
static const topo_pgroup_info_t auth_pgroup = { |
|
123 |
FM_FMRI_AUTHORITY, |
|
124 |
TOPO_STABILITY_PRIVATE, |
|
125 |
TOPO_STABILITY_PRIVATE, |
|
126 |
1 |
|
127 |
}; |
|
1414 | 128 |
|
129 |
static void |
|
130 |
topo_node_destroy(tnode_t *node) |
|
131 |
{ |
|
132 |
int i; |
|
133 |
tnode_t *pnode = node->tn_parent; |
|
134 |
topo_nodehash_t *nhp; |
|
135 |
topo_mod_t *hmod, *mod = node->tn_enum; |
|
136 |
||
137 |
if (node == NULL) |
|
138 |
return; |
|
139 |
||
4328 | 140 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC, "destroying node %s=%d\n", |
141 |
topo_node_name(node), topo_node_instance(node)); |
|
142 |
||
1414 | 143 |
assert(node->tn_refs == 0); |
144 |
||
145 |
/* |
|
146 |
* If not a root node, remove this node from the parent's node hash |
|
147 |
*/ |
|
148 |
||
149 |
if (!(node->tn_state & TOPO_NODE_ROOT)) { |
|
150 |
topo_node_lock(pnode); |
|
151 |
||
152 |
nhp = node->tn_phash; |
|
153 |
for (i = 0; i < nhp->th_arrlen; i++) { |
|
154 |
if (node == nhp->th_nodearr[i]) { |
|
155 |
nhp->th_nodearr[i] = NULL; |
|
156 |
||
157 |
/* |
|
158 |
* Release hold on parent |
|
159 |
*/ |
|
160 |
--pnode->tn_refs; |
|
161 |
if (pnode->tn_refs == 0) |
|
162 |
topo_node_destroy(pnode); |
|
163 |
} |
|
164 |
} |
|
165 |
topo_node_unlock(pnode); |
|
166 |
} |
|
167 |
||
168 |
topo_node_unlock(node); |
|
169 |
||
170 |
/* |
|
171 |
* Allow enumerator to clean-up private data and then release |
|
172 |
* ref count |
|
173 |
*/ |
|
3062 | 174 |
if (mod->tm_info->tmi_ops->tmo_release != NULL) |
175 |
mod->tm_info->tmi_ops->tmo_release(mod, node); |
|
1414 | 176 |
|
177 |
topo_method_unregister_all(mod, node); |
|
178 |
||
179 |
/* |
|
180 |
* Destroy all node hash lists |
|
181 |
*/ |
|
182 |
while ((nhp = topo_list_next(&node->tn_children)) != NULL) { |
|
183 |
for (i = 0; i < nhp->th_arrlen; i++) { |
|
184 |
assert(nhp->th_nodearr[i] == NULL); |
|
185 |
} |
|
186 |
hmod = nhp->th_enum; |
|
187 |
topo_mod_strfree(hmod, nhp->th_name); |
|
188 |
topo_mod_free(hmod, nhp->th_nodearr, |
|
189 |
nhp->th_arrlen * sizeof (tnode_t *)); |
|
190 |
topo_list_delete(&node->tn_children, nhp); |
|
191 |
topo_mod_free(hmod, nhp, sizeof (topo_nodehash_t)); |
|
192 |
topo_mod_rele(hmod); |
|
193 |
} |
|
194 |
||
195 |
/* |
|
196 |
* Destroy all property data structures, free the node and release |
|
197 |
* the module that created it |
|
198 |
*/ |
|
199 |
topo_pgroup_destroy_all(node); |
|
200 |
topo_mod_free(mod, node, sizeof (tnode_t)); |
|
201 |
topo_mod_rele(mod); |
|
202 |
} |
|
203 |
||
204 |
void |
|
205 |
topo_node_lock(tnode_t *node) |
|
206 |
{ |
|
207 |
(void) pthread_mutex_lock(&node->tn_lock); |
|
208 |
} |
|
209 |
||
210 |
void |
|
211 |
topo_node_unlock(tnode_t *node) |
|
212 |
{ |
|
213 |
(void) pthread_mutex_unlock(&node->tn_lock); |
|
214 |
} |
|
215 |
||
216 |
void |
|
217 |
topo_node_hold(tnode_t *node) |
|
218 |
{ |
|
219 |
topo_node_lock(node); |
|
220 |
++node->tn_refs; |
|
221 |
topo_node_unlock(node); |
|
222 |
} |
|
223 |
||
224 |
void |
|
225 |
topo_node_rele(tnode_t *node) |
|
226 |
{ |
|
227 |
topo_node_lock(node); |
|
228 |
--node->tn_refs; |
|
229 |
||
230 |
/* |
|
231 |
* Ok to remove this node from the topo tree and destroy it |
|
232 |
*/ |
|
233 |
if (node->tn_refs == 0) |
|
234 |
topo_node_destroy(node); |
|
235 |
else |
|
236 |
topo_node_unlock(node); |
|
237 |
} |
|
238 |
||
239 |
char * |
|
240 |
topo_node_name(tnode_t *node) |
|
241 |
{ |
|
242 |
return (node->tn_name); |
|
243 |
} |
|
244 |
||
245 |
topo_instance_t |
|
246 |
topo_node_instance(tnode_t *node) |
|
247 |
{ |
|
248 |
return (node->tn_instance); |
|
249 |
} |
|
250 |
||
5068
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
251 |
tnode_t * |
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
252 |
topo_node_parent(tnode_t *node) |
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
253 |
{ |
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
254 |
return (node->tn_parent); |
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
255 |
} |
06d88145c7f7
6492246 x64 cpu/mem topology/diagnosis should include FRU labels
robj
parents:
4328
diff
changeset
|
256 |
|
7243 | 257 |
int |
258 |
topo_node_flags(tnode_t *node) |
|
259 |
{ |
|
260 |
return (node->tn_fflags); |
|
261 |
} |
|
262 |
||
3062 | 263 |
void |
264 |
topo_node_setspecific(tnode_t *node, void *data) |
|
265 |
{ |
|
266 |
node->tn_priv = data; |
|
267 |
} |
|
268 |
||
1414 | 269 |
void * |
3062 | 270 |
topo_node_getspecific(tnode_t *node) |
1414 | 271 |
{ |
272 |
return (node->tn_priv); |
|
273 |
} |
|
274 |
||
275 |
static int |
|
276 |
node_create_seterror(topo_mod_t *mod, tnode_t *pnode, topo_nodehash_t *nhp, |
|
277 |
int err) |
|
278 |
{ |
|
279 |
topo_node_unlock(pnode); |
|
280 |
||
3062 | 281 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR, "unable to insert child:" |
1414 | 282 |
"%s\n", topo_strerror(err)); |
283 |
||
284 |
if (nhp != NULL) { |
|
285 |
if (nhp->th_name != NULL) |
|
286 |
topo_mod_strfree(mod, nhp->th_name); |
|
287 |
if (nhp->th_nodearr != NULL) { |
|
288 |
topo_mod_free(mod, nhp->th_nodearr, |
|
289 |
nhp->th_arrlen * sizeof (tnode_t *)); |
|
290 |
} |
|
291 |
topo_mod_free(mod, nhp, sizeof (topo_nodehash_t)); |
|
292 |
} |
|
293 |
||
294 |
return (topo_mod_seterrno(mod, err)); |
|
295 |
} |
|
296 |
||
297 |
int |
|
298 |
topo_node_range_create(topo_mod_t *mod, tnode_t *pnode, const char *name, |
|
299 |
topo_instance_t min, topo_instance_t max) |
|
300 |
{ |
|
301 |
topo_nodehash_t *nhp; |
|
302 |
||
303 |
topo_node_lock(pnode); |
|
304 |
||
305 |
assert((pnode->tn_state & TOPO_NODE_BOUND) || |
|
306 |
(pnode->tn_state & TOPO_NODE_ROOT)); |
|
307 |
||
308 |
for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; |
|
309 |
nhp = topo_list_next(nhp)) { |
|
310 |
if (strcmp(nhp->th_name, name) == 0) |
|
311 |
return (node_create_seterror(mod, pnode, NULL, |
|
7243 | 312 |
EMOD_NODE_DUP)); |
1414 | 313 |
} |
314 |
||
315 |
if (min < 0 || max < min) |
|
316 |
return (node_create_seterror(mod, pnode, NULL, |
|
7243 | 317 |
EMOD_NODE_RANGE)); |
1414 | 318 |
|
319 |
if ((nhp = topo_mod_zalloc(mod, sizeof (topo_nodehash_t))) == NULL) |
|
7243 | 320 |
return (node_create_seterror(mod, pnode, nhp, EMOD_NOMEM)); |
1414 | 321 |
|
322 |
if ((nhp->th_name = topo_mod_strdup(mod, name)) == NULL) |
|
7243 | 323 |
return (node_create_seterror(mod, pnode, nhp, EMOD_NOMEM)); |
1414 | 324 |
|
325 |
nhp->th_arrlen = max - min + 1; |
|
326 |
||
327 |
if ((nhp->th_nodearr = topo_mod_zalloc(mod, |
|
328 |
nhp->th_arrlen * sizeof (tnode_t *))) == NULL) |
|
7243 | 329 |
return (node_create_seterror(mod, pnode, nhp, EMOD_NOMEM)); |
1414 | 330 |
|
331 |
nhp->th_range.tr_min = min; |
|
332 |
nhp->th_range.tr_max = max; |
|
333 |
nhp->th_enum = mod; |
|
334 |
topo_mod_hold(mod); |
|
335 |
||
336 |
/* |
|
337 |
* Add these nodes to parent child list |
|
338 |
*/ |
|
339 |
topo_list_append(&pnode->tn_children, nhp); |
|
340 |
topo_node_unlock(pnode); |
|
341 |
||
3062 | 342 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC, |
343 |
"created node range %s[%d-%d]\n", name, min, max); |
|
1414 | 344 |
|
345 |
return (0); |
|
346 |
} |
|
347 |
||
348 |
void |
|
349 |
topo_node_range_destroy(tnode_t *pnode, const char *name) |
|
350 |
{ |
|
351 |
int i; |
|
352 |
topo_nodehash_t *nhp; |
|
353 |
topo_mod_t *mod; |
|
354 |
||
355 |
topo_node_lock(pnode); |
|
356 |
for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; |
|
357 |
nhp = topo_list_next(nhp)) { |
|
358 |
if (strcmp(nhp->th_name, name) == 0) { |
|
359 |
break; |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
if (nhp == NULL) { |
|
364 |
topo_node_unlock(pnode); |
|
365 |
return; |
|
366 |
} |
|
367 |
||
4328 | 368 |
for (i = 0; i < nhp->th_arrlen; i++) |
369 |
assert(nhp->th_nodearr[i] == NULL); |
|
370 |
||
1414 | 371 |
topo_list_delete(&pnode->tn_children, nhp); |
372 |
topo_node_unlock(pnode); |
|
373 |
||
374 |
mod = nhp->th_enum; |
|
375 |
if (nhp->th_name != NULL) |
|
376 |
topo_mod_strfree(mod, nhp->th_name); |
|
377 |
if (nhp->th_nodearr != NULL) { |
|
378 |
topo_mod_free(mod, nhp->th_nodearr, |
|
379 |
nhp->th_arrlen * sizeof (tnode_t *)); |
|
380 |
} |
|
381 |
topo_mod_free(mod, nhp, sizeof (topo_nodehash_t)); |
|
382 |
topo_mod_rele(mod); |
|
383 |
||
384 |
} |
|
385 |
||
386 |
tnode_t * |
|
387 |
topo_node_lookup(tnode_t *pnode, const char *name, topo_instance_t inst) |
|
388 |
{ |
|
389 |
int h; |
|
390 |
tnode_t *node; |
|
391 |
topo_nodehash_t *nhp; |
|
392 |
||
393 |
topo_node_lock(pnode); |
|
394 |
for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; |
|
395 |
nhp = topo_list_next(nhp)) { |
|
396 |
if (strcmp(nhp->th_name, name) == 0) { |
|
397 |
||
398 |
if (inst > nhp->th_range.tr_max || |
|
399 |
inst < nhp->th_range.tr_min) { |
|
400 |
topo_node_unlock(pnode); |
|
401 |
return (NULL); |
|
402 |
} |
|
403 |
||
404 |
h = topo_node_hash(nhp, inst); |
|
405 |
node = nhp->th_nodearr[h]; |
|
406 |
topo_node_unlock(pnode); |
|
407 |
return (node); |
|
408 |
} |
|
409 |
} |
|
410 |
topo_node_unlock(pnode); |
|
411 |
||
412 |
return (NULL); |
|
413 |
} |
|
414 |
||
415 |
int |
|
416 |
topo_node_hash(topo_nodehash_t *nhp, topo_instance_t inst) |
|
417 |
{ |
|
5254
38162db71c7d
PSARC 2007/591 Generic x86 Machine Check Architecture
gavinm
parents:
5068
diff
changeset
|
418 |
return ((inst - nhp->th_range.tr_min) % nhp->th_arrlen); |
1414 | 419 |
} |
420 |
||
421 |
static tnode_t * |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
422 |
node_bind_seterror(topo_mod_t *mod, tnode_t *pnode, tnode_t *node, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
423 |
boolean_t pnode_locked, int err) |
1414 | 424 |
{ |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
425 |
if (pnode_locked) |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
426 |
topo_node_unlock(pnode); |
1414 | 427 |
|
428 |
(void) topo_mod_seterrno(mod, err); |
|
429 |
||
430 |
if (node == NULL) |
|
431 |
return (NULL); |
|
432 |
||
3062 | 433 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR, "unable to bind %s=%d: " |
1414 | 434 |
"%s\n", (node->tn_name != NULL ? node->tn_name : "unknown"), |
435 |
node->tn_instance, topo_strerror(err)); |
|
436 |
||
437 |
topo_node_lock(node); /* expected to be locked */ |
|
438 |
topo_node_destroy(node); |
|
439 |
||
440 |
return (NULL); |
|
441 |
} |
|
442 |
||
443 |
tnode_t * |
|
444 |
topo_node_bind(topo_mod_t *mod, tnode_t *pnode, const char *name, |
|
3062 | 445 |
topo_instance_t inst, nvlist_t *fmri) |
1414 | 446 |
{ |
447 |
int h, err; |
|
448 |
tnode_t *node; |
|
449 |
topo_nodehash_t *nhp; |
|
450 |
||
451 |
topo_node_lock(pnode); |
|
452 |
for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; |
|
453 |
nhp = topo_list_next(nhp)) { |
|
454 |
if (strcmp(nhp->th_name, name) == 0) { |
|
455 |
||
456 |
if (inst > nhp->th_range.tr_max || |
|
457 |
inst < nhp->th_range.tr_min) |
|
458 |
return (node_bind_seterror(mod, pnode, NULL, |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
459 |
B_TRUE, EMOD_NODE_RANGE)); |
1414 | 460 |
|
461 |
h = topo_node_hash(nhp, inst); |
|
462 |
if (nhp->th_nodearr[h] != NULL) |
|
463 |
return (node_bind_seterror(mod, pnode, NULL, |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
464 |
B_TRUE, EMOD_NODE_BOUND)); |
1414 | 465 |
else |
466 |
break; |
|
467 |
||
468 |
} |
|
469 |
} |
|
470 |
||
471 |
if (nhp == NULL) |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
472 |
return (node_bind_seterror(mod, pnode, NULL, B_TRUE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
473 |
EMOD_NODE_NOENT)); |
1414 | 474 |
|
475 |
if ((node = topo_mod_zalloc(mod, sizeof (tnode_t))) == NULL) |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
476 |
return (node_bind_seterror(mod, pnode, NULL, B_TRUE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
477 |
EMOD_NOMEM)); |
1414 | 478 |
|
479 |
(void) pthread_mutex_init(&node->tn_lock, NULL); |
|
480 |
||
481 |
node->tn_enum = mod; |
|
482 |
node->tn_hdl = mod->tm_hdl; |
|
483 |
node->tn_parent = pnode; |
|
484 |
node->tn_name = nhp->th_name; |
|
485 |
node->tn_instance = inst; |
|
486 |
node->tn_phash = nhp; |
|
487 |
node->tn_refs = 0; |
|
488 |
||
489 |
/* Ref count module that bound this node */ |
|
490 |
topo_mod_hold(mod); |
|
491 |
||
492 |
if (fmri == NULL) |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
493 |
return (node_bind_seterror(mod, pnode, node, B_TRUE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
494 |
EMOD_NVL_INVAL)); |
1414 | 495 |
|
3062 | 496 |
if (topo_pgroup_create(node, &protocol_pgroup, &err) < 0) |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
497 |
return (node_bind_seterror(mod, pnode, node, B_TRUE, err)); |
1414 | 498 |
|
499 |
if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, |
|
3062 | 500 |
TOPO_PROP_IMMUTABLE, fmri, &err) < 0) |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
501 |
return (node_bind_seterror(mod, pnode, node, B_TRUE, err)); |
1414 | 502 |
|
3062 | 503 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC, |
4328 | 504 |
"node bound %s=%d/%s=%d\n", topo_node_name(pnode), |
505 |
topo_node_instance(pnode), node->tn_name, node->tn_instance); |
|
1414 | 506 |
|
507 |
node->tn_state |= TOPO_NODE_BOUND; |
|
508 |
||
509 |
topo_node_hold(node); |
|
510 |
nhp->th_nodearr[h] = node; |
|
511 |
++pnode->tn_refs; |
|
7243 | 512 |
|
1414 | 513 |
topo_node_unlock(pnode); |
514 |
||
3062 | 515 |
if (topo_pgroup_create(node, &auth_pgroup, &err) == 0) { |
516 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
517 |
FM_FMRI_AUTH_PRODUCT, &err); |
|
518 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
519 |
FM_FMRI_AUTH_CHASSIS, &err); |
|
520 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
521 |
FM_FMRI_AUTH_SERVER, &err); |
|
1414 | 522 |
} |
523 |
||
524 |
return (node); |
|
525 |
} |
|
526 |
||
7243 | 527 |
tnode_t * |
528 |
topo_node_facbind(topo_mod_t *mod, tnode_t *pnode, const char *name, |
|
529 |
const char *type) |
|
530 |
{ |
|
531 |
int h, err; |
|
532 |
tnode_t *node; |
|
533 |
topo_nodehash_t *nhp; |
|
534 |
topo_instance_t inst = 0; |
|
535 |
nvlist_t *pfmri, *fnvl; |
|
536 |
||
537 |
/* |
|
538 |
* Create a single entry range for this facility |
|
539 |
*/ |
|
540 |
if (topo_node_range_create(mod, pnode, name, 0, 0) < 0) |
|
541 |
return (NULL); /* mod errno set */ |
|
542 |
||
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
543 |
topo_node_hold(pnode); |
7243 | 544 |
topo_node_lock(pnode); |
545 |
for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; |
|
546 |
nhp = topo_list_next(nhp)) { |
|
547 |
if (strcmp(nhp->th_name, name) == 0) { |
|
548 |
||
549 |
if (inst > nhp->th_range.tr_max || |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
550 |
inst < nhp->th_range.tr_min) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
551 |
topo_node_rele(pnode); |
7243 | 552 |
return (node_bind_seterror(mod, pnode, NULL, |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
553 |
B_TRUE, EMOD_NVL_INVAL)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
554 |
} |
7243 | 555 |
h = topo_node_hash(nhp, inst); |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
556 |
if (nhp->th_nodearr[h] != NULL) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
557 |
topo_node_rele(pnode); |
7243 | 558 |
return (node_bind_seterror(mod, pnode, NULL, |
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
559 |
B_TRUE, EMOD_NODE_BOUND)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
560 |
} else |
7243 | 561 |
break; |
562 |
||
563 |
} |
|
564 |
} |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
565 |
topo_node_unlock(pnode); |
7243 | 566 |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
567 |
if (nhp == NULL) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
568 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
569 |
return (node_bind_seterror(mod, pnode, NULL, B_FALSE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
570 |
EMOD_NODE_NOENT)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
571 |
} |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
572 |
if ((node = topo_mod_zalloc(mod, sizeof (tnode_t))) == NULL) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
573 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
574 |
return (node_bind_seterror(mod, pnode, NULL, B_FALSE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
575 |
EMOD_NOMEM)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
576 |
} |
7243 | 577 |
|
578 |
(void) pthread_mutex_init(&node->tn_lock, NULL); |
|
579 |
||
580 |
node->tn_enum = mod; |
|
581 |
node->tn_hdl = mod->tm_hdl; |
|
582 |
node->tn_parent = pnode; |
|
583 |
node->tn_name = nhp->th_name; |
|
584 |
node->tn_instance = inst; |
|
585 |
node->tn_phash = nhp; |
|
586 |
node->tn_refs = 0; |
|
587 |
node->tn_fflags = TOPO_NODE_FACILITY; |
|
588 |
||
589 |
/* Ref count module that bound this node */ |
|
590 |
topo_mod_hold(mod); |
|
591 |
||
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
592 |
if (topo_pgroup_create(node, &protocol_pgroup, &err) < 0) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
593 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
594 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, err)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
595 |
} |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
596 |
if (topo_mod_nvalloc(mod, &fnvl, NV_UNIQUE_NAME) < 0) { |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
597 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
598 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
599 |
EMOD_NOMEM)); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
600 |
} |
7243 | 601 |
if (nvlist_add_string(fnvl, FM_FMRI_FACILITY_NAME, name) != 0 || |
602 |
nvlist_add_string(fnvl, FM_FMRI_FACILITY_TYPE, type) != 0) { |
|
603 |
nvlist_free(fnvl); |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
604 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
605 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
606 |
EMOD_FMRI_NVL)); |
7243 | 607 |
} |
608 |
||
609 |
if (topo_node_resource(pnode, &pfmri, &err) < 0) { |
|
610 |
nvlist_free(fnvl); |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
611 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
612 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, err)); |
7243 | 613 |
} |
614 |
||
615 |
if (nvlist_add_nvlist(pfmri, FM_FMRI_FACILITY, fnvl) != 0) { |
|
616 |
nvlist_free(fnvl); |
|
617 |
nvlist_free(pfmri); |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
618 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
619 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
620 |
EMOD_FMRI_NVL)); |
7243 | 621 |
} |
622 |
||
623 |
nvlist_free(fnvl); |
|
624 |
||
625 |
if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, |
|
626 |
TOPO_PROP_IMMUTABLE, pfmri, &err) < 0) { |
|
627 |
nvlist_free(pfmri); |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
628 |
topo_node_rele(pnode); |
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
629 |
return (node_bind_seterror(mod, pnode, node, B_FALSE, err)); |
7243 | 630 |
} |
631 |
||
632 |
nvlist_free(pfmri); |
|
633 |
||
634 |
topo_dprintf(mod->tm_hdl, TOPO_DBG_MODSVC, |
|
635 |
"facility node bound %s=%s\n", type, node->tn_name); |
|
636 |
||
637 |
node->tn_state |= TOPO_NODE_BOUND; |
|
638 |
||
639 |
topo_node_hold(node); |
|
640 |
nhp->th_nodearr[h] = node; |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
641 |
|
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
642 |
topo_node_lock(pnode); |
7243 | 643 |
++pnode->tn_refs; |
644 |
topo_node_unlock(pnode); |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
645 |
topo_node_rele(pnode); |
7243 | 646 |
|
647 |
if (topo_pgroup_create(node, &auth_pgroup, &err) == 0) { |
|
648 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
649 |
FM_FMRI_AUTH_PRODUCT, &err); |
|
650 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
651 |
FM_FMRI_AUTH_CHASSIS, &err); |
|
652 |
(void) topo_prop_inherit(node, FM_FMRI_AUTHORITY, |
|
653 |
FM_FMRI_AUTH_SERVER, &err); |
|
654 |
} |
|
655 |
||
656 |
return (node); |
|
657 |
} |
|
658 |
||
659 |
int |
|
660 |
topo_node_facility(topo_hdl_t *thp, tnode_t *node, const char *fac_type, |
|
661 |
uint32_t fac_subtype, topo_faclist_t *faclist, int *errp) |
|
662 |
{ |
|
663 |
tnode_t *tmp; |
|
7585
6bd9ced8f8a6
6735704 deadlock in topo_node_facility()
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7345
diff
changeset
|
664 |
nvlist_t *rsrc, *fac; |
7243 | 665 |
char *tmp_factype; |
666 |
uint32_t tmp_facsubtype; |
|
667 |
boolean_t list_empty = 1; |
|
668 |
topo_faclist_t *fac_ele; |
|
669 |
||
670 |
bzero(faclist, sizeof (topo_faclist_t)); |
|
671 |
for (tmp = topo_child_first(node); tmp != NULL; |
|
672 |
tmp = topo_child_next(node, tmp)) { |
|
673 |
||
674 |
topo_node_hold(tmp); |
|
675 |
/* |
|
676 |
* If it's not a facility node, move on |
|
677 |
*/ |
|
678 |
if (topo_node_flags(tmp) != TOPO_NODE_FACILITY) { |
|
679 |
topo_node_rele(tmp); |
|
680 |
continue; |
|
681 |
} |
|
682 |
||
683 |
/* |
|
684 |
* Lookup whether the fac type is sensor or indicator and if |
|
685 |
* it's not the type we're looking for, move on |
|
686 |
*/ |
|
687 |
if (topo_node_resource(tmp, &rsrc, errp) != 0) { |
|
688 |
topo_dprintf(thp, TOPO_DBG_ERR, |
|
689 |
"Failed to get resource for node %s=%d (%s)\n", |
|
690 |
topo_node_name(node), topo_node_instance(node), |
|
691 |
topo_strerror(*errp)); |
|
692 |
topo_node_rele(tmp); |
|
693 |
return (-1); |
|
694 |
} |
|
695 |
if ((nvlist_lookup_nvlist(rsrc, "facility", &fac) != 0) || |
|
696 |
(nvlist_lookup_string(fac, FM_FMRI_FACILITY_TYPE, |
|
697 |
&tmp_factype) != 0)) { |
|
698 |
||
7345
ca4ab7af4867
6737553 topo_node_facility() leaks resource
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7243
diff
changeset
|
699 |
nvlist_free(rsrc); |
7243 | 700 |
topo_node_rele(tmp); |
701 |
return (-1); |
|
702 |
} |
|
7345
ca4ab7af4867
6737553 topo_node_facility() leaks resource
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7243
diff
changeset
|
703 |
|
7243 | 704 |
if (strcmp(fac_type, tmp_factype) != 0) { |
705 |
topo_node_rele(tmp); |
|
8526
8159d305568c
PSARC 2008/753 Reflecting Fan/Power Supply Diagnosis in Solaris
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7585
diff
changeset
|
706 |
nvlist_free(rsrc); |
7243 | 707 |
continue; |
708 |
} |
|
8526
8159d305568c
PSARC 2008/753 Reflecting Fan/Power Supply Diagnosis in Solaris
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7585
diff
changeset
|
709 |
nvlist_free(rsrc); |
7243 | 710 |
|
711 |
/* |
|
712 |
* Finally, look up the subtype, which is a property in the |
|
713 |
* facility propgroup. If it's a match return a pointer to the |
|
714 |
* node. Otherwise, move on. |
|
715 |
*/ |
|
716 |
if (topo_prop_get_uint32(tmp, TOPO_PGROUP_FACILITY, |
|
717 |
TOPO_FACILITY_TYPE, &tmp_facsubtype, errp) != 0) { |
|
718 |
topo_node_rele(tmp); |
|
719 |
return (-1); |
|
720 |
} |
|
8526
8159d305568c
PSARC 2008/753 Reflecting Fan/Power Supply Diagnosis in Solaris
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7585
diff
changeset
|
721 |
if (fac_subtype == tmp_facsubtype || |
8159d305568c
PSARC 2008/753 Reflecting Fan/Power Supply Diagnosis in Solaris
Robert Johnston <Robert.Johnston@Sun.COM>
parents:
7585
diff
changeset
|
722 |
fac_subtype == TOPO_FAC_TYPE_ANY) { |
7243 | 723 |
if ((fac_ele = topo_mod_zalloc(tmp->tn_enum, |
724 |
sizeof (topo_faclist_t))) == NULL) { |
|
725 |
*errp = ETOPO_NOMEM; |
|
7345
ca4ab7af4867
6737553 topo_node_facility() leaks resource
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7243
diff
changeset
|
726 |
topo_node_rele(tmp); |
7243 | 727 |
return (-1); |
728 |
} |
|
729 |
fac_ele->tf_node = tmp; |
|
730 |
topo_list_append(&faclist->tf_list, fac_ele); |
|
731 |
list_empty = 0; |
|
732 |
} |
|
733 |
topo_node_rele(tmp); |
|
734 |
} |
|
735 |
||
736 |
if (list_empty) { |
|
737 |
*errp = ETOPO_FAC_NOENT; |
|
738 |
return (-1); |
|
739 |
} |
|
740 |
return (0); |
|
741 |
} |
|
742 |
||
1414 | 743 |
void |
744 |
topo_node_unbind(tnode_t *node) |
|
745 |
{ |
|
746 |
if (node == NULL) |
|
747 |
return; |
|
748 |
||
749 |
topo_node_lock(node); |
|
750 |
if (!(node->tn_state & TOPO_NODE_BOUND)) { |
|
751 |
topo_node_unlock(node); |
|
752 |
return; |
|
753 |
} |
|
754 |
||
755 |
node->tn_state &= ~TOPO_NODE_BOUND; |
|
756 |
topo_node_unlock(node); |
|
757 |
||
4328 | 758 |
topo_dprintf(node->tn_hdl, TOPO_DBG_MODSVC, |
759 |
"node unbound %s=%d/%s=%d refs = %d\n", |
|
760 |
topo_node_name(node->tn_parent), |
|
761 |
topo_node_instance(node->tn_parent), node->tn_name, |
|
762 |
node->tn_instance, node->tn_refs); |
|
763 |
||
1414 | 764 |
topo_node_rele(node); |
765 |
} |
|
766 |
||
767 |
/*ARGSUSED*/ |
|
768 |
int |
|
769 |
topo_node_present(tnode_t *node) |
|
770 |
{ |
|
771 |
return (0); |
|
772 |
} |
|
773 |
||
774 |
/*ARGSUSED*/ |
|
775 |
int |
|
776 |
topo_node_contains(tnode_t *er, tnode_t *ee) |
|
777 |
{ |
|
778 |
return (0); |
|
779 |
} |
|
780 |
||
781 |
/*ARGSUSED*/ |
|
782 |
int |
|
783 |
topo_node_unusable(tnode_t *node) |
|
784 |
{ |
|
785 |
return (0); |
|
786 |
} |
|
4087 | 787 |
|
788 |
topo_walk_t * |
|
789 |
topo_node_walk_init(topo_hdl_t *thp, topo_mod_t *mod, tnode_t *node, |
|
790 |
int (*cb_f)(), void *pdata, int *errp) |
|
791 |
{ |
|
792 |
tnode_t *child; |
|
793 |
topo_walk_t *wp; |
|
794 |
||
795 |
topo_node_hold(node); |
|
796 |
||
797 |
if ((wp = topo_hdl_zalloc(thp, sizeof (topo_walk_t))) == NULL) { |
|
7243 | 798 |
*errp = ETOPO_HDL_NOMEM; |
4087 | 799 |
topo_node_rele(node); |
800 |
return (NULL); |
|
801 |
} |
|
802 |
||
803 |
/* |
|
804 |
* If this is the root of the scheme tree, start with the first |
|
805 |
* child |
|
806 |
*/ |
|
807 |
topo_node_lock(node); |
|
808 |
if (node->tn_state & TOPO_NODE_ROOT) { |
|
809 |
if ((child = topo_child_first(node)) == NULL) { |
|
810 |
/* Nothing to walk */ |
|
811 |
*errp = ETOPO_WALK_EMPTY; |
|
812 |
topo_node_unlock(node); |
|
813 |
topo_node_rele(node); |
|
5501
cca063572f37
6625091 zpool cachefile property has incorrect value help message
eschrock
parents:
5254
diff
changeset
|
814 |
topo_hdl_free(thp, wp, sizeof (topo_walk_t)); |
4087 | 815 |
return (NULL); |
816 |
} |
|
817 |
topo_node_unlock(node); |
|
818 |
topo_node_hold(child); |
|
819 |
wp->tw_node = child; |
|
820 |
} else { |
|
821 |
topo_node_unlock(node); |
|
4328 | 822 |
topo_node_hold(node); /* rele at walk end */ |
4087 | 823 |
wp->tw_node = node; |
824 |
} |
|
825 |
||
826 |
wp->tw_root = node; |
|
827 |
wp->tw_cb = cb_f; |
|
828 |
wp->tw_pdata = pdata; |
|
829 |
wp->tw_thp = thp; |
|
830 |
wp->tw_mod = mod; |
|
831 |
||
832 |
return (wp); |
|
833 |
} |