/*
* 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
*/
/*
*/
#include <libxml/xinclude.h>
#include <alloca.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 **);
static void
{
int i;
for (i = 0; i < nelems; i++)
}
int
{
int rv = 0;
if (n == NULL) {
/* If there is no Stability defined, we default to private */
return (0);
}
}
} else {
}
return (rv);
}
int
{
/* no conversion was done */
}
return (0);
}
static int
{
return (-1);
}
return (0);
}
static topo_type_t
{
return (TOPO_TYPE_INVALID);
}
rv = TOPO_TYPE_FMRI;
} else {
"%s: unrecognized type attribute value '%s'\n",
return (TOPO_TYPE_INVALID);
}
return (rv);
}
static int
const char *name)
{
int rv;
char **strarrbuf;
void *arrbuf;
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:
"xmlattr_to_fmri() failed\n", __func__);
return (-1);
}
break;
case TOPO_TYPE_STRING:
return (-1);
break;
case TOPO_TYPE_INT32_ARRAY:
case TOPO_TYPE_UINT32_ARRAY:
case TOPO_TYPE_INT64_ARRAY:
case TOPO_TYPE_UINT64_ARRAY:
nelems++;
if (nelems == 0) {
(ptype == TOPO_TYPE_UINT32_ARRAY ?
"%s: no <propitem> or <argitem> elements found "
if (ptype != TOPO_TYPE_UINT32_ARRAY)
return (-1);
/*
* This is a workaround for xml integer arrays not
* being in the proper XML format. See topo_2xml.c.
* Try interpreting it as a string.
*/
"%s: failed to interpret as a string\n",
__func__);
return (-1);
} else {
char *str2;
"%s: interpreting array as a string, "
/*
* See how many elements we have by parsing
* a duplicate string.
*/
nelems++;
if (nelems == 0) {
"%s: no elements found, str=%s\n",
return (-1);
}
}
}
== NULL)
break;
case TOPO_TYPE_STRING_ARRAY:
nelems++;
if (nelems == 0) {
"%s: no <propitem> or <argitem> elements found "
"for array val", __func__);
return (-1);
}
== NULL)
break;
case TOPO_TYPE_FMRI_ARRAY:
nelems++;
if (nelems == 0) {
"%s: no <propitem> elements found for array prop",
__func__);
return (-1);
}
break;
default:
"%s: unrecognized type attribute (ptype = %d)\n",
}
switch (ptype) {
case TOPO_TYPE_INT32_ARRAY:
== NULL)
return (-1);
}
}
nelems);
break;
case TOPO_TYPE_UINT32_ARRAY:
== NULL)
return (-1);
}
}
if (array_workaround == B_TRUE) {
/* Parse the string and fill in the array. */
(char **)NULL, 16);
}
/* Sanity check that we parsed the same number. */
if (i != nelems) {
"%s: i=%d != nelems=%d\n",
return (-1);
}
}
nelems);
break;
case TOPO_TYPE_INT64_ARRAY:
== NULL)
return (-1);
}
}
nelems);
break;
case TOPO_TYPE_UINT64_ARRAY:
== NULL)
return (-1);
}
}
break;
case TOPO_TYPE_STRING_ARRAY:
== NULL)
return (-1);
strarrbuf[i++] =
}
}
break;
case TOPO_TYPE_FMRI_ARRAY:
== NULL)
return (-1);
&(nvlarrbuf[i++])) < 0) {
return (-1);
}
}
}
nelems);
break;
}
if (rv != 0) {
"%s: nvlist construction failed\n", __func__);
} else
return (0);
}
static int
{
B_FALSE);
else
B_TRUE);
} else {
}
return (-1);
return (-1);
}
static int
{
int sibs = 0;
"%s: dependents missing grouping attribute", __func__);
}
sibs++;
} else {
"%s: dependents have bogus grouping attribute", __func__);
}
/* Add processed dependents to the tail of the list */
}
"%s: error within dependent .xml topology: %s\n",
return (-1);
}
else if (sibs == 1)
else
return (0);
}
static int
{
return (-1);
}
}
return (0);
}
static int
{
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;
case TOPO_TYPE_INT32_ARRAY:
break;
case TOPO_TYPE_UINT32_ARRAY:
&nelem);
break;
case TOPO_TYPE_INT64_ARRAY:
&nelem);
break;
case TOPO_TYPE_UINT64_ARRAY:
&nelem);
break;
case TOPO_TYPE_STRING_ARRAY:
&nelem);
break;
case TOPO_TYPE_FMRI_ARRAY:
&nelem);
break;
default:
e = ETOPO_PRSR_BADTYPE;
}
if (e != 0) {
"%s: prop value lookup failed: pgrp=%s, prop=%s\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;
case TOPO_TYPE_INT32_ARRAY:
break;
case TOPO_TYPE_UINT32_ARRAY:
break;
case TOPO_TYPE_INT64_ARRAY:
break;
case TOPO_TYPE_UINT64_ARRAY:
break;
case TOPO_TYPE_STRING_ARRAY:
break;
case TOPO_TYPE_FMRI_ARRAY:
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
*/
topo_strerror(err));
}
return (0);
}
static int
{
char *pnm;
int flag;
int pn;
int e;
if (e != 0) {
"%s: lookup (%s) failure: %s", __func__,
}
if (e != 0) {
"%s: lookup (%s) failure: %s", __func__,
INV_IMMUTE, strerror(e));
}
if (e != 0) {
"%s: lookup (%s) failure: %s", __func__,
INV_PVALTYPE, strerror(e));
}
return (-1);
}
return (0);
}
static int
{
char *gnm;
int pg;
int e;
INV_PGRP_NAME, &gnm);
if (e != 0) {
"%s: pad lookup (%s) failed (%s)\n", __func__,
}
if (e != 0) {
if (e != ENOENT) {
"%s: pad lookup (%s) failed\n",
return (topo_mod_seterrno(mp,
} else {
}
}
INV_PGRP_DSTAB, &dstab);
if (e != 0) {
if (e != ENOENT) {
"%s: pad lookup (%s) failed\n", __func__,
return (topo_mod_seterrno(mp,
} else {
}
}
INV_PGRP_VER, &gv);
if (e != 0) {
"%s: pad lookup (%s) failed\n", __func__,
}
if (e != ETOPO_PROP_DEFD) {
"%s: pgroups create failure: %s\n",
__func__, topo_strerror(e));
return (-1);
}
}
/*
* The number of properties could be zero if the property
* group only contains propmethod declarations
*/
if (rnprops > 0) {
"%s: recorded number of props %d does not "
"match number of props recorded %d\n",
}
return (-1);
}
}
return (0);
}
static nvlist_t *
{
"%s: propval lacks a name\n", __func__);
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", __func__,
topo_strerror(err));
return (-1);
}
"%s: registered method %s on %s=%d\n", __func__,
return (0);
}
static int
const char *rname, const char *ppgrp_name)
{
/*
* Get propmethod attribute values
*/
"%s: propmethod element lacks a name attribute\n",
__func__);
}
"%s: propmethod element lacks version attribute\n",
__func__);
goto pmr_done;
}
/*
* The "mutable" and "nonvoltile" attributes are optional. If not
* specified we default to false (0)
*/
"%s: propmethod element lacks propname attribute\n",
__func__);
goto pmr_done;
}
== TOPO_TYPE_INVALID) {
"%s: error decoding proptype attribute\n", __func__);
goto pmr_done;
}
/*
* Allocate method argument nvlist
*/
goto pmr_done;
}
/*
* Iterate through the argval nodes and build the argval nvlist
*/
"%s: found argval element\n", __func__);
== NULL) {
"%s: argval element lacks a name "
"attribute\n", __func__);
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;
"%s: propgroup lacks a name\n", __func__);
}
"%s: propgroup lacks a version\n", __func__);
}
"%s: propgroup lacks name-stability\n", __func__);
}
"%s: propgroup lacks data-stability\n", __func__);
}
pcnt++;
}
"%s: failed to allocate propgroup nvlist\n", __func__);
}
if (pcnt > 0)
if (e != 0 ||
== NULL) {
"%s: failed to allocate nvlist array for "
"properties (e=%d)\n", __func__, 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;
char *key;
"%s: cn->name is %s \n",
/*
* 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) {
"%s: falling back to default set\n", __func__);
joined_set = 1;
== 0)
pgcnt++;
}
}
"%s: 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
*/
"%s: enumeration failed\n", __func__);
}
}
/*
* 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;
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;
"%s: invalid provider specified: %s\n",
goto fenumdone;
}
/*
* Invoke enum entry point in fac provider which will cause the
* facility enumeration node method to be registered.
*/
"%s: enum entry point failed!\n", __func__);
goto fenumdone;
}
}
return (0);
"%s: processing failed\n", __func__);
return (rv);
}
static int
{
int err;
continue;
goto facdone;
goto facdone;
goto facdone;
goto facdone;
"%s: invalid provider attr value: %s\n",
goto facdone;
}
goto facdone;
if (err != ETOPO_PROP_DEFD) {
"%s: pgroups create failure: %s\n",
return (-1);
}
}
/*
* Invoke enum entry point in fac_prov_ipmi module, which will
* cause the provider methods to be registered on this node
*/
"%s: enum entry point failed for provider %s!\n",
goto facdone;
}
goto facdone;
goto facdone;
goto facdone;
}
return (0);
"%s: processing failed\n", __func__);
return (0);
}
static int
{
int s = 0;
"%s: xmlattr_to_int() failed\n", __func__);
goto nodedone;
}
s = 1;
}
/*
* We must call this for "Static" nodes as well since
* xml snapshots have everything defined as such.
*/
"%s: topo_mod_enumerate() failed\n", __func__);
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;
}
"%s: tf_idata_new() failed\n", __func__);
goto nodedone;
}
"%s: tf_idata_insert() failed\n", __func__);
goto nodedone;
}
"%s: pad_process() failed\n", __func__);
goto nodedone;
}
"%s: fac_process() failed\n", __func__);
goto nodedone;
}
rv = 0;
if (rv < 0)
return (rv);
}
static tf_edata_t *
{
return (NULL);
}
"%s: enumerator name attribute missing\n", __func__);
goto enodedone;
}
/*
* Check for recursive enumeration
*/
"%s: recursive enumeration detected for %s\n", __func__,
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) {
"%s: mod_load of %s failed: %s\n", __func__,
return (e);
}
}
/*
* We're live, so let's enumerate.
*/
"%d\n", __func__, e);
if (e != 0) {
"%s: enumeration failed (%s)\n", __func__,
}
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.
*/
"%s: mod_load of %s failed: %s\n", __func__,
return (e);
}
}
/*
* We're live, so let's enumerate.
*/
__func__, e);
if (e != 0) {
"%s: acility provider enumeration failed (%s)\n", __func__,
}
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,
"%s: range create failed due to %s\n", __func__,
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
*/
"%s: enumeration failed\n", __func__);
}
}
/*
* Next, check if a propmap element was found and if so, load it in
* and parse it.
*/
"element\n", __func__);
== NULL) {
"%s: propmap element missing name attribute\n",
__func__);
} else {
B_TRUE) < 0) {
"%s: topo_file_load failed: %s\n",
}
}
}
/* Now look for nodes, i.e., hard instances */
"%s: 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.
*/
"%s: Ignoring nameless xmlnode\n", __func__);
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;
"%s: failed1\n", __func__);
} else {
} 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) {
"%s: failed2\n", __func__);
}
} else {
}
}
/*
* Now we're interested in children xmlNodes of croot tagged
* as 'ranges'. These define what topology nodes may exist, and need
* to be verified.
*/
"%s: Ignoring nameless xmlnode\n", __func__);
continue;
}
continue;
/*
* Range processing error, continue walk
*/
"%s: range processing error, errmsg=%s\n",
continue;
}
} else {
}
}
return (rr);
}
/*
* Convert parsed xml topology description into topology nodes
*/
int
{
"%s: couldn't get root xmlNode\n", __func__);
return (-1);
}
"%s: error within .xml topology: %s\n", __func__,
return (-1);
}
return (0);
}
#define MFG 0
/*
* Parse the high level authority information placing it into the
* authority nvlist.
*/
static void
{
int i;
FM_FMRI_AUTH_TYPE_SYSTEM, /* System */
FM_FMRI_AUTH_TYPE_SYS_COMP, /* Component Systeem */
FM_FMRI_AUTH_TYPE_CHASSIS /* Chassis */
};
{ FM_FMRI_AUTH_V1_SYSTEM_MFG, /* Manufacturer */
FM_FMRI_AUTH_V1_SYSTEM_NM, /* Name */
FM_FMRI_AUTH_V1_SYSTEM_PN, /* Part Number */
FM_FMRI_AUTH_V1_SYSTEM_SN }, /* Serial Number */
};
/* alloc authority nvlist */
"%s: failed to alloc authority nvlist\n", __func__);
return;
}
/* fill in authority nvlist */
for (i = 0; i < MAX_AUTH_TYPES; i++) {
"%s: %s mfg(%s) name(%s) part(%s) serial(%s)\n", __func__,
i == FM_FMRI_AUTH_TYPE_SYSTEM ? "system" :
i == FM_FMRI_AUTH_TYPE_SYS_COMP ? "component system" :
/* add to nvlist */
}
/* set auth nvl to topo handle */
}
/*
* 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;
"%s: tmp=0x%p, thp=0x%p, filenm=%s, escheme=%s, "
/*
* 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.
*/
"%s: couldn't parse document\n", __func__);
return (NULL);
}
/*
* Verify that this is a document type we understand.
*/
"%s: document has no DTD\n", __func__);
return (NULL);
}
"%s: document DTD unknown; bad topology file\n", __func__);
return (NULL);
}
"%s: document is empty\n", __func__);
return (NULL);
}
/*
* Make sure we're looking at a topology description in the
* expected scheme.
*/
"%s: document is not a topology description\n", __func__);
return (NULL);
}
"%s: topology lacks a scheme\n", __func__);
return (NULL);
}
"%s: topology in unrecognized scheme, %s, expecting %s\n",
return (NULL);
}
/*
* If we're loading a snapshot file,
* then we expect a UUID and timestamp to be present.
*/
if (load_snapshot == B_TRUE) {
/*
* Lookup UUID.
*/
"%s: topology snapshot is missing a UUID\n",
__func__);
return (NULL);
}
TOPO_UUID_SIZE)) == NULL) {
"to allocate uuid\n", __func__);
return (NULL);
}
/*
* Lookup timestamp.
*/
== NULL) {
"%s: topology snapshot is missing a timestamp\n",
__func__);
return (NULL);
}
/* authority */
}
"%s: could not parse DTD \"%s\"\n",
return (NULL);
}
}
"%s: couldn't handle XInclude statements in "
"document\n", __func__);
return (NULL);
}
if (validate) {
return (NULL);
}
if (e == 0)
"%s: document is not valid\n", __func__);
}
return (NULL);
}
return (r);
}
{
int fd;
return (NULL);
}
}
return (tip);
}