xref: /illumos-gate/usr/src/uts/common/sys/fs/snode.h (revision 2d6eb4a5)
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
5feb08c6bSbillm  * Common Development and Distribution License (the "License").
6feb08c6bSbillm  * 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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22feb08c6bSbillm /*	  All Rights Reserved	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*e7cbe64fSgw  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_SNODE_H
317c478bd9Sstevel@tonic-gate #define	_SYS_FS_SNODE_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
357c478bd9Sstevel@tonic-gate #include <sys/cred.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * The snode represents a special file in any filesystem.  There is
407c478bd9Sstevel@tonic-gate  * one snode for each active special file.  Filesystems that support
417c478bd9Sstevel@tonic-gate  * special files use specvp(vp, dev, type, cr) to convert a normal
427c478bd9Sstevel@tonic-gate  * vnode to a special vnode in the ops lookup() and create().
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * To handle having multiple snodes that represent the same
457c478bd9Sstevel@tonic-gate  * underlying device vnode without cache aliasing problems,
467c478bd9Sstevel@tonic-gate  * the s_commonvp is used to point to the "common" vnode used for
477c478bd9Sstevel@tonic-gate  * caching data.  If an snode is created internally by the kernel,
487c478bd9Sstevel@tonic-gate  * then the s_realvp field is NULL and s_commonvp points to s_vnode.
497c478bd9Sstevel@tonic-gate  * The other snodes which are created as a result of a lookup of a
507c478bd9Sstevel@tonic-gate  * device in a file system have s_realvp pointing to the vp which
517c478bd9Sstevel@tonic-gate  * represents the device in the file system while the s_commonvp points
527c478bd9Sstevel@tonic-gate  * into the "common" vnode for the device in another snode.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Include SUNDDI type definitions so that the s_dip tag doesn't urk.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
617c478bd9Sstevel@tonic-gate extern "C" {
627c478bd9Sstevel@tonic-gate #endif
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate struct snode {
657c478bd9Sstevel@tonic-gate 	/* These fields are protected by stable_lock */
667c478bd9Sstevel@tonic-gate 	struct	snode *s_next;		/* must be first */
677c478bd9Sstevel@tonic-gate 	struct	vnode *s_vnode;		/* vnode associated with this snode */
687c478bd9Sstevel@tonic-gate 	/*
697c478bd9Sstevel@tonic-gate 	 * These fields are initialized once.
707c478bd9Sstevel@tonic-gate 	 */
717c478bd9Sstevel@tonic-gate 	struct	vnode *s_realvp;	/* vnode for the fs entry (if any) */
727c478bd9Sstevel@tonic-gate 	struct	vnode *s_commonvp;	/* common device vnode */
737c478bd9Sstevel@tonic-gate 	dev_t	s_dev;			/* device the snode represents */
747c478bd9Sstevel@tonic-gate 	dev_info_t *s_dip;		/* dev_info (common snode only) */
757c478bd9Sstevel@tonic-gate 	/*
767c478bd9Sstevel@tonic-gate 	 * Doesn't always need to be updated atomically because it is a hint.
777c478bd9Sstevel@tonic-gate 	 * No lock required.
787c478bd9Sstevel@tonic-gate 	 */
797c478bd9Sstevel@tonic-gate 	u_offset_t s_nextr;		/* next byte read offset (read-ahead) */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/* These fields are protected by spec_syncbusy */
827c478bd9Sstevel@tonic-gate 	struct	snode *s_list;		/* used for syncing */
837c478bd9Sstevel@tonic-gate 	/* These fields are protected by s_lock */
847c478bd9Sstevel@tonic-gate 	struct devplcy *s_plcy;		/* device node open policy (cs only) */
857c478bd9Sstevel@tonic-gate 	u_offset_t s_size;		/* block device size in bytes */
8641162575Svikram 	uint_t	s_flag;			/* flags, see below */
877c478bd9Sstevel@tonic-gate 	dev_t	s_fsid;			/* file system identifier */
887c478bd9Sstevel@tonic-gate 	time_t  s_atime;		/* time of last access */
897c478bd9Sstevel@tonic-gate 	time_t  s_mtime;		/* time of last modification */
907c478bd9Sstevel@tonic-gate 	time_t  s_ctime;		/* time of last attributes change */
917c478bd9Sstevel@tonic-gate 	int	s_count;		/* count of opened references */
927c478bd9Sstevel@tonic-gate 	long	s_mapcnt;		/* count of mappings of pages */
937c478bd9Sstevel@tonic-gate 	/* The locks themselves */
947c478bd9Sstevel@tonic-gate 	kmutex_t	s_lock;		/* protects snode fields */
957c478bd9Sstevel@tonic-gate 	kcondvar_t	s_cv;		/* synchronize open/closes */
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* flags */
997c478bd9Sstevel@tonic-gate #define	SUPD		0x01		/* update device access time */
1007c478bd9Sstevel@tonic-gate #define	SACC		0x02		/* update device modification time */
1017c478bd9Sstevel@tonic-gate #define	SCHG		0x04		/* update device change time */
1027c478bd9Sstevel@tonic-gate #define	SPRIV		0x08		/* file open for private access */
1037c478bd9Sstevel@tonic-gate #define	SLOFFSET	0x10		/* device takes 64-bit uio offsets */
1047c478bd9Sstevel@tonic-gate #define	SLOCKED		0x20		/* use to serialize open/closes */
1057c478bd9Sstevel@tonic-gate #define	SWANT		0x40		/* some process waiting on lock */
1067c478bd9Sstevel@tonic-gate #define	SANYOFFSET	0x80		/* device takes any uio offset */
1077c478bd9Sstevel@tonic-gate #define	SCLONE		0x100		/* represents a cloned device */
1087c478bd9Sstevel@tonic-gate #define	SNEEDCLOSE	0x200		/* needs driver close call */
1097c478bd9Sstevel@tonic-gate #define	SDIPSET		0x400		/* the vnode has an association with */
1107c478bd9Sstevel@tonic-gate 					/* the driver, even though it may */
1117c478bd9Sstevel@tonic-gate 					/* not currently have an association */
1127c478bd9Sstevel@tonic-gate 					/* with a specific hardware instance */
1137c478bd9Sstevel@tonic-gate 					/* if s_dip is NULL */
1147c478bd9Sstevel@tonic-gate #define	SSIZEVALID	0x800		/* s_size field is valid */
1157c478bd9Sstevel@tonic-gate #define	SMUXED		0x1000		/* this snode is a stream that has */
1167c478bd9Sstevel@tonic-gate 					/* been multiplexed */
1177c478bd9Sstevel@tonic-gate #define	SSELFCLONE	0x2000		/* represents a self cloning device */
118feb08c6bSbillm #define	SNOFLUSH	0x4000		/* do not flush device on fsync */
119e099bf07Scth #define	SCLOSING	0x8000		/* in last close(9E) */
12025e8c5aaSvikram #define	SFENCED		0x10000		/* snode fenced off for I/O retire */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * Convert between vnode and snode
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate #define	VTOS(vp)	((struct snode *)((vp)->v_data))
1277c478bd9Sstevel@tonic-gate #define	VTOCS(vp)	(VTOS(VTOS(vp)->s_commonvp))
1287c478bd9Sstevel@tonic-gate #define	STOV(sp)	((sp)->s_vnode)
1297c478bd9Sstevel@tonic-gate 
13025e8c5aaSvikram extern int spec_debug;
13125e8c5aaSvikram 
13225e8c5aaSvikram #define	SPEC_FENCE_DEBUG	0x0001	/* emit fence related debug messages */
13325e8c5aaSvikram 
13425e8c5aaSvikram #define	FENDBG(args)	if (spec_debug & SPEC_FENCE_DEBUG) cmn_err args
13525e8c5aaSvikram 
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * Forward declarations
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate struct vfssw;
1417c478bd9Sstevel@tonic-gate struct cred;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate extern struct vfs	spec_vfs;
1447c478bd9Sstevel@tonic-gate extern struct vfsops	spec_vfsops;
1457c478bd9Sstevel@tonic-gate extern struct kmem_cache *snode_cache;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * specfs functions
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate offset_t	spec_maxoffset(struct vnode *);
1517c478bd9Sstevel@tonic-gate struct vnodeops	*spec_getvnodeops(void);
1527c478bd9Sstevel@tonic-gate struct vnode *specvp(struct vnode *, dev_t, vtype_t, struct cred *);
1537c478bd9Sstevel@tonic-gate struct vnode *makespecvp(dev_t, vtype_t);
1547c478bd9Sstevel@tonic-gate struct vnode *other_specvp(struct vnode *);
1557c478bd9Sstevel@tonic-gate struct vnode *common_specvp(struct vnode *);
1567c478bd9Sstevel@tonic-gate struct vnode *specfind(dev_t, vtype_t);
1577c478bd9Sstevel@tonic-gate struct vnode *commonvp(dev_t, vtype_t);
1587c478bd9Sstevel@tonic-gate struct vnode *makectty(vnode_t *);
1597c478bd9Sstevel@tonic-gate void	sdelete(struct snode *);
1607c478bd9Sstevel@tonic-gate void 	smark(struct snode *, int);
1617c478bd9Sstevel@tonic-gate int	specinit(int, char *);
1627c478bd9Sstevel@tonic-gate int	device_close(struct vnode *, int, struct cred *);
163da6c28aaSamw int	spec_putpage(struct vnode *, offset_t, size_t, int, struct cred *,
164da6c28aaSamw 		caller_context_t *);
1657c478bd9Sstevel@tonic-gate int	spec_segmap(dev_t, off_t, struct as *, caddr_t *, off_t,
1667c478bd9Sstevel@tonic-gate 		    uint_t, uint_t, uint_t, cred_t *);
1677c478bd9Sstevel@tonic-gate struct vnode *specvp_devfs(struct vnode *, dev_t, vtype_t,
1687c478bd9Sstevel@tonic-gate 		    struct cred *, dev_info_t *);
1697c478bd9Sstevel@tonic-gate void	spec_assoc_vp_with_devi(struct vnode *, dev_info_t *);
1707c478bd9Sstevel@tonic-gate dev_info_t *spec_hold_devi_by_vp(struct vnode *);
1717c478bd9Sstevel@tonic-gate int	spec_sync(struct vfs *, short, struct cred *);
1727c478bd9Sstevel@tonic-gate void	spec_snode_walk(int (*callback)(struct snode *, void *), void *);
1737c478bd9Sstevel@tonic-gate int	spec_devi_open_count(struct snode *, dev_info_t **);
1747c478bd9Sstevel@tonic-gate int	spec_is_clone(struct vnode *);
1757c478bd9Sstevel@tonic-gate int	spec_is_selfclone(struct vnode *);
17625e8c5aaSvikram int	spec_fence_snode(dev_info_t *dip, struct vnode *vp);
17725e8c5aaSvikram int	spec_unfence_snode(dev_info_t *dip);
178*e7cbe64fSgw void	spec_size_invalidate(dev_t, vtype_t);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * UNKNOWN_SIZE: If driver does not support the [Ss]ize or [Nn]blocks property
1837c478bd9Sstevel@tonic-gate  * then the size is assumed to be "infinite".  Note that this "infinite" value
1847c478bd9Sstevel@tonic-gate  * may need to be converted to a smaller "infinite" value to avoid EOVERFLOW at
1857c478bd9Sstevel@tonic-gate  * field width conversion locations like the stat(2) and NFS code running
1867c478bd9Sstevel@tonic-gate  * against a special file.  Special file code outside specfs may check the
1877c478bd9Sstevel@tonic-gate  * type of the vnode (VCHR|VBLK) and use MAXOFFSET_T directly to detect
1887c478bd9Sstevel@tonic-gate  * UNKNOWN_SIZE.
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate #define	UNKNOWN_SIZE		MAXOFFSET_T
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate  * SPEC_MAXOFFSET_T: Solaris does not fully support 64-bit offsets for D_64BIT
1947c478bd9Sstevel@tonic-gate  * (SLOFFSET) block drivers on a 32-bit kernels: daddr_t is still a signed
1957c478bd9Sstevel@tonic-gate  * 32-bit quantity - which limits the byte offset to 1TB. This issue goes
1967c478bd9Sstevel@tonic-gate  * beyond a driver needing to convert from daddr_t to diskaddr_t if it sets
1977c478bd9Sstevel@tonic-gate  * D_64BIT. Many of the DDI interfaces which take daddr_t arguments have no
1987c478bd9Sstevel@tonic-gate  * 64-bit counterpart (bioclone, blkflush, bread, bread_common, breada, getblk,
1997c478bd9Sstevel@tonic-gate  * getblk_common). SPEC_MAXOFFSET_T is used by 32-bit kernel code to enforce
2007c478bd9Sstevel@tonic-gate  * this restriction.
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate #ifdef	_ILP32
2037c478bd9Sstevel@tonic-gate #ifdef	_LONGLONG_TYPE
2047c478bd9Sstevel@tonic-gate #define	SPEC_MAXOFFSET_T	((1LL << ((NBBY * sizeof (daddr32_t)) +	\
2057c478bd9Sstevel@tonic-gate 				DEV_BSHIFT - 1)) - 1)
2067c478bd9Sstevel@tonic-gate #else	/* !defined(_LONGLONG_TYPE) */
2077c478bd9Sstevel@tonic-gate #define	SPEC_MAXOFFSET_T	MAXOFF_T
2087c478bd9Sstevel@tonic-gate #endif	/* _LONGLONG_TYPE */
2097c478bd9Sstevel@tonic-gate #endif	/* _ILP32 */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * Snode lookup stuff.
2137c478bd9Sstevel@tonic-gate  * These routines maintain a table of snodes hashed by dev so
2147c478bd9Sstevel@tonic-gate  * that the snode for an dev can be found if it already exists.
2157c478bd9Sstevel@tonic-gate  * NOTE: STABLESIZE must be a power of 2 for STABLEHASH to work!
2167c478bd9Sstevel@tonic-gate  */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate #define	STABLESIZE	256
2197c478bd9Sstevel@tonic-gate #define	STABLEHASH(dev)	((getmajor(dev) + getminor(dev)) & (STABLESIZE - 1))
2207c478bd9Sstevel@tonic-gate extern struct snode *stable[];
2217c478bd9Sstevel@tonic-gate extern kmutex_t	stable_lock;
2227c478bd9Sstevel@tonic-gate extern kmutex_t	spec_syncbusy;
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Variables used by during asynchronous VOP_PUTPAGE operations.
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate extern struct async_reqs *spec_async_reqs;	/* async request list */
2287c478bd9Sstevel@tonic-gate extern kmutex_t spec_async_lock;		/* lock to protect async list */
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate #endif
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_SNODE_H */
237