xref: /titanic_44/usr/src/uts/common/io/strredirm.c (revision 587032cf0967234b39ccb50adca936a367841063)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 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 /*
30  * Redirection STREAMS module.
31  *
32  * This module is intended for use in conjunction with instantiations of the
33  * redirection driver.  Its purpose in life is to detect when the stream that
34  * it's pushed on is closed, thereupon calling back into the redirection
35  * driver so that the driver can cancel redirection to the stream.
36  * It passes all messages on unchanged, in both directions.
37  */
38 
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/errno.h>
42 #include <sys/stream.h>
43 #include <sys/stropts.h>
44 #include <sys/debug.h>
45 #include <sys/strredir.h>
46 #include <sys/strsubr.h>
47 #include <sys/conf.h>
48 #include <sys/ddi.h>
49 #include <sys/sunddi.h>
50 #include <sys/modctl.h>
51 
52 /*
53  * Forward declarations for private routines.
54  */
55 static int	wcmopen(queue_t	*, dev_t *, int, int, cred_t *);
56 static int	wcmclose(queue_t *, int, cred_t *);
57 static int	wcmput(queue_t *, mblk_t *);
58 
59 static struct module_info	wcminfo = {
60 	STRREDIR_MODID,
61 	STRREDIR_MOD,
62 	0,
63 	INFPSZ,
64 	5120,
65 	1024
66 };
67 
68 static struct qinit	wcmrinit = {
69 	(int (*)())putnext,	/* put */
70 	NULL,			/* service */
71 	wcmopen,		/* open */
72 	wcmclose,		/* close */
73 	NULL,			/* qadmin */
74 	&wcminfo,
75 	NULL			/* mstat */
76 };
77 
78 static struct qinit	wcmwinit = {
79 	(int (*)())putnext,	/* put */
80 	NULL,			/* service */
81 	wcmopen,		/* open */
82 	wcmclose,		/* close */
83 	NULL,			/* qadmin */
84 	&wcminfo,
85 	NULL			/* mstat */
86 };
87 
88 static struct streamtab	redirminfo = {
89 	&wcmrinit,
90 	&wcmwinit,
91 	NULL,
92 	NULL
93 };
94 
95 static struct fmodsw fsw = {
96 	"redirmod",
97 	&redirminfo,
98 	D_MP
99 };
100 
101 static struct modlstrmod modlstrmod = {
102 	&mod_strmodops,
103 	"redirection module",
104 	&fsw
105 };
106 
107 static struct modlinkage modlinkage = {
108 	MODREV_1, &modlstrmod, NULL
109 };
110 
111 int
112 _init()
113 {
114 	return (mod_install(&modlinkage));
115 }
116 
117 int
118 _fini()
119 {
120 	return (EBUSY);
121 }
122 
123 int
124 _info(struct modinfo *modinfop)
125 {
126 	return (mod_info(&modlinkage, modinfop));
127 }
128 
129 /* ARGSUSED */
130 static int
131 wcmopen(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
132 {
133 	if (sflag != MODOPEN)
134 		return (EINVAL);
135 	qprocson(q);
136 	return (0);
137 }
138 
139 /* ARGSUSED */
140 static int
141 wcmclose(queue_t *q, int flag, cred_t *cred)
142 {
143 	qprocsoff(q);
144 	srpop(q->q_stream->sd_vnode);
145 	return (0);
146 }
147