7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * See the License for the specific language governing permissions
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and limitations under the License.
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 * CDDL HEADER END
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
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 * 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 * 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 * 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.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check for an existing pgroup
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_method_get(tnode_t *node, topo_propval_t *pv, topo_propmethod_t *pm,
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 if (nvlist_add_nvlist(args, TOPO_PROP_PARGS, pargs) != 0)
5108f83c3f31a54d0e6460b515ff6e776524628drobj * Now, get the latest value
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.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_method_call(node, pm->tpm_name, pm->tpm_version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /* Verify the property contents */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_lookup_string(nvl, TOPO_PROP_VAL_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_lookup_uint32(nvl, TOPO_PROP_VAL_TYPE, (uint32_t *)&type);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi /* Release the last value and re-assign to the new value */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_get(tnode_t *node, const char *pgname, const char *pname, nvlist_t *pargs,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston if (pv->tp_flag & TOPO_PROP_NONVOLATILE && pv->tp_val != NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_method_get(node, pv, pv->tp_method, pargs, err) < 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiprop_getval(tnode_t *node, const char *pgname, const char *pname, void *val,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_int32(pv->tp_val, TOPO_PROP_VAL_VAL,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi ret = nvlist_lookup_int64(pv->tp_val, TOPO_PROP_VAL_VAL,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret == 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (j = 0; j < i; ++j)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (char *));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (char *) * *nelems);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < *nelems; ++i) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (j = 0; j < i; ++j)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int32(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_INT32,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_uint32(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_UINT32,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_int64(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_INT64,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_uint64(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_UINT64,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_get_double(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_DOUBLE,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_string(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_STRING,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_get_fmri(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (prop_getval(node, pgname, pname, (void *)val, TOPO_TYPE_FMRI,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_uint32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_int64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_uint64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_string_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_get_fmri_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindiset_seterror(tnode_t *node, topo_proplist_t *pvl, int *errp, int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_create(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Replace existing prop value with new one
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));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pvl = topo_hdl_zalloc(thp, sizeof (topo_proplist_t)))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pv = topo_hdl_zalloc(thp, sizeof (topo_propval_t)))
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 if (topo_hdl_nvalloc(thp, &nvl, NV_UNIQUE_NAME) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pname);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj *(double *)val);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if (topo_prop_setprop(node, pgname, nvl, flag, nvl, err) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_int32(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT32, flag,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_uint32(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT32, flag,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_int64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT64, flag,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_uint64(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT64, flag,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_set_double(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (topo_prop_set(node, pgname, pname, TOPO_TYPE_DOUBLE, flag,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_string(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_STRING, flag,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_set_fmri(tnode_t *node, const char *pgname, const char *pname,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_FMRI, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_int32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT32_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_uint32_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT32_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_int64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_INT64_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_uint64_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_UINT64_ARRAY, flag,
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_prop_set_string_array(tnode_t *node, const char *pgname, const char *pname,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (topo_prop_set(node, pgname, pname, TOPO_TYPE_STRING_ARRAY, flag,
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 return (topo_prop_set(node, pgname, pname, TOPO_TYPE_FMRI_ARRAY, flag,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * topo_prop_setprop() is a private project function for fmtopo
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_setprop(tnode_t *node, const char *pgname, nvlist_t *prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_string(prop, TOPO_PROP_VAL_NAME, &name) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_uint32(prop, TOPO_PROP_VAL_TYPE, (uint32_t *)&type)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = prop_create(node, pgname, name, type, flag, err)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Set by method or set to new prop value. If we fail, leave
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * property in list with old value.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvalloc(pv->tp_hdl, &args, NV_UNIQUE_NAME) < 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = nvlist_add_nvlist(args, TOPO_PROP_ARGS, pm->tpm_args);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret |= nvlist_add_nvlist(args, TOPO_PROP_PARGS, pargs);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
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 * 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.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi ret = topo_method_call(node, pm->tpm_name, pm->tpm_version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (ret != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiregister_methoderror(tnode_t *node, topo_propmethod_t *pm, int *errp, int l,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (l != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
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 if ((pm = topo_hdl_zalloc(thp, sizeof (topo_propmethod_t))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pm->tpm_name = topo_hdl_strdup(thp, mname)) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(thp, (nvlist_t *)args, &pm->tpm_args) != 0)
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.
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 if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj /* node unlocked */
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
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 return (prop_method_register(node, pgname, pname, ptype, mname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi mp->tim_version, args, err)); /* err set and node unlocked */
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 return (prop_method_register(node, pgname, pname, ptype, mname,
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_method_unregister(tnode_t *node, const char *pgname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pname)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_list); pvl != NULL;
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robjtopo_prop_setmutable(tnode_t *node, const char *pgname, const char *pname,
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * If the property is being inherited then we don't want to allow a
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj * change from IMMUTABLE to MUTABLE.
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (-1);
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnstontopo_prop_setnonvolatile(tnode_t *node, const char *pgname, const char *pname,
e5dcf7beb7c949f9234713d5818b581ec3825443Robert Johnston if ((pv = propval_get(pgroup_get(node, pgname), pname)) == NULL) {
825ba0f20a74fd9c5d0d1ce2c195da2cc88a7f77robj return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_prop_inherit(tnode_t *node, const char *pgname, const char *name, int *err)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * Check if the requested property group and prop val are already set
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * on the node.
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj if (propval_get(pgroup_get(node, pgname), name) != NULL)
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * Check if the requested property group and prop val exists on the
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj * parent node
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = propval_get(pgroup_get(pnode, pgname), name)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOENT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Can this propval be inherited?
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOINHERIT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Property group should already exist: bump the ref count for this
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * propval and add it to the node's property group
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (inherit_seterror(node, err, ETOPO_PROP_NOENT));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((pvl = topo_hdl_zalloc(thp, sizeof (topo_proplist_t)))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_pgroup_info(tnode_t *node, const char *pgname, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindipgroup_seterr(tnode_t *node, topo_pgroup_t *pg, topo_ipgroup_info_t *pip,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pip, sizeof (topo_ipgroup_info_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcinditopo_pgroup_create(tnode_t *node, const topo_pgroup_info_t *pinfo, int *err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check for an existing pgroup
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (strcmp(pg->tpg_info->tpi_name, pinfo->tpi_name) == 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pg = topo_hdl_zalloc(thp, sizeof (topo_pgroup_t))) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pip = topo_hdl_zalloc(thp, sizeof (topo_ipgroup_info_t)))
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((pip->tpi_name = topo_hdl_strdup(thp, pinfo->tpi_name))
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pvl = topo_list_next(&pg->tpg_list)) != NULL) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_hdl_free(thp, pip, sizeof (topo_ipgroup_info_t));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pg = topo_list_next(&node->tn_pgroups)) != NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi while ((pvl = topo_list_next(&pg->tpg_pvals)) != NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindipropmethod_destroy(topo_hdl_t *thp, topo_propval_t *pv)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * topo_prop_getprop() and topo_prop_getprops() are private project functions
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * for fmtopo
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_getprop(tnode_t *node, const char *pgname, const char *pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((pv = prop_get(node, pgname, pname, args, err)) == NULL) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiprop_val_add(tnode_t *node, nvlist_t **nvl, topo_propval_t *pv, int *err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (prop_method_get(node, pv, pv->tp_method, NULL, err) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_hdl_nvdup(pv->tp_hdl, pv->tp_val, nvl) != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiget_pgrp_seterror(tnode_t *node, nvlist_t *nvl, int *errp, int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cinditopo_prop_getpgrp(tnode_t *node, const char *pgname, nvlist_t **pgrp,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_namestab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_datastab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindiget_all_seterror(tnode_t *node, nvlist_t *nvl, int *errp, int err)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, NULL, err, ETOPO_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pg = topo_list_next(&node->tn_pgroups); pg != NULL;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (get_all_seterror(node, nvl, err, ETOPO_NOMEM));
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_namestab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_stability2name(pg->tpg_info->tpi_datastab)) != 0 ||
c40d7343efa60b18ad1ceb316eb337caeea79046cindi for (pvl = topo_list_next(&pg->tpg_pvals); pvl != NULL;