2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
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.
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.
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
18 #ifndef __XFS_VNODE_H__
19 #define __XFS_VNODE_H__
26 struct attrlist_cursor_kern;
28 typedef struct dentry bhv_vname_t;
29 typedef __u64 bhv_vnumber_t;
31 typedef enum bhv_vflags {
32 VMODIFIED = 0x08, /* XFS inode state possibly differs */
33 /* to the Linux inode state. */
34 VTRUNCATED = 0x40, /* truncated down so flush-on-close */
38 * MP locking protocols:
39 * v_flag, v_vfsp VN_LOCK/VN_UNLOCK
41 typedef struct bhv_vnode {
42 bhv_vflags_t v_flag; /* vnode flags (see above) */
43 bhv_vfs_t *v_vfsp; /* ptr to containing VFS */
44 bhv_vnumber_t v_number; /* in-core vnode number */
45 bhv_head_t v_bh; /* behavior head */
46 spinlock_t v_lock; /* VN_LOCK/VN_UNLOCK */
47 atomic_t v_iocount; /* outstanding I/O count */
48 #ifdef XFS_VNODE_TRACE
49 struct ktrace *v_trace; /* trace header structure */
51 struct inode v_inode; /* Linux inode */
52 /* inode MUST be last */
55 #define VN_ISLNK(vp) S_ISLNK((vp)->v_inode.i_mode)
56 #define VN_ISREG(vp) S_ISREG((vp)->v_inode.i_mode)
57 #define VN_ISDIR(vp) S_ISDIR((vp)->v_inode.i_mode)
58 #define VN_ISCHR(vp) S_ISCHR((vp)->v_inode.i_mode)
59 #define VN_ISBLK(vp) S_ISBLK((vp)->v_inode.i_mode)
61 #define VNODE_POSITION_BASE BHV_POSITION_BASE /* chain bottom */
62 #define VNODE_POSITION_TOP BHV_POSITION_TOP /* chain top */
63 #define VNODE_POSITION_INVALID BHV_POSITION_INVALID /* invalid pos. num */
66 VN_BHV_UNKNOWN, /* not specified */
68 VN_BHV_DM, /* data migration */
69 VN_BHV_QM, /* quota manager */
70 VN_BHV_IO, /* IO path */
71 VN_BHV_END /* housekeeping end-of-range */
74 #define VNODE_POSITION_XFS (VNODE_POSITION_BASE)
75 #define VNODE_POSITION_DM (VNODE_POSITION_BASE+10)
76 #define VNODE_POSITION_QM (VNODE_POSITION_BASE+20)
77 #define VNODE_POSITION_IO (VNODE_POSITION_BASE+30)
80 * Macros for dealing with the behavior descriptor inside of the vnode.
82 #define BHV_TO_VNODE(bdp) ((bhv_vnode_t *)BHV_VOBJ(bdp))
83 #define BHV_TO_VNODE_NULL(bdp) ((bhv_vnode_t *)BHV_VOBJNULL(bdp))
85 #define VN_BHV_HEAD(vp) ((bhv_head_t *)(&((vp)->v_bh)))
86 #define vn_bhv_head_init(bhp,name) bhv_head_init(bhp,name)
87 #define vn_bhv_remove(bhp,bdp) bhv_remove(bhp,bdp)
90 * Vnode to Linux inode mapping.
92 static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
94 return container_of(inode, bhv_vnode_t, v_inode);
96 static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
98 return &vnode->v_inode;
102 * Values for the vop_rwlock/rwunlock flags parameter.
104 typedef enum bhv_vrwlock {
108 VRWLOCK_WRITE_DIRECT,
114 * Return values for bhv_vop_inactive. A return value of
115 * VN_INACTIVE_NOCACHE implies that the file system behavior
116 * has disassociated its state and bhv_desc_t from the vnode.
118 #define VN_INACTIVE_CACHE 0
119 #define VN_INACTIVE_NOCACHE 1
122 * Values for the cmd code given to vop_vnode_change.
124 typedef enum bhv_vchange {
125 VCHANGE_FLAGS_FRLOCKS = 0,
126 VCHANGE_FLAGS_ENF_LOCKING = 1,
127 VCHANGE_FLAGS_TRUNCATED = 2,
128 VCHANGE_FLAGS_PAGE_DIRTY = 3,
129 VCHANGE_FLAGS_IOEXCL_COUNT = 4
132 typedef int (*vop_open_t)(bhv_desc_t *, struct cred *);
133 typedef ssize_t (*vop_read_t)(bhv_desc_t *, struct kiocb *,
134 const struct iovec *, unsigned int,
135 loff_t *, int, struct cred *);
136 typedef ssize_t (*vop_write_t)(bhv_desc_t *, struct kiocb *,
137 const struct iovec *, unsigned int,
138 loff_t *, int, struct cred *);
139 typedef ssize_t (*vop_splice_read_t)(bhv_desc_t *, struct file *, loff_t *,
140 struct pipe_inode_info *, size_t, int, int,
142 typedef ssize_t (*vop_splice_write_t)(bhv_desc_t *, struct pipe_inode_info *,
143 struct file *, loff_t *, size_t, int, int,
145 typedef int (*vop_ioctl_t)(bhv_desc_t *, struct inode *, struct file *,
146 int, unsigned int, void __user *);
147 typedef int (*vop_getattr_t)(bhv_desc_t *, struct bhv_vattr *, int,
149 typedef int (*vop_setattr_t)(bhv_desc_t *, struct bhv_vattr *, int,
151 typedef int (*vop_access_t)(bhv_desc_t *, int, struct cred *);
152 typedef int (*vop_lookup_t)(bhv_desc_t *, bhv_vname_t *, bhv_vnode_t **,
153 int, bhv_vnode_t *, struct cred *);
154 typedef int (*vop_create_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr *,
155 bhv_vnode_t **, struct cred *);
156 typedef int (*vop_remove_t)(bhv_desc_t *, bhv_vname_t *, struct cred *);
157 typedef int (*vop_link_t)(bhv_desc_t *, bhv_vnode_t *, bhv_vname_t *,
159 typedef int (*vop_rename_t)(bhv_desc_t *, bhv_vname_t *, bhv_vnode_t *,
160 bhv_vname_t *, struct cred *);
161 typedef int (*vop_mkdir_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr *,
162 bhv_vnode_t **, struct cred *);
163 typedef int (*vop_rmdir_t)(bhv_desc_t *, bhv_vname_t *, struct cred *);
164 typedef int (*vop_readdir_t)(bhv_desc_t *, struct uio *, struct cred *,
166 typedef int (*vop_symlink_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr*,
167 char *, bhv_vnode_t **, struct cred *);
168 typedef int (*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
170 typedef int (*vop_fsync_t)(bhv_desc_t *, int, struct cred *,
171 xfs_off_t, xfs_off_t);
172 typedef int (*vop_inactive_t)(bhv_desc_t *, struct cred *);
173 typedef int (*vop_fid2_t)(bhv_desc_t *, struct fid *);
174 typedef int (*vop_release_t)(bhv_desc_t *);
175 typedef int (*vop_rwlock_t)(bhv_desc_t *, bhv_vrwlock_t);
176 typedef void (*vop_rwunlock_t)(bhv_desc_t *, bhv_vrwlock_t);
177 typedef int (*vop_bmap_t)(bhv_desc_t *, xfs_off_t, ssize_t, int,
178 struct xfs_iomap *, int *);
179 typedef int (*vop_reclaim_t)(bhv_desc_t *);
180 typedef int (*vop_attr_get_t)(bhv_desc_t *, const char *, char *, int *,
182 typedef int (*vop_attr_set_t)(bhv_desc_t *, const char *, char *, int,
184 typedef int (*vop_attr_remove_t)(bhv_desc_t *, const char *,
186 typedef int (*vop_attr_list_t)(bhv_desc_t *, char *, int, int,
187 struct attrlist_cursor_kern *, struct cred *);
188 typedef void (*vop_link_removed_t)(bhv_desc_t *, bhv_vnode_t *, int);
189 typedef void (*vop_vnode_change_t)(bhv_desc_t *, bhv_vchange_t, __psint_t);
190 typedef void (*vop_ptossvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
191 typedef int (*vop_pflushinvalvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
192 typedef int (*vop_pflushvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t,
194 typedef int (*vop_iflush_t)(bhv_desc_t *, int);
197 typedef struct bhv_vnodeops {
198 bhv_position_t vn_position; /* position within behavior chain */
201 vop_write_t vop_write;
202 vop_splice_read_t vop_splice_read;
203 vop_splice_write_t vop_splice_write;
204 vop_ioctl_t vop_ioctl;
205 vop_getattr_t vop_getattr;
206 vop_setattr_t vop_setattr;
207 vop_access_t vop_access;
208 vop_lookup_t vop_lookup;
209 vop_create_t vop_create;
210 vop_remove_t vop_remove;
212 vop_rename_t vop_rename;
213 vop_mkdir_t vop_mkdir;
214 vop_rmdir_t vop_rmdir;
215 vop_readdir_t vop_readdir;
216 vop_symlink_t vop_symlink;
217 vop_readlink_t vop_readlink;
218 vop_fsync_t vop_fsync;
219 vop_inactive_t vop_inactive;
221 vop_rwlock_t vop_rwlock;
222 vop_rwunlock_t vop_rwunlock;
224 vop_reclaim_t vop_reclaim;
225 vop_attr_get_t vop_attr_get;
226 vop_attr_set_t vop_attr_set;
227 vop_attr_remove_t vop_attr_remove;
228 vop_attr_list_t vop_attr_list;
229 vop_link_removed_t vop_link_removed;
230 vop_vnode_change_t vop_vnode_change;
231 vop_ptossvp_t vop_tosspages;
232 vop_pflushinvalvp_t vop_flushinval_pages;
233 vop_pflushvp_t vop_flush_pages;
234 vop_release_t vop_release;
235 vop_iflush_t vop_iflush;
239 * Virtual node operations, operating from head bhv.
241 #define VNHEAD(vp) ((vp)->v_bh.bh_first)
242 #define VOP(op, vp) (*((bhv_vnodeops_t *)VNHEAD(vp)->bd_ops)->op)
243 #define bhv_vop_open(vp, cr) VOP(vop_open, vp)(VNHEAD(vp),cr)
244 #define bhv_vop_read(vp,file,iov,segs,offset,ioflags,cr) \
245 VOP(vop_read, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr)
246 #define bhv_vop_write(vp,file,iov,segs,offset,ioflags,cr) \
247 VOP(vop_write, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr)
248 #define bhv_vop_splice_read(vp,f,o,pipe,cnt,fl,iofl,cr) \
249 VOP(vop_splice_read, vp)(VNHEAD(vp),f,o,pipe,cnt,fl,iofl,cr)
250 #define bhv_vop_splice_write(vp,f,o,pipe,cnt,fl,iofl,cr) \
251 VOP(vop_splice_write, vp)(VNHEAD(vp),f,o,pipe,cnt,fl,iofl,cr)
252 #define bhv_vop_bmap(vp,of,sz,rw,b,n) \
253 VOP(vop_bmap, vp)(VNHEAD(vp),of,sz,rw,b,n)
254 #define bhv_vop_getattr(vp, vap,f,cr) \
255 VOP(vop_getattr, vp)(VNHEAD(vp), vap,f,cr)
256 #define bhv_vop_setattr(vp, vap,f,cr) \
257 VOP(vop_setattr, vp)(VNHEAD(vp), vap,f,cr)
258 #define bhv_vop_access(vp, mode,cr) VOP(vop_access, vp)(VNHEAD(vp), mode,cr)
259 #define bhv_vop_lookup(vp,d,vpp,f,rdir,cr) \
260 VOP(vop_lookup, vp)(VNHEAD(vp),d,vpp,f,rdir,cr)
261 #define bhv_vop_create(dvp,d,vap,vpp,cr) \
262 VOP(vop_create, dvp)(VNHEAD(dvp),d,vap,vpp,cr)
263 #define bhv_vop_remove(dvp,d,cr) VOP(vop_remove, dvp)(VNHEAD(dvp),d,cr)
264 #define bhv_vop_link(dvp,fvp,d,cr) VOP(vop_link, dvp)(VNHEAD(dvp),fvp,d,cr)
265 #define bhv_vop_rename(fvp,fnm,tdvp,tnm,cr) \
266 VOP(vop_rename, fvp)(VNHEAD(fvp),fnm,tdvp,tnm,cr)
267 #define bhv_vop_mkdir(dp,d,vap,vpp,cr) \
268 VOP(vop_mkdir, dp)(VNHEAD(dp),d,vap,vpp,cr)
269 #define bhv_vop_rmdir(dp,d,cr) VOP(vop_rmdir, dp)(VNHEAD(dp),d,cr)
270 #define bhv_vop_readdir(vp,uiop,cr,eofp) \
271 VOP(vop_readdir, vp)(VNHEAD(vp),uiop,cr,eofp)
272 #define bhv_vop_symlink(dvp,d,vap,tnm,vpp,cr) \
273 VOP(vop_symlink, dvp)(VNHEAD(dvp),d,vap,tnm,vpp,cr)
274 #define bhv_vop_readlink(vp,uiop,fl,cr) \
275 VOP(vop_readlink, vp)(VNHEAD(vp),uiop,fl,cr)
276 #define bhv_vop_fsync(vp,f,cr,b,e) VOP(vop_fsync, vp)(VNHEAD(vp),f,cr,b,e)
277 #define bhv_vop_inactive(vp,cr) VOP(vop_inactive, vp)(VNHEAD(vp),cr)
278 #define bhv_vop_release(vp) VOP(vop_release, vp)(VNHEAD(vp))
279 #define bhv_vop_fid2(vp,fidp) VOP(vop_fid2, vp)(VNHEAD(vp),fidp)
280 #define bhv_vop_rwlock(vp,i) VOP(vop_rwlock, vp)(VNHEAD(vp),i)
281 #define bhv_vop_rwlock_try(vp,i) VOP(vop_rwlock, vp)(VNHEAD(vp),i)
282 #define bhv_vop_rwunlock(vp,i) VOP(vop_rwunlock, vp)(VNHEAD(vp),i)
283 #define bhv_vop_frlock(vp,c,fl,flags,offset,fr) \
284 VOP(vop_frlock, vp)(VNHEAD(vp),c,fl,flags,offset,fr)
285 #define bhv_vop_reclaim(vp) VOP(vop_reclaim, vp)(VNHEAD(vp))
286 #define bhv_vop_attr_get(vp, name, val, vallenp, fl, cred) \
287 VOP(vop_attr_get, vp)(VNHEAD(vp),name,val,vallenp,fl,cred)
288 #define bhv_vop_attr_set(vp, name, val, vallen, fl, cred) \
289 VOP(vop_attr_set, vp)(VNHEAD(vp),name,val,vallen,fl,cred)
290 #define bhv_vop_attr_remove(vp, name, flags, cred) \
291 VOP(vop_attr_remove, vp)(VNHEAD(vp),name,flags,cred)
292 #define bhv_vop_attr_list(vp, buf, buflen, fl, cursor, cred) \
293 VOP(vop_attr_list, vp)(VNHEAD(vp),buf,buflen,fl,cursor,cred)
294 #define bhv_vop_link_removed(vp, dvp, linkzero) \
295 VOP(vop_link_removed, vp)(VNHEAD(vp), dvp, linkzero)
296 #define bhv_vop_vnode_change(vp, cmd, val) \
297 VOP(vop_vnode_change, vp)(VNHEAD(vp), cmd, val)
298 #define bhv_vop_toss_pages(vp, first, last, fiopt) \
299 VOP(vop_tosspages, vp)(VNHEAD(vp), first, last, fiopt)
300 #define bhv_vop_flushinval_pages(vp, first, last, fiopt) \
301 VOP(vop_flushinval_pages, vp)(VNHEAD(vp),first,last,fiopt)
302 #define bhv_vop_flush_pages(vp, first, last, flags, fiopt) \
303 VOP(vop_flush_pages, vp)(VNHEAD(vp),first,last,flags,fiopt)
304 #define bhv_vop_ioctl(vp, inode, filp, fl, cmd, arg) \
305 VOP(vop_ioctl, vp)(VNHEAD(vp),inode,filp,fl,cmd,arg)
306 #define bhv_vop_iflush(vp, flags) VOP(vop_iflush, vp)(VNHEAD(vp), flags)
309 * Flags for read/write calls - same values as IRIX
311 #define IO_ISAIO 0x00001 /* don't wait for completion */
312 #define IO_ISDIRECT 0x00004 /* bypass page cache */
313 #define IO_INVIS 0x00020 /* don't update inode timestamps */
316 * Flags for vop_iflush call
318 #define FLUSH_SYNC 1 /* wait for flush to complete */
319 #define FLUSH_INODE 2 /* flush the inode itself */
320 #define FLUSH_LOG 4 /* force the last log entry for
321 * this inode out to disk */
324 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
326 #define FI_NONE 0 /* none */
327 #define FI_REMAPF 1 /* Do a remapf prior to the operation */
328 #define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
329 Prevent VM access to the pages until
330 the operation completes. */
333 * Vnode attributes. va_mask indicates those attributes the caller
334 * wants to set or extract.
336 typedef struct bhv_vattr {
337 int va_mask; /* bit-mask of attributes present */
338 mode_t va_mode; /* file access mode and type */
339 xfs_nlink_t va_nlink; /* number of references to file */
340 uid_t va_uid; /* owner user id */
341 gid_t va_gid; /* owner group id */
342 xfs_ino_t va_nodeid; /* file id */
343 xfs_off_t va_size; /* file size in bytes */
344 u_long va_blocksize; /* blocksize preferred for i/o */
345 struct timespec va_atime; /* time of last access */
346 struct timespec va_mtime; /* time of last modification */
347 struct timespec va_ctime; /* time file changed */
348 u_int va_gen; /* generation number of file */
349 xfs_dev_t va_rdev; /* device the special file represents */
350 __int64_t va_nblocks; /* number of blocks allocated */
351 u_long va_xflags; /* random extended file flags */
352 u_long va_extsize; /* file extent size */
353 u_long va_nextents; /* number of extents in file */
354 u_long va_anextents; /* number of attr extents in file */
355 prid_t va_projid; /* project id */
359 * setattr or getattr attributes
361 #define XFS_AT_TYPE 0x00000001
362 #define XFS_AT_MODE 0x00000002
363 #define XFS_AT_UID 0x00000004
364 #define XFS_AT_GID 0x00000008
365 #define XFS_AT_FSID 0x00000010
366 #define XFS_AT_NODEID 0x00000020
367 #define XFS_AT_NLINK 0x00000040
368 #define XFS_AT_SIZE 0x00000080
369 #define XFS_AT_ATIME 0x00000100
370 #define XFS_AT_MTIME 0x00000200
371 #define XFS_AT_CTIME 0x00000400
372 #define XFS_AT_RDEV 0x00000800
373 #define XFS_AT_BLKSIZE 0x00001000
374 #define XFS_AT_NBLOCKS 0x00002000
375 #define XFS_AT_VCODE 0x00004000
376 #define XFS_AT_MAC 0x00008000
377 #define XFS_AT_UPDATIME 0x00010000
378 #define XFS_AT_UPDMTIME 0x00020000
379 #define XFS_AT_UPDCTIME 0x00040000
380 #define XFS_AT_ACL 0x00080000
381 #define XFS_AT_CAP 0x00100000
382 #define XFS_AT_INF 0x00200000
383 #define XFS_AT_XFLAGS 0x00400000
384 #define XFS_AT_EXTSIZE 0x00800000
385 #define XFS_AT_NEXTENTS 0x01000000
386 #define XFS_AT_ANEXTENTS 0x02000000
387 #define XFS_AT_PROJID 0x04000000
388 #define XFS_AT_SIZE_NOPERM 0x08000000
389 #define XFS_AT_GENCOUNT 0x10000000
391 #define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
392 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
393 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
394 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
395 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
396 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
398 #define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
399 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
400 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
401 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
403 #define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
405 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
407 #define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
408 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
409 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
414 #define VSUID S_ISUID /* set user id on execution */
415 #define VSGID S_ISGID /* set group id on execution */
416 #define VSVTX S_ISVTX /* save swapped text even after use */
417 #define VREAD S_IRUSR /* read, write, execute permissions */
418 #define VWRITE S_IWUSR
419 #define VEXEC S_IXUSR
421 #define MODEMASK S_IALLUGO /* mode bits plus permission bits */
424 * Check whether mandatory file locking is enabled.
426 #define MANDLOCK(vp, mode) \
427 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
429 extern void vn_init(void);
430 extern bhv_vnode_t *vn_initialize(struct inode *);
431 extern int vn_revalidate(struct bhv_vnode *);
432 extern int __vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
433 extern void vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
435 extern void vn_iowait(struct bhv_vnode *vp);
436 extern void vn_iowake(struct bhv_vnode *vp);
438 extern void vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
440 static inline int vn_count(struct bhv_vnode *vp)
442 return atomic_read(&vn_to_inode(vp)->i_count);
446 * Vnode reference counting functions (and macros for compatibility).
448 extern bhv_vnode_t *vn_hold(struct bhv_vnode *);
450 #if defined(XFS_VNODE_TRACE)
451 #define VN_HOLD(vp) \
452 ((void)vn_hold(vp), \
453 vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
454 #define VN_RELE(vp) \
455 (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
456 iput(vn_to_inode(vp)))
458 #define VN_HOLD(vp) ((void)vn_hold(vp))
459 #define VN_RELE(vp) (iput(vn_to_inode(vp)))
462 static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
464 struct inode *inode = igrab(vn_to_inode(vp));
465 return inode ? vn_from_inode(inode) : NULL;
469 * Vname handling macros.
471 #define VNAME(dentry) ((char *) (dentry)->d_name.name)
472 #define VNAMELEN(dentry) ((dentry)->d_name.len)
473 #define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
476 * Vnode spinlock manipulation.
478 #define VN_LOCK(vp) mutex_spinlock(&(vp)->v_lock)
479 #define VN_UNLOCK(vp, s) mutex_spinunlock(&(vp)->v_lock, s)
481 STATIC_INLINE void vn_flagset(struct bhv_vnode *vp, uint flag)
483 spin_lock(&vp->v_lock);
485 spin_unlock(&vp->v_lock);
488 STATIC_INLINE uint vn_flagclr(struct bhv_vnode *vp, uint flag)
492 spin_lock(&vp->v_lock);
493 cleared = (vp->v_flag & flag);
495 spin_unlock(&vp->v_lock);
499 #define VMODIFY(vp) vn_flagset(vp, VMODIFIED)
500 #define VUNMODIFY(vp) vn_flagclr(vp, VMODIFIED)
501 #define VTRUNCATE(vp) vn_flagset(vp, VTRUNCATED)
502 #define VUNTRUNCATE(vp) vn_flagclr(vp, VTRUNCATED)
505 * Dealing with bad inodes
507 static inline void vn_mark_bad(struct bhv_vnode *vp)
509 make_bad_inode(vn_to_inode(vp));
512 static inline int VN_BAD(struct bhv_vnode *vp)
514 return is_bad_inode(vn_to_inode(vp));
518 * Extracting atime values in various formats
520 static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
522 bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
523 bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
526 static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
528 *ts = vp->v_inode.i_atime;
531 static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
533 *tt = vp->v_inode.i_atime.tv_sec;
537 * Some useful predicates.
539 #define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
540 #define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
541 #define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
543 #define VN_TRUNC(vp) ((vp)->v_flag & VTRUNCATED)
546 * Flags to vop_setattr/getattr.
548 #define ATTR_UTIME 0x01 /* non-default utime(2) request */
549 #define ATTR_DMI 0x08 /* invocation from a DMI function */
550 #define ATTR_LAZY 0x80 /* set/get attributes lazily */
551 #define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
552 #define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
553 #define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
556 * Flags to vop_fsync/reclaim.
558 #define FSYNC_NOWAIT 0 /* asynchronous flush */
559 #define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
560 #define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
561 #define FSYNC_DATA 0x4 /* synchronous fsync of data only */
564 * Tracking vnode activity.
566 #if defined(XFS_VNODE_TRACE)
568 #define VNODE_TRACE_SIZE 16 /* number of trace entries */
569 #define VNODE_KTRACE_ENTRY 1
570 #define VNODE_KTRACE_EXIT 2
571 #define VNODE_KTRACE_HOLD 3
572 #define VNODE_KTRACE_REF 4
573 #define VNODE_KTRACE_RELE 5
575 extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
576 extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
577 extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
578 extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
579 extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
581 #define VN_TRACE(vp) \
582 vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
584 #define vn_trace_entry(a,b,c)
585 #define vn_trace_exit(a,b,c)
586 #define vn_trace_hold(a,b,c,d)
587 #define vn_trace_ref(a,b,c,d)
588 #define vn_trace_rele(a,b,c,d)
592 #endif /* __XFS_VNODE_H__ */