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