Pull altix-mmr into release branch
[powerpc.git] / fs / xfs / linux-2.6 / xfs_vnode.h
1 /*
2  * Copyright (c) 2000-2005 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
62 struct uio;
63 struct file;
64 struct vattr;
65 struct xfs_iomap;
66 struct attrlist_cursor_kern;
67
68
69 typedef xfs_ino_t vnumber_t;
70 typedef struct dentry vname_t;
71 typedef bhv_head_t vn_bhv_head_t;
72
73 /*
74  * MP locking protocols:
75  *      v_flag, v_vfsp                          VN_LOCK/VN_UNLOCK
76  */
77 typedef struct vnode {
78         __u32           v_flag;                 /* vnode flags (see below) */
79         struct vfs      *v_vfsp;                /* ptr to containing VFS */
80         vnumber_t       v_number;               /* in-core vnode number */
81         vn_bhv_head_t   v_bh;                   /* behavior head */
82         spinlock_t      v_lock;                 /* VN_LOCK/VN_UNLOCK */
83         atomic_t        v_iocount;              /* outstanding I/O count */
84 #ifdef XFS_VNODE_TRACE
85         struct ktrace   *v_trace;               /* trace header structure    */
86 #endif
87         struct inode    v_inode;                /* Linux inode */
88         /* inode MUST be last */
89 } vnode_t;
90
91 #define VN_ISLNK(vp)    S_ISLNK((vp)->v_inode.i_mode)
92 #define VN_ISREG(vp)    S_ISREG((vp)->v_inode.i_mode)
93 #define VN_ISDIR(vp)    S_ISDIR((vp)->v_inode.i_mode)
94 #define VN_ISCHR(vp)    S_ISCHR((vp)->v_inode.i_mode)
95 #define VN_ISBLK(vp)    S_ISBLK((vp)->v_inode.i_mode)
96
97 #define v_fbhv                  v_bh.bh_first          /* first behavior */
98 #define v_fops                  v_bh.bh_first->bd_ops  /* first behavior ops */
99
100 #define VNODE_POSITION_BASE     BHV_POSITION_BASE       /* chain bottom */
101 #define VNODE_POSITION_TOP      BHV_POSITION_TOP        /* chain top */
102 #define VNODE_POSITION_INVALID  BHV_POSITION_INVALID    /* invalid pos. num */
103
104 typedef enum {
105         VN_BHV_UNKNOWN,         /* not specified */
106         VN_BHV_XFS,             /* xfs */
107         VN_BHV_DM,              /* data migration */
108         VN_BHV_QM,              /* quota manager */
109         VN_BHV_IO,              /* IO path */
110         VN_BHV_END              /* housekeeping end-of-range */
111 } vn_bhv_t;
112
113 #define VNODE_POSITION_XFS      (VNODE_POSITION_BASE)
114 #define VNODE_POSITION_DM       (VNODE_POSITION_BASE+10)
115 #define VNODE_POSITION_QM       (VNODE_POSITION_BASE+20)
116 #define VNODE_POSITION_IO       (VNODE_POSITION_BASE+30)
117
118 /*
119  * Macros for dealing with the behavior descriptor inside of the vnode.
120  */
121 #define BHV_TO_VNODE(bdp)       ((vnode_t *)BHV_VOBJ(bdp))
122 #define BHV_TO_VNODE_NULL(bdp)  ((vnode_t *)BHV_VOBJNULL(bdp))
123
124 #define VN_BHV_HEAD(vp)                 ((bhv_head_t *)(&((vp)->v_bh)))
125 #define vn_bhv_head_init(bhp,name)      bhv_head_init(bhp,name)
126 #define vn_bhv_remove(bhp,bdp)          bhv_remove(bhp,bdp)
127 #define vn_bhv_lookup(bhp,ops)          bhv_lookup(bhp,ops)
128 #define vn_bhv_lookup_unlocked(bhp,ops) bhv_lookup_unlocked(bhp,ops)
129
130 /*
131  * Vnode to Linux inode mapping.
132  */
133 #define LINVFS_GET_VP(inode)    ((vnode_t *)list_entry(inode, vnode_t, v_inode))
134 #define LINVFS_GET_IP(vp)       (&(vp)->v_inode)
135
136 /*
137  * Vnode flags.
138  */
139 #define VMODIFIED              0x8      /* XFS inode state possibly differs */
140                                         /* to the Linux inode state.    */
141
142 /*
143  * Values for the VOP_RWLOCK and VOP_RWUNLOCK flags parameter.
144  */
145 typedef enum vrwlock {
146         VRWLOCK_NONE,
147         VRWLOCK_READ,
148         VRWLOCK_WRITE,
149         VRWLOCK_WRITE_DIRECT,
150         VRWLOCK_TRY_READ,
151         VRWLOCK_TRY_WRITE
152 } vrwlock_t;
153
154 /*
155  * Return values for VOP_INACTIVE.  A return value of
156  * VN_INACTIVE_NOCACHE implies that the file system behavior
157  * has disassociated its state and bhv_desc_t from the vnode.
158  */
159 #define VN_INACTIVE_CACHE       0
160 #define VN_INACTIVE_NOCACHE     1
161
162 /*
163  * Values for the cmd code given to VOP_VNODE_CHANGE.
164  */
165 typedef enum vchange {
166         VCHANGE_FLAGS_FRLOCKS           = 0,
167         VCHANGE_FLAGS_ENF_LOCKING       = 1,
168         VCHANGE_FLAGS_TRUNCATED         = 2,
169         VCHANGE_FLAGS_PAGE_DIRTY        = 3,
170         VCHANGE_FLAGS_IOEXCL_COUNT      = 4
171 } vchange_t;
172
173
174 typedef int     (*vop_open_t)(bhv_desc_t *, struct cred *);
175 typedef ssize_t (*vop_read_t)(bhv_desc_t *, struct kiocb *,
176                                 const struct iovec *, unsigned int,
177                                 loff_t *, int, struct cred *);
178 typedef ssize_t (*vop_write_t)(bhv_desc_t *, struct kiocb *,
179                                 const struct iovec *, unsigned int,
180                                 loff_t *, int, struct cred *);
181 typedef ssize_t (*vop_sendfile_t)(bhv_desc_t *, struct file *,
182                                 loff_t *, int, size_t, read_actor_t,
183                                 void *, struct cred *);
184 typedef int     (*vop_ioctl_t)(bhv_desc_t *, struct inode *, struct file *,
185                                 int, unsigned int, void __user *);
186 typedef int     (*vop_getattr_t)(bhv_desc_t *, struct vattr *, int,
187                                 struct cred *);
188 typedef int     (*vop_setattr_t)(bhv_desc_t *, struct vattr *, int,
189                                 struct cred *);
190 typedef int     (*vop_access_t)(bhv_desc_t *, int, struct cred *);
191 typedef int     (*vop_lookup_t)(bhv_desc_t *, vname_t *, vnode_t **,
192                                 int, vnode_t *, struct cred *);
193 typedef int     (*vop_create_t)(bhv_desc_t *, vname_t *, struct vattr *,
194                                 vnode_t **, struct cred *);
195 typedef int     (*vop_remove_t)(bhv_desc_t *, vname_t *, struct cred *);
196 typedef int     (*vop_link_t)(bhv_desc_t *, vnode_t *, vname_t *,
197                                 struct cred *);
198 typedef int     (*vop_rename_t)(bhv_desc_t *, vname_t *, vnode_t *, vname_t *,
199                                 struct cred *);
200 typedef int     (*vop_mkdir_t)(bhv_desc_t *, vname_t *, struct vattr *,
201                                 vnode_t **, struct cred *);
202 typedef int     (*vop_rmdir_t)(bhv_desc_t *, vname_t *, struct cred *);
203 typedef int     (*vop_readdir_t)(bhv_desc_t *, struct uio *, struct cred *,
204                                 int *);
205 typedef int     (*vop_symlink_t)(bhv_desc_t *, vname_t *, struct vattr *,
206                                 char *, vnode_t **, struct cred *);
207 typedef int     (*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
208                                 struct cred *);
209 typedef int     (*vop_fsync_t)(bhv_desc_t *, int, struct cred *,
210                                 xfs_off_t, xfs_off_t);
211 typedef int     (*vop_inactive_t)(bhv_desc_t *, struct cred *);
212 typedef int     (*vop_fid2_t)(bhv_desc_t *, struct fid *);
213 typedef int     (*vop_release_t)(bhv_desc_t *);
214 typedef int     (*vop_rwlock_t)(bhv_desc_t *, vrwlock_t);
215 typedef void    (*vop_rwunlock_t)(bhv_desc_t *, vrwlock_t);
216 typedef int     (*vop_bmap_t)(bhv_desc_t *, xfs_off_t, ssize_t, int,
217                                 struct xfs_iomap *, int *);
218 typedef int     (*vop_reclaim_t)(bhv_desc_t *);
219 typedef int     (*vop_attr_get_t)(bhv_desc_t *, char *, char *, int *, int,
220                                 struct cred *);
221 typedef int     (*vop_attr_set_t)(bhv_desc_t *, char *, char *, int, int,
222                                 struct cred *);
223 typedef int     (*vop_attr_remove_t)(bhv_desc_t *, char *, int, struct cred *);
224 typedef int     (*vop_attr_list_t)(bhv_desc_t *, char *, int, int,
225                                 struct attrlist_cursor_kern *, struct cred *);
226 typedef void    (*vop_link_removed_t)(bhv_desc_t *, vnode_t *, int);
227 typedef void    (*vop_vnode_change_t)(bhv_desc_t *, vchange_t, __psint_t);
228 typedef void    (*vop_ptossvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
229 typedef void    (*vop_pflushinvalvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
230 typedef int     (*vop_pflushvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t,
231                                 uint64_t, int);
232 typedef int     (*vop_iflush_t)(bhv_desc_t *, int);
233
234
235 typedef struct vnodeops {
236         bhv_position_t  vn_position;    /* position within behavior chain */
237         vop_open_t              vop_open;
238         vop_read_t              vop_read;
239         vop_write_t             vop_write;
240         vop_sendfile_t          vop_sendfile;
241         vop_ioctl_t             vop_ioctl;
242         vop_getattr_t           vop_getattr;
243         vop_setattr_t           vop_setattr;
244         vop_access_t            vop_access;
245         vop_lookup_t            vop_lookup;
246         vop_create_t            vop_create;
247         vop_remove_t            vop_remove;
248         vop_link_t              vop_link;
249         vop_rename_t            vop_rename;
250         vop_mkdir_t             vop_mkdir;
251         vop_rmdir_t             vop_rmdir;
252         vop_readdir_t           vop_readdir;
253         vop_symlink_t           vop_symlink;
254         vop_readlink_t          vop_readlink;
255         vop_fsync_t             vop_fsync;
256         vop_inactive_t          vop_inactive;
257         vop_fid2_t              vop_fid2;
258         vop_rwlock_t            vop_rwlock;
259         vop_rwunlock_t          vop_rwunlock;
260         vop_bmap_t              vop_bmap;
261         vop_reclaim_t           vop_reclaim;
262         vop_attr_get_t          vop_attr_get;
263         vop_attr_set_t          vop_attr_set;
264         vop_attr_remove_t       vop_attr_remove;
265         vop_attr_list_t         vop_attr_list;
266         vop_link_removed_t      vop_link_removed;
267         vop_vnode_change_t      vop_vnode_change;
268         vop_ptossvp_t           vop_tosspages;
269         vop_pflushinvalvp_t     vop_flushinval_pages;
270         vop_pflushvp_t          vop_flush_pages;
271         vop_release_t           vop_release;
272         vop_iflush_t            vop_iflush;
273 } vnodeops_t;
274
275 /*
276  * VOP's.
277  */
278 #define _VOP_(op, vp)   (*((vnodeops_t *)(vp)->v_fops)->op)
279
280 #define VOP_READ(vp,file,iov,segs,offset,ioflags,cr,rv)                 \
281         rv = _VOP_(vop_read, vp)((vp)->v_fbhv,file,iov,segs,offset,ioflags,cr)
282 #define VOP_WRITE(vp,file,iov,segs,offset,ioflags,cr,rv)                \
283         rv = _VOP_(vop_write, vp)((vp)->v_fbhv,file,iov,segs,offset,ioflags,cr)
284 #define VOP_SENDFILE(vp,f,off,ioflags,cnt,act,targ,cr,rv)               \
285         rv = _VOP_(vop_sendfile, vp)((vp)->v_fbhv,f,off,ioflags,cnt,act,targ,cr)
286 #define VOP_BMAP(vp,of,sz,rw,b,n,rv)                                    \
287         rv = _VOP_(vop_bmap, vp)((vp)->v_fbhv,of,sz,rw,b,n)
288 #define VOP_OPEN(vp, cr, rv)                                            \
289         rv = _VOP_(vop_open, vp)((vp)->v_fbhv, cr)
290 #define VOP_GETATTR(vp, vap, f, cr, rv)                                 \
291         rv = _VOP_(vop_getattr, vp)((vp)->v_fbhv, vap, f, cr)
292 #define VOP_SETATTR(vp, vap, f, cr, rv)                                 \
293         rv = _VOP_(vop_setattr, vp)((vp)->v_fbhv, vap, f, cr)
294 #define VOP_ACCESS(vp, mode, cr, rv)                                    \
295         rv = _VOP_(vop_access, vp)((vp)->v_fbhv, mode, cr)
296 #define VOP_LOOKUP(vp,d,vpp,f,rdir,cr,rv)                               \
297         rv = _VOP_(vop_lookup, vp)((vp)->v_fbhv,d,vpp,f,rdir,cr)
298 #define VOP_CREATE(dvp,d,vap,vpp,cr,rv)                                 \
299         rv = _VOP_(vop_create, dvp)((dvp)->v_fbhv,d,vap,vpp,cr)
300 #define VOP_REMOVE(dvp,d,cr,rv)                                         \
301         rv = _VOP_(vop_remove, dvp)((dvp)->v_fbhv,d,cr)
302 #define VOP_LINK(tdvp,fvp,d,cr,rv)                                      \
303         rv = _VOP_(vop_link, tdvp)((tdvp)->v_fbhv,fvp,d,cr)
304 #define VOP_RENAME(fvp,fnm,tdvp,tnm,cr,rv)                              \
305         rv = _VOP_(vop_rename, fvp)((fvp)->v_fbhv,fnm,tdvp,tnm,cr)
306 #define VOP_MKDIR(dp,d,vap,vpp,cr,rv)                                   \
307         rv = _VOP_(vop_mkdir, dp)((dp)->v_fbhv,d,vap,vpp,cr)
308 #define VOP_RMDIR(dp,d,cr,rv)                                           \
309         rv = _VOP_(vop_rmdir, dp)((dp)->v_fbhv,d,cr)
310 #define VOP_READDIR(vp,uiop,cr,eofp,rv)                                 \
311         rv = _VOP_(vop_readdir, vp)((vp)->v_fbhv,uiop,cr,eofp)
312 #define VOP_SYMLINK(dvp,d,vap,tnm,vpp,cr,rv)                            \
313         rv = _VOP_(vop_symlink, dvp) ((dvp)->v_fbhv,d,vap,tnm,vpp,cr)
314 #define VOP_READLINK(vp,uiop,fl,cr,rv)                                  \
315         rv = _VOP_(vop_readlink, vp)((vp)->v_fbhv,uiop,fl,cr)
316 #define VOP_FSYNC(vp,f,cr,b,e,rv)                                       \
317         rv = _VOP_(vop_fsync, vp)((vp)->v_fbhv,f,cr,b,e)
318 #define VOP_INACTIVE(vp, cr, rv)                                        \
319         rv = _VOP_(vop_inactive, vp)((vp)->v_fbhv, cr)
320 #define VOP_RELEASE(vp, rv)                                             \
321         rv = _VOP_(vop_release, vp)((vp)->v_fbhv)
322 #define VOP_FID2(vp, fidp, rv)                                          \
323         rv = _VOP_(vop_fid2, vp)((vp)->v_fbhv, fidp)
324 #define VOP_RWLOCK(vp,i)                                                \
325         (void)_VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
326 #define VOP_RWLOCK_TRY(vp,i)                                            \
327         _VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
328 #define VOP_RWUNLOCK(vp,i)                                              \
329         (void)_VOP_(vop_rwunlock, vp)((vp)->v_fbhv, i)
330 #define VOP_FRLOCK(vp,c,fl,flags,offset,fr,rv)                          \
331         rv = _VOP_(vop_frlock, vp)((vp)->v_fbhv,c,fl,flags,offset,fr)
332 #define VOP_RECLAIM(vp, rv)                                             \
333         rv = _VOP_(vop_reclaim, vp)((vp)->v_fbhv)
334 #define VOP_ATTR_GET(vp, name, val, vallenp, fl, cred, rv)              \
335         rv = _VOP_(vop_attr_get, vp)((vp)->v_fbhv,name,val,vallenp,fl,cred)
336 #define VOP_ATTR_SET(vp, name, val, vallen, fl, cred, rv)               \
337         rv = _VOP_(vop_attr_set, vp)((vp)->v_fbhv,name,val,vallen,fl,cred)
338 #define VOP_ATTR_REMOVE(vp, name, flags, cred, rv)                      \
339         rv = _VOP_(vop_attr_remove, vp)((vp)->v_fbhv,name,flags,cred)
340 #define VOP_ATTR_LIST(vp, buf, buflen, fl, cursor, cred, rv)            \
341         rv = _VOP_(vop_attr_list, vp)((vp)->v_fbhv,buf,buflen,fl,cursor,cred)
342 #define VOP_LINK_REMOVED(vp, dvp, linkzero)                             \
343         (void)_VOP_(vop_link_removed, vp)((vp)->v_fbhv, dvp, linkzero)
344 #define VOP_VNODE_CHANGE(vp, cmd, val)                                  \
345         (void)_VOP_(vop_vnode_change, vp)((vp)->v_fbhv,cmd,val)
346 /*
347  * These are page cache functions that now go thru VOPs.
348  * 'last' parameter is unused and left in for IRIX compatibility
349  */
350 #define VOP_TOSS_PAGES(vp, first, last, fiopt)                          \
351         _VOP_(vop_tosspages, vp)((vp)->v_fbhv,first, last, fiopt)
352 /*
353  * 'last' parameter is unused and left in for IRIX compatibility
354  */
355 #define VOP_FLUSHINVAL_PAGES(vp, first, last, fiopt)                    \
356         _VOP_(vop_flushinval_pages, vp)((vp)->v_fbhv,first,last,fiopt)
357 /*
358  * 'last' parameter is unused and left in for IRIX compatibility
359  */
360 #define VOP_FLUSH_PAGES(vp, first, last, flags, fiopt, rv)              \
361         rv = _VOP_(vop_flush_pages, vp)((vp)->v_fbhv,first,last,flags,fiopt)
362 #define VOP_IOCTL(vp, inode, filp, fl, cmd, arg, rv)                    \
363         rv = _VOP_(vop_ioctl, vp)((vp)->v_fbhv,inode,filp,fl,cmd,arg)
364 #define VOP_IFLUSH(vp, flags, rv)                                       \
365         rv = _VOP_(vop_iflush, vp)((vp)->v_fbhv, flags)
366
367 /*
368  * Flags for read/write calls - same values as IRIX
369  */
370 #define IO_ISAIO        0x00001         /* don't wait for completion */
371 #define IO_ISDIRECT     0x00004         /* bypass page cache */
372 #define IO_INVIS        0x00020         /* don't update inode timestamps */
373
374 /*
375  * Flags for VOP_IFLUSH call
376  */
377 #define FLUSH_SYNC              1       /* wait for flush to complete   */
378 #define FLUSH_INODE             2       /* flush the inode itself       */
379 #define FLUSH_LOG               4       /* force the last log entry for
380                                          * this inode out to disk       */
381
382 /*
383  * Flush/Invalidate options for VOP_TOSS_PAGES, VOP_FLUSHINVAL_PAGES and
384  *      VOP_FLUSH_PAGES.
385  */
386 #define FI_NONE                 0       /* none */
387 #define FI_REMAPF               1       /* Do a remapf prior to the operation */
388 #define FI_REMAPF_LOCKED        2       /* Do a remapf prior to the operation.
389                                            Prevent VM access to the pages until
390                                            the operation completes. */
391
392 /*
393  * Vnode attributes.  va_mask indicates those attributes the caller
394  * wants to set or extract.
395  */
396 typedef struct vattr {
397         int             va_mask;        /* bit-mask of attributes present */
398         mode_t          va_mode;        /* file access mode and type */
399         xfs_nlink_t     va_nlink;       /* number of references to file */
400         uid_t           va_uid;         /* owner user id */
401         gid_t           va_gid;         /* owner group id */
402         xfs_ino_t       va_nodeid;      /* file id */
403         xfs_off_t       va_size;        /* file size in bytes */
404         u_long          va_blocksize;   /* blocksize preferred for i/o */
405         struct timespec va_atime;       /* time of last access */
406         struct timespec va_mtime;       /* time of last modification */
407         struct timespec va_ctime;       /* time file changed */
408         u_int           va_gen;         /* generation number of file */
409         xfs_dev_t       va_rdev;        /* device the special file represents */
410         __int64_t       va_nblocks;     /* number of blocks allocated */
411         u_long          va_xflags;      /* random extended file flags */
412         u_long          va_extsize;     /* file extent size */
413         u_long          va_nextents;    /* number of extents in file */
414         u_long          va_anextents;   /* number of attr extents in file */
415         prid_t          va_projid;      /* project id */
416 } vattr_t;
417
418 /*
419  * setattr or getattr attributes
420  */
421 #define XFS_AT_TYPE             0x00000001
422 #define XFS_AT_MODE             0x00000002
423 #define XFS_AT_UID              0x00000004
424 #define XFS_AT_GID              0x00000008
425 #define XFS_AT_FSID             0x00000010
426 #define XFS_AT_NODEID           0x00000020
427 #define XFS_AT_NLINK            0x00000040
428 #define XFS_AT_SIZE             0x00000080
429 #define XFS_AT_ATIME            0x00000100
430 #define XFS_AT_MTIME            0x00000200
431 #define XFS_AT_CTIME            0x00000400
432 #define XFS_AT_RDEV             0x00000800
433 #define XFS_AT_BLKSIZE          0x00001000
434 #define XFS_AT_NBLOCKS          0x00002000
435 #define XFS_AT_VCODE            0x00004000
436 #define XFS_AT_MAC              0x00008000
437 #define XFS_AT_UPDATIME         0x00010000
438 #define XFS_AT_UPDMTIME         0x00020000
439 #define XFS_AT_UPDCTIME         0x00040000
440 #define XFS_AT_ACL              0x00080000
441 #define XFS_AT_CAP              0x00100000
442 #define XFS_AT_INF              0x00200000
443 #define XFS_AT_XFLAGS           0x00400000
444 #define XFS_AT_EXTSIZE          0x00800000
445 #define XFS_AT_NEXTENTS         0x01000000
446 #define XFS_AT_ANEXTENTS        0x02000000
447 #define XFS_AT_PROJID           0x04000000
448 #define XFS_AT_SIZE_NOPERM      0x08000000
449 #define XFS_AT_GENCOUNT         0x10000000
450
451 #define XFS_AT_ALL      (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
452                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
453                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
454                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
455                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
456                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
457
458 #define XFS_AT_STAT     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
459                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
460                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
461                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
462
463 #define XFS_AT_TIMES    (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
464
465 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
466
467 #define XFS_AT_NOSET    (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
468                 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
469                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
470
471 /*
472  *  Modes.
473  */
474 #define VSUID   S_ISUID         /* set user id on execution */
475 #define VSGID   S_ISGID         /* set group id on execution */
476 #define VSVTX   S_ISVTX         /* save swapped text even after use */
477 #define VREAD   S_IRUSR         /* read, write, execute permissions */
478 #define VWRITE  S_IWUSR
479 #define VEXEC   S_IXUSR
480
481 #define MODEMASK S_IALLUGO      /* mode bits plus permission bits */
482
483 /*
484  * Check whether mandatory file locking is enabled.
485  */
486 #define MANDLOCK(vp, mode)      \
487         (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
488
489 extern void     vn_init(void);
490 extern vnode_t  *vn_initialize(struct inode *);
491
492 /*
493  * vnode_map structures _must_ match vn_epoch and vnode structure sizes.
494  */
495 typedef struct vnode_map {
496         vfs_t           *v_vfsp;
497         vnumber_t       v_number;               /* in-core vnode number */
498         xfs_ino_t       v_ino;                  /* inode #      */
499 } vmap_t;
500
501 #define VMAP(vp, vmap)  {(vmap).v_vfsp   = (vp)->v_vfsp,        \
502                          (vmap).v_number = (vp)->v_number,      \
503                          (vmap).v_ino    = (vp)->v_inode.i_ino; }
504
505 extern int      vn_revalidate(struct vnode *);
506 extern void     vn_revalidate_core(struct vnode *, vattr_t *);
507
508 extern void     vn_iowait(struct vnode *vp);
509 extern void     vn_iowake(struct vnode *vp);
510
511 static inline int vn_count(struct vnode *vp)
512 {
513         return atomic_read(&LINVFS_GET_IP(vp)->i_count);
514 }
515
516 /*
517  * Vnode reference counting functions (and macros for compatibility).
518  */
519 extern vnode_t  *vn_hold(struct vnode *);
520
521 #if defined(XFS_VNODE_TRACE)
522 #define VN_HOLD(vp)             \
523         ((void)vn_hold(vp),     \
524           vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
525 #define VN_RELE(vp)             \
526           (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
527            iput(LINVFS_GET_IP(vp)))
528 #else
529 #define VN_HOLD(vp)             ((void)vn_hold(vp))
530 #define VN_RELE(vp)             (iput(LINVFS_GET_IP(vp)))
531 #endif
532
533 static inline struct vnode *vn_grab(struct vnode *vp)
534 {
535         struct inode *inode = igrab(LINVFS_GET_IP(vp));
536         return inode ? LINVFS_GET_VP(inode) : NULL;
537 }
538
539 /*
540  * Vname handling macros.
541  */
542 #define VNAME(dentry)           ((char *) (dentry)->d_name.name)
543 #define VNAMELEN(dentry)        ((dentry)->d_name.len)
544 #define VNAME_TO_VNODE(dentry)  (LINVFS_GET_VP((dentry)->d_inode))
545
546 /*
547  * Vnode spinlock manipulation.
548  */
549 #define VN_LOCK(vp)             mutex_spinlock(&(vp)->v_lock)
550 #define VN_UNLOCK(vp, s)        mutex_spinunlock(&(vp)->v_lock, s)
551 #define VN_FLAGSET(vp,b)        vn_flagset(vp,b)
552 #define VN_FLAGCLR(vp,b)        vn_flagclr(vp,b)
553
554 static __inline__ void vn_flagset(struct vnode *vp, uint flag)
555 {
556         spin_lock(&vp->v_lock);
557         vp->v_flag |= flag;
558         spin_unlock(&vp->v_lock);
559 }
560
561 static __inline__ void vn_flagclr(struct vnode *vp, uint flag)
562 {
563         spin_lock(&vp->v_lock);
564         vp->v_flag &= ~flag;
565         spin_unlock(&vp->v_lock);
566 }
567
568 /*
569  * Update modify/access/change times on the vnode
570  */
571 #define VN_MTIMESET(vp, tvp)    (LINVFS_GET_IP(vp)->i_mtime = *(tvp))
572 #define VN_ATIMESET(vp, tvp)    (LINVFS_GET_IP(vp)->i_atime = *(tvp))
573 #define VN_CTIMESET(vp, tvp)    (LINVFS_GET_IP(vp)->i_ctime = *(tvp))
574
575 /*
576  * Dealing with bad inodes
577  */
578 static inline void vn_mark_bad(struct vnode *vp)
579 {
580         make_bad_inode(LINVFS_GET_IP(vp));
581 }
582
583 static inline int VN_BAD(struct vnode *vp)
584 {
585         return is_bad_inode(LINVFS_GET_IP(vp));
586 }
587
588 /*
589  * Some useful predicates.
590  */
591 #define VN_MAPPED(vp)   mapping_mapped(LINVFS_GET_IP(vp)->i_mapping)
592 #define VN_CACHED(vp)   (LINVFS_GET_IP(vp)->i_mapping->nrpages)
593 #define VN_DIRTY(vp)    mapping_tagged(LINVFS_GET_IP(vp)->i_mapping, \
594                                         PAGECACHE_TAG_DIRTY)
595 #define VMODIFY(vp)     VN_FLAGSET(vp, VMODIFIED)
596 #define VUNMODIFY(vp)   VN_FLAGCLR(vp, VMODIFIED)
597
598 /*
599  * Flags to VOP_SETATTR/VOP_GETATTR.
600  */
601 #define ATTR_UTIME      0x01    /* non-default utime(2) request */
602 #define ATTR_DMI        0x08    /* invocation from a DMI function */
603 #define ATTR_LAZY       0x80    /* set/get attributes lazily */
604 #define ATTR_NONBLOCK   0x100   /* return EAGAIN if operation would block */
605 #define ATTR_NOLOCK     0x200   /* Don't grab any conflicting locks */
606
607 /*
608  * Flags to VOP_FSYNC and VOP_RECLAIM.
609  */
610 #define FSYNC_NOWAIT    0       /* asynchronous flush */
611 #define FSYNC_WAIT      0x1     /* synchronous fsync or forced reclaim */
612 #define FSYNC_INVAL     0x2     /* flush and invalidate cached data */
613 #define FSYNC_DATA      0x4     /* synchronous fsync of data only */
614
615 /*
616  * Tracking vnode activity.
617  */
618 #if defined(XFS_VNODE_TRACE)
619
620 #define VNODE_TRACE_SIZE        16              /* number of trace entries */
621 #define VNODE_KTRACE_ENTRY      1
622 #define VNODE_KTRACE_EXIT       2
623 #define VNODE_KTRACE_HOLD       3
624 #define VNODE_KTRACE_REF        4
625 #define VNODE_KTRACE_RELE       5
626
627 extern void vn_trace_entry(struct vnode *, const char *, inst_t *);
628 extern void vn_trace_exit(struct vnode *, const char *, inst_t *);
629 extern void vn_trace_hold(struct vnode *, char *, int, inst_t *);
630 extern void vn_trace_ref(struct vnode *, char *, int, inst_t *);
631 extern void vn_trace_rele(struct vnode *, char *, int, inst_t *);
632
633 #define VN_TRACE(vp)            \
634         vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
635 #else
636 #define vn_trace_entry(a,b,c)
637 #define vn_trace_exit(a,b,c)
638 #define vn_trace_hold(a,b,c,d)
639 #define vn_trace_ref(a,b,c,d)
640 #define vn_trace_rele(a,b,c,d)
641 #define VN_TRACE(vp)
642 #endif
643
644 #endif  /* __XFS_VNODE_H__ */