topo_tree.c revision c93c462eec9d46f84d567abf52eb29a27c2e134b
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
12054bfce7d1b03f143c8287d83cc15b25ff43cfnd * Common Development and Distribution License (the "License").
12054bfce7d1b03f143c8287d83cc15b25ff43cfnd * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
91de656b0815c0aeab4e6fc638e9bb4577aa9513Neil Perrin * Use is subject to license terms.
91de656b0815c0aeab4e6fc638e9bb4577aa9513Neil Perrin * Topology Trees
12054bfce7d1b03f143c8287d83cc15b25ff43cfnd * Toplogy trees are instantiated for each builtin (FMRI) scheme specified
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * in topo_builtin.c. Each ttree_t data structure contains the
12054bfce7d1b03f143c8287d83cc15b25ff43cfnd * skeleton of the topology tree (scheme, root node, and file information).
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * The root node of a topology does not represent any FMRI but rather serves
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * as the entry point for topology access interfaces. The file information
fa9e4066f08beec538e775443c5be79dd423fcabahrens * provides a handle to access static .xml files that seed scheme-specifc
91de656b0815c0aeab4e6fc638e9bb4577aa9513Neil Perrin * topologies
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Topology trees will remain unpopulated until topo_snap_hold() is called.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * At that time, a ttree_t structure is allocated and added to the list
fa9e4066f08beec538e775443c5be79dd423fcabahrens * trees maintained in topo_hdl_t. Builtin scheme-specific enumerators are
d5285cae913f4e01ffa0e6693a6d8ef1fbea30baGeorge Wilson * called upon to create nodes that represent FMRIs for resources present in the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * system. If a <scheme>-topology.xml file exists in a standard file
fa9e4066f08beec538e775443c5be79dd423fcabahrens * location, the file is used to seed the topology while the rest is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dynamically created by the builtin or helper enumerator modules.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For example, the 'hc' tree is enumerated by the hc enumerator (hc.c)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * after the hc-topology.xml is read from /usr/platform/`uname -i`/lib/fm/topo,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * /usr/platform/`uname -r`/lib/fm/topo, or /usr/lib/fm/topo. Each node
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is created with a properly formatted hc FMRI resource.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Toplogy trees are released and deallocated when topo_snap_hold is called.
c9431fa1e59a88c2f0abf611f25b97af964449e5ahl * Upon return from topo_snap_rele(), all node resources are deallocated
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and all that remains is the ttree_t structure containing the root node.
fa9e4066f08beec538e775443c5be79dd423fcabahrensset_create_error(topo_hdl_t *thp, ttree_t *tp, int err)
fa9e4066f08beec538e775443c5be79dd423fcabahrenstopo_tree_create(topo_hdl_t *thp, topo_mod_t *mod, const char *scheme)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((tp = topo_mod_zalloc(mod, sizeof (ttree_t))) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((tp->tt_scheme = topo_mod_strdup(mod, scheme)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize a private walker for internal use
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((tp->tt_walk = topo_mod_zalloc(mod, sizeof (topo_walk_t))) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create the root of this tree: LINKED but never BOUND
d5285cae913f4e01ffa0e6693a6d8ef1fbea30baGeorge Wilson if ((rp = topo_mod_zalloc(mod, sizeof (tnode_t))) == NULL)
d5285cae913f4e01ffa0e6693a6d8ef1fbea30baGeorge Wilson return (set_create_error(thp, tp, 0)); /* th_errno set */
fa9e4066f08beec538e775443c5be79dd423fcabahrens topo_mod_hold(mod); /* released when root node destroyed */
int rv = 0;
char *pp;
pp++;
pp++;
if (rv != 0)
int err = 0;
if (err != 0)