7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Common Development and Distribution License (the "License").
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You may not use this file except in compliance with the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * or http://www.opensolaris.org/os/licensing.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * When distributing Covered Code, include this CDDL HEADER in each
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If applicable, add the following below this CDDL HEADER, with the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fields enclosed by brackets "[]" replaced with your own identifying
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * information: Portions Copyright [yyyy] [name of copyright owner]
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER END
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
940d71d237794874e18a0eb72f6564821a823517eschrock#include <ctype.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <string.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <limits.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <fm/topo_mod.h>
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh#include <fm/fmd_fmri.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <sys/fm/protocol.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_alloc.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_error.h>
940d71d237794874e18a0eb72f6564821a823517eschrock#include <topo_hc.h>
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#include <topo_method.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_subr.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_string.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Topology node properties and method operations may be accessed by FMRI.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * The FMRI used to perform property look-ups and method operations is
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * the FMRI contained in the matching topology node's protocol property
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * grouping for the resource property. The full range of fmd(1M)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * scheme plugin operations are supported as long as a backend method is
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * supplied by a scheme-specific enumerator or the enumerator module that
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * created the matching topology node. Support for fmd scheme operations
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * include:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - expand
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - present
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * - replaced
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - contains
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - unusable
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh * - service_state
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - nvl2str
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * - retire
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye * - unretire
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * In addition, the following operations are supported per-FMRI:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - str2nvl: convert string-based FMRI to nvlist
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - compare: compare two FMRIs
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - asru: lookup associated ASRU property by FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - fru: lookup associated FRU by FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - create: an FMRI nvlist by scheme type
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - propery lookup
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * These routines may only be called by consumers of a topology snapshot.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * They may not be called by libtopo enumerator or method modules.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiset_error(topo_hdl_t *thp, int err, int *errp, char *method, nvlist_t *nvlp)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(nvlp);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_dprintf(thp, TOPO_DBG_ERR, "%s failed: %s\n", method,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_strerror(err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic nvlist_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiset_nverror(topo_hdl_t *thp, int err, int *errp, char *method, nvlist_t *nvlp)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(nvlp);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_dprintf(thp, TOPO_DBG_ERR, "%s failed: %s\n", method,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_strerror(err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_nvl2str(topo_hdl_t *thp, nvlist_t *fmri, char **fmristr, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme, *str;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_NVL2STR, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_NVL2STR, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_method_invoke(rnode, TOPO_METH_NVL2STR,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_NVL2STR_VERSION, fmri, &out, err) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, TOPO_METH_NVL2STR, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (out == NULL || nvlist_lookup_string(out, "fmri-string", &str) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_INVAL, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_NVL2STR, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((*fmristr = topo_hdl_strdup(thp, str)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_NOMEM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_NVL2STR, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_free(out);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_str2nvl(topo_hdl_t *thp, const char *fmristr, nvlist_t **fmri,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi char *f, buf[PATH_MAX];
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL, *in = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) strlcpy(buf, fmristr, sizeof (buf));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((f = strchr(buf, ':')) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_STR2NVL, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *f = '\0'; /* strip trailing FMRI path */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((rnode = topo_hdl_root(thp, buf)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_STR2NVL, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_STR2NVL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_string(in, "fmri-string", fmristr) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_STR2NVL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_method_invoke(rnode, TOPO_METH_STR2NVL,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_STR2NVL_VERSION, in, &out, err) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, TOPO_METH_STR2NVL, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
12cc75c814f0c017004a9bbc96429911e008601bcindi nvlist_free(in);
12cc75c814f0c017004a9bbc96429911e008601bcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (out == NULL ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_nvdup(thp, out, fmri) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err,
12cc75c814f0c017004a9bbc96429911e008601bcindi TOPO_METH_STR2NVL, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_free(out);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_present(topo_hdl_t *thp, nvlist_t *fmri, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi uint32_t present = 0;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_PRESENT, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_PRESENT, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_method_invoke(rnode, TOPO_METH_PRESENT,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_METH_PRESENT_VERSION, fmri, &out, err) < 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) set_error(thp, *err, err, TOPO_METH_PRESENT, out);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (present);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) nvlist_lookup_uint32(out, TOPO_METH_PRESENT_RET, &present);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_free(out);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (present);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhint
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhtopo_fmri_replaced(topo_hdl_t *thp, nvlist_t *fmri, int *err)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh{
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh uint32_t replaced = FMD_OBJ_STATE_NOT_PRESENT;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh char *scheme;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh nvlist_t *out = NULL;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh tnode_t *rnode;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (set_error(thp, ETOPO_FMRI_MALFORM, err,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_REPLACED, out));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_REPLACED, out));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if (topo_method_invoke(rnode, TOPO_METH_REPLACED,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_REPLACED_VERSION, fmri, &out, err) < 0) {
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh (void) set_error(thp, *err, err, TOPO_METH_REPLACED, out);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (FMD_OBJ_STATE_UNKNOWN);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh }
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh (void) nvlist_lookup_uint32(out, TOPO_METH_REPLACED_RET, &replaced);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh nvlist_free(out);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (replaced);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh}
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_contains(topo_hdl_t *thp, nvlist_t *fmri, nvlist_t *subfmri, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi uint32_t contains;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *in = NULL, *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_CONTAINS, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_CONTAINS, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_CONTAINS,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_FMRI, fmri) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_SUBFMRI, subfmri) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_CONTAINS,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_method_invoke(rnode, TOPO_METH_CONTAINS,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_CONTAINS_VERSION, in, &out, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, *err, err, TOPO_METH_CONTAINS, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvlist_lookup_uint32(out, TOPO_METH_CONTAINS_RET, &contains);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(in);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(out);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (contains);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_unusable(topo_hdl_t *thp, nvlist_t *fmri, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme;
dd566498928f08e7c9a79797a40db893c6a4b9fbvn uint32_t unusable = 0;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_UNUSABLE, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_UNUSABLE, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
dd566498928f08e7c9a79797a40db893c6a4b9fbvn if (topo_method_invoke(rnode, TOPO_METH_UNUSABLE,
dd566498928f08e7c9a79797a40db893c6a4b9fbvn TOPO_METH_UNUSABLE_VERSION, fmri, &out, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, TOPO_METH_UNUSABLE, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
dd566498928f08e7c9a79797a40db893c6a4b9fbvn (void) nvlist_lookup_uint32(out, TOPO_METH_UNUSABLE_RET, &unusable);
dd566498928f08e7c9a79797a40db893c6a4b9fbvn nvlist_free(out);
dd566498928f08e7c9a79797a40db893c6a4b9fbvn
dd566498928f08e7c9a79797a40db893c6a4b9fbvn return (unusable);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yeint
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yetopo_fmri_retire(topo_hdl_t *thp, nvlist_t *fmri, int *err)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye{
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye char *scheme;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye uint32_t status;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_t *out = NULL;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye tnode_t *rnode;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_FMRI_MALFORM, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_RETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_RETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_method_invoke(rnode, TOPO_METH_RETIRE,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_RETIRE_VERSION, fmri, &out, err) < 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, *err, err, TOPO_METH_RETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_uint32(out, TOPO_METH_RETIRE_RET, &status) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_METHOD_FAIL, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_RETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_free(out);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (status);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye}
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yeint
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Yetopo_fmri_unretire(topo_hdl_t *thp, nvlist_t *fmri, int *err)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye{
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye char *scheme;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye uint32_t status;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_t *out = NULL;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye tnode_t *rnode;
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_FMRI_MALFORM, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (topo_method_invoke(rnode, TOPO_METH_UNRETIRE,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE_VERSION, fmri, &out, err) < 0)
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, *err, err, TOPO_METH_UNRETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye if (nvlist_lookup_uint32(out, TOPO_METH_UNRETIRE_RET, &status) != 0) {
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_free(out);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (set_error(thp, ETOPO_METHOD_FAIL, err,
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye TOPO_METH_UNRETIRE, out));
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye }
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye nvlist_free(out);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye return (status);
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye}
e4b86885570d77af552e9cf94f142f4d744fb8c8Cheng Sean Ye
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhint
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephhtopo_fmri_service_state(topo_hdl_t *thp, nvlist_t *fmri, int *err)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh{
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh char *scheme;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh uint32_t service_state = FMD_SERVICE_STATE_UNKNOWN;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh nvlist_t *out = NULL;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh tnode_t *rnode;
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (set_error(thp, ETOPO_FMRI_MALFORM, err,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_SERVICE_STATE, out));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_SERVICE_STATE, out));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh if (topo_method_invoke(rnode, TOPO_METH_SERVICE_STATE,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh TOPO_METH_SERVICE_STATE_VERSION, fmri, &out, err) < 0)
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (set_error(thp, *err, err, TOPO_METH_SERVICE_STATE,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh out));
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh (void) nvlist_lookup_uint32(out, TOPO_METH_SERVICE_STATE_RET,
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh &service_state);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh nvlist_free(out);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh return (service_state);
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh}
25c6ff4b77fcddf4097ce78a8277275ca603b46cstephh
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_expand(topo_hdl_t *thp, nvlist_t *fmri, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &scheme) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_EXPAND, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_EXPAND, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_method_invoke(rnode, TOPO_METH_EXPAND,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_EXPAND_VERSION, fmri, &out, err) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, TOPO_METH_EXPAND, out));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindifmri_prop(topo_hdl_t *thp, nvlist_t *rsrc, const char *pgname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pname, nvlist_t *args, nvlist_t **prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int rv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *in = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi tnode_t *rnode;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *scheme;
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(rsrc, FM_FMRI_SCHEME, &scheme) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = nvlist_add_nvlist(in, TOPO_PROP_RESOURCE, rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_string(in, TOPO_PROP_GROUP, pgname);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_string(in, TOPO_PROP_VAL_NAME, pname);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (args != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_nvlist(in, TOPO_PROP_PARGS, args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
3cb1d85271919d3a09b22d2e6955363b1bb8d2f8cindi *prop = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = topo_method_invoke(rnode, TOPO_METH_PROP_GET,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET_VERSION, in, prop, err);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(in);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1); /* *err is set for us */
3cb1d85271919d3a09b22d2e6955363b1bb8d2f8cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (*prop == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NOENT, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecinditopo_fmri_asru(topo_hdl_t *thp, nvlist_t *nvl, nvlist_t **asru, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *ap, *prop = NULL;
3cb1d85271919d3a09b22d2e6955363b1bb8d2f8cindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi if (fmri_prop(thp, nvl, TOPO_PGROUP_PROTOCOL, TOPO_PROP_ASRU,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvl, &prop, err) < 0)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi return (set_error(thp, *err, err, "topo_fmri_asru", NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &ap) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NVL, err, "topo_fmri_asru",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(thp, ap, asru) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NOMEM, err, "topo_fmri_asru",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi return (0);
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindiint
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecinditopo_fmri_fru(topo_hdl_t *thp, nvlist_t *nvl, nvlist_t **fru, int *err)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *fp, *prop = NULL;
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi if (fmri_prop(thp, nvl, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock nvl, &prop, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, "topo_fmri_fru", NULL));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &fp) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NVL, err, "topo_fmri_fru",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(thp, fp, fru) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NOMEM, err, "topo_fmri_fru",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi return (0);
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi}
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_fmri_label(topo_hdl_t *thp, nvlist_t *nvl, char **label, int *err)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *prop = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *lp;
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (fmri_prop(thp, nvl, TOPO_PGROUP_PROTOCOL, TOPO_PROP_LABEL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi NULL, &prop, err) < 0)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi return (set_error(thp, *err, err, "topo_fmri_label", NULL));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(prop, TOPO_PROP_VAL_VAL, &lp) != 0)
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi return (set_error(thp, ETOPO_PROP_NVL, err, "topo_fmri_label",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((*label = topo_hdl_strdup(thp, lp)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NOMEM, err, "topo_fmri_label",
c40d7343efa60b18ad1ceb316eb337caeea79046cindi prop));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(prop);
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj return (0);
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj}
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
2cb5535af222653abf2eba5c180ded4a7b85d8b6robjint
2cb5535af222653abf2eba5c180ded4a7b85d8b6robjtopo_fmri_serial(topo_hdl_t *thp, nvlist_t *nvl, char **serial, int *err)
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj{
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj nvlist_t *prop = NULL;
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj char *sp;
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson /*
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson * If there is a serial id in the resource fmri, then use that.
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson * Otherwise fall back to looking for a serial id property in the
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson * protocol group.
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson */
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson if (nvlist_lookup_string(nvl, FM_FMRI_HC_SERIAL_ID, &sp) == 0) {
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson if ((*serial = topo_hdl_strdup(thp, sp)) == NULL)
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson return (set_error(thp, ETOPO_PROP_NOMEM, err,
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson "topo_fmri_serial", prop));
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson else
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson return (0);
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson }
6e1fa242609208de48dfe1939b8814d4dff455a5Stephen Hanson
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj if (fmri_prop(thp, nvl, TOPO_PGROUP_PROTOCOL, FM_FMRI_HC_SERIAL_ID,
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj NULL, &prop, err) < 0)
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj return (set_error(thp, *err, err, "topo_fmri_serial", NULL));
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj if (nvlist_lookup_string(prop, TOPO_PROP_VAL_VAL, &sp) != 0)
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj return (set_error(thp, ETOPO_PROP_NVL, err, "topo_fmri_serial",
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj prop));
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj if ((*serial = topo_hdl_strdup(thp, sp)) == NULL)
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj return (set_error(thp, ETOPO_PROP_NOMEM, err,
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj "topo_fmri_serial", prop));
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj
2cb5535af222653abf2eba5c180ded4a7b85d8b6robj nvlist_free(prop);
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint topo_fmri_getprop(topo_hdl_t *thp, nvlist_t *nvl, const char *pg,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pname, nvlist_t *args, nvlist_t **prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *prop = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (fmri_prop(thp, nvl, pg, pname, args, prop, err));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint topo_fmri_setprop(topo_hdl_t *thp, nvlist_t *nvl, const char *pg,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *prop, int flag, nvlist_t *args, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int rv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *in = NULL, *out = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi tnode_t *rnode;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *scheme;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &scheme) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_SET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_SET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_SET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = nvlist_add_nvlist(in, TOPO_PROP_RESOURCE, nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_string(in, TOPO_PROP_GROUP, pg);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_nvlist(in, TOPO_PROP_VAL, prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_int32(in, TOPO_PROP_FLAG, (int32_t)flag);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (args != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_nvlist(in, TOPO_PROP_PARGS, args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_SET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = topo_method_invoke(rnode, TOPO_METH_PROP_SET,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_SET_VERSION, in, &out, err);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(in);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /* no return values */
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(out);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_fmri_getpgrp(topo_hdl_t *thp, nvlist_t *rsrc, const char *pgname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t **pgroup, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int rv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *in = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi tnode_t *rnode;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *scheme;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(rsrc, FM_FMRI_SCHEME, &scheme) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = nvlist_add_nvlist(in, TOPO_PROP_RESOURCE, rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv |= nvlist_add_string(in, TOPO_PROP_GROUP, pgname);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_FMRI_NVL, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, in));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *pgroup = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi rv = topo_method_invoke(rnode, TOPO_METH_PGRP_GET,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PGRP_GET_VERSION, in, pgroup, err);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(in);
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (rv != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1); /* *err is set for us */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (*pgroup == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (set_error(thp, ETOPO_PROP_NOENT, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PROP_GET, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_compare(topo_hdl_t *thp, nvlist_t *f1, nvlist_t *f2, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi uint32_t compare;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char *scheme1, *scheme2;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *in;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(f1, FM_FMRI_SCHEME, &scheme1) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_COMPARE, NULL));
724365f7556fc4201fdb11766ebc6bd918523130sethg if (nvlist_lookup_string(f2, FM_FMRI_SCHEME, &scheme2) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_MALFORM, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_COMPARE, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (strcmp(scheme1, scheme2) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme1)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_COMPARE, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_COMPARE,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_NV1, f1) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_nvlist(in, TOPO_METH_FMRI_ARG_NV2, f2) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, ETOPO_FMRI_NVL, err, TOPO_METH_COMPARE,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_method_invoke(rnode, TOPO_METH_COMPARE,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_COMPARE_VERSION, in, &out, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_error(thp, *err, err, TOPO_METH_COMPARE, in));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) nvlist_lookup_uint32(out, TOPO_METH_COMPARE_RET, &compare);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(out);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_free(in);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (compare);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * topo_fmri_create
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * If possible, creates an FMRI of the requested version in the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * requested scheme. Args are passed as part of the inputs to the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * fmri-create method of the scheme.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindinvlist_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_fmri_create(topo_hdl_t *thp, const char *scheme, const char *name,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t inst, nvlist_t *nvl, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *ins;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t *out;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *rnode;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi ins = out = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_nverror(thp, ETOPO_METHOD_NOTSUP, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_FMRI, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((*err = topo_hdl_nvalloc(thp, &ins, NV_UNIQUE_NAME)) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_nverror(thp, ETOPO_FMRI_NVL, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_FMRI, NULL));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_string(ins, TOPO_METH_FMRI_ARG_NAME, name) != 0 ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_add_uint32(ins, TOPO_METH_FMRI_ARG_INST, inst) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_nverror(thp, ETOPO_FMRI_NVL, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_FMRI, ins));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvl != NULL &&
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_add_nvlist(ins, TOPO_METH_FMRI_ARG_NVL, nvl) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_nverror(thp, ETOPO_FMRI_NVL, err,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_FMRI, ins));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_method_invoke(rnode,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi TOPO_METH_FMRI, TOPO_METH_FMRI_VERSION, ins, &out, err) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_nverror(thp, *err, err, TOPO_METH_FMRI, ins));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_free(ins);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (out);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock/*
940d71d237794874e18a0eb72f6564821a823517eschrock * These private utility functions are used by fmd to maintain its resource
940d71d237794874e18a0eb72f6564821a823517eschrock * cache. Because hc instance numbers are not guaranteed, it's possible to
940d71d237794874e18a0eb72f6564821a823517eschrock * have two different FMRI strings represent the same logical entity. These
940d71d237794874e18a0eb72f6564821a823517eschrock * functions hide this implementation detail from unknowing consumers such as
940d71d237794874e18a0eb72f6564821a823517eschrock * fmd.
940d71d237794874e18a0eb72f6564821a823517eschrock *
940d71d237794874e18a0eb72f6564821a823517eschrock * Ideally, we'd like to do a str2nvl() and then a full FMRI hash and
940d71d237794874e18a0eb72f6564821a823517eschrock * comparison, but these functions are designed to be fast and efficient.
940d71d237794874e18a0eb72f6564821a823517eschrock * Given that there is only a single hc node that has this property
940d71d237794874e18a0eb72f6564821a823517eschrock * (ses-enclosure), we hard-code this behavior here. If there are more
940d71d237794874e18a0eb72f6564821a823517eschrock * instances of this behavior in the future, this function could be made more
940d71d237794874e18a0eb72f6564821a823517eschrock * generic.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock *
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * This code also handles changes in the server-id or revision fields of the hc
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FMRI, as these fields have no bearing on equivalence of FRUs.
940d71d237794874e18a0eb72f6564821a823517eschrock */
940d71d237794874e18a0eb72f6564821a823517eschrockstatic ulong_t
940d71d237794874e18a0eb72f6564821a823517eschrocktopo_fmri_strhash_one(const char *fmri, size_t len)
940d71d237794874e18a0eb72f6564821a823517eschrock{
940d71d237794874e18a0eb72f6564821a823517eschrock ulong_t g, h = 0;
940d71d237794874e18a0eb72f6564821a823517eschrock size_t i;
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock for (i = 0; i < len; i++) {
940d71d237794874e18a0eb72f6564821a823517eschrock h = (h << 4) + fmri[i];
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock if ((g = (h & 0xf0000000)) != 0) {
940d71d237794874e18a0eb72f6564821a823517eschrock h ^= (g >> 24);
940d71d237794874e18a0eb72f6564821a823517eschrock h ^= g;
940d71d237794874e18a0eb72f6564821a823517eschrock }
940d71d237794874e18a0eb72f6564821a823517eschrock }
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock return (h);
940d71d237794874e18a0eb72f6564821a823517eschrock}
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockstatic const char *
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_next_auth(const char *auth)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *colon, *slash;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock colon = strchr(auth + 1, ':');
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock slash = strchr(auth, '/');
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (colon == NULL && slash == NULL)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (NULL);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (colon == NULL)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (slash);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock else if (slash < colon)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (slash);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock else
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (colon);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * List of authority information we care about. Note that we explicitly ignore
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * things that are properties of the chassis and not the resource itself:
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock *
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_PRODUCT_SN "product-sn"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_PRODUCT "product-id"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_DOMAIN "domain-id"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_SERVER "server-id"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_HOST "host-id"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock *
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * We also ignore the "revision" authority member, as that typically indicates
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * the firmware revision and is not a static property of the FRU. This leaves
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * the following interesting members:
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock *
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_AUTH_CHASSIS "chassis-id"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_HC_SERIAL_ID "serial"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * FM_FMRI_HC_PART "part"
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktypedef enum {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock HC_AUTH_CHASSIS,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock HC_AUTH_SERIAL,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock HC_AUTH_PART,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock HC_AUTH_MAX
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock} hc_auth_type_t;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockstatic char *hc_auth_table[] = {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock FM_FMRI_AUTH_CHASSIS,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock FM_FMRI_HC_SERIAL_ID,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock FM_FMRI_HC_PART
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock};
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * Takes an authority member, with leading ":" and trailing "=", and returns
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * one of the above types if it's one of the things we care about. If
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * 'authlen' is specified, it is filled in with the length of the authority
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * member, including leading and trailing characters.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockstatic hc_auth_type_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockhc_auth_to_type(const char *auth, size_t *authlen)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock int i;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock size_t len;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (auth[0] != ':')
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (HC_AUTH_MAX);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock for (i = 0; i < HC_AUTH_MAX; i++) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock len = strlen(hc_auth_table[i]);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (strncmp(auth + 1, hc_auth_table[i], len) == 0 &&
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock auth[len + 1] == '=') {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (authlen)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock *authlen = len + 2;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock break;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (i);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
940d71d237794874e18a0eb72f6564821a823517eschrock/*ARGSUSED*/
940d71d237794874e18a0eb72f6564821a823517eschrockulong_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strhash_internal(topo_hdl_t *thp, const char *fmri, boolean_t noauth)
940d71d237794874e18a0eb72f6564821a823517eschrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *auth, *next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *enclosure;
940d71d237794874e18a0eb72f6564821a823517eschrock ulong_t h;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock hc_auth_type_t type;
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (strncmp(fmri, "hc://", 5) != 0)
940d71d237794874e18a0eb72f6564821a823517eschrock return (topo_fmri_strhash_one(fmri, strlen(fmri)));
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock enclosure = strstr(fmri, SES_ENCLOSURE);
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock h = 0;
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock auth = next = fmri + 5;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock while (*next != '/') {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock auth = next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if ((next = topo_fmri_next_auth(auth)) == NULL) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock next = auth;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock break;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if ((type = hc_auth_to_type(auth, NULL)) == HC_AUTH_MAX)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock continue;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (!noauth || type == HC_AUTH_CHASSIS)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock h += topo_fmri_strhash_one(auth, next - auth);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (enclosure) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock next = enclosure + sizeof (SES_ENCLOSURE);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock while (isdigit(*next))
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock next++;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock h += topo_fmri_strhash_one(next, strlen(next));
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock return (h);
940d71d237794874e18a0eb72f6564821a823517eschrock}
940d71d237794874e18a0eb72f6564821a823517eschrock
940d71d237794874e18a0eb72f6564821a823517eschrock/*ARGSUSED*/
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockulong_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strhash(topo_hdl_t *thp, const char *fmri)
940d71d237794874e18a0eb72f6564821a823517eschrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (topo_fmri_strhash_internal(thp, fmri, B_FALSE));
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*ARGSUSED*/
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockulong_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strhash_noauth(topo_hdl_t *thp, const char *fmri)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (topo_fmri_strhash_internal(thp, fmri, B_TRUE));
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockstatic void
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strcmp_parse_auth(const char *auth, const char *authtype[],
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock size_t authlen[])
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock int i;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock hc_auth_type_t type;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock size_t len;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock for (i = 0; i < HC_AUTH_MAX; i++)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock authlen[i] = 0;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock while (*auth != '/' &&
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock (next = topo_fmri_next_auth(auth)) != NULL) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if ((type = hc_auth_to_type(auth, &len)) == HC_AUTH_MAX) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock auth = next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock continue;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock authtype[type] = auth + len;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock authlen[type] = next - (auth + len);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock auth = next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*ARGSUSED*/
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockstatic boolean_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strcmp_internal(topo_hdl_t *thp, const char *a, const char *b,
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock boolean_t noauth)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *fmria, *fmrib;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock const char *autha[HC_AUTH_MAX], *authb[HC_AUTH_MAX];
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock size_t authlena[HC_AUTH_MAX], authlenb[HC_AUTH_MAX];
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock int i;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock /*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * For non-hc FMRIs, we don't do anything.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
940d71d237794874e18a0eb72f6564821a823517eschrock if (strncmp(a, "hc://", 5) != 0 ||
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock strncmp(b, "hc://", 5) != 0)
940d71d237794874e18a0eb72f6564821a823517eschrock return (strcmp(a, b) == 0);
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock /*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * Get the portion of the FMRI independent of the authority
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * information.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmria = strchr(a + 5, '/');
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmrib = strchr(b + 5, '/');
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (fmria == NULL || fmrib == NULL)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (strcmp(a, b));
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmria++;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmrib++;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock /*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * Comparing fmri authority information is a bit of a pain, because
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * there may be a different number of members, and they can (but
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * shouldn't be) in a different order. We need to create a copy of the
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * authority and parse it into pieces. Because this function is
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * intended to be fast (and not necessarily extensible), we hard-code
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * the list of possible authority members in an enum and parse it into
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * an array.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock topo_fmri_strcmp_parse_auth(a + 5, autha, authlena);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock topo_fmri_strcmp_parse_auth(b + 5, authb, authlenb);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock for (i = 0; i < HC_AUTH_MAX; i++) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (noauth && i != HC_AUTH_CHASSIS)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock continue;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (authlena[i] == 0 && authlenb[i] == 0)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock continue;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (authlena[i] != authlenb[i])
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (B_FALSE);
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (strncmp(autha[i], authb[i], authlena[i]) != 0)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (B_FALSE);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock /*
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * If this is rooted at a ses-enclosure node, skip past the instance
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock * number, as it has no meaning.
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock */
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock if (strncmp(fmria, SES_ENCLOSURE, sizeof (SES_ENCLOSURE) - 1) == 0 &&
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock strncmp(fmrib, SES_ENCLOSURE, sizeof (SES_ENCLOSURE) - 1) == 0) {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmria += sizeof (SES_ENCLOSURE);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmrib += sizeof (SES_ENCLOSURE);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock while (isdigit(*fmria))
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmria++;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock while (isdigit(*fmrib))
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock fmrib++;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock }
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (strcmp(fmria, fmrib) == 0);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
940d71d237794874e18a0eb72f6564821a823517eschrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*ARGSUSED*/
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockboolean_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strcmp(topo_hdl_t *thp, const char *a, const char *b)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (topo_fmri_strcmp_internal(thp, a, b, B_FALSE));
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock}
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock/*ARGSUSED*/
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockboolean_t
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktopo_fmri_strcmp_noauth(topo_hdl_t *thp, const char *a, const char *b)
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock{
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock return (topo_fmri_strcmp_internal(thp, a, b, B_TRUE));
940d71d237794874e18a0eb72f6564821a823517eschrock}
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjint
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_fmri_facility(topo_hdl_t *thp, nvlist_t *rsrc, const char *fac_type,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj uint32_t fac_subtype, topo_walk_cb_t cb, void *cb_args, int *err)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj{
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj int rv;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_t *in = NULL, *out;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj tnode_t *rnode;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj char *scheme;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (nvlist_lookup_string(rsrc, FM_FMRI_SCHEME, &scheme) != 0)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (set_error(thp, ETOPO_FMRI_MALFORM, err,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_METH_PROP_GET, in));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((rnode = topo_hdl_root(thp, scheme)) == NULL)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (set_error(thp, ETOPO_METHOD_NOTSUP, err,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_METH_PROP_GET, in));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (topo_hdl_nvalloc(thp, &in, NV_UNIQUE_NAME) != 0)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (set_error(thp, ETOPO_FMRI_NVL, err,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_METH_PROP_GET, in));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv = nvlist_add_nvlist(in, TOPO_PROP_RESOURCE, rsrc);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_string(in, FM_FMRI_FACILITY_TYPE, fac_type);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_uint32(in, "type", fac_subtype);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj#ifdef _LP64
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_uint64(in, "callback", (uint64_t)cb);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_uint64(in, "callback-args", (uint64_t)cb_args);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj#else
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_uint32(in, "callback", (uint32_t)cb);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv |= nvlist_add_uint32(in, "callback-args", (uint32_t)cb_args);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj#endif
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (rv != 0)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (set_error(thp, ETOPO_FMRI_NVL, err,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_METH_PROP_GET, in));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj rv = topo_method_invoke(rnode, TOPO_METH_FACILITY,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_METH_FACILITY_VERSION, in, &out, err);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_free(in);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (rv != 0)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1); /* *err is set for us */
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj}