xref: /titanic_52/usr/src/uts/common/sys/fs/snode.h (revision 74e20cfe817b82802b16fac8690dadcda76f54f5)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef	_SYS_FS_SNODE_H
32 #define	_SYS_FS_SNODE_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/types.h>
37 #include <sys/t_lock.h>
38 #include <sys/cred.h>
39 #include <sys/vnode.h>
40 
41 /*
42  * The snode represents a special file in any filesystem.  There is
43  * one snode for each active special file.  Filesystems that support
44  * special files use specvp(vp, dev, type, cr) to convert a normal
45  * vnode to a special vnode in the ops lookup() and create().
46  *
47  * To handle having multiple snodes that represent the same
48  * underlying device vnode without cache aliasing problems,
49  * the s_commonvp is used to point to the "common" vnode used for
50  * caching data.  If an snode is created internally by the kernel,
51  * then the s_realvp field is NULL and s_commonvp points to s_vnode.
52  * The other snodes which are created as a result of a lookup of a
53  * device in a file system have s_realvp pointing to the vp which
54  * represents the device in the file system while the s_commonvp points
55  * into the "common" vnode for the device in another snode.
56  */
57 
58 /*
59  * Include SUNDDI type definitions so that the s_dip tag doesn't urk.
60  */
61 #include <sys/dditypes.h>
62 
63 #ifdef	__cplusplus
64 extern "C" {
65 #endif
66 
67 struct snode {
68 	/* These fields are protected by stable_lock */
69 	struct	snode *s_next;		/* must be first */
70 	struct	vnode *s_vnode;		/* vnode associated with this snode */
71 	/*
72 	 * These fields are initialized once.
73 	 */
74 	struct	vnode *s_realvp;	/* vnode for the fs entry (if any) */
75 	struct	vnode *s_commonvp;	/* common device vnode */
76 	dev_t	s_dev;			/* device the snode represents */
77 	dev_info_t *s_dip;		/* dev_info (common snode only) */
78 	/*
79 	 * Doesn't always need to be updated atomically because it is a hint.
80 	 * No lock required.
81 	 */
82 	u_offset_t s_nextr;		/* next byte read offset (read-ahead) */
83 
84 	/* These fields are protected by spec_syncbusy */
85 	struct	snode *s_list;		/* used for syncing */
86 	/* These fields are protected by s_lock */
87 	struct devplcy *s_plcy;		/* device node open policy (cs only) */
88 	u_offset_t s_size;		/* block device size in bytes */
89 	ushort_t s_flag;		/* flags, see below */
90 	dev_t	s_fsid;			/* file system identifier */
91 	time_t  s_atime;		/* time of last access */
92 	time_t  s_mtime;		/* time of last modification */
93 	time_t  s_ctime;		/* time of last attributes change */
94 	int	s_count;		/* count of opened references */
95 	long	s_mapcnt;		/* count of mappings of pages */
96 	/* The locks themselves */
97 	kmutex_t	s_lock;		/* protects snode fields */
98 	kcondvar_t	s_cv;		/* synchronize open/closes */
99 };
100 
101 /* flags */
102 #define	SUPD		0x01		/* update device access time */
103 #define	SACC		0x02		/* update device modification time */
104 #define	SCHG		0x04		/* update device change time */
105 #define	SPRIV		0x08		/* file open for private access */
106 #define	SLOFFSET	0x10		/* device takes 64-bit uio offsets */
107 #define	SLOCKED		0x20		/* use to serialize open/closes */
108 #define	SWANT		0x40		/* some process waiting on lock */
109 #define	SANYOFFSET	0x80		/* device takes any uio offset */
110 #define	SCLONE		0x100		/* represents a cloned device */
111 #define	SNEEDCLOSE	0x200		/* needs driver close call */
112 #define	SDIPSET		0x400		/* the vnode has an association with */
113 					/* the driver, even though it may */
114 					/* not currently have an association */
115 					/* with a specific hardware instance */
116 					/* if s_dip is NULL */
117 #define	SSIZEVALID	0x800		/* s_size field is valid */
118 #define	SMUXED		0x1000		/* this snode is a stream that has */
119 					/* been multiplexed */
120 #define	SSELFCLONE	0x2000		/* represents a self cloning device */
121 
122 #ifdef _KERNEL
123 /*
124  * Convert between vnode and snode
125  */
126 #define	VTOS(vp)	((struct snode *)((vp)->v_data))
127 #define	VTOCS(vp)	(VTOS(VTOS(vp)->s_commonvp))
128 #define	STOV(sp)	((sp)->s_vnode)
129 
130 
131 /*
132  * Forward declarations
133  */
134 struct vfssw;
135 struct cred;
136 
137 extern struct vfs	spec_vfs;
138 extern struct vfsops	spec_vfsops;
139 extern struct kmem_cache *snode_cache;
140 
141 /*
142  * specfs functions
143  */
144 offset_t	spec_maxoffset(struct vnode *);
145 struct vnodeops	*spec_getvnodeops(void);
146 struct vnode *specvp(struct vnode *, dev_t, vtype_t, struct cred *);
147 struct vnode *makespecvp(dev_t, vtype_t);
148 struct vnode *other_specvp(struct vnode *);
149 struct vnode *common_specvp(struct vnode *);
150 struct vnode *specfind(dev_t, vtype_t);
151 struct vnode *commonvp(dev_t, vtype_t);
152 struct vnode *makectty(vnode_t *);
153 void	sdelete(struct snode *);
154 void 	smark(struct snode *, int);
155 int	specinit(int, char *);
156 int	device_close(struct vnode *, int, struct cred *);
157 int	spec_putpage(struct vnode *, offset_t, size_t, int, struct cred *);
158 int	spec_segmap(dev_t, off_t, struct as *, caddr_t *, off_t,
159 		    uint_t, uint_t, uint_t, cred_t *);
160 struct vnode *specvp_devfs(struct vnode *, dev_t, vtype_t,
161 		    struct cred *, dev_info_t *);
162 void	spec_assoc_vp_with_devi(struct vnode *, dev_info_t *);
163 dev_info_t *spec_hold_devi_by_vp(struct vnode *);
164 int	spec_sync(struct vfs *, short, struct cred *);
165 void	spec_snode_walk(int (*callback)(struct snode *, void *), void *);
166 int	spec_devi_open_count(struct snode *, dev_info_t **);
167 int	spec_is_clone(struct vnode *);
168 int	spec_is_selfclone(struct vnode *);
169 
170 
171 /*
172  * UNKNOWN_SIZE: If driver does not support the [Ss]ize or [Nn]blocks property
173  * then the size is assumed to be "infinite".  Note that this "infinite" value
174  * may need to be converted to a smaller "infinite" value to avoid EOVERFLOW at
175  * field width conversion locations like the stat(2) and NFS code running
176  * against a special file.  Special file code outside specfs may check the
177  * type of the vnode (VCHR|VBLK) and use MAXOFFSET_T directly to detect
178  * UNKNOWN_SIZE.
179  */
180 #define	UNKNOWN_SIZE		MAXOFFSET_T
181 
182 /*
183  * SPEC_MAXOFFSET_T: Solaris does not fully support 64-bit offsets for D_64BIT
184  * (SLOFFSET) block drivers on a 32-bit kernels: daddr_t is still a signed
185  * 32-bit quantity - which limits the byte offset to 1TB. This issue goes
186  * beyond a driver needing to convert from daddr_t to diskaddr_t if it sets
187  * D_64BIT. Many of the DDI interfaces which take daddr_t arguments have no
188  * 64-bit counterpart (bioclone, blkflush, bread, bread_common, breada, getblk,
189  * getblk_common). SPEC_MAXOFFSET_T is used by 32-bit kernel code to enforce
190  * this restriction.
191  */
192 #ifdef	_ILP32
193 #ifdef	_LONGLONG_TYPE
194 #define	SPEC_MAXOFFSET_T	((1LL << ((NBBY * sizeof (daddr32_t)) +	\
195 				DEV_BSHIFT - 1)) - 1)
196 #else	/* !defined(_LONGLONG_TYPE) */
197 #define	SPEC_MAXOFFSET_T	MAXOFF_T
198 #endif	/* _LONGLONG_TYPE */
199 #endif	/* _ILP32 */
200 
201 /*
202  * Snode lookup stuff.
203  * These routines maintain a table of snodes hashed by dev so
204  * that the snode for an dev can be found if it already exists.
205  * NOTE: STABLESIZE must be a power of 2 for STABLEHASH to work!
206  */
207 
208 #define	STABLESIZE	256
209 #define	STABLEHASH(dev)	((getmajor(dev) + getminor(dev)) & (STABLESIZE - 1))
210 extern struct snode *stable[];
211 extern kmutex_t	stable_lock;
212 extern kmutex_t	spec_syncbusy;
213 
214 /*
215  * Variables used by during asynchronous VOP_PUTPAGE operations.
216  */
217 extern struct async_reqs *spec_async_reqs;	/* async request list */
218 extern kmutex_t spec_async_lock;		/* lock to protect async list */
219 
220 #endif	/* _KERNEL */
221 
222 #ifdef	__cplusplus
223 }
224 #endif
225 
226 #endif	/* _SYS_FS_SNODE_H */
227