/*
* 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
*/
/*
*/
/*
* 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>
1
};
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 *
{
}
/*
* Returns the existing range(min and max) for the child node with the matching
* name under the given pnode.
*/
int
{
break;
}
if (nhp) {
} else {
"unable to locate the matching child range with name %s:"
}
return (0);
}
static int
int err)
{
}
}
}
int
{
}
/*
* Add these nodes to parent child list
*/
return (0);
}
static int
int err)
{
}
}
}
/*
* Extends the range for the child node with the matching name under the given
* pnode. The incr parameter indicates the size of range to be increased and
* should be greater zero.
*
* Note that the range is increased with the same min value to keep the
* node placement in the original node array intact.
* The min and max is set with the value after extension of the range.
*
* The caller should check the instance number of the existing child nodes
* to make sure no duplicate instance number is used when it binds a new
* child node after extending the range.
*/
int
{
if (incr <= 0)
break;
}
if (nhp) {
/* extend the max value and adjust the array length. */
EMOD_NOMEM));
/*
* move the existing elements(pointers to the child node) to
* extended array.
*/
sizeof (tnode_t *));
/*
* free the original node array and link the extended node
* array.
*/
} else {
}
"extended node range %s[%d-%d]\n", name,
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);
}
/*
* Chassis authority: inherit from parent when possible.
*/
int
{
int i, result;
const char *ch_auths[] = {
};
/* not in the parent or auth list */
++rerr;
} else {
if (result != 0) {
/* Preserve the error and continue */
"failed to set property %s (%d) "
topo_strerror(err));
++rerr;
}
}
}
}
return (rerr);
}
tnode_t *
{
int h, err;
else
break;
}
}
EMOD_NOMEM));
/* Ref count module that bound this node */
/* chassis */
}
return (node);
}
tnode_t *
const char *type)
{
int h, err;
/*
* 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));
}
}
}
}
}
/* chassis */
}
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",
}
{
*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);
}