topo_node.c revision 9c94f155585ea35e938fea603bc227c685223abd
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Topology Nodes
*
* Topology nodes, tnode_t, are data structures containing per-FMRI
* information and are linked together to form the topology tree.
* Nodes are created during the enumeration process of topo_snap_hold()
* and destroyed during topo_snap_rele(). For the most part, tnode_t data
* is read-only and no lock protection is required. Nodes are
* held in place during tree walk functions. Tree walk functions
* may access node data safely without locks. The exception to this rule
* is data associated with node properties (topo_prop.c). Properties
* may change at anytime and are protected by a per-property locking
* strategy.
*
* Enumerator plugin modules may also safely access topology nodes within their
* scope of operation: the parent node passed into the enumeration op or those
* nodes created by the enumerator. Enumeration occurs only during
* topo_snap_hold() where a per-topo_hdl_t lock prevents multi-threaded access
* to the topology trees.
*
* Enumerator method operation functions may safely access and change topology
* node property data, and contruct or destroy child nodes for the node
* on which the operation applies. The method may also be called to destroy
* the node for which the method operation is called. This permits
* dynamic topology tree snapshots and partial enumerations for branches that
* may not be needed right away.
*
* Node Interfaces
*
* Nodes are created when an enumerator calls topo_node_bind(). Prior to
* calling topo_node_bind(), the enumerator should have reserved a range of
* node instances with topo_node_range_create(). topo_node_range_create()
* does not allocate any node resources but creates the infrastruture
* required for a fully populated topology level. This allows enumerators
* reading from a <scheme>-topology.xml file to parse the file for a range
* of resources before confirming the existence of a resource via a helper
* plugin. Only when the resource has been confirmed to exist should
* the node be bound.
*
* Node range and node linkage and unlinkage is performed during enumeration and
* method operations when it is safe to change node hash lists. Nodes and node
* ranges are deallocated when all references to the node have been released:
* last walk completes and topo_snap_rele() is called.
*
*
* Each parent node may have one or more ranges of child nodes. Each range
* is uniquely named and serves as a hash list of like sibling nodes with
* different instance numbers. A parent may have more than one node hash
* (child range). If that is the case, the hash lists are strung together to
* populated with only nodes that have represented resources in the system.
*
* _________________
* | |
* | tnode_t | -----------------------------
* | tn_phash ---> | topo_nodehash_t |
* | (children)| | th_nodearr (instances)|
* ----------------- | ------------------- |
* | ---| 0 | 1 | ...| N | |
* | | ------------------- | -------------------
* | | th_list (siblings) ----->| topo_nodehash_t |
* | | | -------------------
* ---|-------------------------
* |
* v
* -----------
* | tnode_t |
* -----------
*
* Facility Nodes
*
* Facility nodes are always leaf nodes in the topology and represent a FMRI
* sensor or indicator facility for the path to which it is connected.
* Facility nodes are bound to the topology with topo_node_facbind() and
* unbound with topo_node_unbind().
*/
#include <assert.h>
#include <pthread.h>
#include <strings.h>
#include <topo_alloc.h>
#include <topo_error.h>
#include <topo_list.h>
#include <topo_method.h>
#include <topo_subr.h>
#include <topo_tree.h>
static topo_pgroup_info_t protocol_pgroup = {
1
};
static const topo_pgroup_info_t auth_pgroup = {
1
};
static void
{
int i;
return;
/*
* If not a root node, remove this node from the parent's node hash
*/
/*
* Release hold on parent
*/
}
}
}
/*
* Allow enumerator to clean-up private data and then release
* ref count
*/
/*
* Destroy all node hash lists
*/
}
}
/*
* Destroy all property data structures, free the node and release
* the module that created it
*/
}
void
{
}
void
{
}
void
{
}
void
{
/*
* Ok to remove this node from the topo tree and destroy it
*/
else
}
char *
{
}
{
return (node->tn_instance);
}
tnode_t *
{
}
int
{
}
void
{
}
void *
{
}
static int
int err)
{
}
}
}
int
{
}
/*
* Add these nodes to parent child list
*/
return (0);
}
void
{
int i;
break;
}
}
return;
}
}
}
tnode_t *
{
int h;
return (NULL);
}
return (node);
}
}
return (NULL);
}
int
{
}
static tnode_t *
{
if (pnode_locked)
return (NULL);
return (NULL);
}
tnode_t *
{
int h, err;
else
break;
}
}
EMOD_NOMEM));
/* Ref count module that bound this node */
}
return (node);
}
tnode_t *
const char *type)
{
int h, err;
topo_instance_t inst = 0;
/*
* Create a single entry range for this facility
*/
return (NULL); /* mod errno set */
B_TRUE, EMOD_NVL_INVAL));
}
} else
break;
}
}
}
EMOD_NOMEM));
}
/* Ref count module that bound this node */
}
EMOD_NOMEM));
}
}
}
}
}
}
return (node);
}
int
{
char *tmp_factype;
/*
* If it's not a facility node, move on
*/
continue;
}
/*
* Lookup whether the fac type is sensor or indicator and if
* it's not the type we're looking for, move on
*/
"Failed to get resource for node %s=%d (%s)\n",
topo_strerror(*errp));
return (-1);
}
&tmp_factype) != 0)) {
return (-1);
}
continue;
}
/*
* Finally, look up the subtype, which is a property in the
* facility propgroup. If it's a match return a pointer to the
* node. Otherwise, move on.
*/
return (-1);
}
if (fac_subtype == tmp_facsubtype ||
fac_subtype == TOPO_FAC_TYPE_ANY) {
sizeof (topo_faclist_t))) == NULL) {
*errp = ETOPO_NOMEM;
return (-1);
}
list_empty = 0;
}
}
if (list_empty) {
*errp = ETOPO_FAC_NOENT;
return (-1);
}
return (0);
}
void
{
return;
return;
}
"node unbound %s=%d/%s=%d refs = %d\n",
}
/*ARGSUSED*/
int
{
return (0);
}
/*ARGSUSED*/
int
{
return (0);
}
/*ARGSUSED*/
int
{
return (0);
}
{
*errp = ETOPO_HDL_NOMEM;
return (NULL);
}
/*
* If this is the root of the scheme tree, start with the first
* child
*/
/* Nothing to walk */
*errp = ETOPO_WALK_EMPTY;
return (NULL);
}
} else {
}
return (wp);
}