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