static tnode_t * hb_tnode_create(topo_mod_t *mod, tnode_t *parent, const char *name, topo_instance_t i, void *priv) { int err; nvlist_t *fmri; tnode_t *ntn; nvlist_t *auth = topo_mod_auth(mod, parent); fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL, auth, NULL, NULL, NULL); nvlist_free(auth); if (fmri == NULL) { topo_mod_dprintf(mod, "Unable to make nvlist for %s bind: %s.\n", name, topo_mod_errmsg(mod)); return (NULL); } ntn = topo_node_bind(mod, parent, name, i, fmri); if (ntn == NULL) { topo_mod_dprintf(mod, "topo_node_bind (%s%d/%s%d) failed: %s\n", topo_node_name(parent), topo_node_instance(parent), name, i, topo_strerror(topo_mod_errno(mod))); nvlist_free(fmri); return (NULL); } nvlist_free(fmri); topo_node_setspecific(ntn, priv); if (topo_pgroup_create(ntn, &hb_auth_pgroup, &err) == 0) { (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); } if (topo_method_register(mod, ntn, Hb_methods) < 0) { topo_mod_dprintf(mod, "topo_method_register failed: %s\n", topo_strerror(topo_mod_errno(mod))); topo_node_unbind(ntn); return (NULL); } return (ntn); }
tnode_t * topo_node_bind(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t inst, nvlist_t *fmri, void *priv) { int h, err; tnode_t *node; topo_nodehash_t *nhp; topo_node_lock(pnode); for (nhp = topo_list_next(&pnode->tn_children); nhp != NULL; nhp = topo_list_next(nhp)) { if (strcmp(nhp->th_name, name) == 0) { if (inst > nhp->th_range.tr_max || inst < nhp->th_range.tr_min) return (node_bind_seterror(mod, pnode, NULL, ETOPO_NODE_INVAL)); h = topo_node_hash(nhp, inst); if (nhp->th_nodearr[h] != NULL) return (node_bind_seterror(mod, pnode, NULL, ETOPO_NODE_BOUND)); else break; } } if (nhp == NULL) return (node_bind_seterror(mod, pnode, NULL, ETOPO_NODE_NOENT)); if ((node = topo_mod_zalloc(mod, sizeof (tnode_t))) == NULL) return (node_bind_seterror(mod, pnode, NULL, ETOPO_NOMEM)); (void) pthread_mutex_init(&node->tn_lock, NULL); node->tn_enum = mod; node->tn_hdl = mod->tm_hdl; node->tn_parent = pnode; node->tn_name = nhp->th_name; node->tn_instance = inst; node->tn_phash = nhp; node->tn_refs = 0; /* Ref count module that bound this node */ topo_mod_hold(mod); if (fmri == NULL) return (node_bind_seterror(mod, pnode, node, ETOPO_NODE_INVAL)); if (topo_pgroup_create(node, TOPO_PGROUP_PROTOCOL, TOPO_STABILITY_PRIVATE, &err) < 0) return (node_bind_seterror(mod, pnode, node, err)); if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, TOPO_PROP_SET_ONCE, fmri, &err) < 0) return (node_bind_seterror(mod, pnode, node, err)); topo_dprintf(TOPO_DBG_MOD, "node bound %s=%d\n", node->tn_name, node->tn_instance); node->tn_state |= TOPO_NODE_BOUND; node->tn_priv = priv; topo_node_hold(node); nhp->th_nodearr[h] = node; ++pnode->tn_refs; topo_node_unlock(pnode); if (topo_pgroup_create(node, TOPO_PGROUP_SYSTEM, TOPO_STABILITY_PRIVATE, &err) == 0) { (void) topo_prop_inherit(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &err); (void) topo_prop_inherit(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA, &err); (void) topo_prop_inherit(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &err); } return (node); }
/* * Calculate the system information for a node. Inherit the data if * possible, but always create an appropriate property group. */ int x86pi_set_system(topo_mod_t *mod, tnode_t *t_node) { int result; int err; struct utsname uts; char isa[MAXNAMELEN]; if (mod == NULL || t_node == NULL) { return (-1); } result = topo_pgroup_create(t_node, &sys_pgroup, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { /* * We failed to create the property group and it was not * already defined. Set the err code and return failure. */ (void) topo_mod_seterrno(mod, err); return (-1); } result = topo_prop_inherit(t_node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { isa[0] = '\0'; result = sysinfo(SI_ARCHITECTURE, isa, sizeof (isa)); if (result == -1) { /* Preserve the error and continue */ topo_mod_dprintf(mod, "x86pi_set_system: failed to " "read SI_ARCHITECTURE: %d\n", errno); } if (strnlen(isa, MAXNAMELEN) > 0) { result = topo_prop_set_string(t_node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA, TOPO_PROP_IMMUTABLE, isa, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "x86pi_set_auth: failed to " "set property %s (%d) : %s\n", TOPO_PROP_ISA, err, topo_strerror(err)); } } } result = topo_prop_inherit(t_node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { result = uname(&uts); if (result == -1) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, errno); topo_mod_dprintf(mod, "x86pi_set_system: failed to " "read uname: %d\n", errno); } if (strnlen(uts.machine, sizeof (uts.machine)) > 0) { result = topo_prop_set_string(t_node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, TOPO_PROP_IMMUTABLE, uts.machine, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "x86pi_set_auth: failed to " "set property %s (%d) : %s\n", TOPO_PROP_MACHINE, err, topo_strerror(err)); } } } return (0); }
/* * Calculate the authority information for a node. Inherit the data if * possible, but always create an appropriate property group. */ int x86pi_set_auth(topo_mod_t *mod, x86pi_hcfmri_t *hcfmri, tnode_t *t_parent, tnode_t *t_node) { int result; int err; int is_chassis = 0; int chassis_instance = 0; nvlist_t *auth; char *val = NULL; char *prod = NULL; char *psn = NULL; char *csn = NULL; char *server = NULL; char *f = "x86pi_set_auth"; if (mod == NULL || t_parent == NULL || t_node == NULL) { return (-1); } result = topo_pgroup_create(t_node, &auth_pgroup, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { /* * We failed to create the property group and it was not * already defined. Set the err code and return failure. */ (void) topo_mod_seterrno(mod, err); return (-1); } /* Get the authority information already available from the parent */ auth = topo_mod_auth(mod, t_parent); /* Determnine if this is a chassis node and set it's instance */ if ((strlen(hcfmri->hc_name) == strlen(CHASSIS)) && strncmp(hcfmri->hc_name, CHASSIS, strlen(CHASSIS)) == 0) { is_chassis = 1; chassis_instance = hcfmri->instance; } /* * Set the authority data, inheriting it if possible, but creating it * if necessary. */ /* product-id */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { result = nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod); if (result != 0 || prod == NULL) { /* * No product information in the parent node or auth * list. Use the product information in the hcfrmi * struct. */ prod = (char *)hcfmri->product; if (prod == NULL) { topo_mod_dprintf(mod, "%s: product name not " "found for %s node\n", f, hcfmri->hc_name); } } /* * We continue even if the product information is not available * to enumerate as much as possible. */ if (prod != NULL) { result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "%s: failed to set " "property %s (%d) : %s\n", f, FM_FMRI_AUTH_PRODUCT, err, topo_strerror(err)); } } } /* product-sn */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { result = nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &psn); if (result != 0 || psn == NULL) { /* * No product-sn information in the parent node or auth * list. */ topo_mod_dprintf(mod, "%s: psn not found\n", f); } else { /* * We continue even if the product-sn information is * not available to enumerate as much as possible. */ result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "%s: failed to " "set property %s (%d) : %s\n", f, FM_FMRI_AUTH_PRODUCT_SN, err, topo_strerror(err)); } } } /* chassis-id */ if (is_chassis == 0 || (is_chassis == 1 && chassis_instance == 0)) { /* either not a chassis node, or chassis #0 */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); } else { /* chassis 'n' in a >1 chassis system */ result = err = -1; } if (result != 0 && err != ETOPO_PROP_DEFD) { if (is_chassis == 0) { result = nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn); if (result != 0 || csn == NULL) { /* * No chassis information in the parent * node or auth list. */ topo_mod_dprintf(mod, "%s: csn name not found\n", f); } } else { /* * So as not to blindly set the chassis-id to * chassis #0's serial number. */ csn = val = topo_mod_strdup(mod, hcfmri->serial_number); } /* * We continue even if the chassis information is not available * to enumerate as much as possible. */ if (csn != NULL) { if (is_chassis == 1) result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, TOPO_PROP_MUTABLE, csn, &err); else result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, TOPO_PROP_IMMUTABLE, csn, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "%s: failed to " "set property %s (%d) : %s\n", f, FM_FMRI_AUTH_CHASSIS, err, topo_strerror(err)); } } if (val != NULL) { topo_mod_strfree(mod, val); val = NULL; } } /* server-id */ result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); if (result != 0 && err != ETOPO_PROP_DEFD) { result = nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server); if (result != 0 || server == NULL) { /* * No server information in the parent node or auth * list. Find the server information in hostname. */ server = val = x86pi_get_serverid(mod); if (server == NULL) { topo_mod_dprintf(mod, "%s: server " "name not found for %s node\n", f, hcfmri->hc_name); } } /* * We continue even if the server information is not available * to enumerate as much as possible. */ if (server != NULL) { result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, TOPO_PROP_IMMUTABLE, server, &err); if (result != 0) { /* Preserve the error and continue */ (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "%s: failed to " "set property %s (%d) : %s\n", f, FM_FMRI_AUTH_SERVER, err, topo_strerror(err)); } } if (val != NULL) topo_mod_strfree(mod, val); } nvlist_free(auth); return (0); }