7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/conf.h>
33 #include <sys/stream.h>
34 #include <sys/strsubr.h>
35 #include <sys/modctl.h>
36 #include <sys/modhash.h>
37 #include <sys/atomic.h>
38
39 #include <sys/ddi.h>
40 #include <sys/sunddi.h>
41 #include <sys/t_lock.h>
42
43 /*
44 * This module provides the framework that manage STREAMS modules.
45 * fmodsw_alloc() is called from modconf.c as a result of a module calling
46 * mod_install() and fmodsw_free() is called as the result of the module
47 * calling mod_remove().
48 * fmodsw_find() will find the fmodsw_impl_t structure relating to a named
267
268 i_fmodsw_dprintf(FMODSW_UNREGISTER, "unregistered module '%s'\n",
269 name);
270 return (0);
271 failed:
272 i_fmodsw_dprintf(FMODSW_UNREGISTER, "failed to unregister module "
273 "'%s'\n", name);
274 return (err);
275 }
276
277 fmodsw_impl_t *
278 fmodsw_find(const char *name, fmodsw_flags_t flags)
279 {
280 fmodsw_impl_t *fp;
281 int id;
282
283 try_again:
284 rw_enter(&fmodsw_lock, RW_READER);
285 if (i_fmodsw_hash_find(name, &fp) == 0) {
286 if (flags & FMODSW_HOLD) {
287 atomic_add_32(&(fp->f_ref), 1); /* lock must be held */
288 ASSERT(fp->f_ref > 0);
289 }
290
291 rw_exit(&fmodsw_lock);
292 return (fp);
293 }
294 rw_exit(&fmodsw_lock);
295
296 if (flags & FMODSW_LOAD) {
297 if ((id = modload("strmod", (char *)name)) != -1) {
298 i_fmodsw_dprintf(FMODSW_FIND,
299 "module '%s' loaded: id = %d\n", name, id);
300 goto try_again;
301 }
302 }
303
304 return (NULL);
305 }
306
307 void
308 fmodsw_rele(fmodsw_impl_t *fp)
309 {
310 ASSERT(fp->f_ref > 0);
311 atomic_add_32(&(fp->f_ref), -1);
312 }
|
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/conf.h>
31 #include <sys/stream.h>
32 #include <sys/strsubr.h>
33 #include <sys/modctl.h>
34 #include <sys/modhash.h>
35 #include <sys/atomic.h>
36
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/t_lock.h>
40
41 /*
42 * This module provides the framework that manage STREAMS modules.
43 * fmodsw_alloc() is called from modconf.c as a result of a module calling
44 * mod_install() and fmodsw_free() is called as the result of the module
45 * calling mod_remove().
46 * fmodsw_find() will find the fmodsw_impl_t structure relating to a named
265
266 i_fmodsw_dprintf(FMODSW_UNREGISTER, "unregistered module '%s'\n",
267 name);
268 return (0);
269 failed:
270 i_fmodsw_dprintf(FMODSW_UNREGISTER, "failed to unregister module "
271 "'%s'\n", name);
272 return (err);
273 }
274
275 fmodsw_impl_t *
276 fmodsw_find(const char *name, fmodsw_flags_t flags)
277 {
278 fmodsw_impl_t *fp;
279 int id;
280
281 try_again:
282 rw_enter(&fmodsw_lock, RW_READER);
283 if (i_fmodsw_hash_find(name, &fp) == 0) {
284 if (flags & FMODSW_HOLD) {
285 atomic_inc_32(&(fp->f_ref)); /* lock must be held */
286 ASSERT(fp->f_ref > 0);
287 }
288
289 rw_exit(&fmodsw_lock);
290 return (fp);
291 }
292 rw_exit(&fmodsw_lock);
293
294 if (flags & FMODSW_LOAD) {
295 if ((id = modload("strmod", (char *)name)) != -1) {
296 i_fmodsw_dprintf(FMODSW_FIND,
297 "module '%s' loaded: id = %d\n", name, id);
298 goto try_again;
299 }
300 }
301
302 return (NULL);
303 }
304
305 void
306 fmodsw_rele(fmodsw_impl_t *fp)
307 {
308 ASSERT(fp->f_ref > 0);
309 atomic_dec_32(&(fp->f_ref));
310 }
|