hc.c revision 01e689ccb14727455003b77ee332005223497875
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
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#pragma ident "%Z%%M% %I% %E% SMI"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi topo_instance_t, void *, void *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_nvl2str(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_str2nvl(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_compare(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_present(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_unusable(topo_mod_t *, tnode_t *, topo_version_t, nvlist_t *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic int hc_fmri_create_meth(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_prop_get(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_prop_set(topo_mod_t *, tnode_t *, topo_version_t,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic int hc_fmri_pgrp_get(topo_mod_t *, tnode_t *, topo_version_t,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindistatic nvlist_t *hc_fmri_create(topo_mod_t *, nvlist_t *, int, const char *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t inst, const nvlist_t *, const char *, const char *,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi const char *);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_STR2NVL, TOPO_METH_STR2NVL_DESC, TOPO_METH_STR2NVL_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_COMPARE, TOPO_METH_COMPARE_DESC, TOPO_METH_COMPARE_VERSION,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi { TOPO_METH_PRESENT, TOPO_METH_PRESENT_DESC, TOPO_METH_PRESENT_VERSION,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi { TOPO_METH_FMRI, TOPO_METH_FMRI_DESC, TOPO_METH_FMRI_VERSION,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int hc_ncanon = sizeof (hc_canon) / sizeof (hcc_t);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Turn on module debugging output
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_mod_register(mod, &hc_info, TOPO_VERSION) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (0);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_pgroup_create(node, &auth_pgroup, &err) != 0) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Inherit if we can, it saves memory
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
0eb822a1c0c2bea495647510b75f77f0e57633ebcindihc_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t min,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Register root node methods
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "Request to enumerate %s component with an "
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi "ambiguous instance number, min (%d) != max (%d).\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi nvl = hc_fmri_create(mod, pfmri, FM_HC_SCHEME_VERSION, name, min,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((node = topo_node_bind(mod, pnode, name, min, nvl)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindifmri_compare(topo_mod_t *mod, nvlist_t *nv1, nvlist_t *nv2)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi v1 > FM_HC_SCHEME_VERSION || v2 > FM_HC_SCHEME_VERSION)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist_array(nv1, FM_FMRI_HC_LIST, &hcp1, &nhcp1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_lookup_nvlist_array(nv2, FM_FMRI_HC_LIST, &hcp2, &nhcp2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < nhcp1; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp1[i], FM_FMRI_HC_NAME, &nm1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp2[i], FM_FMRI_HC_NAME, &nm2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp1[i], FM_FMRI_HC_ID, &id1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcp2[i], FM_FMRI_HC_ID, &id2);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nm1 == NULL || nm2 == NULL || id1 == NULL || id2 == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_compare(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NV1, &nv1) != 0 ||
12cc75c814f0c017004a9bbc96429911e008601bcindi nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NV2, &nv2) != 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, out, NV_UNIQUE_NAME) == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* Get authority, if present */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist(nvl, FM_FMRI_AUTHORITY, &anvl);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((err = nvlist_lookup_string(nvl, FM_FMRI_HC_ROOT, &root)) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_lookup_nvlist_array(nvl, FM_FMRI_HC_LIST, &hcprs, &hcnprs);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_SERIAL_ID, &serial);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_PART, &part);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(nvl, FM_FMRI_HC_REVISION, &rev);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hc:// */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, FM_FMRI_SCHEME_HC, NULL, "://");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* authority, if any */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, aprod, ":" FM_FMRI_AUTH_PRODUCT "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, achas, ":" FM_FMRI_AUTH_CHASSIS "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, adom, ":" FM_FMRI_AUTH_DOMAIN "=", NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi buf, buflen, asrvr, ":" FM_FMRI_AUTH_SERVER "=", NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hardware-id part */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh buf, buflen, serial, ":" FM_FMRI_HC_SERIAL_ID "=", NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* separating slash */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, "/", NULL, NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* hc-root */
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, root, NULL, NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* all the pairs */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < hcnprs; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcprs[i], FM_FMRI_HC_NAME, &nm);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_lookup_string(hcprs[i], FM_FMRI_HC_ID, &id);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
74a31ce69a88d851777ca840d31ec610ce9ecab3timh topo_fmristr_build(&size, buf, buflen, id, NULL, NULL);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
12cc75c814f0c017004a9bbc96429911e008601bcindi if (topo_mod_nvalloc(mod, &fmristr, NV_UNIQUE_NAME) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_string(fmristr, "fmri-string", name) != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_base_fmri_create(topo_mod_t *mod, const nvlist_t *auth, const char *part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Create base HC nvlist
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_mod_nvalloc(mod, &fmri, NV_UNIQUE_NAME) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err = nvlist_add_uint8(fmri, FM_VERSION, FM_HC_SCHEME_VERSION);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Add optional payload members
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_SERIAL_ID, serial);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_PART, part);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) nvlist_add_string(fmri, FM_FMRI_HC_REVISION, rev);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Count equal signs and slashes to determine how many
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * hc-pairs will be present in the final FMRI. There should
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * be at least as many slashes as equal signs. There can be
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * more, though if the string after an = includes them.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Do we appear to have a well-formed string version of the FMRI?
12cc75c814f0c017004a9bbc96429911e008601bcindi if ((pa = topo_mod_zalloc(mod, npairs * sizeof (nvlist_t *))) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * We go through a pretty complicated procedure to find the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * name and id for each pair. That's because, unfortunately,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * we have some ids that can have slashes within them. So
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * we can't just search for the next slash after the equal sign
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * and decide that starts a new pair. Instead we have to find
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * an equal sign for the next pair and work our way back to the
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * slash from there.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, &pa[i], NV_UNIQUE_NAME) < 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_add_string(pa[i], FM_FMRI_HC_NAME, cname) ||
12cc75c814f0c017004a9bbc96429911e008601bcindi for (i = 0; i < npairs; i++)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindimake_hc_auth(topo_mod_t *mod, char *fmri, char **serial, char **part,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Make sure there are a valid authority members
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * The first colon we encounter must occur before the
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * first slash
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Return possible serial, part and revision
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_str2nvl(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, "fmri-string", &str) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* We're expecting a string version of an hc scheme FMRI */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if ((nf = hc_base_fmri_create(mod, auth, part, rev, serial)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((e = nvlist_add_uint32(nf, FM_FMRI_HC_LIST_SZ, npairs)) == 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi e = nvlist_add_nvlist_array(nf, FM_FMRI_HC_LIST, pa, npairs);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (e != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_dprintf(mod, "construction of new hc nvl failed");
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < npairs; i++)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_list_create(topo_mod_t *mod, const char *name, char *inst)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (err != 0) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_create_seterror(topo_mod_t *mod, nvlist_t **hcl, int n, nvlist_t *fmri,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < n + 1; ++i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mod, hcl, sizeof (nvlist_t *) * (n + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_dprintf(mod, "unable to create hc FMRI: %s\n",
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Only enumerate elements with correct canonical names
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (i = 0; i < hc_ncanon; i++) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindihc_fmri_create(topo_mod_t *mod, nvlist_t *pfmri, int version, const char *name,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_instance_t inst, const nvlist_t *auth, const char *part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Check that the requested name is in our canonical list
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copy the parent's HC_LIST
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_nvlist_array(pfmri, FM_FMRI_HC_LIST,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi hcl = topo_mod_zalloc(mod, sizeof (nvlist_t *) * (pelems + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < pelems; ++i)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((hcl[i] = hc_list_create(mod, name, str)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((fmri = hc_base_fmri_create(mod, auth, part, rev, serial)) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, hcl, pelems + 1)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_mod_free(mod, hcl, sizeof (nvlist_t *) * (pelems + 1));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi/*ARGSUSED*/
0eb822a1c0c2bea495647510b75f77f0e57633ebcindihc_fmri_create_meth(topo_mod_t *mod, tnode_t *node, topo_version_t version,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi /* First the must-have fields */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_string(in, TOPO_METH_FMRI_ARG_NAME, &name) != 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (nvlist_lookup_uint32(in, TOPO_METH_FMRI_ARG_INST, &inst) != 0)
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi * args is optional
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi if ((ret = nvlist_lookup_nvlist(in, TOPO_METH_FMRI_ARG_NVL, &args))
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi /* And then optional arguments */
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_nvlist(args, TOPO_METH_FMRI_ARG_PARENT,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_nvlist(args, TOPO_METH_FMRI_ARG_AUTH,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_PART,
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_REV, &rev);
89c0ae934a35c2ab26de63e1d9fba6bcb04c6306cindi (void) nvlist_lookup_string(args, TOPO_METH_FMRI_ARG_SER,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *out = hc_fmri_create(mod, pfmri, version, name, inst, auth, part,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Generic walker for the hc-scheme topo tree. This function uses the
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * hierachical nature of the hc-scheme to step through efficiently through
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * the topo hc tree. Node lookups are done by topo_walk_byid() at each
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * component level to avoid unnecessary traversal of the tree.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err = nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_ID, &id);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
01e689ccb14727455003b77ee332005223497875cindi * Special case for the root node. We need to walk by siblings
01e689ccb14727455003b77ee332005223497875cindi * until we find a matching node for cases where there may be multiple
01e689ccb14727455003b77ee332005223497875cindi * nodes just below the hc root.
01e689ccb14727455003b77ee332005223497875cindi if (i == 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_mod_dprintf(mod, "hc_walker: walking node:%s=%d for hc:"
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_node_instance(node), name, inst, i, hwp->hcw_end);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * We are at the end of the hc-list. Verify that
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * the last node contains the name/instance we are looking for.
c40d7343efa60b18ad1ceb316eb337caeea79046cindi "complete: terminate walk\n");
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err = nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_NAME, &name);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_string(hwp->hcw_list[i], FM_FMRI_HC_ID, &id);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi topo_mod_dprintf(mod, "hc_walker: walk byid of %s=%d \n", name,
c40d7343efa60b18ad1ceb316eb337caeea79046cindistatic struct hc_walk *
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_walk_init(topo_mod_t *mod, tnode_t *node, nvlist_t *rsrc,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = topo_mod_alloc(mod, sizeof (struct hc_walk))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (nvlist_lookup_nvlist_array(rsrc, FM_FMRI_HC_LIST, &hwp->hcw_list,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((wp = topo_mod_walk_init(mod, node, hc_walker, (void *)hwp, &err))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pl_pgroup;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi const char *pl_pname;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_prop_get(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_getprop(node, plp->pl_pgroup, plp->pl_pname,
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_prop_get(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Private args to prop method are optional
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((err = nvlist_lookup_nvlist(in, TOPO_PROP_PARGS, &plp->pl_args))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_prop_get,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_pgrp_get(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_getpgrp(node, plp->pl_pgroup, &plp->pl_prop, &err);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_pgrp_get(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_pgrp_get,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_prop_setprop(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi struct prop_lookup *plp = (struct prop_lookup *)pdata;
c40d7343efa60b18ad1ceb316eb337caeea79046cindi (void) topo_prop_setprop(node, plp->pl_pgroup, plp->pl_prop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi/*ARGSUSED*/
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_prop_set(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((plp = topo_mod_alloc(mod, sizeof (struct prop_lookup))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_RESOURCE, &plp->pl_rsrc);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_nvlist(in, TOPO_PROP_VAL, &plp->pl_prop);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi err |= nvlist_lookup_int32(in, TOPO_PROP_FLAG, &plp->pl_flag);
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (err != 0) {
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Private args to prop method are optional
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((err = nvlist_lookup_nvlist(in, TOPO_PROP_PARGS, &plp->pl_args))
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, plp->pl_rsrc, hc_prop_setprop,
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_is_present(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * check with the enumerator that created this FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * (topo node)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_PRESENT_VERSION, hap->ha_fmri, &hap->ha_nvl,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Err on the side of caution and return present
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, &hap->ha_nvl, NV_UNIQUE_NAME) == 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_present(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hwp = hc_walk_init(mod, node, hap->ha_fmri, hc_is_present,
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_unusable(topo_mod_t *mod, tnode_t *node, void *pdata)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * check with the enumerator that created this FMRI
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * (topo node)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi TOPO_METH_UNUSABLE_VERSION, hap->ha_fmri, &hap->ha_nvl,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi * Err on the side of caution and return usable
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if (topo_mod_nvalloc(mod, &hap->ha_nvl, NV_UNIQUE_NAME) == 0)
c40d7343efa60b18ad1ceb316eb337caeea79046cindi return (0);
c40d7343efa60b18ad1ceb316eb337caeea79046cindihc_fmri_unusable(topo_mod_t *mod, tnode_t *node, topo_version_t version,
c40d7343efa60b18ad1ceb316eb337caeea79046cindi if ((hap = topo_mod_alloc(mod, sizeof (struct hc_args))) == NULL)