blob: 7cff0f3e9bc3ef77fc9f6dcf6aa7465545a3f2a1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 *
32 * Portions Copyright (c) 1989, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 */
59#ifndef __XFS_VNODE_H__
60#define __XFS_VNODE_H__
61
62struct uio;
63struct file;
64struct vattr;
65struct xfs_iomap;
66struct attrlist_cursor_kern;
67
68/*
69 * Vnode types. VNON means no type.
70 */
71enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VFIFO, VBAD, VSOCK };
72
73typedef xfs_ino_t vnumber_t;
74typedef struct dentry vname_t;
75typedef bhv_head_t vn_bhv_head_t;
76
77/*
78 * MP locking protocols:
79 * v_flag, v_vfsp VN_LOCK/VN_UNLOCK
80 * v_type read-only or fs-dependent
81 */
82typedef struct vnode {
83 __u32 v_flag; /* vnode flags (see below) */
84 enum vtype v_type; /* vnode type */
85 struct vfs *v_vfsp; /* ptr to containing VFS */
86 vnumber_t v_number; /* in-core vnode number */
87 vn_bhv_head_t v_bh; /* behavior head */
88 spinlock_t v_lock; /* VN_LOCK/VN_UNLOCK */
89 struct inode v_inode; /* Linux inode */
90#ifdef XFS_VNODE_TRACE
91 struct ktrace *v_trace; /* trace header structure */
92#endif
93} vnode_t;
94
95#define v_fbhv v_bh.bh_first /* first behavior */
96#define v_fops v_bh.bh_first->bd_ops /* first behavior ops */
97
98#define VNODE_POSITION_BASE BHV_POSITION_BASE /* chain bottom */
99#define VNODE_POSITION_TOP BHV_POSITION_TOP /* chain top */
100#define VNODE_POSITION_INVALID BHV_POSITION_INVALID /* invalid pos. num */
101
102typedef enum {
103 VN_BHV_UNKNOWN, /* not specified */
104 VN_BHV_XFS, /* xfs */
105 VN_BHV_DM, /* data migration */
106 VN_BHV_QM, /* quota manager */
107 VN_BHV_IO, /* IO path */
108 VN_BHV_END /* housekeeping end-of-range */
109} vn_bhv_t;
110
111#define VNODE_POSITION_XFS (VNODE_POSITION_BASE)
112#define VNODE_POSITION_DM (VNODE_POSITION_BASE+10)
113#define VNODE_POSITION_QM (VNODE_POSITION_BASE+20)
114#define VNODE_POSITION_IO (VNODE_POSITION_BASE+30)
115
116/*
117 * Macros for dealing with the behavior descriptor inside of the vnode.
118 */
119#define BHV_TO_VNODE(bdp) ((vnode_t *)BHV_VOBJ(bdp))
120#define BHV_TO_VNODE_NULL(bdp) ((vnode_t *)BHV_VOBJNULL(bdp))
121
122#define VN_BHV_HEAD(vp) ((bhv_head_t *)(&((vp)->v_bh)))
123#define vn_bhv_head_init(bhp,name) bhv_head_init(bhp,name)
124#define vn_bhv_remove(bhp,bdp) bhv_remove(bhp,bdp)
125#define vn_bhv_lookup(bhp,ops) bhv_lookup(bhp,ops)
126#define vn_bhv_lookup_unlocked(bhp,ops) bhv_lookup_unlocked(bhp,ops)
127
128/*
129 * Vnode to Linux inode mapping.
130 */
131#define LINVFS_GET_VP(inode) ((vnode_t *)list_entry(inode, vnode_t, v_inode))
132#define LINVFS_GET_IP(vp) (&(vp)->v_inode)
133
134/*
135 * Convert between vnode types and inode formats (since POSIX.1
136 * defines mode word of stat structure in terms of inode formats).
137 */
138extern enum vtype iftovt_tab[];
139extern u_short vttoif_tab[];
140#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
141#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
142#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
143
144
145/*
146 * Vnode flags.
147 */
148#define VINACT 0x1 /* vnode is being inactivated */
149#define VRECLM 0x2 /* vnode is being reclaimed */
150#define VWAIT 0x4 /* waiting for VINACT/VRECLM to end */
151#define VMODIFIED 0x8 /* XFS inode state possibly differs */
152 /* to the Linux inode state. */
153
154/*
155 * Values for the VOP_RWLOCK and VOP_RWUNLOCK flags parameter.
156 */
157typedef enum vrwlock {
158 VRWLOCK_NONE,
159 VRWLOCK_READ,
160 VRWLOCK_WRITE,
161 VRWLOCK_WRITE_DIRECT,
162 VRWLOCK_TRY_READ,
163 VRWLOCK_TRY_WRITE
164} vrwlock_t;
165
166/*
167 * Return values for VOP_INACTIVE. A return value of
168 * VN_INACTIVE_NOCACHE implies that the file system behavior
169 * has disassociated its state and bhv_desc_t from the vnode.
170 */
171#define VN_INACTIVE_CACHE 0
172#define VN_INACTIVE_NOCACHE 1
173
174/*
175 * Values for the cmd code given to VOP_VNODE_CHANGE.
176 */
177typedef enum vchange {
178 VCHANGE_FLAGS_FRLOCKS = 0,
179 VCHANGE_FLAGS_ENF_LOCKING = 1,
180 VCHANGE_FLAGS_TRUNCATED = 2,
181 VCHANGE_FLAGS_PAGE_DIRTY = 3,
182 VCHANGE_FLAGS_IOEXCL_COUNT = 4
183} vchange_t;
184
185
186typedef int (*vop_open_t)(bhv_desc_t *, struct cred *);
187typedef ssize_t (*vop_read_t)(bhv_desc_t *, struct kiocb *,
188 const struct iovec *, unsigned int,
189 loff_t *, int, struct cred *);
190typedef ssize_t (*vop_write_t)(bhv_desc_t *, struct kiocb *,
191 const struct iovec *, unsigned int,
192 loff_t *, int, struct cred *);
193typedef ssize_t (*vop_sendfile_t)(bhv_desc_t *, struct file *,
194 loff_t *, int, size_t, read_actor_t,
195 void *, struct cred *);
196typedef int (*vop_ioctl_t)(bhv_desc_t *, struct inode *, struct file *,
197 int, unsigned int, void __user *);
198typedef int (*vop_getattr_t)(bhv_desc_t *, struct vattr *, int,
199 struct cred *);
200typedef int (*vop_setattr_t)(bhv_desc_t *, struct vattr *, int,
201 struct cred *);
202typedef int (*vop_access_t)(bhv_desc_t *, int, struct cred *);
203typedef int (*vop_lookup_t)(bhv_desc_t *, vname_t *, vnode_t **,
204 int, vnode_t *, struct cred *);
205typedef int (*vop_create_t)(bhv_desc_t *, vname_t *, struct vattr *,
206 vnode_t **, struct cred *);
207typedef int (*vop_remove_t)(bhv_desc_t *, vname_t *, struct cred *);
208typedef int (*vop_link_t)(bhv_desc_t *, vnode_t *, vname_t *,
209 struct cred *);
210typedef int (*vop_rename_t)(bhv_desc_t *, vname_t *, vnode_t *, vname_t *,
211 struct cred *);
212typedef int (*vop_mkdir_t)(bhv_desc_t *, vname_t *, struct vattr *,
213 vnode_t **, struct cred *);
214typedef int (*vop_rmdir_t)(bhv_desc_t *, vname_t *, struct cred *);
215typedef int (*vop_readdir_t)(bhv_desc_t *, struct uio *, struct cred *,
216 int *);
217typedef int (*vop_symlink_t)(bhv_desc_t *, vname_t *, struct vattr *,
218 char *, vnode_t **, struct cred *);
219typedef int (*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
220 struct cred *);
221typedef int (*vop_fsync_t)(bhv_desc_t *, int, struct cred *,
222 xfs_off_t, xfs_off_t);
223typedef int (*vop_inactive_t)(bhv_desc_t *, struct cred *);
224typedef int (*vop_fid2_t)(bhv_desc_t *, struct fid *);
225typedef int (*vop_release_t)(bhv_desc_t *);
226typedef int (*vop_rwlock_t)(bhv_desc_t *, vrwlock_t);
227typedef void (*vop_rwunlock_t)(bhv_desc_t *, vrwlock_t);
228typedef int (*vop_bmap_t)(bhv_desc_t *, xfs_off_t, ssize_t, int,
229 struct xfs_iomap *, int *);
230typedef int (*vop_reclaim_t)(bhv_desc_t *);
231typedef int (*vop_attr_get_t)(bhv_desc_t *, char *, char *, int *, int,
232 struct cred *);
233typedef int (*vop_attr_set_t)(bhv_desc_t *, char *, char *, int, int,
234 struct cred *);
235typedef int (*vop_attr_remove_t)(bhv_desc_t *, char *, int, struct cred *);
236typedef int (*vop_attr_list_t)(bhv_desc_t *, char *, int, int,
237 struct attrlist_cursor_kern *, struct cred *);
238typedef void (*vop_link_removed_t)(bhv_desc_t *, vnode_t *, int);
239typedef void (*vop_vnode_change_t)(bhv_desc_t *, vchange_t, __psint_t);
240typedef void (*vop_ptossvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
241typedef void (*vop_pflushinvalvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
242typedef int (*vop_pflushvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t,
243 uint64_t, int);
244typedef int (*vop_iflush_t)(bhv_desc_t *, int);
245
246
247typedef struct vnodeops {
248 bhv_position_t vn_position; /* position within behavior chain */
249 vop_open_t vop_open;
250 vop_read_t vop_read;
251 vop_write_t vop_write;
252 vop_sendfile_t vop_sendfile;
253 vop_ioctl_t vop_ioctl;
254 vop_getattr_t vop_getattr;
255 vop_setattr_t vop_setattr;
256 vop_access_t vop_access;
257 vop_lookup_t vop_lookup;
258 vop_create_t vop_create;
259 vop_remove_t vop_remove;
260 vop_link_t vop_link;
261 vop_rename_t vop_rename;
262 vop_mkdir_t vop_mkdir;
263 vop_rmdir_t vop_rmdir;
264 vop_readdir_t vop_readdir;
265 vop_symlink_t vop_symlink;
266 vop_readlink_t vop_readlink;
267 vop_fsync_t vop_fsync;
268 vop_inactive_t vop_inactive;
269 vop_fid2_t vop_fid2;
270 vop_rwlock_t vop_rwlock;
271 vop_rwunlock_t vop_rwunlock;
272 vop_bmap_t vop_bmap;
273 vop_reclaim_t vop_reclaim;
274 vop_attr_get_t vop_attr_get;
275 vop_attr_set_t vop_attr_set;
276 vop_attr_remove_t vop_attr_remove;
277 vop_attr_list_t vop_attr_list;
278 vop_link_removed_t vop_link_removed;
279 vop_vnode_change_t vop_vnode_change;
280 vop_ptossvp_t vop_tosspages;
281 vop_pflushinvalvp_t vop_flushinval_pages;
282 vop_pflushvp_t vop_flush_pages;
283 vop_release_t vop_release;
284 vop_iflush_t vop_iflush;
285} vnodeops_t;
286
287/*
288 * VOP's.
289 */
290#define _VOP_(op, vp) (*((vnodeops_t *)(vp)->v_fops)->op)
291
292#define VOP_READ(vp,file,iov,segs,offset,ioflags,cr,rv) \
293 rv = _VOP_(vop_read, vp)((vp)->v_fbhv,file,iov,segs,offset,ioflags,cr)
294#define VOP_WRITE(vp,file,iov,segs,offset,ioflags,cr,rv) \
295 rv = _VOP_(vop_write, vp)((vp)->v_fbhv,file,iov,segs,offset,ioflags,cr)
296#define VOP_SENDFILE(vp,f,off,ioflags,cnt,act,targ,cr,rv) \
297 rv = _VOP_(vop_sendfile, vp)((vp)->v_fbhv,f,off,ioflags,cnt,act,targ,cr)
298#define VOP_BMAP(vp,of,sz,rw,b,n,rv) \
299 rv = _VOP_(vop_bmap, vp)((vp)->v_fbhv,of,sz,rw,b,n)
300#define VOP_OPEN(vp, cr, rv) \
301 rv = _VOP_(vop_open, vp)((vp)->v_fbhv, cr)
302#define VOP_GETATTR(vp, vap, f, cr, rv) \
303 rv = _VOP_(vop_getattr, vp)((vp)->v_fbhv, vap, f, cr)
304#define VOP_SETATTR(vp, vap, f, cr, rv) \
305 rv = _VOP_(vop_setattr, vp)((vp)->v_fbhv, vap, f, cr)
306#define VOP_ACCESS(vp, mode, cr, rv) \
307 rv = _VOP_(vop_access, vp)((vp)->v_fbhv, mode, cr)
308#define VOP_LOOKUP(vp,d,vpp,f,rdir,cr,rv) \
309 rv = _VOP_(vop_lookup, vp)((vp)->v_fbhv,d,vpp,f,rdir,cr)
310#define VOP_CREATE(dvp,d,vap,vpp,cr,rv) \
311 rv = _VOP_(vop_create, dvp)((dvp)->v_fbhv,d,vap,vpp,cr)
312#define VOP_REMOVE(dvp,d,cr,rv) \
313 rv = _VOP_(vop_remove, dvp)((dvp)->v_fbhv,d,cr)
314#define VOP_LINK(tdvp,fvp,d,cr,rv) \
315 rv = _VOP_(vop_link, tdvp)((tdvp)->v_fbhv,fvp,d,cr)
316#define VOP_RENAME(fvp,fnm,tdvp,tnm,cr,rv) \
317 rv = _VOP_(vop_rename, fvp)((fvp)->v_fbhv,fnm,tdvp,tnm,cr)
318#define VOP_MKDIR(dp,d,vap,vpp,cr,rv) \
319 rv = _VOP_(vop_mkdir, dp)((dp)->v_fbhv,d,vap,vpp,cr)
320#define VOP_RMDIR(dp,d,cr,rv) \
321 rv = _VOP_(vop_rmdir, dp)((dp)->v_fbhv,d,cr)
322#define VOP_READDIR(vp,uiop,cr,eofp,rv) \
323 rv = _VOP_(vop_readdir, vp)((vp)->v_fbhv,uiop,cr,eofp)
324#define VOP_SYMLINK(dvp,d,vap,tnm,vpp,cr,rv) \
325 rv = _VOP_(vop_symlink, dvp) ((dvp)->v_fbhv,d,vap,tnm,vpp,cr)
326#define VOP_READLINK(vp,uiop,fl,cr,rv) \
327 rv = _VOP_(vop_readlink, vp)((vp)->v_fbhv,uiop,fl,cr)
328#define VOP_FSYNC(vp,f,cr,b,e,rv) \
329 rv = _VOP_(vop_fsync, vp)((vp)->v_fbhv,f,cr,b,e)
330#define VOP_INACTIVE(vp, cr, rv) \
331 rv = _VOP_(vop_inactive, vp)((vp)->v_fbhv, cr)
332#define VOP_RELEASE(vp, rv) \
333 rv = _VOP_(vop_release, vp)((vp)->v_fbhv)
334#define VOP_FID2(vp, fidp, rv) \
335 rv = _VOP_(vop_fid2, vp)((vp)->v_fbhv, fidp)
336#define VOP_RWLOCK(vp,i) \
337 (void)_VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
338#define VOP_RWLOCK_TRY(vp,i) \
339 _VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
340#define VOP_RWUNLOCK(vp,i) \
341 (void)_VOP_(vop_rwunlock, vp)((vp)->v_fbhv, i)
342#define VOP_FRLOCK(vp,c,fl,flags,offset,fr,rv) \
343 rv = _VOP_(vop_frlock, vp)((vp)->v_fbhv,c,fl,flags,offset,fr)
344#define VOP_RECLAIM(vp, rv) \
345 rv = _VOP_(vop_reclaim, vp)((vp)->v_fbhv)
346#define VOP_ATTR_GET(vp, name, val, vallenp, fl, cred, rv) \
347 rv = _VOP_(vop_attr_get, vp)((vp)->v_fbhv,name,val,vallenp,fl,cred)
348#define VOP_ATTR_SET(vp, name, val, vallen, fl, cred, rv) \
349 rv = _VOP_(vop_attr_set, vp)((vp)->v_fbhv,name,val,vallen,fl,cred)
350#define VOP_ATTR_REMOVE(vp, name, flags, cred, rv) \
351 rv = _VOP_(vop_attr_remove, vp)((vp)->v_fbhv,name,flags,cred)
352#define VOP_ATTR_LIST(vp, buf, buflen, fl, cursor, cred, rv) \
353 rv = _VOP_(vop_attr_list, vp)((vp)->v_fbhv,buf,buflen,fl,cursor,cred)
354#define VOP_LINK_REMOVED(vp, dvp, linkzero) \
355 (void)_VOP_(vop_link_removed, vp)((vp)->v_fbhv, dvp, linkzero)
356#define VOP_VNODE_CHANGE(vp, cmd, val) \
357 (void)_VOP_(vop_vnode_change, vp)((vp)->v_fbhv,cmd,val)
358/*
359 * These are page cache functions that now go thru VOPs.
360 * 'last' parameter is unused and left in for IRIX compatibility
361 */
362#define VOP_TOSS_PAGES(vp, first, last, fiopt) \
363 _VOP_(vop_tosspages, vp)((vp)->v_fbhv,first, last, fiopt)
364/*
365 * 'last' parameter is unused and left in for IRIX compatibility
366 */
367#define VOP_FLUSHINVAL_PAGES(vp, first, last, fiopt) \
368 _VOP_(vop_flushinval_pages, vp)((vp)->v_fbhv,first,last,fiopt)
369/*
370 * 'last' parameter is unused and left in for IRIX compatibility
371 */
372#define VOP_FLUSH_PAGES(vp, first, last, flags, fiopt, rv) \
373 rv = _VOP_(vop_flush_pages, vp)((vp)->v_fbhv,first,last,flags,fiopt)
374#define VOP_IOCTL(vp, inode, filp, fl, cmd, arg, rv) \
375 rv = _VOP_(vop_ioctl, vp)((vp)->v_fbhv,inode,filp,fl,cmd,arg)
376#define VOP_IFLUSH(vp, flags, rv) \
377 rv = _VOP_(vop_iflush, vp)((vp)->v_fbhv, flags)
378
379/*
380 * Flags for read/write calls - same values as IRIX
381 */
382#define IO_ISAIO 0x00001 /* don't wait for completion */
383#define IO_ISDIRECT 0x00004 /* bypass page cache */
384#define IO_INVIS 0x00020 /* don't update inode timestamps */
385
386/*
387 * Flags for VOP_IFLUSH call
388 */
389#define FLUSH_SYNC 1 /* wait for flush to complete */
390#define FLUSH_INODE 2 /* flush the inode itself */
391#define FLUSH_LOG 4 /* force the last log entry for
392 * this inode out to disk */
393
394/*
395 * Flush/Invalidate options for VOP_TOSS_PAGES, VOP_FLUSHINVAL_PAGES and
396 * VOP_FLUSH_PAGES.
397 */
398#define FI_NONE 0 /* none */
399#define FI_REMAPF 1 /* Do a remapf prior to the operation */
400#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
401 Prevent VM access to the pages until
402 the operation completes. */
403
404/*
405 * Vnode attributes. va_mask indicates those attributes the caller
406 * wants to set or extract.
407 */
408typedef struct vattr {
409 int va_mask; /* bit-mask of attributes present */
410 enum vtype va_type; /* vnode type (for create) */
411 mode_t va_mode; /* file access mode and type */
Nathan Scott31b084a2005-05-05 13:25:00 -0700412 xfs_nlink_t va_nlink; /* number of references to file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 uid_t va_uid; /* owner user id */
414 gid_t va_gid; /* owner group id */
415 xfs_ino_t va_nodeid; /* file id */
416 xfs_off_t va_size; /* file size in bytes */
417 u_long va_blocksize; /* blocksize preferred for i/o */
418 struct timespec va_atime; /* time of last access */
419 struct timespec va_mtime; /* time of last modification */
420 struct timespec va_ctime; /* time file changed */
421 u_int va_gen; /* generation number of file */
422 xfs_dev_t va_rdev; /* device the special file represents */
423 __int64_t va_nblocks; /* number of blocks allocated */
424 u_long va_xflags; /* random extended file flags */
425 u_long va_extsize; /* file extent size */
426 u_long va_nextents; /* number of extents in file */
427 u_long va_anextents; /* number of attr extents in file */
428 int va_projid; /* project id */
429} vattr_t;
430
431/*
432 * setattr or getattr attributes
433 */
434#define XFS_AT_TYPE 0x00000001
435#define XFS_AT_MODE 0x00000002
436#define XFS_AT_UID 0x00000004
437#define XFS_AT_GID 0x00000008
438#define XFS_AT_FSID 0x00000010
439#define XFS_AT_NODEID 0x00000020
440#define XFS_AT_NLINK 0x00000040
441#define XFS_AT_SIZE 0x00000080
442#define XFS_AT_ATIME 0x00000100
443#define XFS_AT_MTIME 0x00000200
444#define XFS_AT_CTIME 0x00000400
445#define XFS_AT_RDEV 0x00000800
446#define XFS_AT_BLKSIZE 0x00001000
447#define XFS_AT_NBLOCKS 0x00002000
448#define XFS_AT_VCODE 0x00004000
449#define XFS_AT_MAC 0x00008000
450#define XFS_AT_UPDATIME 0x00010000
451#define XFS_AT_UPDMTIME 0x00020000
452#define XFS_AT_UPDCTIME 0x00040000
453#define XFS_AT_ACL 0x00080000
454#define XFS_AT_CAP 0x00100000
455#define XFS_AT_INF 0x00200000
456#define XFS_AT_XFLAGS 0x00400000
457#define XFS_AT_EXTSIZE 0x00800000
458#define XFS_AT_NEXTENTS 0x01000000
459#define XFS_AT_ANEXTENTS 0x02000000
460#define XFS_AT_PROJID 0x04000000
461#define XFS_AT_SIZE_NOPERM 0x08000000
462#define XFS_AT_GENCOUNT 0x10000000
463
464#define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
465 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
466 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
467 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
468 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
469 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
470
471#define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
472 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
473 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
474 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
475
476#define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
477
478#define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
479
480#define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
481 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
482 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
483
484/*
485 * Modes.
486 */
487#define VSUID S_ISUID /* set user id on execution */
488#define VSGID S_ISGID /* set group id on execution */
489#define VSVTX S_ISVTX /* save swapped text even after use */
490#define VREAD S_IRUSR /* read, write, execute permissions */
491#define VWRITE S_IWUSR
492#define VEXEC S_IXUSR
493
494#define MODEMASK S_IALLUGO /* mode bits plus permission bits */
495
496/*
497 * Check whether mandatory file locking is enabled.
498 */
499#define MANDLOCK(vp, mode) \
500 ((vp)->v_type == VREG && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
501
502extern void vn_init(void);
503extern int vn_wait(struct vnode *);
504extern vnode_t *vn_initialize(struct inode *);
505
506/*
507 * Acquiring and invalidating vnodes:
508 *
509 * if (vn_get(vp, version, 0))
510 * ...;
511 * vn_purge(vp, version);
512 *
513 * vn_get and vn_purge must be called with vmap_t arguments, sampled
514 * while a lock that the vnode's VOP_RECLAIM function acquires is
515 * held, to ensure that the vnode sampled with the lock held isn't
516 * recycled (VOP_RECLAIMed) or deallocated between the release of the lock
517 * and the subsequent vn_get or vn_purge.
518 */
519
520/*
521 * vnode_map structures _must_ match vn_epoch and vnode structure sizes.
522 */
523typedef struct vnode_map {
524 vfs_t *v_vfsp;
525 vnumber_t v_number; /* in-core vnode number */
526 xfs_ino_t v_ino; /* inode # */
527} vmap_t;
528
529#define VMAP(vp, vmap) {(vmap).v_vfsp = (vp)->v_vfsp, \
530 (vmap).v_number = (vp)->v_number, \
531 (vmap).v_ino = (vp)->v_inode.i_ino; }
532
533extern void vn_purge(struct vnode *, vmap_t *);
534extern vnode_t *vn_get(struct vnode *, vmap_t *);
535extern int vn_revalidate(struct vnode *);
536extern void vn_revalidate_core(struct vnode *, vattr_t *);
537extern void vn_remove(struct vnode *);
538
539static inline int vn_count(struct vnode *vp)
540{
541 return atomic_read(&LINVFS_GET_IP(vp)->i_count);
542}
543
544/*
545 * Vnode reference counting functions (and macros for compatibility).
546 */
547extern vnode_t *vn_hold(struct vnode *);
548extern void vn_rele(struct vnode *);
549
550#if defined(XFS_VNODE_TRACE)
551#define VN_HOLD(vp) \
552 ((void)vn_hold(vp), \
553 vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
554#define VN_RELE(vp) \
555 (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
556 iput(LINVFS_GET_IP(vp)))
557#else
558#define VN_HOLD(vp) ((void)vn_hold(vp))
559#define VN_RELE(vp) (iput(LINVFS_GET_IP(vp)))
560#endif
561
562/*
563 * Vname handling macros.
564 */
565#define VNAME(dentry) ((char *) (dentry)->d_name.name)
566#define VNAMELEN(dentry) ((dentry)->d_name.len)
567#define VNAME_TO_VNODE(dentry) (LINVFS_GET_VP((dentry)->d_inode))
568
569/*
570 * Vnode spinlock manipulation.
571 */
572#define VN_LOCK(vp) mutex_spinlock(&(vp)->v_lock)
573#define VN_UNLOCK(vp, s) mutex_spinunlock(&(vp)->v_lock, s)
574#define VN_FLAGSET(vp,b) vn_flagset(vp,b)
575#define VN_FLAGCLR(vp,b) vn_flagclr(vp,b)
576
577static __inline__ void vn_flagset(struct vnode *vp, uint flag)
578{
579 spin_lock(&vp->v_lock);
580 vp->v_flag |= flag;
581 spin_unlock(&vp->v_lock);
582}
583
584static __inline__ void vn_flagclr(struct vnode *vp, uint flag)
585{
586 spin_lock(&vp->v_lock);
587 vp->v_flag &= ~flag;
588 spin_unlock(&vp->v_lock);
589}
590
591/*
592 * Update modify/access/change times on the vnode
593 */
594#define VN_MTIMESET(vp, tvp) (LINVFS_GET_IP(vp)->i_mtime = *(tvp))
595#define VN_ATIMESET(vp, tvp) (LINVFS_GET_IP(vp)->i_atime = *(tvp))
596#define VN_CTIMESET(vp, tvp) (LINVFS_GET_IP(vp)->i_ctime = *(tvp))
597
598/*
599 * Dealing with bad inodes
600 */
601static inline void vn_mark_bad(struct vnode *vp)
602{
603 make_bad_inode(LINVFS_GET_IP(vp));
604}
605
606static inline int VN_BAD(struct vnode *vp)
607{
608 return is_bad_inode(LINVFS_GET_IP(vp));
609}
610
611/*
612 * Some useful predicates.
613 */
614#define VN_MAPPED(vp) mapping_mapped(LINVFS_GET_IP(vp)->i_mapping)
615#define VN_CACHED(vp) (LINVFS_GET_IP(vp)->i_mapping->nrpages)
616#define VN_DIRTY(vp) mapping_tagged(LINVFS_GET_IP(vp)->i_mapping, \
617 PAGECACHE_TAG_DIRTY)
618#define VMODIFY(vp) VN_FLAGSET(vp, VMODIFIED)
619#define VUNMODIFY(vp) VN_FLAGCLR(vp, VMODIFIED)
620
621/*
622 * Flags to VOP_SETATTR/VOP_GETATTR.
623 */
624#define ATTR_UTIME 0x01 /* non-default utime(2) request */
625#define ATTR_DMI 0x08 /* invocation from a DMI function */
626#define ATTR_LAZY 0x80 /* set/get attributes lazily */
627#define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
628
629/*
630 * Flags to VOP_FSYNC and VOP_RECLAIM.
631 */
632#define FSYNC_NOWAIT 0 /* asynchronous flush */
633#define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
634#define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
635#define FSYNC_DATA 0x4 /* synchronous fsync of data only */
636
637/*
638 * Tracking vnode activity.
639 */
640#if defined(XFS_VNODE_TRACE)
641
642#define VNODE_TRACE_SIZE 16 /* number of trace entries */
643#define VNODE_KTRACE_ENTRY 1
644#define VNODE_KTRACE_EXIT 2
645#define VNODE_KTRACE_HOLD 3
646#define VNODE_KTRACE_REF 4
647#define VNODE_KTRACE_RELE 5
648
649extern void vn_trace_entry(struct vnode *, char *, inst_t *);
650extern void vn_trace_exit(struct vnode *, char *, inst_t *);
651extern void vn_trace_hold(struct vnode *, char *, int, inst_t *);
652extern void vn_trace_ref(struct vnode *, char *, int, inst_t *);
653extern void vn_trace_rele(struct vnode *, char *, int, inst_t *);
654
655#define VN_TRACE(vp) \
656 vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
657#else
658#define vn_trace_entry(a,b,c)
659#define vn_trace_exit(a,b,c)
660#define vn_trace_hold(a,b,c,d)
661#define vn_trace_ref(a,b,c,d)
662#define vn_trace_rele(a,b,c,d)
663#define VN_TRACE(vp)
664#endif
665
666#endif /* __XFS_VNODE_H__ */