topo_xml.c revision 738c43b514a3570e657652233a5a19291a328a28
/*
* 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.
*/
#include <libxml/xinclude.h>
#include <assert.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <topo_file.h>
#include <topo_mod.h>
#include <topo_subr.h>
#include <topo_alloc.h>
#include <topo_parse.h>
#include <topo_error.h>
tnode_t *);
tf_pad_t **);
int
{
int rv = 0;
if (n == NULL) {
/* If there is no Stability defined, we default to private */
return (0);
}
"attribute to stability:\n");
}
} else {
}
return (rv);
}
int
{
propname);
/* no conversion was done */
}
return (0);
}
static int
{
propname);
return (-1);
}
return (0);
}
static topo_type_t
{
attr);
return (TOPO_TYPE_INVALID);
}
rv = TOPO_TYPE_FMRI;
} else {
"Unrecognized type attribute value '%s'.\n", str);
return (TOPO_TYPE_INVALID);
}
return (rv);
}
static int
const char *name)
{
int rv;
name);
switch (ptype) {
case TOPO_TYPE_INT32:
return (-1);
break;
case TOPO_TYPE_UINT32:
return (-1);
break;
case TOPO_TYPE_INT64:
return (-1);
break;
case TOPO_TYPE_UINT64:
return (-1);
break;
case TOPO_TYPE_FMRI:
return (-1);
break;
case TOPO_TYPE_STRING:
return (-1);
break;
default:
"Unrecognized type attribute.\n");
}
if (rv != 0) {
"Nvlist construction failed.\n");
} else
return (0);
}
static int
{
B_FALSE);
else
B_TRUE);
} else {
}
return (-1);
return (-1);
}
static int
{
int sibs = 0;
"Dependents missing grouping attribute");
}
sibs++;
} else {
"Dependents have bogus grouping attribute");
}
/* Add processed dependents to the tail of the list */
}
"error within dependent .xml topology: "
return (-1);
}
else if (sibs == 1)
else
return (0);
}
static int
{
return (-1);
}
}
return (0);
}
static int
{
char *str;
int err, e;
switch (ptype) {
case TOPO_TYPE_INT32:
break;
case TOPO_TYPE_UINT32:
break;
case TOPO_TYPE_INT64:
break;
case TOPO_TYPE_UINT64:
break;
case TOPO_TYPE_FMRI:
break;
case TOPO_TYPE_STRING:
break;
default:
e = ETOPO_PRSR_BADTYPE;
}
if (e != 0) {
"prop_create: prop value lookup failed.\n");
return (topo_mod_seterrno(mp, e));
}
switch (ptype) {
case TOPO_TYPE_INT32:
break;
case TOPO_TYPE_UINT32:
break;
case TOPO_TYPE_INT64:
break;
case TOPO_TYPE_UINT64:
break;
case TOPO_TYPE_FMRI:
break;
case TOPO_TYPE_STRING:
break;
}
if (e != 0 && err != ETOPO_PROP_DEFD) {
/*
* Some properties may have already been set
* in topo_node_bind() or topo_prop_inherit if we are
* enumerating from a static .xml file
*/
}
return (0);
}
static int
{
char *pnm;
int flag;
int pn;
int e;
gnm);
if (e != 0) {
"props create lookup (%s) failure: %s",
}
if (e != 0) {
"props create lookup (%s) failure: %s",
INV_IMMUTE, strerror(e));
}
if (e != 0) {
"props create lookup (%s) failure: %s",
INV_PVALTYPE, strerror(e));
}
return (-1);
}
return (0);
}
static int
{
char *gnm;
int pg;
int e;
INV_PGRP_NAME, &gnm);
if (e != 0) {
"pad lookup (%s) failed (%s).\n",
}
if (e != 0) {
if (e != ENOENT) {
"pad lookup (%s) "
"failed.\n", INV_PGRP_NMSTAB);
return (topo_mod_seterrno(mp,
} else {
}
}
INV_PGRP_DSTAB, &dstab);
if (e != 0) {
if (e != ENOENT) {
"pad lookup (%s) failed.\n",
return (topo_mod_seterrno(mp,
} else {
}
}
INV_PGRP_VER, &gv);
if (e != 0) {
"pad lookup (%s) failed.\n",
}
if (e != ETOPO_PROP_DEFD) {
"pgroups create failure: %s\n",
topo_strerror(e));
return (-1);
}
}
/*
* The number of properties could be zero if the property
* group only contains propmethod declarations
*/
if (rnprops > 0) {
"recorded number of props %d does not "
"match number of props recorded %d.\n",
}
return (-1);
}
}
return (0);
}
static nvlist_t *
{
"propval lacks a name\n");
return (NULL);
}
return (NULL);
}
return (NULL);
}
/* FMXXX stability of the property name */
return (NULL);
}
return (pnvl);
}
struct propmeth_data {
const char *pg_name;
const char *prop_name;
const char *meth_name;
};
static int
{
int err;
"propmethod %s for property \"%s\" in propgrp %s on node "
"%s=%d (%s)\n",
topo_strerror(err));
return (-1);
}
"registered method %s on %s=%d\n",
return (0);
}
static int
const char *rname, const char *ppgrp_name)
{
struct propmeth_data meth;
/*
* Get propmethod attribute values
*/
"propmethod element lacks a name attribute\n");
}
"propmethod element lacks version attribute\n");
goto pmr_done;
}
/*
* The "mutable" and "nonvoltile" attributes are optional. If not
* specified we default to false (0)
*/
"propmethod element lacks propname attribute\n");
goto pmr_done;
}
== TOPO_TYPE_INVALID) {
"error decoding proptype attribute\n");
goto pmr_done;
}
/*
* Allocate method argument nvlist
*/
goto pmr_done;
}
/*
* Iterate through the argval nodes and build the argval nvlist
*/
"found argval element\n");
== NULL) {
"argval element lacks a name attribute\n");
goto pmr_done;
}
== TOPO_TYPE_INVALID) {
break;
}
(const char *)arg_name) != 0) {
break;
}
}
if (arg_name) {
}
}
if (ret != 0)
goto pmr_done;
/*
* Register the prop method for all of the nodes in our range
*/
/*
* If the propgroup element is under a range element, we'll apply
* the method to all of the topo nodes at this level with the same
* range name.
*
* Otherwise, if the propgroup element is under a node element
* then we'll simply register the method for this node.
*/
goto pmr_done;
}
if (is_mutable) {
if (topo_prop_setmutable(tmp,
!= 0) {
goto pmr_done;
}
}
if (is_nonvolatile) {
!= 0) {
goto pmr_done;
}
}
}
}
} else {
goto pmr_done;
}
if (is_mutable) {
goto pmr_done;
}
}
if (is_nonvolatile) {
goto pmr_done;
}
}
}
if (meth_name)
if (prop_name)
if (arg_nvl)
return (ret);
}
static int
{
int pcnt = 0;
int ai = 0;
int e;
"propgroup lacks a name\n");
}
"propgroup lacks a version\n");
}
"propgroup lacks name-stability\n");
}
"propgroup lacks data-stability\n");
}
pcnt++;
}
"failed to allocate propgroup nvlist\n");
}
if (pcnt > 0)
if (e != 0 ||
== NULL) {
"failed to allocate nvlist array for properties"
"(e=%d)\n", e);
}
break;
}
ai++;
ppgrp_name) < 0)
break;
}
}
if (pcnt > 0) {
pcnt);
if (e != 0) {
return (-1);
}
}
return (0);
}
static int
{
int pi = 0;
< 0)
return (-1);
}
}
return (0);
}
/*
* psn: pointer to a "set" XML node
* key: string to search the set for
*
* returns: 1, if the set contains key
* 0, otherwise
*/
static int
{
char *prod;
int rv = 0;
return (1);
return (1);
return (rv);
}
/*
* Process the property group and dependents xmlNode children of
* parent xmlNode pxn.
*/
static int
{
int pgcnt = 0;
int dcnt = 0;
int ecnt = 0;
int joined_set = 0;
char *key;
/*
* We're iterating through the XML children looking for
* four types of elements:
* 1) dependents elements
* 2) unconstrained pgroup elements
* 3) pgroup elements constrained by set elements
* 4) enum-method elements for the case that we want
* to post-process a statically defined node
*/
dcnt++;
pgcnt++;
== 0) {
ecnt++;
if (joined_set)
continue;
else
/*
* If it's the default set then we'll store
* a pointer to it so that if none of the other
* sets apply to our product we can fall
* back to this one.
*/
joined_set = 1;
pgcnt++;
}
}
}
}
/*
* If we haven't found a set that contains our product AND
* a default set exists, then we'll process it.
*/
if (!joined_set && def_set) {
"Falling back to default set\n");
joined_set = 1;
== 0)
pgcnt++;
}
}
"pad_process: dcnt=%d, pgcnt=%d, ecnt=%d, joined_set=%d\n",
/*
* If an enum-method element was found, AND we're a child of a
* node element, then we invoke the enumerator so that it can do
* post-processing of the node.
*/
== NULL)
return (-1);
/*
* Note the failure but continue on
*/
"pad_process: enumeration failed.\n");
}
}
/*
* Here we allocate an element in an intermediate data structure
* which keeps track property groups and dependents of the range
* currently being processed.
*
* This structure is referenced in pgroups_record() to create
* the actual property groups in the topo tree
*/
return (-1);
if (pgcnt > 0) {
return (-1);
}
}
/*
* If the property groups are contained within a set
* then they will be one level lower in the XML tree.
*/
if (joined_set)
else
/*
* If there is no "node" element under the "range"
* element, then we need to attach the facility node to
* each node in this range.
*
* Otherwise we only attach it to the current node
*/
continue;
return (-1);
return (-1);
}
} else {
return (-1);
return (-1);
}
return (-1);
}
}
return (-1);
if (new->tpad_pgcnt > 0)
return (-1);
return (0);
}
static int
{
int rv = 0;
continue;
goto fenumdone;
"Invalid provider specified: %s\n", fprov);
goto fenumdone;
}
/*
* Invoke enum entry point in fac provider which will cause the
* facility enumeration node method to be registered.
*/
"fac_enum_process: enum entry point failed!\n");
goto fenumdone;
}
}
return (0);
return (rv);
}
static int
{
int err;
continue;
goto facdone;
"processing facility node '%s'\n", fname);
goto facdone;
goto facdone;
goto facdone;
"Invalid provider attr value: %s\n", provider);
goto facdone;
}
goto facdone;
if (err != ETOPO_PROP_DEFD) {
"pgroups create failure: %s\n",
topo_strerror(err));
return (-1);
}
}
/*
* Invoke enum entry point in fac_prov_ipmi module, which will
* cause the provider methods to be registered on this node
*/
"enum entry point failed for provider %s!\n",
provider);
goto facdone;
}
goto facdone;
goto facdone;
goto facdone;
}
return (0);
return (0);
}
static int
{
int rv = -1;
int s = 0;
goto nodedone;
s = 1;
}
if (s == 0) {
s == 1 ? &s : NULL) < 0)
goto nodedone;
}
/*
* If this is a static node declaration, we can
* ignore the lookup failure and continue
* processing. Otherwise, something
* went wrong during enumeration
*/
if (s == 1)
rv = 0;
goto nodedone;
}
"node_process: tf_idata_new failed.\n");
goto nodedone;
}
"node_process: tf_idata_insert failed.\n");
goto nodedone;
}
goto nodedone;
goto nodedone;
rv = 0;
return (rv);
}
static tf_edata_t *
{
return (NULL);
}
"Enumerator name attribute missing.\n");
goto enodedone;
}
/*
* Check for recursive enumeration
*/
"Recursive enumeration detected for %s\n",
goto enodedone;
}
goto enodedone;
return (einfo);
return (NULL);
}
static int
{
int e = -1;
/*
* Check if the enumerator module is already loaded.
* Module loading is single-threaded at this point so there's
* no need to worry about the module going away or bumping the
* ref count.
*/
0)) == NULL) {
"enum_run: mod_load of %s failed: %s.\n",
return (e);
}
}
/*
* We're live, so let's enumerate.
*/
e);
if (e != 0) {
"Enumeration failed (%s)\n",
}
return (e);
}
static int
{
int e = -1;
/*
* Check if the enumerator module is already loaded.
* Module loading is single-threaded at this point so there's
* no need to worry about the module going away or bumping the
* ref count.
*/
"fac_enum_run: mod_load of %s failed: %s.\n",
return (e);
}
}
/*
* We're live, so let's enumerate.
*/
if (e != 0) {
"Facility provider enumeration failed (%s)\n",
}
return (e);
}
int
{
/* Only care about instances within the range */
continue;
}
return (-1);
return (-1);
}
return (0);
}
int
{
/*
* The range may have several children xmlNodes, that may
* represent the enumeration method, property groups,
* dependents, nodes or services.
*/
int e, ccnt = 0;
e = topo_node_range_create(mp,
"Range create failed due to %s.\n",
return (-1);
}
/*
* Before we process any of the other child xmlNodes, we iterate through
* the children and looking for either enum-method or propmap elements.
*/
/*
* If we found an enum-method element, process it first
*/
== NULL)
return (-1);
/*
* Note the failure but continue on
*/
"Enumeration failed.\n");
}
}
/*
* Next, check if a propmap element was found and if so, load it in
* and parse it.
*/
"element\n");
== NULL) {
"propmap element missing name attribute.\n");
} else {
(const char *)pmap_name,
"topo_xml_range_process: topo_file_load"
"failed: %s.\n",
}
}
}
/* Now look for nodes, i.e., hard instances */
"node processing failed: %s.\n",
return (topo_mod_seterrno(mp,
}
ccnt++;
}
}
/*
* Finally, process the property groups and dependents
*
* If the TF_PROPMAP flag is set for the XML file we're currently
* processing, then this XML file was loaded via propmap. In that case
* we call a special routine to recursively apply the propgroup settings
* to all of nodes in this range
*/
else {
/* Only care about instances within the range */
continue;
}
< 0)
return (-1);
return (-1);
ccnt++;
}
}
return (0);
}
static tf_rdata_t *
{
char *key;
int joined_set = 0;
/*
* First iterate through all the XML nodes at this level to look for
* set nodes.
*/
"topo_xml_walk: Ignoring nameless xmlnode\n");
continue;
}
if (joined_set)
continue;
else
/*
* If it's the default set then we'll store
* a pointer to it so that if none of the other
* sets apply to our product we can fall
* back to this one.
*/
joined_set = 1;
"topo_xml_walk: failed1\n");
}
} else {
}
}
}
}
/*
* If we haven't found a set that contains our product AND a default set
* exists, then we'll process it.
*/
if (!joined_set && def_set)
"topo_xml_walk: failed2\n");
}
/*
* Now we're interested in children xmlNodes of croot tagged
* as 'ranges'. These define what topology nodes may exist, and need
* to be verified.
*/
"topo_xml_walk: Ignoring nameless xmlnode\n");
continue;
}
continue;
/*
* Range processing error, continue walk
*/
continue;
}
} else {
}
}
return (rr);
}
/*
* Convert parsed xml topology description into topology nodes
*/
int
{
"Couldn't get root xmlNode.\n");
return (-1);
}
"error within .xml topology: %s\n",
return (-1);
}
return (0);
}
/*
* Load an XML tree from filename and read it into a DOM parse tree.
*/
static tf_info_t *
{
int readflags = 0;
tf_info_t *r;
int e, validate = 0;
/*
* Since topologies can XInclude other topologies, and libxml2
* doesn't do DTD-based validation with XInclude, by default
* we don't validate topology files. One can force
* validation, though, by creating a TOPOXML_VALIDATE
* environment variable and creating a TOPO_DTD environment
* variable with the path to the DTD against which to validate.
*/
validate = 1;
}
/*
* Splat warnings and errors related to parsing the topology
* file if the TOPOXML_PERROR environment variable exists.
*/
"txml_file_parse: couldn't parse document.\n");
return (NULL);
}
/*
* Verify that this is a document type we understand.
*/
"document has no DTD.\n");
return (NULL);
}
"document DTD unknown; bad topology file\n");
return (NULL);
}
return (NULL);
}
/*
* Make sure we're looking at a topology description in the
* expected scheme.
*/
"document is not a topology description.\n");
return (NULL);
}
"topology lacks a scheme.\n");
return (NULL);
}
"topology in unrecognized scheme, %s, expecting %s\n",
return (NULL);
}
"Could not parse DTD \"%s\".\n",
dtdpath);
return (NULL);
}
}
"couldn't handle XInclude statements in document\n");
return (NULL);
}
if (validate) {
return (NULL);
}
if (e == 0)
"Document is not valid.\n");
}
return (NULL);
}
return (r);
}
{
int fd;
"failed to open %s for reading\n", path);
return (NULL);
}
return (tip);
}