/*
* 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 <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
* - retire
* - unretire
*
* 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));
return (contains);
}
int
{
char *scheme;
return (unusable);
}
int
{
char *scheme;
TOPO_METH_RETIRE, out));
TOPO_METH_RETIRE, out));
TOPO_METH_RETIRE, out));
return (status);
}
int
{
char *scheme;
}
return (status);
}
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;
/*
* If there is a serial id in the resource fmri, then use that.
* Otherwise fall back to looking for a serial id property in the
* protocol group.
*/
"topo_fmri_serial", prop));
else
return (0);
}
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.
*
* This code also handles changes in the server-id or revision fields of the hc
* FMRI, as these fields have no bearing on equivalence of FRUs.
*/
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);
}
static const char *
{
return (NULL);
return (slash);
return (slash);
else
return (colon);
}
/*
* List of authority information we care about. Note that we explicitly ignore
* things that are properties of the chassis and not the resource itself:
*
* FM_FMRI_AUTH_PRODUCT_SN "product-sn"
* FM_FMRI_AUTH_PRODUCT "product-id"
* FM_FMRI_AUTH_DOMAIN "domain-id"
* FM_FMRI_AUTH_SERVER "server-id"
* FM_FMRI_AUTH_HOST "host-id"
*
* We also ignore the "revision" authority member, as that typically indicates
* the firmware revision and is not a static property of the FRU. This leaves
* the following interesting members:
*
* FM_FMRI_AUTH_CHASSIS "chassis-id"
* FM_FMRI_HC_SERIAL_ID "serial"
* FM_FMRI_HC_PART "part"
*/
typedef enum {
static char *hc_auth_table[] = {
};
/*
* Takes an authority member, with leading ":" and trailing "=", and returns
* one of the above types if it's one of the things we care about. If
* 'authlen' is specified, it is filled in with the length of the authority
* member, including leading and trailing characters.
*/
static hc_auth_type_t
{
int i;
if (auth[0] != ':')
return (HC_AUTH_MAX);
for (i = 0; i < HC_AUTH_MAX; i++) {
if (authlen)
break;
}
}
return (i);
}
/*ARGSUSED*/
{
const char *enclosure;
ulong_t h;
h = 0;
while (*next != '/') {
break;
}
continue;
}
if (enclosure) {
next++;
}
return (h);
}
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
static void
{
int i;
const char *next;
for (i = 0; i < HC_AUTH_MAX; i++)
authlen[i] = 0;
while (*auth != '/' &&
continue;
}
}
}
/*ARGSUSED*/
static boolean_t
{
int i;
/*
* For non-hc FMRIs, we don't do anything.
*/
return (strcmp(a, b) == 0);
/*
* Get the portion of the FMRI independent of the authority
* information.
*/
return (strcmp(a, b));
fmria++;
fmrib++;
/*
* Comparing fmri authority information is a bit of a pain, because
* there may be a different number of members, and they can (but
* shouldn't be) in a different order. We need to create a copy of the
* authority and parse it into pieces. Because this function is
* intended to be fast (and not necessarily extensible), we hard-code
* the list of possible authority members in an enum and parse it into
* an array.
*/
for (i = 0; i < HC_AUTH_MAX; i++) {
if (noauth && i != HC_AUTH_CHASSIS)
continue;
continue;
return (B_FALSE);
return (B_FALSE);
}
/*
* If this is rooted at a ses-enclosure node, skip past the instance
* number, as it has no meaning.
*/
fmria += sizeof (SES_ENCLOSURE);
fmrib += sizeof (SES_ENCLOSURE);
fmria++;
fmrib++;
}
}
/*ARGSUSED*/
{
}
/*ARGSUSED*/
{
}
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);
}