ipath.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * CDDL HEADER START
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * The contents of this file are subject to the terms of the
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * Common Development and Distribution License, Version 1.0 only
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * (the "License"). You may not use this file except in compliance
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * with the License.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * or http://www.opensolaris.org/os/licensing.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * See the License for the specific language governing permissions
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * and limitations under the License.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * When distributing Covered Code, include this CDDL HEADER in each
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * If applicable, add the following below this CDDL HEADER, with the
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * fields enclosed by brackets "[]" replaced with your own identifying
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * information: Portions Copyright [yyyy] [name of copyright owner]
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * CDDL HEADER END
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * Use is subject to license terms.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * ipath.c -- instanced pathname module
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * this module provides a cache of fully instantized component paths,
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * stored in a fairly compact format.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik#pragma ident "%Z%%M% %I% %E% SMI"
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik/* an ipath cache entry is an array of these, with s==NULL at the end */
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik const char *s; /* component name (in stable) */
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik int i; /* instance number */
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvikstatic struct lut *Ipaths; /* the ipath cache itself */
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * ipath_init -- initialize the ipath module
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik Nipath = stats_new_counter("ievent.nipath", "ipath cache entries", 1);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik Nbytes = stats_new_counter("ievent.nbytes", "total cache size", 1);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * ipath_cmp -- compare two ipath entries
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * since two ipaths containing the same components and instance
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * numbers always point to the same cache entry, they are equal
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * if their pointers are equal, so this function is not necessary
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * to test if two ipaths are same. but when inserting a new ipath
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * into the cache, we must use the same lut comparison logic as when
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * we're searching for it, so this function must always match the
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * itree_epnamecmp() function's logic (see below) for searching the lut.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvikipath_cmp(struct ipath *ipp1, struct ipath *ipp2)
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik for (i = 0; ipp1[i].s != NULL && ipp2[i].s != NULL; i++)
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * ipath_epnamecmp -- compare an ipath with a struct node *epname list
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * this function is used when searching the cache, allowing us to search
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * a lut full of ipaths by looking directly at a struct node *epname
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * (without having to convert it first). the comparison logic here must
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * exactly match itree_cmp()'s logic (see above) so lut lookups use find
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik * the same node as lut inserts.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvikipath_epnamecmp(struct ipath *ipp, struct node *np)
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik for (i = 0; ipp[i].s != NULL && np != NULL; i++, np = np->u.name.next) {
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik ASSERTinfo(np->t == T_NAME, ptree_nodetype2str(np->t));
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik config_getcompname(np->u.name.cp, NULL, &inum);
const struct ipath *
int count;
count = 0;
count++;
return (ret);
* name (e.g. "mothboard0/hostbridge0/pcibus1/pcidev0/pcifn1"), depending
char *ret;
char *cp;
len++;
return (ret);
ipp++;
ipath_fini(void)
if (Nipath) {
if (Nbytes) {