xref: /illumos-gate/usr/src/uts/common/sys/fs/fifonode.h (revision b4203d75)
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
539cba716Swroche  * Common Development and Distribution License (the "License").
639cba716Swroche  * 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  */
217c478bd9Sstevel@tonic-gate /*
22d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_FIFONODE_H
317c478bd9Sstevel@tonic-gate #define	_SYS_FS_FIFONODE_H
327c478bd9Sstevel@tonic-gate 
33d67944fbSScott Rotondo #if defined(_KERNEL)
34d67944fbSScott Rotondo #include <sys/vfs_opreg.h>
35d67944fbSScott Rotondo #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * Each FIFOFS object is identified by a struct fifonode/vnode pair.
447c478bd9Sstevel@tonic-gate  * This is also the hierarchy
457c478bd9Sstevel@tonic-gate  * flk_lock protects:
467c478bd9Sstevel@tonic-gate  *		fn_mp
477c478bd9Sstevel@tonic-gate  *		fn_tail
487c478bd9Sstevel@tonic-gate  *		fn_count
497c478bd9Sstevel@tonic-gate  *		fn_flag
507c478bd9Sstevel@tonic-gate  *		fn_wcnt
517c478bd9Sstevel@tonic-gate  *		fn_rcnt
527c478bd9Sstevel@tonic-gate  *		fn_open
537c478bd9Sstevel@tonic-gate  *		fn_rsynccnt
547c478bd9Sstevel@tonic-gate  *		fn_wsynccnt
557c478bd9Sstevel@tonic-gate  *		fn_wwaitcnt
567c478bd9Sstevel@tonic-gate  *		fn_atime
577c478bd9Sstevel@tonic-gate  *		fn_mtime
587c478bd9Sstevel@tonic-gate  *		fn_ctime
597c478bd9Sstevel@tonic-gate  *		fn_insync
607c478bd9Sstevel@tonic-gate  *		flk_ref
617c478bd9Sstevel@tonic-gate  *		flk_ocsync
627c478bd9Sstevel@tonic-gate  * ftable lock protects		- actually this is independent
637c478bd9Sstevel@tonic-gate  *		fifoalloc[]
647c478bd9Sstevel@tonic-gate  *		fn_nextp
657c478bd9Sstevel@tonic-gate  *		fn_backp
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef struct fifolock {
687c478bd9Sstevel@tonic-gate 	kmutex_t	flk_lock;	/* fifo lock */
697c478bd9Sstevel@tonic-gate 	int		flk_ref;	/* number of fifonodes using this */
707c478bd9Sstevel@tonic-gate 	short		flk_ocsync;	/* sync open/close */
717c478bd9Sstevel@tonic-gate 	kcondvar_t	flk_wait_cv;	/* conditional for flk_ocsync */
727c478bd9Sstevel@tonic-gate 	uint_t		flk_fill[4];	/* cache align lock structure */
737c478bd9Sstevel@tonic-gate } fifolock_t;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate typedef struct fifonode fifonode_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate struct fifonode {
787c478bd9Sstevel@tonic-gate 	struct vnode	*fn_vnode;	/* represents the fifo/pipe */
797c478bd9Sstevel@tonic-gate 	struct vnode	*fn_realvp;	/* node being shadowed by fifo */
807c478bd9Sstevel@tonic-gate 	ino_t		fn_ino;		/* node id for pipes */
817c478bd9Sstevel@tonic-gate 	fifonode_t	*fn_dest;	/* the other end of a pipe */
827c478bd9Sstevel@tonic-gate 	struct msgb	*fn_mp;		/* message waiting to be read */
837c478bd9Sstevel@tonic-gate 	struct msgb	*fn_tail;	/* last message to read */
847c478bd9Sstevel@tonic-gate 	fifolock_t	*fn_lock;	/* pointer to per fifo lock */
857c478bd9Sstevel@tonic-gate 	uint_t		fn_count;	/* Number of bytes on fn_mp */
867c478bd9Sstevel@tonic-gate 	kcondvar_t	fn_wait_cv;	/* fifo conditional variable */
877c478bd9Sstevel@tonic-gate 	ushort_t	fn_wcnt;	/* number of writers */
887c478bd9Sstevel@tonic-gate 	ushort_t	fn_rcnt;	/* number of readers */
897c478bd9Sstevel@tonic-gate 	ushort_t	fn_open;	/* open count of node */
907c478bd9Sstevel@tonic-gate 	ushort_t	fn_wsynccnt;	/* fifos waiting for open write sync */
917c478bd9Sstevel@tonic-gate 	ushort_t	fn_rsynccnt;	/* fifos waiting for open read sync */
927c478bd9Sstevel@tonic-gate 	ushort_t	fn_wwaitcnt;	/* threads waiting to write data */
937c478bd9Sstevel@tonic-gate 	time_t		fn_atime;	/* access times */
947c478bd9Sstevel@tonic-gate 	time_t		fn_mtime;	/* modification time */
957c478bd9Sstevel@tonic-gate 	time_t		fn_ctime;	/* change time */
967c478bd9Sstevel@tonic-gate 	fifonode_t	*fn_nextp;	/* next link in the linked list */
977c478bd9Sstevel@tonic-gate 	fifonode_t	*fn_backp;	/* back link in linked list */
987c478bd9Sstevel@tonic-gate 	struct cred	*fn_pcredp;	/* credential associated with peer */
997c478bd9Sstevel@tonic-gate 	pid_t		fn_cpid;	/* original peer pid */
1007c478bd9Sstevel@tonic-gate 	int		fn_insync;
1017c478bd9Sstevel@tonic-gate 	uint_t		fn_flag;	/* flags as defined below */
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate typedef struct fifodata {
1067c478bd9Sstevel@tonic-gate 	fifolock_t	fifo_lock;
1077c478bd9Sstevel@tonic-gate 	fifonode_t	fifo_fnode[2];
1087c478bd9Sstevel@tonic-gate } fifodata_t;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Valid flags for fifonodes.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate #define	ISPIPE		0x0001	/* fifonode is that of a pipe */
1147c478bd9Sstevel@tonic-gate #define	FIFOSEND	0x0002	/* file descriptor at stream head of pipe */
1157c478bd9Sstevel@tonic-gate #define	FIFOOPEN	0x0004	/* fifo is opening */
1167c478bd9Sstevel@tonic-gate #define	FIFOCLOSE	0x0008	/* fifo is closing */
1177c478bd9Sstevel@tonic-gate #define	FIFOCONNLD	0x0010	/* connld pushed on pipe */
1187c478bd9Sstevel@tonic-gate #define	FIFOFAST	0x0020	/* FIFO in fast mode */
1197c478bd9Sstevel@tonic-gate #define	FIFOWANTR	0x0040	/* reader waiting for data */
1207c478bd9Sstevel@tonic-gate #define	FIFOWANTW	0x0080	/* writer waiting to write */
1217c478bd9Sstevel@tonic-gate #define	FIFOSETSIG	0x0100	/* I_SETSIG ioctl was issued */
1227c478bd9Sstevel@tonic-gate #define	FIFOHIWATW	0x0200	/* We have gone over hi water mark */
1237c478bd9Sstevel@tonic-gate #define	FIFORWBUSY	0x0400	/* Fifo is busy in read or write */
1247c478bd9Sstevel@tonic-gate #define	FIFOPOLLW	0x0800	/* process waiting on poll write */
1257c478bd9Sstevel@tonic-gate #define	FIFOPOLLR	0x1000	/* process waiting on poll read */
1267c478bd9Sstevel@tonic-gate #define	FIFOISOPEN	0x2000	/* pipe is open */
1277c478bd9Sstevel@tonic-gate #define	FIFOSYNC	0x4000	/* FIFO is waiting for open sync */
128da6c28aaSamw #define	FIFOWOCR	0x8000	/* Write open occurred */
129da6c28aaSamw #define	FIFOROCR	0x10000	/* Read open occurred */
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * process waiting on poll read on band data
1327c478bd9Sstevel@tonic-gate  * this can only occur if we go to streams
1337c478bd9Sstevel@tonic-gate  * mode
1347c478bd9Sstevel@tonic-gate  */
13539cba716Swroche #define	FIFOPOLLRBAND	0x20000
13639cba716Swroche #define	FIFOSTAYFAST	0x40000	/* don't turn into stream mode */
13739cba716Swroche #define	FIFOWAITMODE	0x80000	/* waiting for the possibility to change mode */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	FIFOHIWAT	(16 * 1024)
1407c478bd9Sstevel@tonic-gate #define	FIFOLOWAT	(0)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * Macros to convert a vnode to a fifnode, and vice versa.
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate #define	VTOF(vp) ((struct fifonode *)((vp)->v_data))
1467c478bd9Sstevel@tonic-gate #define	FTOV(fp) ((fp)->fn_vnode)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Fifohiwat defined as a variable is to allow tuning of the high
1527c478bd9Sstevel@tonic-gate  * water mark if needed. It is not meant to be released.
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate #if FIFODEBUG
1557c478bd9Sstevel@tonic-gate extern int Fifohiwat;
1567c478bd9Sstevel@tonic-gate #else /* FIFODEBUG */
1577c478bd9Sstevel@tonic-gate #define	Fifohiwat	FIFOHIWAT
1587c478bd9Sstevel@tonic-gate #endif /* FIFODEBUG */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate extern struct vnodeops *fifo_vnodeops;
1617c478bd9Sstevel@tonic-gate extern const struct fs_operation_def fifo_vnodeops_template[];
1627c478bd9Sstevel@tonic-gate extern struct kmem_cache *fnode_cache;
1637c478bd9Sstevel@tonic-gate extern struct kmem_cache *pipe_cache;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate struct vfssw;
1667c478bd9Sstevel@tonic-gate struct queue;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate extern int	fifoinit(int, char *);
1697c478bd9Sstevel@tonic-gate extern int	fifo_stropen(vnode_t **, int, cred_t *, int, int);
170da6c28aaSamw extern int	fifo_open(vnode_t **, int, cred_t *, caller_context_t *);
171da6c28aaSamw extern int	fifo_close(vnode_t *, int, int, offset_t, cred_t *,
172da6c28aaSamw 			caller_context_t *);
1737c478bd9Sstevel@tonic-gate extern void	fifo_cleanup(vnode_t *, int);
1747c478bd9Sstevel@tonic-gate extern void	fiforemove(fifonode_t *);
1757c478bd9Sstevel@tonic-gate extern ino_t	fifogetid(void);
1767c478bd9Sstevel@tonic-gate extern vnode_t	*fifovp(vnode_t *, cred_t *);
1777c478bd9Sstevel@tonic-gate extern void	makepipe(vnode_t **, vnode_t **);
1787c478bd9Sstevel@tonic-gate extern void	fifo_fastflush(fifonode_t *);
1797c478bd9Sstevel@tonic-gate extern void	fifo_vfastoff(vnode_t *);
1807c478bd9Sstevel@tonic-gate extern void	fifo_fastoff(fifonode_t *);
1817c478bd9Sstevel@tonic-gate extern struct streamtab *fifo_getinfo();
1827c478bd9Sstevel@tonic-gate extern void	fifo_wakereader(fifonode_t *, fifolock_t *);
1837c478bd9Sstevel@tonic-gate extern void	fifo_wakewriter(fifonode_t *, fifolock_t *);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate #endif
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_FIFONODE_H */
192