]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/gnu/fs/xfs/FreeBSD/xfs_vnode.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / gnu / fs / xfs / FreeBSD / xfs_vnode.h
1 /*
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
62 #include <sys/vnode.h>
63 #include <sys/namei.h>
64
65 struct  xfs_iomap;
66 typedef struct componentname vname_t;
67 typedef bhv_head_t vn_bhv_head_t;
68
69 /*
70  * MP locking protocols:
71  *      v_flag, v_vfsp                          VN_LOCK/VN_UNLOCK
72  *      v_type                                  read-only or fs-dependent
73  */
74 typedef struct xfs_vnode {
75         __u32           v_flag;                 /* vnode flags (see below) */
76         struct xfs_vfs  *v_vfsp;                /* ptr to containing VFS */
77         xfs_ino_t       v_number;               /* in-core vnode number */
78         vn_bhv_head_t   v_bh;                   /* behavior head */
79         struct vnode    *v_vnode;               /* FreeBSD vnode */
80         struct xfs_inode *v_inode;              /* XFS inode */
81 #ifdef XFS_VNODE_TRACE
82         struct ktrace   *v_trace;               /* trace header structure    */
83 #endif
84 } xfs_vnode_t;
85
86
87 /* vnode types */
88 #define VN_ISLNK(vp)    ((vp)->v_vnode->v_type & VLNK)
89 #define VN_ISREG(vp)    ((vp)->v_vnode->v_type & VREG)
90 #define VN_ISDIR(vp)    ((vp)->v_vnode->v_type & VDIR)
91 #define VN_ISCHR(vp)    ((vp)->v_vnode->v_type & VCHR)
92 #define VN_ISBLK(vp)    ((vp)->v_vnode->v_type & VBLK)
93 #define VN_BAD(vp)      ((vp)->v_vnode->v_type & VBAD)
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
102 typedef 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 #define VPTOXFSVP(vp) ((struct xfs_vnode *)(vp)->v_data)
117
118 /*
119  * Macros for dealing with the behavior descriptor inside of the vnode.
120  */
121 #define BHV_TO_VNODE(bdp)       ((xfs_vnode_t *)BHV_VOBJ(bdp))
122 #define BHV_TO_VNODE_NULL(bdp)  ((xfs_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)    ((xfs_vnode_t *)NULL)
134 #define LINVFS_GET_IP(vp)       ((xfs_inode_t *)NULL)
135
136 /*
137  * Vnode flags.
138  */
139 #define VINACT                 0x1      /* vnode is being inactivated   */
140 #define VRECLM                 0x2      /* vnode is being reclaimed     */
141 #define VWAIT                  0x4      /* waiting for VINACT/VRECLM to end */
142 #define VMODIFIED              0x8      /* XFS inode state possibly differs */
143                                         /* to the Linux inode state.    */
144
145 /*
146  * Values for the VOP_RWLOCK and VOP_RWUNLOCK flags parameter.
147  */
148 typedef enum vrwlock {
149         VRWLOCK_NONE,
150         VRWLOCK_READ,
151         VRWLOCK_WRITE,
152         VRWLOCK_WRITE_DIRECT,
153         VRWLOCK_TRY_READ,
154         VRWLOCK_TRY_WRITE
155 } vrwlock_t;
156
157 /*
158  * Return values for VOP_INACTIVE.  A return value of
159  * VN_INACTIVE_NOCACHE implies that the file system behavior
160  * has disassociated its state and bhv_desc_t from the vnode.
161  */
162 #define VN_INACTIVE_CACHE       0
163 #define VN_INACTIVE_NOCACHE     1
164
165 /*
166  * Values for the cmd code given to VOP_VNODE_CHANGE.
167  */
168 typedef enum vchange {
169         VCHANGE_FLAGS_FRLOCKS           = 0,
170         VCHANGE_FLAGS_ENF_LOCKING       = 1,
171         VCHANGE_FLAGS_TRUNCATED         = 2,
172         VCHANGE_FLAGS_PAGE_DIRTY        = 3,
173         VCHANGE_FLAGS_IOEXCL_COUNT      = 4
174 } vchange_t;
175
176 struct file_lock;
177 struct xfs_iomap_s;
178 struct xfs_vattr;
179 struct attrlist_cursor_kern;
180
181 typedef int     (*xfs_vop_open_t)(bhv_desc_t *, struct cred *);
182 typedef ssize_t (*xfs_vop_read_t)(bhv_desc_t *, uio_t *, int, struct cred *);
183 typedef ssize_t (*xfs_vop_write_t)(bhv_desc_t *, uio_t *, int, struct cred *);
184 typedef int     (*xfs_vop_ioctl_t)(bhv_desc_t *, struct inode *, struct file *,
185                                 int, u_long, void *);
186 typedef int     (*xfs_vop_getattr_t)(bhv_desc_t *, struct xfs_vattr *, int,
187                                 struct cred *);
188 typedef int     (*xfs_vop_setattr_t)(bhv_desc_t *, struct xfs_vattr *, int,
189                                 struct cred *);
190 typedef int     (*xfs_vop_access_t)(bhv_desc_t *, int, struct cred *);
191 typedef int     (*xfs_vop_lookup_t)(bhv_desc_t *, vname_t *, xfs_vnode_t **,
192                                 int, xfs_vnode_t *, struct cred *);
193 typedef int     (*xfs_vop_create_t)(bhv_desc_t *, vname_t *, struct xfs_vattr *,
194                                 xfs_vnode_t **, struct cred *);
195 typedef int     (*xfs_vop_remove_t)(bhv_desc_t *, bhv_desc_t *, vname_t *, struct cred *);
196 typedef int     (*xfs_vop_link_t)(bhv_desc_t *, xfs_vnode_t *, vname_t *,
197                                 struct cred *);
198 typedef int     (*xfs_vop_rename_t)(bhv_desc_t *, vname_t *, xfs_vnode_t *, vname_t *,
199                                 struct cred *);
200 typedef int     (*xfs_vop_mkdir_t)(bhv_desc_t *, vname_t *, struct xfs_vattr *,
201                                 xfs_vnode_t **, struct cred *);
202 typedef int     (*xfs_vop_rmdir_t)(bhv_desc_t *, vname_t *, struct cred *);
203 typedef int     (*xfs_vop_readdir_t)(bhv_desc_t *, struct uio *, struct cred *,
204                                 int *);
205 typedef int     (*xfs_vop_symlink_t)(bhv_desc_t *, vname_t *, struct xfs_vattr *,
206                                 char *, xfs_vnode_t **, struct cred *);
207
208 typedef int     (*xfs_vop_readlink_t)(bhv_desc_t *, struct uio *, int,
209                                 struct cred *);
210 typedef int     (*xfs_vop_fsync_t)(bhv_desc_t *, int, struct cred *,
211                                 xfs_off_t, xfs_off_t);
212 typedef int     (*xfs_vop_inactive_t)(bhv_desc_t *, struct cred *);
213 typedef int     (*xfs_vop_fid2_t)(bhv_desc_t *, struct fid *);
214 typedef int     (*xfs_vop_release_t)(bhv_desc_t *);
215 typedef int     (*xfs_vop_rwlock_t)(bhv_desc_t *, vrwlock_t);
216 typedef void    (*xfs_vop_rwunlock_t)(bhv_desc_t *, vrwlock_t);
217 typedef int     (*xfs_vop_frlock_t)(bhv_desc_t *, int, struct file_lock *,int,
218                                 xfs_off_t, struct cred *);
219 typedef int     (*xfs_vop_bmap_t)(bhv_desc_t *, xfs_off_t, ssize_t, int,
220                                 struct xfs_iomap *, int *);
221 typedef int     (*xfs_vop_reclaim_t)(bhv_desc_t *);
222 typedef int     (*xfs_vop_attr_get_t)(bhv_desc_t *, const char *, char *, int *, int,
223                                 struct cred *);
224 typedef int     (*xfs_vop_attr_set_t)(bhv_desc_t *, const char *, char *, int, int,
225                                 struct cred *);
226 typedef int     (*xfs_vop_attr_remove_t)(bhv_desc_t *, const char *, int, struct cred *);
227 typedef int     (*xfs_vop_attr_list_t)(bhv_desc_t *, char *, int, int,
228                                 struct attrlist_cursor_kern *, struct cred *);
229 typedef void    (*xfs_vop_link_removed_t)(bhv_desc_t *, xfs_vnode_t *, int);
230 typedef void    (*xfs_vop_vnode_change_t)(bhv_desc_t *, vchange_t, __psint_t);
231 typedef void    (*xfs_vop_ptossvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
232 typedef void    (*xfs_vop_pflushinvalvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
233 typedef int     (*xfs_vop_pflushvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t,
234                                 uint64_t, int);
235 typedef int     (*xfs_vop_iflush_t)(bhv_desc_t *, int);
236
237
238 typedef struct xfs_vnodeops {
239         bhv_position_t  vn_position;    /* position within behavior chain */
240         xfs_vop_open_t          vop_open;
241         xfs_vop_read_t          vop_read;
242         xfs_vop_write_t         vop_write;
243         xfs_vop_ioctl_t         vop_ioctl;
244         xfs_vop_getattr_t       vop_getattr;
245         xfs_vop_setattr_t       vop_setattr;
246         xfs_vop_access_t        vop_access;
247         xfs_vop_lookup_t        vop_lookup;
248         xfs_vop_create_t        vop_create;
249         xfs_vop_remove_t        vop_remove;
250         xfs_vop_link_t          vop_link;
251         xfs_vop_rename_t        vop_rename;
252         xfs_vop_mkdir_t         vop_mkdir;
253         xfs_vop_rmdir_t         vop_rmdir;
254         xfs_vop_readdir_t       vop_readdir;
255         xfs_vop_symlink_t       vop_symlink;
256         xfs_vop_readlink_t      vop_readlink;
257         xfs_vop_fsync_t         vop_fsync;
258         xfs_vop_inactive_t      vop_inactive;
259         xfs_vop_fid2_t          vop_fid2;
260         xfs_vop_rwlock_t        vop_rwlock;
261         xfs_vop_rwunlock_t      vop_rwunlock;
262         xfs_vop_frlock_t        vop_frlock;
263         xfs_vop_bmap_t          vop_bmap;
264         xfs_vop_reclaim_t       vop_reclaim;
265         xfs_vop_attr_get_t      vop_attr_get;
266         xfs_vop_attr_set_t      vop_attr_set;
267         xfs_vop_attr_remove_t   vop_attr_remove;
268         xfs_vop_attr_list_t     vop_attr_list;
269         xfs_vop_link_removed_t  vop_link_removed;
270         xfs_vop_vnode_change_t  vop_vnode_change;
271         xfs_vop_ptossvp_t       vop_tosspages;
272         xfs_vop_pflushinvalvp_t vop_flushinval_pages;
273         xfs_vop_pflushvp_t      vop_flush_pages;
274         xfs_vop_release_t       vop_release;
275         xfs_vop_iflush_t        vop_iflush;
276 } xfs_vnodeops_t;
277
278 /*
279  * VOP's.
280  */
281 #define _VOP_(op, vp)   (*((xfs_vnodeops_t *)(vp)->v_fops)->op)
282
283 #define XVOP_READ(vp,uio,ioflags,cr,rv)                 \
284         rv = _VOP_(vop_read, vp)((vp)->v_fbhv,uio,ioflags,cr)
285 #define XVOP_WRITE(vp,file,uio,ioflags,cr,rv)           \
286         rv = _VOP_(vop_write, vp)((vp)->v_fbhv,uio,ioflags,cr)
287 #define XVOP_BMAP(vp,of,sz,rw,b,n,rv)                                   \
288         rv = _VOP_(vop_bmap, vp)((vp)->v_fbhv,of,sz,rw,b,n)
289 #define XVOP_OPEN(vp, cr, rv)                                           \
290         rv = _VOP_(vop_open, vp)((vp)->v_fbhv, cr)
291 #define XVOP_GETATTR(vp, vap, f, cr, rv)                                \
292         rv = _VOP_(vop_getattr, vp)((vp)->v_fbhv, vap, f, cr)
293 #define XVOP_SETATTR(vp, vap, f, cr, rv)                                \
294         rv = _VOP_(vop_setattr, vp)((vp)->v_fbhv, vap, f, cr)
295 #define XVOP_ACCESS(vp, accmode, cr, rv)                                        \
296         rv = _VOP_(vop_access, vp)((vp)->v_fbhv, accmode, cr)
297 #define XVOP_LOOKUP(vp,d,vpp,f,rdir,cr,rv)                              \
298         rv = _VOP_(vop_lookup, vp)((vp)->v_fbhv,d,vpp,f,rdir,cr)
299 #define XVOP_CREATE(dvp,d,vap,vpp,cr,rv)                                        \
300         rv = _VOP_(vop_create, dvp)((dvp)->v_fbhv,d,vap,vpp,cr)
301 #define XVOP_REMOVE(dvp,d,cr,rv)                                                \
302         rv = _VOP_(vop_remove, dvp)((dvp)->v_fbhv,d,cr)
303 #define XVOP_LINK(tdvp,fvp,d,cr,rv)                                     \
304         rv = _VOP_(vop_link, tdvp)((tdvp)->v_fbhv,fvp,d,cr)
305 #define XVOP_RENAME(fvp,fnm,tdvp,tnm,cr,rv)                             \
306         rv = _VOP_(vop_rename, fvp)((fvp)->v_fbhv,fnm,tdvp,tnm,cr)
307 #define XVOP_MKDIR(dp,d,vap,vpp,cr,rv)                                  \
308         rv = _VOP_(vop_mkdir, dp)((dp)->v_fbhv,d,vap,vpp,cr)
309 #define XVOP_RMDIR(dp,d,cr,rv)                                          \
310         rv = _VOP_(vop_rmdir, dp)((dp)->v_fbhv,d,cr)
311 #define XVOP_READDIR(vp,uiop,cr,eofp,rv)                                \
312         rv = _VOP_(vop_readdir, vp)((vp)->v_fbhv,uiop,cr,eofp)
313 #define XVOP_SYMLINK(dvp,d,vap,tnm,vpp,cr,rv)                           \
314         rv = _VOP_(vop_symlink, dvp) ((dvp)->v_fbhv,d,vap,tnm,vpp,cr)
315 #define XVOP_READLINK(vp,uiop,fl,cr,rv)                                 \
316         rv = _VOP_(vop_readlink, vp)((vp)->v_fbhv,uiop,fl,cr)
317
318 #define XVOP_FSYNC(vp,f,cr,b,e,rv)                                      \
319         rv = _VOP_(vop_fsync, vp)((vp)->v_fbhv,f,cr,b,e)
320 #define XVOP_INACTIVE(vp, cr, rv)                                       \
321         rv = _VOP_(vop_inactive, vp)((vp)->v_fbhv, cr)
322 #define XVOP_RELEASE(vp, rv)                                            \
323         rv = _VOP_(vop_release, vp)((vp)->v_fbhv)
324 #define XVOP_FID2(vp, fidp, rv)                                         \
325         rv = _VOP_(vop_fid2, vp)((vp)->v_fbhv, fidp)
326 #define XVOP_RWLOCK(vp,i)                                               \
327         (void)_VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
328 #define XVOP_RWLOCK_TRY(vp,i)                                           \
329         _VOP_(vop_rwlock, vp)((vp)->v_fbhv, i)
330 #define XVOP_RWUNLOCK(vp,i)                                             \
331         (void)_VOP_(vop_rwunlock, vp)((vp)->v_fbhv, i)
332 #define XVOP_FRLOCK(vp,c,fl,flags,offset,fr,rv)                         \
333         rv = _VOP_(vop_frlock, vp)((vp)->v_fbhv,c,fl,flags,offset,fr)
334 #define XVOP_RECLAIM(vp, rv)                                            \
335         rv = _VOP_(vop_reclaim, vp)((vp)->v_fbhv)
336 #define XVOP_ATTR_GET(vp, name, val, vallenp, fl, cred, rv)             \
337         rv = _VOP_(vop_attr_get, vp)((vp)->v_fbhv,name,val,vallenp,fl,cred)
338 #define XVOP_ATTR_SET(vp, name, val, vallen, fl, cred, rv)              \
339         rv = _VOP_(vop_attr_set, vp)((vp)->v_fbhv,name,val,vallen,fl,cred)
340 #define XVOP_ATTR_REMOVE(vp, name, flags, cred, rv)                     \
341         rv = _VOP_(vop_attr_remove, vp)((vp)->v_fbhv,name,flags,cred)
342 #define XVOP_ATTR_LIST(vp, buf, buflen, fl, cursor, cred, rv)           \
343         rv = _VOP_(vop_attr_list, vp)((vp)->v_fbhv,buf,buflen,fl,cursor,cred)
344 #define XVOP_LINK_REMOVED(vp, dvp, linkzero)                            \
345         (void)_VOP_(vop_link_removed, vp)((vp)->v_fbhv, dvp, linkzero)
346 #define XVOP_VNODE_CHANGE(vp, cmd, val)                                 \
347         (void)_VOP_(vop_vnode_change, vp)((vp)->v_fbhv,cmd,val)
348 /*
349  * These are page cache functions that now go thru VOPs.
350  * 'last' parameter is unused and left in for IRIX compatibility
351  */
352 #define XVOP_TOSS_PAGES(vp, first, last, fiopt)                         \
353         _VOP_(vop_tosspages, vp)((vp)->v_fbhv,first, last, fiopt)
354 /*
355  * 'last' parameter is unused and left in for IRIX compatibility
356  */
357 #define XVOP_FLUSHINVAL_PAGES(vp, first, last, fiopt)                   \
358         _VOP_(vop_flushinval_pages, vp)((vp)->v_fbhv,first,last,fiopt)
359 /*
360  * 'last' parameter is unused and left in for IRIX compatibility
361  */
362 #define XVOP_FLUSH_PAGES(vp, first, last, flags, fiopt, rv)             \
363         rv = _VOP_(vop_flush_pages, vp)((vp)->v_fbhv,first,last,flags,fiopt)
364 #define XVOP_IOCTL(vp, inode, filp, fl, cmd, arg, rv)                   \
365         rv = _VOP_(vop_ioctl, vp)((vp)->v_fbhv,inode,filp,fl,cmd,arg)
366 #define XVOP_IFLUSH(vp, flags, rv)                                      \
367         rv = _VOP_(vop_iflush, vp)((vp)->v_fbhv, flags)
368
369 /*
370  * Flags for read/write calls - select values from FreeBSD IO_ flags
371  * or non-conflicting bits.
372  */
373 #define IO_ISDIRECT     IO_DIRECT       /* bypass page cache */
374 #define IO_INVIS        0x02000         /* don't update inode timestamps */
375 /* #define IO_ISLOCKED  0x04000         don't do inode locking, strictly a CXFS thing */
376
377 /*
378  * Flags for VOP_IFLUSH call
379  */
380 #define FLUSH_SYNC              1       /* wait for flush to complete   */
381 #define FLUSH_INODE             2       /* flush the inode itself       */
382 #define FLUSH_LOG               4       /* force the last log entry for
383                                          * this inode out to disk       */
384
385 /*
386  * Flush/Invalidate options for VOP_TOSS_PAGES, VOP_FLUSHINVAL_PAGES and
387  *      VOP_FLUSH_PAGES.
388  */
389 #define FI_NONE                 0       /* none */
390 #define FI_REMAPF               1       /* Do a remapf prior to the operation */
391 #define FI_REMAPF_LOCKED        2       /* Do a remapf prior to the operation.
392                                            Prevent VM access to the pages until
393                                            the operation completes. */
394
395 /*
396  * Vnode attributes.  va_mask indicates those attributes the caller
397  * wants to set or extract.
398  */
399 typedef struct xfs_vattr {
400         int             va_mask;        /* bit-mask of attributes present */
401         mode_t          va_mode;        /* file access mode and type */
402         nlink_t         va_nlink;       /* number of references to file */
403         uid_t           va_uid;         /* owner user id */
404         gid_t           va_gid;         /* owner group id */
405         xfs_ino_t       va_nodeid;      /* file id */
406         xfs_off_t       va_size;        /* file size in bytes */
407         u_long          va_blocksize;   /* blocksize preferred for i/o */
408         struct timespec va_atime;       /* time of last access */
409         struct timespec va_mtime;       /* time of last modification */
410         struct timespec va_ctime;       /* time file changed */
411         u_int           va_gen;         /* generation number of file */
412         xfs_dev_t       va_rdev;        /* device the special file represents */
413         __int64_t       va_nblocks;     /* number of blocks allocated */
414         u_long          va_xflags;      /* random extended file flags */
415         u_long          va_extsize;     /* file extent size */
416         u_long          va_nextents;    /* number of extents in file */
417         u_long          va_anextents;   /* number of attr extents in file */
418         int             va_projid;      /* project id */
419 } xfs_vattr_t;
420
421 /*
422  * setattr or getattr attributes
423  */
424 #define XFS_AT_TYPE             0x00000001
425 #define XFS_AT_MODE             0x00000002
426 #define XFS_AT_UID              0x00000004
427 #define XFS_AT_GID              0x00000008
428 #define XFS_AT_FSID             0x00000010
429 #define XFS_AT_NODEID           0x00000020
430 #define XFS_AT_NLINK            0x00000040
431 #define XFS_AT_SIZE             0x00000080
432 #define XFS_AT_ATIME            0x00000100
433 #define XFS_AT_MTIME            0x00000200
434 #define XFS_AT_CTIME            0x00000400
435 #define XFS_AT_RDEV             0x00000800
436 #define XFS_AT_BLKSIZE          0x00001000
437 #define XFS_AT_NBLOCKS          0x00002000
438 #define XFS_AT_VCODE            0x00004000
439 #define XFS_AT_MAC              0x00008000
440 #define XFS_AT_UPDATIME         0x00010000
441 #define XFS_AT_UPDMTIME         0x00020000
442 #define XFS_AT_UPDCTIME         0x00040000
443 #define XFS_AT_ACL              0x00080000
444 #define XFS_AT_CAP              0x00100000
445 #define XFS_AT_INF              0x00200000
446 #define XFS_AT_XFLAGS           0x00400000
447 #define XFS_AT_EXTSIZE          0x00800000
448 #define XFS_AT_NEXTENTS         0x01000000
449 #define XFS_AT_ANEXTENTS        0x02000000
450 #define XFS_AT_PROJID           0x04000000
451 #define XFS_AT_SIZE_NOPERM      0x08000000
452 #define XFS_AT_GENCOUNT         0x10000000
453
454 #define XFS_AT_ALL      (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
455                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
456                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
457                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
458                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
459                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
460
461 #define XFS_AT_STAT     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
462                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
463                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
464                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
465
466 #define XFS_AT_TIMES    (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
467
468 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
469
470 #define XFS_AT_NOSET    (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
471                 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
472                 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
473
474 #ifndef __FreeBSD__
475 /*
476  *  Modes.
477  */
478 #define VSUID   S_ISUID         /* set user id on execution */
479 #define VSGID   S_ISGID         /* set group id on execution */
480 #define VSVTX   S_ISVTX         /* save swapped text even after use */
481 #define VREAD   S_IRUSR         /* read, write, execute permissions */
482 #define VWRITE  S_IWUSR
483 #define VEXEC   S_IXUSR
484 #endif /* __FreeBSD__ */
485
486 #define MODEMASK ALLPERMS       /* mode bits plus permission bits */
487
488 /*
489  * Check whether mandatory file locking is enabled.
490  */
491 #define MANDLOCK(vp, mode)      \
492         ((vp)->v_vnode->v_type == VREG && ((mode) & (S_ISGID|(VEXEC>>3))) == S_ISGID)
493
494 extern void             vn_init(void);
495 extern int              vn_wait(struct xfs_vnode *);
496 extern void             vn_iowait(struct xfs_vnode *);
497 extern xfs_vnode_t      *vn_initialize(struct xfs_vnode *);
498
499 /*
500  * Acquiring and invalidating vnodes:
501  *
502  *      if (vn_get(vp, version, 0))
503  *              ...;
504  *      vn_purge(vp, version);
505  *
506  * vn_get and vn_purge must be called with vmap_t arguments, sampled
507  * while a lock that the vnode's VOP_RECLAIM function acquires is
508  * held, to ensure that the vnode sampled with the lock held isn't
509  * recycled (VOP_RECLAIMed) or deallocated between the release of the lock
510  * and the subsequent vn_get or vn_purge.
511  */
512
513 /*
514  * vnode_map structures _must_ match vn_epoch and vnode structure sizes.
515  */
516 typedef struct vnode_map {
517         xfs_vfs_t       *v_vfsp;
518         xfs_ino_t       v_ino;
519         struct vnode    *v_vp;
520 } vmap_t;
521
522 #if 1
523 #define VMAP(vp, vmap)  {(vmap).v_vfsp   = (vp)->v_vfsp;        \
524                          (vmap).v_vp     = (vp)->v_vnode;       \
525                          (vmap).v_ino    = (vp)->v_inode->i_ino;\
526                          vhold((vp)->v_vnode);                  \
527                         }
528 #endif
529
530 extern void     vn_purge(struct xfs_vnode *);
531 extern xfs_vnode_t      *vn_get(struct xfs_vnode *, vmap_t *);
532 extern int      vn_revalidate(struct xfs_vnode *);
533
534 static inline int vn_count(struct xfs_vnode *vp)
535 {
536         return vp->v_vnode->v_usecount;
537 }
538
539 /*
540  * Vnode reference counting functions (and macros for compatibility).
541  */
542 extern xfs_vnode_t      *vn_hold(struct xfs_vnode *);
543 extern void     vn_rele(struct xfs_vnode *);
544
545 #if defined(XFS_VNODE_TRACE)
546 #define VN_HOLD(vp)             \
547         ((void)vref((vp)->v_vnode), \
548           vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
549 #define VN_RELE(vp)             \
550           (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
551            vrele((vp)->v_vnode))
552 #else
553 #define VN_HOLD(vp)             vref((vp)->v_vnode)
554 #define VN_RELE(vp)             vrele((vp)->v_vnode)
555 #endif
556
557 /*
558  * Vname handling macros.
559  */
560 #define VNAME(cnp)              ((cnp)->cn_nameptr)
561 #define VNAMELEN(cnp)           ((cnp)->cn_namelen)
562 #define VNAME_TO_VNODE(dentry)  (printf("VNAME_TO_VNODE NI"), (xfs_vnode_t *)0)
563
564 /*
565  * Vnode spinlock manipulation.
566  */
567 #define VN_LOCK(vp)             VI_LOCK(vp->v_vnode)
568 #define VN_UNLOCK(vp, s)        VI_UNLOCK(vp->v_vnode)
569 #define VN_FLAGSET(vp,b)        vn_flagset(vp,b)
570 #define VN_FLAGCLR(vp,b)        vn_flagclr(vp,b)
571
572 static __inline__ void vn_flagset(struct xfs_vnode *vp, __u32 flag)
573 {
574         VN_LOCK(vp);
575         vp->v_flag |= flag;
576         VN_UNLOCK(vp, 0);
577 }
578
579 static __inline__ void vn_flagclr(struct xfs_vnode *vp, __u32 flag)
580 {
581         VN_LOCK(vp);
582         vp->v_flag &= ~flag;
583         VN_UNLOCK(vp, 0);
584 }
585
586 /*
587  * Update modify/access/change times on the vnode
588  */
589 #define VN_MTIMESET(vp, tvp)
590 #define VN_ATIMESET(vp, tvp)
591 #define VN_CTIMESET(vp, tvp)
592
593 /*
594  * Some useful predicates.
595  */
596 #define VN_MAPPED(vp)   0
597 #define VN_CACHED(vp)   0
598 #define VN_DIRTY(vp)    0
599 #define VMODIFY(vp)     VN_FLAGSET(vp, VMODIFIED)
600 #define VUNMODIFY(vp)   VN_FLAGCLR(vp, VMODIFIED)
601
602
603 /*
604  * Flags to VOP_SETATTR/VOP_GETATTR.
605  */
606 #define ATTR_UTIME      0x01    /* non-default utime(2) request */
607 #define ATTR_DMI        0x08    /* invocation from a DMI function */
608 #define ATTR_LAZY       0x80    /* set/get attributes lazily */
609 #define ATTR_NONBLOCK   0x100   /* return EAGAIN if operation would block */
610 #define ATTR_NOLOCK     0x200   /* Don't grab any conflicting locks */
611 #define ATTR_NOSIZETOK  0x400   /* Don't get the SIZE token */
612
613 /*
614  * Flags to VOP_FSYNC and VOP_RECLAIM.
615  */
616 #define FSYNC_NOWAIT    0       /* asynchronous flush */
617 #define FSYNC_WAIT      0x1     /* synchronous fsync or forced reclaim */
618 #define FSYNC_INVAL     0x2     /* flush and invalidate cached data */
619 #define FSYNC_DATA      0x4     /* synchronous fsync of data only */
620
621
622 static inline struct xfs_vnode *vn_grab(struct xfs_vnode *vp)
623 {
624         printf("vn_grab NI\n");
625 //      struct inode *inode = igrab(vn_to_inode(vp));
626 //      return inode ? vn_from_inode(inode) : NULL;
627         return NULL;
628 }
629
630 static inline void vn_atime_to_bstime(struct xfs_vnode *vp, xfs_bstime_t *bs_atime)
631 {
632         printf("%s NI\n", __func__);
633 //        bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
634 //        bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
635
636
637 static inline void vn_atime_to_timespec(struct xfs_vnode *vp, struct timespec *ts)
638 {
639 //      *ts = vp->v_vnode->va_atime;
640 }
641
642 /*
643  * Tracking vnode activity.
644  */
645 #if defined(XFS_VNODE_TRACE)
646
647 #define VNODE_TRACE_SIZE        16              /* number of trace entries */
648 #define VNODE_KTRACE_ENTRY      1
649 #define VNODE_KTRACE_EXIT       2
650 #define VNODE_KTRACE_HOLD       3
651 #define VNODE_KTRACE_REF        4
652 #define VNODE_KTRACE_RELE       5
653
654 extern void vn_trace_entry(struct xfs_vnode *, char *, inst_t *);
655 extern void vn_trace_exit(struct xfs_vnode *, char *, inst_t *);
656 extern void vn_trace_hold(struct xfs_vnode *, char *, int, inst_t *);
657 extern void vn_trace_ref(struct xfs_vnode *, char *, int, inst_t *);
658 extern void vn_trace_rele(struct xfs_vnode *, char *, int, inst_t *);
659
660
661
662 #define VN_TRACE(vp)            \
663         vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
664 #else
665 #define vn_trace_entry(a,b,c)
666 #define vn_trace_exit(a,b,c)
667 #define vn_trace_hold(a,b,c,d)
668 #define vn_trace_ref(a,b,c,d)
669 #define vn_trace_rele(a,b,c,d)
670 #define VN_TRACE(vp)
671 #endif
672
673 #endif  /* __XFS_VNODE_H__ */