topo_xml.c revision 15fa52896e9787fce4a833ef05eea383ab22181a
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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_mod.h>
#include <topo_subr.h>
#include <topo_alloc.h>
#include <topo_parse.h>
#include <topo_error.h>
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
{
/* 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 {
"Unrecognized type attribute.\n");
return (TOPO_TYPE_INVALID);
}
return (rv);
}
static int
{
int e;
B_FALSE);
else
B_TRUE);
} else {
}
return (-1);
if (e != 0)
return (-1);
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 (e != 0) {
"Nvlist construction failed.\n");
}
return (0);
}
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 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;
if (e != 0) {
"props create lookup (%s) failure: %s",
INV_PNAME, topo_strerror(e));
}
if (e != 0) {
"props create lookup (%s) failure: %s",
INV_IMMUTE, topo_strerror(e));
}
if (e != 0) {
"props create lookup (%s) failure: %s",
INV_PVALTYPE, topo_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.\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);
}
}
"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);
}
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++;
}
return (-1);
}
if (e != 0 ||
return (-1);
}
break;
}
ai++;
}
}
if (e != 0) {
return (-1);
}
return (0);
}
static int
{
int pi = 0;
return (-1);
}
}
return (0);
}
/*
* Process the property group and dependents xmlNode children of
* parent xmlNode pxn.
*/
static int
{
int pgcnt = 0;
int dcnt = 0;
dcnt++;
pgcnt++;
}
return (-1);
return (0);
}
if (pgcnt > 0) {
return (NULL);
}
return (NULL);
}
}
}
return (-1);
if (new->tpad_pgcnt > 0)
return (-1);
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;
}
"tf_idata_new failed.\n");
goto nodedone;
}
"tf_idata_insert failed.\n");
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) {
"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);
}
int
{
/*
* The range may have several children xmlNodes, that may
* represent the enumeration method, property groups,
* dependents or nodes.
*/
int e, ccnt = 0;
e = topo_node_range_create(mp,
"Range create failed due to %s.\n",
return (-1);
}
break;
return (-1);
/*
* Note the failure but continue on
*/
"Enumeration failed.\n");
}
}
/* Now look for nodes, i.e., hard instances */
"node processing failed: %s.\n",
return (topo_mod_seterrno(mp,
}
}
/* Property groups and Dependencies */
/* Only care about instances within the range */
continue;
}
return (-1);
ccnt++;
}
if (ccnt == 0) {
return (-1);
}
return (0);
}
static tf_rdata_t *
{
/*
* What we're interested in are children xmlNodes of croot tagged
* as 'ranges', these define topology nodes may exist, and need
* to be verified.
*/
"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.
*/
"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);
}
static int
{
int rfd;
return (rfd);
}
{
int fd;
return (NULL);
}
return (tip);
}