int topo_file_load(topo_hdl_t *thp, topo_mod_t *mod, ttree_t *tp) { topo_file_t *tfp; if ((tfp = topo_hdl_zalloc(thp, sizeof (topo_file_t))) == NULL) return (topo_hdl_seterrno(thp, ETOPO_NOMEM)); tp->tt_file = tfp; tfp->tf_mod = mod; if (xml_read(thp, tp) < 0) { topo_file_unload(thp, tp); return (-1); } if (topo_xml_enum(tfp->tf_mod, tfp->tf_fileinfo, tp->tt_root) < 0) { topo_dprintf(TOPO_DBG_ERR, "Failed to enumerate topology: %s\n", topo_strerror(topo_hdl_errno(thp))); topo_file_unload(thp, tp); return (-1); } return (0); }
static ttree_t * set_create_error(topo_hdl_t *thp, ttree_t *tp, int err) { if (tp != NULL) topo_tree_destroy(tp); if (err != 0) (void) topo_hdl_seterrno(thp, err); return (NULL); }
static int topo_tree_enum(topo_hdl_t *thp, ttree_t *tp) { int rv = 0; char *pp; /* * Attempt to enumerate the tree from a topology map in the * following order: * <product-name>-<scheme>-topology * <platform-name>-<scheme>-topology (uname -i) * <machine-name>-<scheme>-topology (uname -m) * <scheme>-topology * * Trim any SUNW, from the product or platform name * before loading file */ if (thp->th_product == NULL || (pp = strchr(thp->th_product, ',')) == NULL) pp = thp->th_product; else pp++; if (topo_file_load(tp->tt_root->tn_enum, tp->tt_root, pp, tp->tt_scheme, 0) < 0) { if ((pp = strchr(thp->th_platform, ',')) == NULL) pp = thp->th_platform; else pp++; if (topo_file_load(tp->tt_root->tn_enum, tp->tt_root, pp, tp->tt_scheme, 0) < 0) { if (topo_file_load(tp->tt_root->tn_enum, tp->tt_root, thp->th_machine, tp->tt_scheme, 0) < 0) { if ((rv = topo_file_load(tp->tt_root->tn_enum, tp->tt_root, NULL, tp->tt_scheme, 0)) < 0) { topo_dprintf(thp, TOPO_DBG_ERR, "no " "topology map found for the %s " "FMRI set\n", tp->tt_scheme); } } } } if (rv != 0) return (topo_hdl_seterrno(thp, ETOPO_ENUM_NOMAP)); return (0); }
static int xml_read(topo_hdl_t *hp, ttree_t *tp) { topo_file_t *tfp; char *pplat, *pmach; int err, e; char _topo_file[MAXNAMELEN * 2]; char _topo_path[PATH_MAX]; tfp = (topo_file_t *)tp->tt_file; (void) snprintf(_topo_file, 2 * MAXNAMELEN, TOPO_DEFAULT_FILE, tp->tt_scheme); /* * Look for a platform-specific topology file first */ e = topo_prop_get_string(tp->tt_root, TOPO_PGROUP_SYSTEM, TOPO_PROP_PLATFORM, &pplat, &err); if (e < 0) return (topo_hdl_seterrno(hp, err)); (void) snprintf(_topo_path, PATH_MAX, PLATFORM_TOPO_PATH, hp->th_rootdir, pplat, _topo_file); tfp->tf_fileinfo = topo_xml_read(tfp->tf_mod, _topo_path, tp->tt_scheme); if (tfp->tf_fileinfo != NULL) { topo_hdl_strfree(hp, pplat); return (0); } topo_dprintf(TOPO_DBG_MOD, "failed to load topology file %s: %s\n", _topo_path, topo_strerror(topo_hdl_errno(hp))); /* * No luck with the platform-specific file, how about a * machine-specific one? */ e = topo_prop_get_string(tp->tt_root, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, &pmach, &err); if (e < 0) { topo_hdl_strfree(hp, pplat); return (topo_hdl_seterrno(hp, err)); } /* * Don't waste time trying to open the same file twice in the * cases where the platform name is identical to the machine * name */ if (strcmp(pplat, pmach) != 0) { (void) snprintf(_topo_path, PATH_MAX, PLATFORM_TOPO_PATH, hp->th_rootdir, pmach, _topo_file); tfp->tf_fileinfo = topo_xml_read(tfp->tf_mod, _topo_path, tp->tt_scheme); } if (tfp->tf_fileinfo != NULL) { topo_hdl_strfree(hp, pplat); topo_hdl_strfree(hp, pmach); return (0); } else { topo_dprintf(TOPO_DBG_MOD, "failed to load topology file %s: %s\n", _topo_path, topo_strerror(topo_hdl_errno(hp))); } topo_hdl_strfree(hp, pplat); topo_hdl_strfree(hp, pmach); (void) snprintf(_topo_path, PATH_MAX, COMMON_TOPO_PATH, hp->th_rootdir, _topo_file); tfp->tf_fileinfo = topo_xml_read(tfp->tf_mod, _topo_path, tp->tt_scheme); if (tfp->tf_fileinfo == NULL) { topo_dprintf(TOPO_DBG_MOD, "failed to load topology file %s: %s\n", _topo_path, topo_strerror(topo_hdl_errno(hp))); return (topo_hdl_seterrno(hp, ETOPO_FILE_NOENT)); } return (0); }