xref: /titanic_51/usr/src/uts/common/io/strredirm.c (revision e493d0fad05322dfa9e424b7591501b5f9855a9f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58ec5a142Sedp  * Common Development and Distribution License (the "License").
68ec5a142Sedp  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
218ec5a142Sedp 
227c478bd9Sstevel@tonic-gate /*
238ec5a142Sedp  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Redirection STREAMS module.
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * This module is intended for use in conjunction with instantiations of the
337c478bd9Sstevel@tonic-gate  * redirection driver.  Its purpose in life is to detect when the stream that
347c478bd9Sstevel@tonic-gate  * it's pushed on is closed, thereupon calling back into the redirection
357c478bd9Sstevel@tonic-gate  * driver so that the driver can cancel redirection to the stream.
368ec5a142Sedp  * It passes all messages on unchanged, in both directions.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include <sys/errno.h>
427c478bd9Sstevel@tonic-gate #include <sys/stream.h>
437c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
447c478bd9Sstevel@tonic-gate #include <sys/debug.h>
457c478bd9Sstevel@tonic-gate #include <sys/strredir.h>
468ec5a142Sedp #include <sys/strsubr.h>
47*e493d0faSns92644 #include <sys/strsun.h>
487c478bd9Sstevel@tonic-gate #include <sys/conf.h>
497c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
507c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
517c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * Forward declarations for private routines.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate static int	wcmopen(queue_t	*, dev_t *, int, int, cred_t *);
577c478bd9Sstevel@tonic-gate static int	wcmclose(queue_t *, int, cred_t *);
58*e493d0faSns92644 static int	wcmrput(queue_t *, mblk_t *);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate static struct module_info	wcminfo = {
618ec5a142Sedp 	STRREDIR_MODID,
628ec5a142Sedp 	STRREDIR_MOD,
637c478bd9Sstevel@tonic-gate 	0,
647c478bd9Sstevel@tonic-gate 	INFPSZ,
657c478bd9Sstevel@tonic-gate 	5120,
667c478bd9Sstevel@tonic-gate 	1024
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static struct qinit	wcmrinit = {
70*e493d0faSns92644 	wcmrput,		/* put */
717c478bd9Sstevel@tonic-gate 	NULL,			/* service */
727c478bd9Sstevel@tonic-gate 	wcmopen,		/* open */
737c478bd9Sstevel@tonic-gate 	wcmclose,		/* close */
747c478bd9Sstevel@tonic-gate 	NULL,			/* qadmin */
757c478bd9Sstevel@tonic-gate 	&wcminfo,
767c478bd9Sstevel@tonic-gate 	NULL			/* mstat */
777c478bd9Sstevel@tonic-gate };
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static struct qinit	wcmwinit = {
808ec5a142Sedp 	(int (*)())putnext,	/* put */
817c478bd9Sstevel@tonic-gate 	NULL,			/* service */
827c478bd9Sstevel@tonic-gate 	wcmopen,		/* open */
837c478bd9Sstevel@tonic-gate 	wcmclose,		/* close */
847c478bd9Sstevel@tonic-gate 	NULL,			/* qadmin */
857c478bd9Sstevel@tonic-gate 	&wcminfo,
867c478bd9Sstevel@tonic-gate 	NULL			/* mstat */
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static struct streamtab	redirminfo = {
907c478bd9Sstevel@tonic-gate 	&wcmrinit,
917c478bd9Sstevel@tonic-gate 	&wcmwinit,
927c478bd9Sstevel@tonic-gate 	NULL,
937c478bd9Sstevel@tonic-gate 	NULL
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
977c478bd9Sstevel@tonic-gate 	"redirmod",
987c478bd9Sstevel@tonic-gate 	&redirminfo,
998ec5a142Sedp 	D_MP
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1037c478bd9Sstevel@tonic-gate 	&mod_strmodops,
1047c478bd9Sstevel@tonic-gate 	"redirection module",
1057c478bd9Sstevel@tonic-gate 	&fsw
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1097c478bd9Sstevel@tonic-gate 	MODREV_1, &modlstrmod, NULL
1107c478bd9Sstevel@tonic-gate };
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate int
1137c478bd9Sstevel@tonic-gate _init()
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate int
1197c478bd9Sstevel@tonic-gate _fini()
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	return (EBUSY);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate int
1257c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /* ARGSUSED */
1317c478bd9Sstevel@tonic-gate static int
1327c478bd9Sstevel@tonic-gate wcmopen(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
1337c478bd9Sstevel@tonic-gate {
1347c478bd9Sstevel@tonic-gate 	if (sflag != MODOPEN)
1357c478bd9Sstevel@tonic-gate 		return (EINVAL);
1367c478bd9Sstevel@tonic-gate 	qprocson(q);
1377c478bd9Sstevel@tonic-gate 	return (0);
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /* ARGSUSED */
1417c478bd9Sstevel@tonic-gate static int
1427c478bd9Sstevel@tonic-gate wcmclose(queue_t *q, int flag, cred_t *cred)
1437c478bd9Sstevel@tonic-gate {
1447c478bd9Sstevel@tonic-gate 	qprocsoff(q);
145*e493d0faSns92644 	srpop(q->q_stream->sd_vnode, B_TRUE);
146*e493d0faSns92644 	return (0);
147*e493d0faSns92644 }
148*e493d0faSns92644 
149*e493d0faSns92644 /*
150*e493d0faSns92644  * Upstream messages are passed unchanged.
151*e493d0faSns92644  * If a hangup occurs the target is no longer usable, so deprecate it.
152*e493d0faSns92644  */
153*e493d0faSns92644 static int
154*e493d0faSns92644 wcmrput(queue_t *q, mblk_t *mp)
155*e493d0faSns92644 {
156*e493d0faSns92644 	if (DB_TYPE(mp) == M_HANGUP)
157*e493d0faSns92644 		/* Don't block waiting for outstanding operations to complete */
158*e493d0faSns92644 		srpop(q->q_stream->sd_vnode, B_FALSE);
159*e493d0faSns92644 	putnext(q, mp);
1607c478bd9Sstevel@tonic-gate 	return (0);
1617c478bd9Sstevel@tonic-gate }
162