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