[XFS] call common xfs vnode-level helpers directly and remove vnode operations
[deliverable/linux.git] / fs / xfs / linux-2.6 / xfs_vnode.h
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #ifndef __XFS_VNODE_H__
19 #define __XFS_VNODE_H__
20
21 struct file;
22 struct bhv_vfs;
23 struct bhv_vattr;
24 struct xfs_iomap;
25 struct attrlist_cursor_kern;
26
27 typedef struct dentry bhv_vname_t;
28 typedef __u64 bhv_vnumber_t;
29
30 typedef enum bhv_vflags {
31 VMODIFIED = 0x08, /* XFS inode state possibly differs */
32 /* to the Linux inode state. */
33 VTRUNCATED = 0x40, /* truncated down so flush-on-close */
34 } bhv_vflags_t;
35
36 /*
37 * MP locking protocols:
38 * v_flag, v_vfsp VN_LOCK/VN_UNLOCK
39 */
40 typedef struct bhv_vnode {
41 bhv_vflags_t v_flag; /* vnode flags (see above) */
42 bhv_vfs_t *v_vfsp; /* ptr to containing VFS */
43 bhv_vnumber_t v_number; /* in-core vnode number */
44 spinlock_t v_lock; /* VN_LOCK/VN_UNLOCK */
45 atomic_t v_iocount; /* outstanding I/O count */
46 #ifdef XFS_VNODE_TRACE
47 struct ktrace *v_trace; /* trace header structure */
48 #endif
49 struct inode v_inode; /* Linux inode */
50 /* inode MUST be last */
51 } bhv_vnode_t;
52
53 #define VN_ISLNK(vp) S_ISLNK((vp)->v_inode.i_mode)
54 #define VN_ISREG(vp) S_ISREG((vp)->v_inode.i_mode)
55 #define VN_ISDIR(vp) S_ISDIR((vp)->v_inode.i_mode)
56 #define VN_ISCHR(vp) S_ISCHR((vp)->v_inode.i_mode)
57 #define VN_ISBLK(vp) S_ISBLK((vp)->v_inode.i_mode)
58
59 /*
60 * Vnode to Linux inode mapping.
61 */
62 static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
63 {
64 return container_of(inode, bhv_vnode_t, v_inode);
65 }
66 static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
67 {
68 return &vnode->v_inode;
69 }
70
71 /*
72 * Values for the vop_rwlock/rwunlock flags parameter.
73 */
74 typedef enum bhv_vrwlock {
75 VRWLOCK_NONE,
76 VRWLOCK_READ,
77 VRWLOCK_WRITE,
78 VRWLOCK_WRITE_DIRECT,
79 VRWLOCK_TRY_READ,
80 VRWLOCK_TRY_WRITE
81 } bhv_vrwlock_t;
82
83 /*
84 * Return values for xfs_inactive. A return value of
85 * VN_INACTIVE_NOCACHE implies that the file system behavior
86 * has disassociated its state and bhv_desc_t from the vnode.
87 */
88 #define VN_INACTIVE_CACHE 0
89 #define VN_INACTIVE_NOCACHE 1
90
91 /*
92 * Flags for read/write calls - same values as IRIX
93 */
94 #define IO_ISAIO 0x00001 /* don't wait for completion */
95 #define IO_ISDIRECT 0x00004 /* bypass page cache */
96 #define IO_INVIS 0x00020 /* don't update inode timestamps */
97
98 /*
99 * Flags for vop_iflush call
100 */
101 #define FLUSH_SYNC 1 /* wait for flush to complete */
102 #define FLUSH_INODE 2 /* flush the inode itself */
103 #define FLUSH_LOG 4 /* force the last log entry for
104 * this inode out to disk */
105
106 /*
107 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
108 */
109 #define FI_NONE 0 /* none */
110 #define FI_REMAPF 1 /* Do a remapf prior to the operation */
111 #define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
112 Prevent VM access to the pages until
113 the operation completes. */
114
115 /*
116 * Vnode attributes. va_mask indicates those attributes the caller
117 * wants to set or extract.
118 */
119 typedef struct bhv_vattr {
120 int va_mask; /* bit-mask of attributes present */
121 mode_t va_mode; /* file access mode and type */
122 xfs_nlink_t va_nlink; /* number of references to file */
123 uid_t va_uid; /* owner user id */
124 gid_t va_gid; /* owner group id */
125 xfs_ino_t va_nodeid; /* file id */
126 xfs_off_t va_size; /* file size in bytes */
127 u_long va_blocksize; /* blocksize preferred for i/o */
128 struct timespec va_atime; /* time of last access */
129 struct timespec va_mtime; /* time of last modification */
130 struct timespec va_ctime; /* time file changed */
131 u_int va_gen; /* generation number of file */
132 xfs_dev_t va_rdev; /* device the special file represents */
133 __int64_t va_nblocks; /* number of blocks allocated */
134 u_long va_xflags; /* random extended file flags */
135 u_long va_extsize; /* file extent size */
136 u_long va_nextents; /* number of extents in file */
137 u_long va_anextents; /* number of attr extents in file */
138 prid_t va_projid; /* project id */
139 } bhv_vattr_t;
140
141 /*
142 * setattr or getattr attributes
143 */
144 #define XFS_AT_TYPE 0x00000001
145 #define XFS_AT_MODE 0x00000002
146 #define XFS_AT_UID 0x00000004
147 #define XFS_AT_GID 0x00000008
148 #define XFS_AT_FSID 0x00000010
149 #define XFS_AT_NODEID 0x00000020
150 #define XFS_AT_NLINK 0x00000040
151 #define XFS_AT_SIZE 0x00000080
152 #define XFS_AT_ATIME 0x00000100
153 #define XFS_AT_MTIME 0x00000200
154 #define XFS_AT_CTIME 0x00000400
155 #define XFS_AT_RDEV 0x00000800
156 #define XFS_AT_BLKSIZE 0x00001000
157 #define XFS_AT_NBLOCKS 0x00002000
158 #define XFS_AT_VCODE 0x00004000
159 #define XFS_AT_MAC 0x00008000
160 #define XFS_AT_UPDATIME 0x00010000
161 #define XFS_AT_UPDMTIME 0x00020000
162 #define XFS_AT_UPDCTIME 0x00040000
163 #define XFS_AT_ACL 0x00080000
164 #define XFS_AT_CAP 0x00100000
165 #define XFS_AT_INF 0x00200000
166 #define XFS_AT_XFLAGS 0x00400000
167 #define XFS_AT_EXTSIZE 0x00800000
168 #define XFS_AT_NEXTENTS 0x01000000
169 #define XFS_AT_ANEXTENTS 0x02000000
170 #define XFS_AT_PROJID 0x04000000
171 #define XFS_AT_SIZE_NOPERM 0x08000000
172 #define XFS_AT_GENCOUNT 0x10000000
173
174 #define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
175 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
176 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
177 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
178 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
179 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
180
181 #define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
182 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
183 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
184 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
185
186 #define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
187
188 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
189
190 #define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
191 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
192 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
193
194 /*
195 * Modes.
196 */
197 #define VSUID S_ISUID /* set user id on execution */
198 #define VSGID S_ISGID /* set group id on execution */
199 #define VSVTX S_ISVTX /* save swapped text even after use */
200 #define VREAD S_IRUSR /* read, write, execute permissions */
201 #define VWRITE S_IWUSR
202 #define VEXEC S_IXUSR
203
204 #define MODEMASK S_IALLUGO /* mode bits plus permission bits */
205
206 /*
207 * Check whether mandatory file locking is enabled.
208 */
209 #define MANDLOCK(vp, mode) \
210 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
211
212 extern void vn_init(void);
213 extern bhv_vnode_t *vn_initialize(struct inode *);
214 extern int vn_revalidate(struct bhv_vnode *);
215 extern int __vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
216 extern void vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
217
218 extern void vn_iowait(struct bhv_vnode *vp);
219 extern void vn_iowake(struct bhv_vnode *vp);
220
221 extern void vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
222
223 static inline int vn_count(struct bhv_vnode *vp)
224 {
225 return atomic_read(&vn_to_inode(vp)->i_count);
226 }
227
228 /*
229 * Vnode reference counting functions (and macros for compatibility).
230 */
231 extern bhv_vnode_t *vn_hold(struct bhv_vnode *);
232
233 #if defined(XFS_VNODE_TRACE)
234 #define VN_HOLD(vp) \
235 ((void)vn_hold(vp), \
236 vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
237 #define VN_RELE(vp) \
238 (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
239 iput(vn_to_inode(vp)))
240 #else
241 #define VN_HOLD(vp) ((void)vn_hold(vp))
242 #define VN_RELE(vp) (iput(vn_to_inode(vp)))
243 #endif
244
245 static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
246 {
247 struct inode *inode = igrab(vn_to_inode(vp));
248 return inode ? vn_from_inode(inode) : NULL;
249 }
250
251 /*
252 * Vname handling macros.
253 */
254 #define VNAME(dentry) ((char *) (dentry)->d_name.name)
255 #define VNAMELEN(dentry) ((dentry)->d_name.len)
256 #define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
257
258 /*
259 * Vnode spinlock manipulation.
260 */
261 #define VN_LOCK(vp) mutex_spinlock(&(vp)->v_lock)
262 #define VN_UNLOCK(vp, s) mutex_spinunlock(&(vp)->v_lock, s)
263
264 STATIC_INLINE void vn_flagset(struct bhv_vnode *vp, uint flag)
265 {
266 spin_lock(&vp->v_lock);
267 vp->v_flag |= flag;
268 spin_unlock(&vp->v_lock);
269 }
270
271 STATIC_INLINE uint vn_flagclr(struct bhv_vnode *vp, uint flag)
272 {
273 uint cleared;
274
275 spin_lock(&vp->v_lock);
276 cleared = (vp->v_flag & flag);
277 vp->v_flag &= ~flag;
278 spin_unlock(&vp->v_lock);
279 return cleared;
280 }
281
282 #define VMODIFY(vp) vn_flagset(vp, VMODIFIED)
283 #define VUNMODIFY(vp) vn_flagclr(vp, VMODIFIED)
284 #define VTRUNCATE(vp) vn_flagset(vp, VTRUNCATED)
285 #define VUNTRUNCATE(vp) vn_flagclr(vp, VTRUNCATED)
286
287 /*
288 * Dealing with bad inodes
289 */
290 static inline void vn_mark_bad(struct bhv_vnode *vp)
291 {
292 make_bad_inode(vn_to_inode(vp));
293 }
294
295 static inline int VN_BAD(struct bhv_vnode *vp)
296 {
297 return is_bad_inode(vn_to_inode(vp));
298 }
299
300 /*
301 * Extracting atime values in various formats
302 */
303 static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
304 {
305 bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
306 bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
307 }
308
309 static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
310 {
311 *ts = vp->v_inode.i_atime;
312 }
313
314 static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
315 {
316 *tt = vp->v_inode.i_atime.tv_sec;
317 }
318
319 /*
320 * Some useful predicates.
321 */
322 #define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
323 #define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
324 #define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
325 PAGECACHE_TAG_DIRTY)
326 #define VN_TRUNC(vp) ((vp)->v_flag & VTRUNCATED)
327
328 /*
329 * Flags to vop_setattr/getattr.
330 */
331 #define ATTR_UTIME 0x01 /* non-default utime(2) request */
332 #define ATTR_DMI 0x08 /* invocation from a DMI function */
333 #define ATTR_LAZY 0x80 /* set/get attributes lazily */
334 #define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
335 #define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
336 #define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
337
338 /*
339 * Flags to vop_fsync/reclaim.
340 */
341 #define FSYNC_NOWAIT 0 /* asynchronous flush */
342 #define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
343 #define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
344 #define FSYNC_DATA 0x4 /* synchronous fsync of data only */
345
346 /*
347 * Tracking vnode activity.
348 */
349 #if defined(XFS_VNODE_TRACE)
350
351 #define VNODE_TRACE_SIZE 16 /* number of trace entries */
352 #define VNODE_KTRACE_ENTRY 1
353 #define VNODE_KTRACE_EXIT 2
354 #define VNODE_KTRACE_HOLD 3
355 #define VNODE_KTRACE_REF 4
356 #define VNODE_KTRACE_RELE 5
357
358 extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
359 extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
360 extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
361 extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
362 extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
363
364 #define VN_TRACE(vp) \
365 vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
366 #else
367 #define vn_trace_entry(a,b,c)
368 #define vn_trace_exit(a,b,c)
369 #define vn_trace_hold(a,b,c,d)
370 #define vn_trace_ref(a,b,c,d)
371 #define vn_trace_rele(a,b,c,d)
372 #define VN_TRACE(vp)
373 #endif
374
375 #endif /* __XFS_VNODE_H__ */
This page took 0.048544 seconds and 5 git commands to generate.