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