topo_fmri.c revision 25c6ff4b77fcddf4097ce78a8277275ca603b46c
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <fm/topo_mod.h>
#include <fm/fmd_fmri.h>
#include <topo_alloc.h>
#include <topo_error.h>
#include <topo_hc.h>
#include <topo_method.h>
#include <topo_subr.h>
#include <topo_string.h>
/*
* Topology node properties and method operations may be accessed by FMRI.
* The FMRI used to perform property look-ups and method operations is
* the FMRI contained in the matching topology node's protocol property
* grouping for the resource property. The full range of fmd(1M)
* scheme plugin operations are supported as long as a backend method is
* supplied by a scheme-specific enumerator or the enumerator module that
* created the matching topology node. Support for fmd scheme operations
* include:
*
* - expand
* - present
* - replaced
* - contains
* - unusable
* - service_state
* - nvl2str
*
* In addition, the following operations are supported per-FMRI:
*
* - str2nvl: convert string-based FMRI to nvlist
* - compare: compare two FMRIs
* - asru: lookup associated ASRU property by FMRI
* - fru: lookup associated FRU by FMRI
* - create: an FMRI nvlist by scheme type
* - propery lookup
*
* These routines may only be called by consumers of a topology snapshot.
* They may not be called by libtopo enumerator or method modules.
*/
/*ARGSUSED*/
static int
{
topo_strerror(err));
return (-1);
}
/*ARGSUSED*/
static nvlist_t *
{
topo_strerror(err));
return (NULL);
}
int
{
TOPO_METH_NVL2STR, out));
TOPO_METH_NVL2STR, out));
TOPO_METH_NVL2STR, out));
TOPO_METH_NVL2STR, out));
return (0);
}
int
int *err)
{
TOPO_METH_STR2NVL, in));
*f = '\0'; /* strip trailing FMRI path */
TOPO_METH_STR2NVL, in));
in));
in));
TOPO_METH_STR2NVL, out));
return (0);
}
int
{
char *scheme;
TOPO_METH_PRESENT, out));
TOPO_METH_PRESENT, out));
return (present);
}
return (present);
}
int
{
char *scheme;
return (FMD_OBJ_STATE_UNKNOWN);
}
return (replaced);
}
int
{
char *scheme;
NULL));
in));
out));
}
return (contains);
}
int
{
char *scheme;
return (unusable);
}
int
{
char *scheme;
out));
return (service_state);
}
int
{
char *scheme;
TOPO_METH_EXPAND, out));
TOPO_METH_EXPAND, out));
return (0);
}
static int
int *err)
{
int rv;
char *scheme;
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
if (rv != 0)
TOPO_METH_PROP_GET, in));
if (rv != 0)
return (-1); /* *err is set for us */
return (0);
}
int
{
prop));
prop));
return (0);
}
int
{
prop));
prop));
return (0);
}
int
{
char *lp;
prop));
prop));
return (0);
}
int
{
char *sp;
prop));
"topo_fmri_serial", prop));
return (0);
}
int *err)
{
}
{
int rv;
char *scheme;
TOPO_METH_PROP_SET, in));
TOPO_METH_PROP_SET, in));
TOPO_METH_PROP_SET, in));
if (rv != 0)
TOPO_METH_PROP_SET, in));
/* no return values */
if (rv)
return (-1);
return (0);
}
int
{
int rv;
char *scheme;
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
if (rv != 0)
TOPO_METH_PROP_GET, in));
if (rv != 0)
return (-1); /* *err is set for us */
return (0);
}
int
{
return (0);
NULL));
in));
return (compare);
}
/*
* topo_fmri_create
*
* If possible, creates an FMRI of the requested version in the
* requested scheme. Args are passed as part of the inputs to the
* fmri-create method of the scheme.
*/
nvlist_t *
{
TOPO_METH_FMRI, NULL));
TOPO_METH_FMRI, NULL));
TOPO_METH_FMRI, ins));
}
TOPO_METH_FMRI, ins));
}
if (topo_method_invoke(rnode,
}
return (out);
}
/*
* These private utility functions are used by fmd to maintain its resource
* cache. Because hc instance numbers are not guaranteed, it's possible to
* have two different FMRI strings represent the same logical entity. These
* functions hide this implementation detail from unknowing consumers such as
* fmd.
*
* Ideally, we'd like to do a str2nvl() and then a full FMRI hash and
* comparison, but these functions are designed to be fast and efficient.
* Given that there is only a single hc node that has this property
* (ses-enclosure), we hard-code this behavior here. If there are more
* instances of this behavior in the future, this function could be made more
* generic.
*/
static ulong_t
{
ulong_t g, h = 0;
size_t i;
for (i = 0; i < len; i++) {
h = (h << 4) + fmri[i];
if ((g = (h & 0xf0000000)) != 0) {
h ^= (g >> 24);
h ^= g;
}
}
return (h);
}
/*ARGSUSED*/
{
char *e;
ulong_t h;
e += sizeof (SES_ENCLOSURE);
while (isdigit(*e))
e++;
h += topo_fmri_strhash_one(e, strlen(e));
return (h);
}
/*ARGSUSED*/
{
return (strcmp(a, b) == 0);
return (B_FALSE);
return (B_FALSE);
ea += sizeof (SES_ENCLOSURE);
eb += sizeof (SES_ENCLOSURE);
ea++;
eb++;
}
int
{
int rv;
char *scheme;
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
TOPO_METH_PROP_GET, in));
#ifdef _LP64
#else
#endif
if (rv != 0)
TOPO_METH_PROP_GET, in));
if (rv != 0)
return (-1); /* *err is set for us */
return (0);
}