xref: /onnv-gate/usr/src/uts/common/sys/strredir.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1990-1998 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_STRREDIR_H
28*0Sstevel@tonic-gate #define	_SYS_STRREDIR_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * strredir.h:	Declarations for the redirection driver and its matching
38*0Sstevel@tonic-gate  *		STREAMS module.
39*0Sstevel@tonic-gate  */
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate  * The module's module id.
43*0Sstevel@tonic-gate  *
44*0Sstevel@tonic-gate  * XXX:	Since there's no authority responsible for administering this name
45*0Sstevel@tonic-gate  *	space, there's no guarantee that this value is unique.  That wouldn't
46*0Sstevel@tonic-gate  *	be so bad except that the DKI now suggests that ioctl cookie values
47*0Sstevel@tonic-gate  *	should be based on module id to make them unique...
48*0Sstevel@tonic-gate  */
49*0Sstevel@tonic-gate #define	_STRREDIR_MODID	7326
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate /*
52*0Sstevel@tonic-gate  * Redirection ioctls:
53*0Sstevel@tonic-gate  */
54*0Sstevel@tonic-gate #define	SRIOCSREDIR	((_STRREDIR_MODID<<16) | 1)	/* set redir target */
55*0Sstevel@tonic-gate #define	SRIOCISREDIR	((_STRREDIR_MODID<<16) | 2)	/* is redir target? */
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate /*
59*0Sstevel@tonic-gate  * Everything from here on is of interest only to the kernel.
60*0Sstevel@tonic-gate  */
61*0Sstevel@tonic-gate #ifdef	_KERNEL
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate #include <sys/types.h>
64*0Sstevel@tonic-gate #include <sys/cred.h>
65*0Sstevel@tonic-gate #include <sys/vnode.h>
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate  * Per-open instance driver state information.
69*0Sstevel@tonic-gate  *
70*0Sstevel@tonic-gate  * The underlying device potentially can be opened through (at least) two
71*0Sstevel@tonic-gate  * paths:  through this driver and through the underlying device's driver.  To
72*0Sstevel@tonic-gate  * ensure that reference counts are meaningful and therefore that close
73*0Sstevel@tonic-gate  * routines are called at the right time, it's important to make sure that the
74*0Sstevel@tonic-gate  * snode for the underlying device instance never has a contribution of more
75*0Sstevel@tonic-gate  * than one through this driver, regardless of how many times this driver's
76*0Sstevel@tonic-gate  * been opened.  The wd_wsconsopen field keeps track of the necessary
77*0Sstevel@tonic-gate  * information to ensure this property.
78*0Sstevel@tonic-gate  *
79*0Sstevel@tonic-gate  * The structure also contains copies of the flag and cred values supplied
80*0Sstevel@tonic-gate  * when the device instance was first opened, so that it's possible to reopen
81*0Sstevel@tonic-gate  * the underlying device in srreset.
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate typedef struct wcd_data {
84*0Sstevel@tonic-gate 	struct wcd_data	*wd_next;	/* link to next open instance */
85*0Sstevel@tonic-gate 	minor_t		wd_unit;	/* minor device # for this instance */
86*0Sstevel@tonic-gate 	struct wcrlist	*wd_list;	/* the head of the redirection list */
87*0Sstevel@tonic-gate 	vnode_t		*wd_vp;		/* underlying device instance vnode */
88*0Sstevel@tonic-gate 	int		wd_wsconsopen;	/* see above */
89*0Sstevel@tonic-gate 	int		wd_flag;	/* see above */
90*0Sstevel@tonic-gate 	cred_t		*wd_cred;	/* see above */
91*0Sstevel@tonic-gate } wcd_data_t;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /*
94*0Sstevel@tonic-gate  * Per-open instance module state information.
95*0Sstevel@tonic-gate  *
96*0Sstevel@tonic-gate  * An invariant:  when wm_wd is non-NULL, wm_entry is also non-NULL and is on
97*0Sstevel@tonic-gate  * the list rooted at wm_wd->wd_list.
98*0Sstevel@tonic-gate  */
99*0Sstevel@tonic-gate typedef struct wcm_data {
100*0Sstevel@tonic-gate 	struct wcd_data	*wm_wd;		/* Xref to redir driver data */
101*0Sstevel@tonic-gate 	struct wcrlist	*wm_entry;	/* Redir entry that refers to us */
102*0Sstevel@tonic-gate } wcm_data_t;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate /*
105*0Sstevel@tonic-gate  * We record the list of redirections as a linked list of wcrlist
106*0Sstevel@tonic-gate  * structures.
107*0Sstevel@tonic-gate  *
108*0Sstevel@tonic-gate  * We need to keep track of:
109*0Sstevel@tonic-gate  * 1)	The target's vp, so that we can vector reads, writes, etc. off to the
110*0Sstevel@tonic-gate  *	current designee.
111*0Sstevel@tonic-gate  * 2)	The per-open instance private data structure of the redirmod module
112*0Sstevel@tonic-gate  *	instance we push onto the target stream, so that we can clean up there
113*0Sstevel@tonic-gate  *	when we go away.  (I'm not sure that this is actually necessary.)
114*0Sstevel@tonic-gate  */
115*0Sstevel@tonic-gate typedef struct wcrlist {
116*0Sstevel@tonic-gate 	struct wcrlist	*wl_next;	/* next entry */
117*0Sstevel@tonic-gate 	vnode_t		*wl_vp;		/* target's vnode */
118*0Sstevel@tonic-gate 	struct wcm_data	*wl_data;	/* target's redirmod private data */
119*0Sstevel@tonic-gate } wcrlist_t;
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate /*
122*0Sstevel@tonic-gate  * A given instance of the redirection driver must be able to open the
123*0Sstevel@tonic-gate  * corresponding instance of the underlying device when the redirection list
124*0Sstevel@tonic-gate  * empties.  To do so it needs a vnode for the underlying instance.  The
125*0Sstevel@tonic-gate  * underlying driver is responsible for supplying routines for producing and
126*0Sstevel@tonic-gate  * disposing of this vnode.  The get routine must return a held vnode, so that
127*0Sstevel@tonic-gate  * it can't vanish while the redirecting driver is using it.
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate typedef struct srvnops {
130*0Sstevel@tonic-gate 	int	(*svn_get)();	/* (minor #, vpp) --> errno value */
131*0Sstevel@tonic-gate 	void	(*svn_rele)();	/* (minor #, vp) */
132*0Sstevel@tonic-gate } srvnops_t;
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate extern void srpop(wcm_data_t *, int, cred_t *);
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate #endif	/* _KERNEL */
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #ifdef	__cplusplus
139*0Sstevel@tonic-gate }
140*0Sstevel@tonic-gate #endif
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate #endif	/* _SYS_STRREDIR_H */
143