ipath.c revision 27134bda765f3e2c7e4bfd072058f72e509b39bc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* ipath.c -- instanced pathname module
*
* this module provides a cache of fully instantized component paths,
* stored in a fairly compact format.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include "alloc.h"
#include "out.h"
#include "lut.h"
#include "tree.h"
#include "ptree.h"
#include "itree.h"
#include "ipath.h"
#include "ipath_impl.h"
#include "stats.h"
#include "eval.h"
#include "config.h"
/*
* ipath_init -- initialize the ipath module
*/
void
ipath_init(void)
{
}
/*
* ipath_cmp -- compare two ipath entries
*
* since two ipaths containing the same components and instance
* numbers always point to the same cache entry, they are equal
* if their pointers are equal, so this function is not necessary
* to test if two ipaths are same. but when inserting a new ipath
* into the cache, we must use the same lut comparison logic as when
* we're searching for it, so this function must always match the
* itree_epnamecmp() function's logic (see below) for searching the lut.
*/
static int
{
int i;
return (0);
return (1);
else
return (-1);
}
/*
* ipath_epnamecmp -- compare an ipath with a struct node *epname list
*
* this function is used when searching the cache, allowing us to search
* a lut full of ipaths by looking directly at a struct node *epname
* (without having to convert it first). the comparison logic here must
* exactly match itree_cmp()'s logic (see above) so lut lookups use find
* the same node as lut inserts.
*/
static int
{
int i;
else {
int inum;
else
}
}
return (0);
return (1);
else
return (-1);
}
void
{
ipp++;
}
ipp++;
}
}
struct ipath *
{
ipp++;
return (ret);
ret[0].i = 0;
return (ipp);
}
return (ret);
}
/*
* ipath -- find instanced path in cache, or add it if necessary
*/
const struct ipath *
{
int count;
int i;
return (ret); /* already in cache */
/*
* not in cache, make new cache entry.
* start by counting the length of the name.
*/
count = 0;
count++;
}
/* allocate array for name and last NULL entry */
/* fill in ipath entry */
i = 0;
else
i++;
}
/* add it to the cache */
return (ret);
}
/*
* ipath2str -- convert ename and ipath to class@path string
*
* if both ename and ipp are provided (non-NULL), the resulting string
* will be "class@path". otherwise, the string will just contain the
* event class name (e.g. "ereport.io.pci.device") or just the path
* name (e.g. "mothboard0/hostbridge0/pcibus1/pcidev0/pcifn1"), depending
* on which argument is non-NULL.
*/
char *
{
int i;
char *ret;
char *cp;
/* count up length of class string */
/* count up length of path string, including slash separators */
/* add slash separator, but no leading slash */
if (i != 0)
len++;
}
}
len++; /* room for '@' */
len++; /* room for final '\0' */
/* construct class string */
}
/* if doing both strings, put '@' between them */
*cp++ = '@';
/* construct path string */
if (i != 0)
*cp++ = '/';
}
}
*cp++ = '\0';
return (ret);
}
/*
* ipath2strlen -- calculate the len of what ipath2str() would return
*/
{
int i;
/* count up length of class string */
/* count up length of path string, including slash separators */
/* add slash separator, but no leading slash */
if (i != 0)
len++;
}
}
len++; /* room for '@' */
return (len);
}
/*
* ipath_print -- print out an ename, ipath, or both with '@' between them
*/
void
{
}
char *sep = "";
ipp++;
sep = "/";
}
}
}
/*ARGSUSED*/
static void
{
}
/*
* ipath_fini -- free the ipath cache
*/
void
ipath_fini(void)
{
if (Nipath) {
}
if (Nbytes) {
}
}