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/*
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <strings.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <assert.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <fm/libtopo.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_prop.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_string.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_alloc.h>
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#include <topo_error.h>
c40d7343efa60b18ad1ceb316eb337caeea79046cindi#include <topo_method.h>
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Topology nodes are permitted to contain property information.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Property information is organized according to property grouping.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Each property group defines a name, a stability level for that name,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * a stability level for all underlying property data (name, type, values),
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * a version for the property group definition and and a list of uniquely
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * defined properties. Property group versions are incremented when one of
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * the following changes occurs:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - a property name changes
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - a property type changes
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * - a property definition is removed from the group
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Compatible changes such as new property definitions in the group do
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * not require version changes.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Each property defines a unique (within the group) name, a type and
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * a value. Properties may be statically defined as int32, uint32, int64,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * uint64, fmri, string or arrays of each type. Properties may also be
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * dynamically exported via module registered methods. For example, a module
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * may register a method to export an ASRU property that is dynamically
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * contructed when a call to topo_node_fmri() is invoked for a particular
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * topology node.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Static properties are persistently attached to topology nodes during
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * enumeration by an enumeration module or as part of XML statements in a
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * toplogy map file using the topo_prop_set* family of routines. Similarly,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * property methods are registered during enumeration or as part of
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * statements in topololgy map files. Set-up of property methods is performed
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * by calling topo_prop_method_register().
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * All properties, whether statically persisted in a snapshot or dynamically
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * obtained, may be read via the topo_prop_get* family of interfaces.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Callers wishing to receive all property groups and properties for a given
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * node may use topo_prop_getall(). This routine returns a nested nvlist
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * of all groupings and property (name, type, value) sets. Groupings
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * are defined by TOPO_PROP_GROUP (name, data stability, name stability and
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * version) and a nested nvlist of properties (TOPO_PROP_VAL). Each property
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * value is defined by its name, type and value.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic void topo_propval_destroy(topo_propval_t *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic topo_pgroup_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindipgroup_get(tnode_t *node, const char *pgname)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check for an existing pgroup
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pg = topo_list_next(pg)) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (strcmp(pg->tpg_info->tpi_name, pgname) == 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (pg);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic topo_propval_t *
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindipropval_get(topo_pgroup_t *pg, const char *pname)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_proplist_t *pvl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pg == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pvl = topo_list_next(pvl)) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (strcmp(pvl->tp_pval->tp_name, pname) == 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (pvl->tp_pval);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindimethod_geterror(nvlist_t *nvl, int err, int *errp)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(nvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_method_get(tnode_t *node, topo_propval_t *pv, topo_propmethod_t *pm,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *pargs, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int ret;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *args, *nvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *name;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t type;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(pv->tp_hdl, &args, NV_UNIQUE_NAME) < 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_nvlist(args, TOPO_PROP_ARGS, pm->tpm_args) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (method_geterror(NULL, ETOPO_PROP_NVL, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pargs != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_nvlist(args, TOPO_PROP_PARGS, pargs) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (method_geterror(args, ETOPO_PROP_NVL, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
5108f83c3f31a54d0e6460b515ff6e776524628drobj /*
5108f83c3f31a54d0e6460b515ff6e776524628drobj * Now, get the latest value
5108f83c3f31a54d0e6460b515ff6e776524628drobj *
5108f83c3f31a54d0e6460b515ff6e776524628drobj * Grab a reference to the property and then unlock the node. This will
5108f83c3f31a54d0e6460b515ff6e776524628drobj * allow property methods to safely re-enter the prop_get codepath,
5108f83c3f31a54d0e6460b515ff6e776524628drobj * making it possible for property methods to access other property
5108f83c3f31a54d0e6460b515ff6e776524628drobj * values on the same node w\o causing a deadlock.
5108f83c3f31a54d0e6460b515ff6e776524628drobj */
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_prop_hold(pv);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_method_call(node, pm->tpm_name, pm->tpm_version,
5108f83c3f31a54d0e6460b515ff6e776524628drobj args, &nvl, err) < 0) {
29852fb9434e36450cf23dc258893a4d2d7a6236robj topo_node_lock(node);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_prop_rele(pv);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (method_geterror(args, *err, err));
5108f83c3f31a54d0e6460b515ff6e776524628drobj }
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_node_lock(node);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_prop_rele(pv);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(args);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /* Verify the property contents */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_lookup_string(nvl, TOPO_PROP_VAL_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0 || strcmp(name, pv->tp_name) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (method_geterror(nvl, ETOPO_PROP_NAME, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_lookup_uint32(nvl, TOPO_PROP_VAL_TYPE, (uint32_t *)&type);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0 || type != pv->tp_type)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (method_geterror(nvl, ETOPO_PROP_TYPE, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /* Release the last value and re-assign to the new value */
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(pv->tp_val);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv->tp_val = nvl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic topo_propval_t *
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_get(tnode_t *node, const char *pgname, const char *pname, nvlist_t *pargs,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOENT;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston if (pv->tp_flag & TOPO_PROP_NONVOLATILE && pv->tp_val != NULL)
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston return (pv);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pv->tp_method != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_method_get(node, pv, pv->tp_method, pargs, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (pv);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindiget_properror(tnode_t *node, int *errp, int err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiprop_getval(tnode_t *node, const char *pgname, const char *pname, void *val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_type_t type, uint_t *nelems, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int i, j, ret = 0;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_propval_t *pv;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = prop_get(node, pgname, pname, NULL, err))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_properror(node, err, *err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pv->tp_type != type)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_properror(node, err, ETOPO_PROP_TYPE));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi switch (type) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT32:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_int32(pv->tp_val, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (int32_t *)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT32:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_uint32(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (uint32_t *)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT64:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_int64(pv->tp_val, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (int64_t *)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT64:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_uint64(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (uint64_t *)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj case TOPO_TYPE_DOUBLE:
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj ret = nvlist_lookup_double(pv->tp_val,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_PROP_VAL_VAL, (double *)val);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_STRING: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi char *str;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_string(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &str);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *s2;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((s2 = topo_hdl_strdup(thp, str)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = -1;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi else
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *(char **)val = s2;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_FMRI: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_t *nvl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_nvlist(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &nvl);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (ret == 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = topo_hdl_nvdup(thp, nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (nvlist_t **)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT32_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int32_t *a1, *a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_int32_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (int32_t) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi a1[i] = a2[i];
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(int32_t **)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT32_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi uint32_t *a1, *a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_uint32_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (uint32_t) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi a1[i] = a2[i];
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(uint32_t **)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT64_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int64_t *a1, *a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_int64_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (int64_t) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi a1[i] = a2[i];
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(int64_t **)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT64_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi uint64_t *a1, *a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_uint64_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (uint64_t) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi a1[i] = a2[i];
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(uint64_t **)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_STRING_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi char **a1, **a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_string_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (char *) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1[i] = topo_hdl_strdup(thp, a2[i]))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (j = 0; j < i; ++j)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, a1[j],
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (char *));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, a1,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (char *) * *nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(char ***)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_FMRI_ARRAY: {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_t **a1, **a2;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((ret = nvlist_lookup_nvlist_array(pv->tp_val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, &a2, nelems)) != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((a1 = topo_hdl_alloc(thp, sizeof (nvlist_t *) *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *nelems)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_hdl_nvdup(thp, a2[i], &a1[i]) < 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (j = 0; j < i; ++j)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_free(a1[j]);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, a1,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (nvlist_t *) * *nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(nvlist_t ***)val = a1;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi default:
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = ETOPO_PROP_NOENT;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (ret != 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (ret == ENOENT)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_properror(node, err, ETOPO_PROP_NOENT));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi else if (ret < ETOPO_UNKNOWN)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_properror(node, err, ETOPO_PROP_NVL));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi else
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_properror(node, err, ret));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int32(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int32_t *val, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_INT32,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_uint32(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi uint32_t *val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_UINT32,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_int64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int64_t *val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_INT64,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_uint64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi uint64_t *val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_UINT64,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjint
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_get_double(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj double *val, int *err)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj{
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_DOUBLE,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj NULL, err));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj}
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_string(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi char **val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_STRING,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_fmri(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi nvlist_t **val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_FMRI,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi NULL, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int32_t **val, uint_t *nelem, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_INT32_ARRAY, nelem, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_uint32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi uint32_t **val, uint_t *nelem, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_UINT32_ARRAY, nelem, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int64_t **val, uint_t *nelem, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_INT64_ARRAY, nelem, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_uint64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi uint64_t **val, uint_t *nelem, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_UINT64_ARRAY, nelem, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_string_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi char ***val, uint_t *nelem, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_STRING_ARRAY, nelem, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_fmri_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_t ***val, uint_t *nelem, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_TYPE_FMRI_ARRAY, nelem, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic topo_propval_t *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiset_seterror(tnode_t *node, topo_proplist_t *pvl, int *errp, int err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_t *thp = node->tn_hdl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_propval_t *pv;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pvl != NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pv = pvl->tp_pval;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_destroy(pv);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pvl, sizeof (topo_proplist_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic topo_propval_t *
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_create(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t type, int flag, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_propval_t *pv;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_proplist_t *pvl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /*
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Replace existing prop value with new one
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi */
12cc75c814f0c017004a9bbc96429911e008601bcindi if ((pg = pgroup_get(node, pgname)) == NULL) {
12cc75c814f0c017004a9bbc96429911e008601bcindi topo_node_unlock(node);
12cc75c814f0c017004a9bbc96429911e008601bcindi *err = ETOPO_PROP_NOENT;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
12cc75c814f0c017004a9bbc96429911e008601bcindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pv = propval_get(pg, pname)) != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (pv->tp_type != type)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (set_seterror(node, NULL, err, ETOPO_PROP_TYPE));
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston else if (! (pv->tp_flag & TOPO_PROP_MUTABLE))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (set_seterror(node, NULL, err, ETOPO_PROP_DEFD));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvlist_free(pv->tp_val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pv->tp_val = NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi } else {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pvl = topo_hdl_zalloc(thp, sizeof (topo_proplist_t)))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (set_seterror(node, NULL, err, ETOPO_NOMEM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pv = topo_hdl_zalloc(thp, sizeof (topo_propval_t)))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (set_seterror(node, pvl, err, ETOPO_NOMEM));
12cc75c814f0c017004a9bbc96429911e008601bcindi
12cc75c814f0c017004a9bbc96429911e008601bcindi pv->tp_hdl = thp;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pvl->tp_pval = pv;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pv->tp_name = topo_hdl_strdup(thp, pname))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (set_seterror(node, pvl, err, ETOPO_NOMEM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pv->tp_flag = flag;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pv->tp_type = type;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_prop_hold(pv);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_list_append(&pg->tpg_pvals, pvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (pv);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_set(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t type, int flag, void *val, int nelems, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int ret;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *nvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &nvl, NV_UNIQUE_NAME) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NVL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pname);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi switch (type) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_INT32:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_int32(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(int32_t *)val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_UINT32:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(uint32_t *)val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_INT64:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_int64(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(int64_t *)val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_UINT64:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint64(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *(uint64_t *)val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj case TOPO_TYPE_DOUBLE:
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj ret |= nvlist_add_double(nvl, TOPO_PROP_VAL_VAL,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj *(double *)val);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_STRING:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_string(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (char *)val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi case TOPO_TYPE_FMRI:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_nvlist(nvl, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (nvlist_t *)val);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT32_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_int32_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (int32_t *)val, nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT32_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint32_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (uint32_t *)val, nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_INT64_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_int64_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (int64_t *)val, nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_UINT64_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint64_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (uint64_t *)val, nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_STRING_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_string_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (char **)val, nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi break;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi case TOPO_TYPE_FMRI_ARRAY:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_nvlist_array(nvl,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi TOPO_PROP_VAL_VAL, (nvlist_t **)val, nelems);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi default:
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_TYPE;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret == ENOMEM) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOMEM;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi } else {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NVL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (topo_prop_setprop(node, pgname, nvl, flag, nvl, err) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(nvl);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1); /* err set */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj nvlist_free(nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (ret);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_int32(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, int32_t val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT32, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi &val, 1, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_uint32(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, uint32_t val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT32, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi &val, 1, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_int64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, int64_t val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT64, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi &val, 1, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_uint64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, uint64_t val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT64, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi &val, 1, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjint
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_set_double(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj int flag, double val, int *err)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj{
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (topo_prop_set(node, pgname, pname, TOPO_TYPE_DOUBLE, flag,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj &val, 1, err));
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj}
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_string(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, const char *val, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_STRING, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void *)val, 1, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_fmri(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi int flag, const nvlist_t *fmri, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_FMRI, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void *)fmri, 1, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_int32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, int32_t *val, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT32_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi val, nelems, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_uint32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, uint32_t *val, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT32_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi val, nelems, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_int64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, int64_t *val, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT64_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi val, nelems, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_uint64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, uint64_t *val, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT64_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi val, nelems, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_string_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, const char **val, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_STRING_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void *)val, nelems, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_fmri_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int flag, const nvlist_t **fmri, uint_t nelems, int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_FMRI_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void *)fmri, nelems, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * topo_prop_setprop() is a private project function for fmtopo
c40d7343efa60b18ad1ceb316eb337caeea79046cindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_setprop(tnode_t *node, const char *pgname, nvlist_t *prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int flag, nvlist_t *pargs, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int ret;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *nvl, *args;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi char *name;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t type;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(prop, TOPO_PROP_VAL_NAME, &name) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NAME;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_uint32(prop, TOPO_PROP_VAL_TYPE, (uint32_t *)&type)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_TYPE;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = prop_create(node, pgname, name, type, flag, err)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1); /* unlocked and err set */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Set by method or set to new prop value. If we fail, leave
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * property in list with old value.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pv->tp_method != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propmethod_t *pm = pv->tp_method;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(pv->tp_hdl, &args, NV_UNIQUE_NAME) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOMEM;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_add_nvlist(args, TOPO_PROP_ARGS, pm->tpm_args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pargs != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_nvlist(args, TOPO_PROP_PARGS, pargs);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NVL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
5108f83c3f31a54d0e6460b515ff6e776524628drobj /*
5108f83c3f31a54d0e6460b515ff6e776524628drobj *
5108f83c3f31a54d0e6460b515ff6e776524628drobj * Grab a reference to the property and then unlock the node.
5108f83c3f31a54d0e6460b515ff6e776524628drobj * This will allow property methods to safely re-enter the
5108f83c3f31a54d0e6460b515ff6e776524628drobj * prop_get codepath, making it possible for property methods
5108f83c3f31a54d0e6460b515ff6e776524628drobj * to access other property values on the same node w\o causing
5108f83c3f31a54d0e6460b515ff6e776524628drobj * a deadlock.
5108f83c3f31a54d0e6460b515ff6e776524628drobj *
5108f83c3f31a54d0e6460b515ff6e776524628drobj * We don't technically need this now, since this interface is
5108f83c3f31a54d0e6460b515ff6e776524628drobj * currently only used by fmtopo (which is single-threaded), but
5108f83c3f31a54d0e6460b515ff6e776524628drobj * we may make this interface available to other parts of
5108f83c3f31a54d0e6460b515ff6e776524628drobj * libtopo in the future, so best to make it MT-safe now.
5108f83c3f31a54d0e6460b515ff6e776524628drobj */
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_prop_hold(pv);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = topo_method_call(node, pm->tpm_name, pm->tpm_version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi args, &nvl, err);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_node_lock(node);
5108f83c3f31a54d0e6460b515ff6e776524628drobj topo_prop_rele(pv);
5108f83c3f31a54d0e6460b515ff6e776524628drobj
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi } else {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((ret = topo_hdl_nvdup(thp, prop, &nvl)) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOMEM;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv->tp_val = nvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindiregister_methoderror(tnode_t *node, topo_propmethod_t *pm, int *errp, int l,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pm != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pm->tpm_name != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_strfree(thp, pm->tpm_name);
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(pm->tpm_args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_free(thp, pm, sizeof (topo_propmethod_t));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *errp = err;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (l != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_method_register(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t ptype, const char *mname, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const nvlist_t *args, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propmethod_t *pm = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pm = topo_hdl_zalloc(thp, sizeof (topo_propmethod_t))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, pm, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_PROP_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pm->tpm_name = topo_hdl_strdup(thp, mname)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, pm, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_PROP_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pm->tpm_version = version;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(thp, (nvlist_t *)args, &pm->tpm_args) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, pm, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_PROP_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj /*
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * It's possible the property may already exist. However we still want
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * to allow the method to be registered. This is to handle the case
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * where we specify a prop method in an xml map to override the value
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * that was set by the enumerator.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj *
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * By default, propmethod-backed properties are not MUTABLE. This is
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * done to simplify the programming model for modules that implement
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * property methods as most propmethods tend to only support get
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * operations. Enumerator modules can override this by calling
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * topo_prop_setmutable(). Propmethods that are registered via XML can
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * be set as mutable via the optional "mutable" attribute, which will
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * result in the xml parser calling topo_prop_setflags() after
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * registering the propmethod.
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj */
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if ((pv = prop_create(node, pgname, pname, ptype,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj TOPO_PROP_IMMUTABLE, err)) == NULL) {
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj /* node unlocked */
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj return (register_methoderror(node, pm, err, 0, *err));
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj if (pv->tp_method != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, pm, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_METHOD_DEFD));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if (pv->tp_val != NULL) {
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj nvlist_free(pv->tp_val);
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj pv->tp_val = NULL;
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv->tp_method = pm;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_method_register(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_type_t ptype, const char *mname, const nvlist_t *args, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_imethod_t *mp;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((mp = topo_method_lookup(node, mname)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, NULL, err, 1,
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj ETOPO_METHOD_NOTSUP)); /* node unlocked */
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (prop_method_register(node, pgname, pname, ptype, mname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi mp->tim_version, args, err)); /* err set and node unlocked */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_method_version_register(tnode_t *node, const char *pgname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pname, topo_type_t ptype, const char *mname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_version_t version, const nvlist_t *args, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_imethod_t *mp;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((mp = topo_method_lookup(node, mname)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, NULL, err, 1,
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj ETOPO_METHOD_NOTSUP)); /* node unlocked */
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj
4557a2a1868181b517f5dfe61ba6eeba58edf4c0robj topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (version < mp->tim_version)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, NULL, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_METHOD_VEROLD));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (version > mp->tim_version)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (register_methoderror(node, NULL, err, 1,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_METHOD_VERNEW));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (prop_method_register(node, pgname, pname, ptype, mname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi version, args, err)); /* err set and node unlocked */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindivoid
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_method_unregister(tnode_t *node, const char *pgname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pname)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_pgroup_t *pg;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_proplist_t *pvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg = topo_list_next(pg)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (strcmp(pg->tpg_info->tpi_name, pgname) == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi break;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pg == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_list); pvl != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pvl = topo_list_next(pvl)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv = pvl->tp_pval;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (strcmp(pv->tp_name, pname) == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_list_delete(&pg->tpg_pvals, pvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi assert(pv->tp_refs == 1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_prop_rele(pv);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_free(thp, pvl, sizeof (topo_proplist_t));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi break;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjint
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_setmutable(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj int *err)
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj{
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_propval_t *pv = NULL;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_node_lock(node);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_node_unlock(node);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj *err = ETOPO_PROP_NOENT;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj }
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj /*
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * If the property is being inherited then we don't want to allow a
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * change from IMMUTABLE to MUTABLE.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj */
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (pv->tp_refs > 1) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_node_unlock(node);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj *err = ETOPO_PROP_DEFD;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj }
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston pv->tp_flag |= TOPO_PROP_MUTABLE;
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston topo_node_unlock(node);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston return (0);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston}
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnstonint
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnstontopo_prop_setnonvolatile(tnode_t *node, const char *pgname, const char *pname,
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston int *err)
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston{
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston topo_propval_t *pv = NULL;
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston topo_node_lock(node);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston topo_node_unlock(node);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston *err = ETOPO_PROP_NOENT;
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston return (-1);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston }
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston pv->tp_flag |= TOPO_PROP_NONVOLATILE;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj topo_node_unlock(node);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj}
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiinherit_seterror(tnode_t *node, int *errp, int err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node->tn_parent);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *errp = err;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_inherit(tnode_t *node, const char *pgname, const char *name, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi tnode_t *pnode = node->tn_parent;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_propval_t *pv;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_proplist_t *pvl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_lock(pnode);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_lock(node);
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj /*
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * Check if the requested property group and prop val are already set
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * on the node.
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj */
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if (propval_get(pgroup_get(node, pgname), name) != NULL)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj return (inherit_seterror(node, err, ETOPO_PROP_DEFD));
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * Check if the requested property group and prop val exists on the
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * parent node
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = propval_get(pgroup_get(pnode, pgname), name)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOENT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Can this propval be inherited?
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston if (pv->tp_flag & TOPO_PROP_MUTABLE)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOINHERIT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Property group should already exist: bump the ref count for this
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * propval and add it to the node's property group
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pg = pgroup_get(node, pgname)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOENT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pvl = topo_hdl_zalloc(thp, sizeof (topo_proplist_t)))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_NOMEM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_prop_hold(pv);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pvl->tp_pval = pv;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_append(&pg->tpg_pvals, pvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(pnode);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_pgroup_info_t *
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_pgroup_info(tnode_t *node, const char *pgname, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_ipgroup_info_t *pip;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_pgroup_info_t *info;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_lock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pg = topo_list_next(pg)) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (strcmp(pgname, pg->tpg_info->tpi_name) == 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((info = topo_hdl_alloc(thp,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (topo_pgroup_info_t))) == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip = pg->tpg_info;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((info->tpi_name =
12cc75c814f0c017004a9bbc96429911e008601bcindi topo_hdl_strdup(thp, pip->tpi_name)) == NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *err = ETOPO_PROP_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, info,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (topo_pgroup_info_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi info->tpi_namestab = pip->tpi_namestab;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi info->tpi_datastab = pip->tpi_datastab;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi info->tpi_version = pip->tpi_version;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (info);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *err = ETOPO_PROP_NOENT;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int
0eb822a1c0c2bea495647510b75f77f0e57633ebcindipgroup_seterr(tnode_t *node, topo_pgroup_t *pg, topo_ipgroup_info_t *pip,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi int *err)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_t *thp = node->tn_hdl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip != NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip->tpi_name != NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_strfree(thp, (char *)pip->tpi_name);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pip, sizeof (topo_ipgroup_info_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pg, sizeof (topo_pgroup_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *err = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiint
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_pgroup_create(tnode_t *node, const topo_pgroup_info_t *pinfo, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_ipgroup_info_t *pip;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *err = 0;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_lock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /*
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check for an existing pgroup
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pg = topo_list_next(pg)) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (strcmp(pg->tpg_info->tpi_name, pinfo->tpi_name) == 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *err = ETOPO_PROP_DEFD;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pg = topo_hdl_zalloc(thp, sizeof (topo_pgroup_t))) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *err = ETOPO_NOMEM;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pip = topo_hdl_zalloc(thp, sizeof (topo_ipgroup_info_t)))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (pgroup_seterr(node, pg, pip, err));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pip->tpi_name = topo_hdl_strdup(thp, pinfo->tpi_name))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi == NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (pgroup_seterr(node, pg, pip, err));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip->tpi_namestab = pinfo->tpi_namestab;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip->tpi_datastab = pinfo->tpi_datastab;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip->tpi_version = pinfo->tpi_version;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pg->tpg_info = pip;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_append(&node->tn_pgroups, pg);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_pgroup_destroy(tnode_t *node, const char *pname)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_proplist_t *pvl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_ipgroup_info_t *pip;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_lock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pg = topo_list_next(pg)) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (strcmp(pg->tpg_info->tpi_name, pname) == 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi break;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (pg == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pvl = topo_list_next(&pg->tpg_list)) != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_delete(&pg->tpg_pvals, pvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_prop_rele(pvl->tp_pval);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_free(thp, pvl, sizeof (topo_proplist_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_delete(&node->tn_pgroups, pg);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip = pg->tpg_info;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip != NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip->tpi_name != NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_strfree(thp, (char *)pip->tpi_name);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pip, sizeof (topo_ipgroup_info_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pg, sizeof (topo_pgroup_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_pgroup_destroy_all(tnode_t *node)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_t *thp = node->tn_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_pgroup_t *pg;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_proplist_t *pvl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_ipgroup_info_t *pip;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_lock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pg = topo_list_next(&node->tn_pgroups)) != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pvl = topo_list_next(&pg->tpg_pvals)) != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_delete(&pg->tpg_pvals, pvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_prop_rele(pvl->tp_pval);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_free(thp, pvl, sizeof (topo_proplist_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_list_delete(&node->tn_pgroups, pg);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi pip = pg->tpg_info;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip != NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (pip->tpi_name != NULL)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_strfree(thp, (char *)pip->tpi_name);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pip, sizeof (topo_pgroup_info_t));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_free(thp, pg, sizeof (topo_pgroup_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi }
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_node_unlock(node);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic void
c40d7343efa60b18ad1ceb316eb337caeea79046cindipropmethod_destroy(topo_hdl_t *thp, topo_propval_t *pv)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propmethod_t *pm;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pm = pv->tp_method;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pm != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pm->tpm_name != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_strfree(thp, pm->tpm_name);
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(pm->tpm_args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_free(thp, pm, sizeof (topo_propmethod_t));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv->tp_method = NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic void
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_propval_destroy(topo_propval_t *pv)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pv == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi thp = pv->tp_hdl;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (pv->tp_name != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_strfree(thp, pv->tp_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(pv->tp_val);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi propmethod_destroy(thp, pv);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_free(thp, pv, sizeof (topo_propval_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_hold(topo_propval_t *pv)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pv->tp_refs++;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindivoid
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_rele(topo_propval_t *pv)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi{
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi pv->tp_refs--;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi assert(pv->tp_refs >= 0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (pv->tp_refs == 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_propval_destroy(pv);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * topo_prop_getprop() and topo_prop_getprops() are private project functions
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * for fmtopo
c40d7343efa60b18ad1ceb316eb337caeea79046cindi */
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_getprop(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *args, nvlist_t **prop, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = prop_get(node, pgname, pname, args, err)) == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) get_properror(node, err, *err);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(thp, pv->tp_val, prop) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) get_properror(node, err, ETOPO_NOMEM);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_val_add(tnode_t *node, nvlist_t **nvl, topo_propval_t *pv, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pv->tp_method != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_method_get(node, pv, pv->tp_method, NULL, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (pv->tp_val == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOENT;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(pv->tp_hdl, pv->tp_val, nvl) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOMEM;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int
c40d7343efa60b18ad1ceb316eb337caeea79046cindiget_pgrp_seterror(tnode_t *node, nvlist_t *nvl, int *errp, int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *errp = err;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindiint
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_getpgrp(tnode_t *node, const char *pgname, nvlist_t **pgrp,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int ret;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *nvl, *pvnvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_pgroup_t *pg;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_proplist_t *pvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &nvl, 0) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_NOMEM;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg = topo_list_next(pg)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (strcmp(pgname, pg->tpg_info->tpi_name) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi continue;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_string(nvl, TOPO_PROP_GROUP_NAME,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg->tpg_info->tpi_name) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_string(nvl, TOPO_PROP_GROUP_NSTAB,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_namestab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_string(nvl, TOPO_PROP_GROUP_DSTAB,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_datastab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_int32(nvl, TOPO_PROP_GROUP_VERSION,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg->tpg_info->tpi_version) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_pgrp_seterror(node, nvl, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_PROP_NVL));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pvl = topo_list_next(pvl)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv = pvl->tp_pval;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_val_add(node, &pvnvl, pv, err) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_pgrp_seterror(node, nvl, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_VAL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pvnvl)) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pvnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_pgrp_seterror(node, nvl, err, ret));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pvnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *pgrp = nvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *err = ETOPO_PROP_NOENT;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic nvlist_t *
c40d7343efa60b18ad1ceb316eb337caeea79046cindiget_all_seterror(tnode_t *node, nvlist_t *nvl, int *errp, int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
aab83bb83be7342f6cfccaed8d5fe0b2f404855dJosef 'Jeff' Sipek nvlist_free(nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi *errp = err;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (NULL);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindinvlist_t *
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_getprops(tnode_t *node, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi{
c40d7343efa60b18ad1ceb316eb337caeea79046cindi int ret;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_hdl_t *thp = node->tn_hdl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_t *nvl, *pgnvl, *pvnvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_pgroup_t *pg;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_propval_t *pv;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_proplist_t *pvl;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_lock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &nvl, 0) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, NULL, err, ETOPO_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg = topo_list_next(pg)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(thp, &pgnvl, 0) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err, ETOPO_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_string(pgnvl, TOPO_PROP_GROUP_NAME,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg->tpg_info->tpi_name) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_string(pgnvl, TOPO_PROP_GROUP_NSTAB,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_namestab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_string(pgnvl, TOPO_PROP_GROUP_DSTAB,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_datastab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_add_int32(pgnvl, TOPO_PROP_GROUP_VERSION,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pg->tpg_info->tpi_version) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ETOPO_PROP_NVL));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pvl = topo_list_next(pvl)) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pv = pvl->tp_pval;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_val_add(node, &pvnvl, pv, err) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pgnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err, *err));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((ret = nvlist_add_nvlist(pgnvl, TOPO_PROP_VAL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi pvnvl)) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pgnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pvnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err, ret));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pvnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_GROUP, pgnvl))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pgnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err, ret));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi nvlist_free(pgnvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi }
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_unlock(node);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (nvl);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi}