topo_module.c revision 724365f7556fc4201fdb11766ebc6bd918523130
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * CDDL HEADER START
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * The contents of this file are subject to the terms of the
724365f7556fc4201fdb11766ebc6bd918523130sethg * Common Development and Distribution License (the "License").
724365f7556fc4201fdb11766ebc6bd918523130sethg * 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
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Use is subject to license terms.
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi#pragma ident "%Z%%M% %I% %E% SMI"
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Lazy unload module
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_dprintf(TOPO_DBG_MOD, "module %s stopped\n", mod->tm_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_dprintf(TOPO_DBG_MOD, "starting module %s\n", mod->tm_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (-1);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_dprintf(TOPO_DBG_MOD, "module %s started\n", mod->tm_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (0);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) strlcpy(name, topo_strbasename(path), sizeof (name));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((p = strrchr(name, '.')) != NULL && strcmp(p, ".so") == 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *p = '\0'; /* strip trailing .so from any module name */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindiset_create_error(topo_hdl_t *thp, topo_mod_t *mod, const char *path, int err)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_dprintf(TOPO_DBG_ERR, "unable to load module %s: %s\n",
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_mod_create(topo_hdl_t *thp, const char *name, const char *path,
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if (topo_modhash_lookup(thp->th_modhash, name) != NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_create_error(thp, NULL, path, ETOPO_MOD_LOADED));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((mod = topo_hdl_zalloc(thp, sizeof (topo_mod_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_create_error(thp, mod, path, ETOPO_NOMEM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi mod->tm_rootdir = topo_hdl_strdup(thp, thp->th_rootdir);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_create_error(thp, mod, path, ETOPO_NOMEM));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi * Module will be held upon a successful return from topo_mod_start()
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi return (set_create_error(thp, mod, path, mod->tm_errno));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_dprintf(TOPO_DBG_MOD, "loaded module %s\n", mod->tm_name);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((mhp = topo_hdl_zalloc(thp, sizeof (topo_modhash_t))) == NULL)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi topo_hdl_free(thp, mhp->mh_hash, sizeof (void *) * mhp->mh_hashlen);
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_modhash_lookup(topo_modhash_t *mhp, const char *name)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (mod = mhp->mh_hash[h]; mod != NULL; mod = mod->tm_next) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecinditopo_modhash_load(topo_hdl_t *thp, const char *path, const topo_modops_t *ops)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi (void) strlcpy(name, topo_strbasename(path), sizeof (name));
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((p = strrchr(name, '.')) != NULL && strcmp(p, ".so") == 0)
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi *p = '\0'; /* strip trailing .so from any module name */
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi if ((mod = topo_mod_create(thp, name, path, ops)) == NULL) {
7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fecindi for (i = 0; i < TOPO_HASH_BUCKETS; ++i) {