xref: /titanic_51/usr/src/uts/common/sys/fs/fifonode.h (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 
30 #ifndef	_SYS_FS_FIFONODE_H
31 #define	_SYS_FS_FIFONODE_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.15	*/
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 
40 /*
41  * Each FIFOFS object is identified by a struct fifonode/vnode pair.
42  * This is also the hierarchy
43  * flk_lock protects:
44  *		fn_mp
45  *		fn_tail
46  *		fn_count
47  *		fn_flag
48  *		fn_wcnt
49  *		fn_rcnt
50  *		fn_open
51  *		fn_rsynccnt
52  *		fn_wsynccnt
53  *		fn_wwaitcnt
54  *		fn_atime
55  *		fn_mtime
56  *		fn_ctime
57  *		fn_insync
58  *		flk_ref
59  *		flk_ocsync
60  * ftable lock protects		- actually this is independent
61  *		fifoalloc[]
62  *		fn_nextp
63  *		fn_backp
64  */
65 typedef struct fifolock {
66 	kmutex_t	flk_lock;	/* fifo lock */
67 	int		flk_ref;	/* number of fifonodes using this */
68 	short		flk_ocsync;	/* sync open/close */
69 	kcondvar_t	flk_wait_cv;	/* conditional for flk_ocsync */
70 	uint_t		flk_fill[4];	/* cache align lock structure */
71 } fifolock_t;
72 
73 typedef struct fifonode fifonode_t;
74 
75 struct fifonode {
76 	struct vnode	*fn_vnode;	/* represents the fifo/pipe */
77 	struct vnode	*fn_realvp;	/* node being shadowed by fifo */
78 	ino_t		fn_ino;		/* node id for pipes */
79 	fifonode_t	*fn_dest;	/* the other end of a pipe */
80 	struct msgb	*fn_mp;		/* message waiting to be read */
81 	struct msgb	*fn_tail;	/* last message to read */
82 	fifolock_t	*fn_lock;	/* pointer to per fifo lock */
83 	uint_t		fn_count;	/* Number of bytes on fn_mp */
84 	kcondvar_t	fn_wait_cv;	/* fifo conditional variable */
85 	ushort_t	fn_wcnt;	/* number of writers */
86 	ushort_t	fn_rcnt;	/* number of readers */
87 	ushort_t	fn_open;	/* open count of node */
88 	ushort_t	fn_wsynccnt;	/* fifos waiting for open write sync */
89 	ushort_t	fn_rsynccnt;	/* fifos waiting for open read sync */
90 	ushort_t	fn_wwaitcnt;	/* threads waiting to write data */
91 	time_t		fn_atime;	/* access times */
92 	time_t		fn_mtime;	/* modification time */
93 	time_t		fn_ctime;	/* change time */
94 	fifonode_t	*fn_nextp;	/* next link in the linked list */
95 	fifonode_t	*fn_backp;	/* back link in linked list */
96 	struct cred	*fn_pcredp;	/* credential associated with peer */
97 	pid_t		fn_cpid;	/* original peer pid */
98 	int		fn_insync;
99 	uint_t		fn_flag;	/* flags as defined below */
100 };
101 
102 
103 typedef struct fifodata {
104 	fifolock_t	fifo_lock;
105 	fifonode_t	fifo_fnode[2];
106 } fifodata_t;
107 
108 /*
109  * Valid flags for fifonodes.
110  */
111 #define	ISPIPE		0x0001	/* fifonode is that of a pipe */
112 #define	FIFOSEND	0x0002	/* file descriptor at stream head of pipe */
113 #define	FIFOOPEN	0x0004	/* fifo is opening */
114 #define	FIFOCLOSE	0x0008	/* fifo is closing */
115 #define	FIFOCONNLD	0x0010	/* connld pushed on pipe */
116 #define	FIFOFAST	0x0020	/* FIFO in fast mode */
117 #define	FIFOWANTR	0x0040	/* reader waiting for data */
118 #define	FIFOWANTW	0x0080	/* writer waiting to write */
119 #define	FIFOSETSIG	0x0100	/* I_SETSIG ioctl was issued */
120 #define	FIFOHIWATW	0x0200	/* We have gone over hi water mark */
121 #define	FIFORWBUSY	0x0400	/* Fifo is busy in read or write */
122 #define	FIFOPOLLW	0x0800	/* process waiting on poll write */
123 #define	FIFOPOLLR	0x1000	/* process waiting on poll read */
124 #define	FIFOISOPEN	0x2000	/* pipe is open */
125 #define	FIFOSYNC	0x4000	/* FIFO is waiting for open sync */
126 #define	FIFOWOCR	0x8000	/* Write open occurred */
127 #define	FIFOROCR	0x10000	/* Read open occurred */
128 /*
129  * process waiting on poll read on band data
130  * this can only occur if we go to streams
131  * mode
132  */
133 #define	FIFOPOLLRBAND	0x20000
134 #define	FIFOSTAYFAST	0x40000	/* don't turn into stream mode */
135 #define	FIFOWAITMODE	0x80000	/* waiting for the possibility to change mode */
136 
137 #define	FIFOHIWAT	(16 * 1024)
138 #define	FIFOLOWAT	(0)
139 
140 /*
141  * Macros to convert a vnode to a fifnode, and vice versa.
142  */
143 #define	VTOF(vp) ((struct fifonode *)((vp)->v_data))
144 #define	FTOV(fp) ((fp)->fn_vnode)
145 
146 #if defined(_KERNEL)
147 
148 /*
149  * Fifohiwat defined as a variable is to allow tuning of the high
150  * water mark if needed. It is not meant to be released.
151  */
152 #if FIFODEBUG
153 extern int Fifohiwat;
154 #else /* FIFODEBUG */
155 #define	Fifohiwat	FIFOHIWAT
156 #endif /* FIFODEBUG */
157 
158 extern struct vnodeops *fifo_vnodeops;
159 extern const struct fs_operation_def fifo_vnodeops_template[];
160 extern struct kmem_cache *fnode_cache;
161 extern struct kmem_cache *pipe_cache;
162 
163 struct vfssw;
164 struct queue;
165 
166 extern int	fifoinit(int, char *);
167 extern int	fifo_stropen(vnode_t **, int, cred_t *, int, int);
168 extern int	fifo_open(vnode_t **, int, cred_t *, caller_context_t *);
169 extern int	fifo_close(vnode_t *, int, int, offset_t, cred_t *,
170 			caller_context_t *);
171 extern void	fifo_cleanup(vnode_t *, int);
172 extern void	fiforemove(fifonode_t *);
173 extern ino_t	fifogetid(void);
174 extern vnode_t	*fifovp(vnode_t *, cred_t *);
175 extern void	makepipe(vnode_t **, vnode_t **);
176 extern void	fifo_fastflush(fifonode_t *);
177 extern void	fifo_vfastoff(vnode_t *);
178 extern void	fifo_fastoff(fifonode_t *);
179 extern struct streamtab *fifo_getinfo();
180 extern void	fifo_wakereader(fifonode_t *, fifolock_t *);
181 extern void	fifo_wakewriter(fifonode_t *, fifolock_t *);
182 
183 #endif /* _KERNEL */
184 
185 #ifdef	__cplusplus
186 }
187 #endif
188 
189 #endif	/* _SYS_FS_FIFONODE_H */
190