xfs_vnode.h 20.9 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18 19 20 21 22
 */
#ifndef __XFS_VNODE_H__
#define __XFS_VNODE_H__

struct uio;
struct file;
23 24
struct bhv_vfs;
struct bhv_vattr;
L
Linus Torvalds 已提交
25 26 27
struct xfs_iomap;
struct attrlist_cursor_kern;

28 29
typedef struct dentry	bhv_vname_t;
typedef __u64		bhv_vnumber_t;
L
Linus Torvalds 已提交
30

31
typedef enum bhv_vflags {
32 33 34
	VMODIFIED	= 0x08,	/* XFS inode state possibly differs */
				/* to the Linux inode state. */
	VTRUNCATED	= 0x40,	/* truncated down so flush-on-close */
35
} bhv_vflags_t;
36

L
Linus Torvalds 已提交
37 38 39 40
/*
 * MP locking protocols:
 *	v_flag, v_vfsp				VN_LOCK/VN_UNLOCK
 */
41
typedef struct bhv_vnode {
42 43 44 45
	bhv_vflags_t	v_flag;			/* vnode flags (see above) */
	bhv_vfs_t	*v_vfsp;		/* ptr to containing VFS */
	bhv_vnumber_t	v_number;		/* in-core vnode number */
	bhv_head_t	v_bh;			/* behavior head */
L
Linus Torvalds 已提交
46
	spinlock_t	v_lock;			/* VN_LOCK/VN_UNLOCK */
47
	atomic_t	v_iocount;		/* outstanding I/O count */
L
Linus Torvalds 已提交
48 49 50
#ifdef XFS_VNODE_TRACE
	struct ktrace	*v_trace;		/* trace header structure    */
#endif
E
Eric Sandeen 已提交
51 52
	struct inode	v_inode;		/* Linux inode */
	/* inode MUST be last */
53
} bhv_vnode_t;
L
Linus Torvalds 已提交
54

55 56 57 58 59 60
#define VN_ISLNK(vp)	S_ISLNK((vp)->v_inode.i_mode)
#define VN_ISREG(vp)	S_ISREG((vp)->v_inode.i_mode)
#define VN_ISDIR(vp)	S_ISDIR((vp)->v_inode.i_mode)
#define VN_ISCHR(vp)	S_ISCHR((vp)->v_inode.i_mode)
#define VN_ISBLK(vp)	S_ISBLK((vp)->v_inode.i_mode)

L
Linus Torvalds 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#define VNODE_POSITION_BASE	BHV_POSITION_BASE	/* chain bottom */
#define VNODE_POSITION_TOP	BHV_POSITION_TOP	/* chain top */
#define VNODE_POSITION_INVALID	BHV_POSITION_INVALID	/* invalid pos. num */

typedef enum {
	VN_BHV_UNKNOWN,		/* not specified */
	VN_BHV_XFS,		/* xfs */
	VN_BHV_DM,		/* data migration */
	VN_BHV_QM,		/* quota manager */
	VN_BHV_IO,		/* IO path */
	VN_BHV_END		/* housekeeping end-of-range */
} vn_bhv_t;

#define VNODE_POSITION_XFS	(VNODE_POSITION_BASE)
#define VNODE_POSITION_DM	(VNODE_POSITION_BASE+10)
#define VNODE_POSITION_QM	(VNODE_POSITION_BASE+20)
#define VNODE_POSITION_IO	(VNODE_POSITION_BASE+30)

/*
 * Macros for dealing with the behavior descriptor inside of the vnode.
 */
82 83
#define BHV_TO_VNODE(bdp)	((bhv_vnode_t *)BHV_VOBJ(bdp))
#define BHV_TO_VNODE_NULL(bdp)	((bhv_vnode_t *)BHV_VOBJNULL(bdp))
L
Linus Torvalds 已提交
84 85 86 87 88 89 90 91

#define VN_BHV_HEAD(vp)			((bhv_head_t *)(&((vp)->v_bh)))
#define vn_bhv_head_init(bhp,name)	bhv_head_init(bhp,name)
#define vn_bhv_remove(bhp,bdp)		bhv_remove(bhp,bdp)

/*
 * Vnode to Linux inode mapping.
 */
92
static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
93
{
94
	return container_of(inode, bhv_vnode_t, v_inode);
95
}
96
static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
97 98 99
{
	return &vnode->v_inode;
}
L
Linus Torvalds 已提交
100 101

/*
102
 * Values for the vop_rwlock/rwunlock flags parameter.
L
Linus Torvalds 已提交
103
 */
104
typedef enum bhv_vrwlock {
L
Linus Torvalds 已提交
105 106 107 108 109 110
	VRWLOCK_NONE,
	VRWLOCK_READ,
	VRWLOCK_WRITE,
	VRWLOCK_WRITE_DIRECT,
	VRWLOCK_TRY_READ,
	VRWLOCK_TRY_WRITE
111
} bhv_vrwlock_t;
L
Linus Torvalds 已提交
112 113

/*
114
 * Return values for bhv_vop_inactive.  A return value of
L
Linus Torvalds 已提交
115 116 117 118 119 120 121
 * VN_INACTIVE_NOCACHE implies that the file system behavior
 * has disassociated its state and bhv_desc_t from the vnode.
 */
#define	VN_INACTIVE_CACHE	0
#define	VN_INACTIVE_NOCACHE	1

/*
122
 * Values for the cmd code given to vop_vnode_change.
L
Linus Torvalds 已提交
123
 */
124
typedef enum bhv_vchange {
L
Linus Torvalds 已提交
125 126 127 128 129
	VCHANGE_FLAGS_FRLOCKS		= 0,
	VCHANGE_FLAGS_ENF_LOCKING	= 1,
	VCHANGE_FLAGS_TRUNCATED		= 2,
	VCHANGE_FLAGS_PAGE_DIRTY	= 3,
	VCHANGE_FLAGS_IOEXCL_COUNT	= 4
130
} bhv_vchange_t;
L
Linus Torvalds 已提交
131

132
typedef enum { L_FALSE, L_TRUE } lastclose_t;
L
Linus Torvalds 已提交
133 134

typedef int	(*vop_open_t)(bhv_desc_t *, struct cred *);
135
typedef int	(*vop_close_t)(bhv_desc_t *, int, lastclose_t, struct cred *);
L
Linus Torvalds 已提交
136 137 138 139 140 141
typedef ssize_t (*vop_read_t)(bhv_desc_t *, struct kiocb *,
				const struct iovec *, unsigned int,
				loff_t *, int, struct cred *);
typedef ssize_t (*vop_write_t)(bhv_desc_t *, struct kiocb *,
				const struct iovec *, unsigned int,
				loff_t *, int, struct cred *);
142
typedef ssize_t (*vop_splice_read_t)(bhv_desc_t *, struct file *, loff_t *,
143
				struct pipe_inode_info *, size_t, int, int,
144
				struct cred *);
145
typedef ssize_t (*vop_splice_write_t)(bhv_desc_t *, struct pipe_inode_info *,
146
				struct file *, loff_t *, size_t, int, int,
147
				struct cred *);
L
Linus Torvalds 已提交
148 149
typedef int	(*vop_ioctl_t)(bhv_desc_t *, struct inode *, struct file *,
				int, unsigned int, void __user *);
150
typedef int	(*vop_getattr_t)(bhv_desc_t *, struct bhv_vattr *, int,
L
Linus Torvalds 已提交
151
				struct cred *);
152
typedef int	(*vop_setattr_t)(bhv_desc_t *, struct bhv_vattr *, int,
L
Linus Torvalds 已提交
153 154
				struct cred *);
typedef int	(*vop_access_t)(bhv_desc_t *, int, struct cred *);
155
typedef int	(*vop_lookup_t)(bhv_desc_t *, bhv_vname_t *, bhv_vnode_t **,
156
				int, bhv_vnode_t *, struct cred *);
157
typedef int	(*vop_create_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr *,
158
				bhv_vnode_t **, struct cred *);
159 160
typedef int	(*vop_remove_t)(bhv_desc_t *, bhv_vname_t *, struct cred *);
typedef int	(*vop_link_t)(bhv_desc_t *, bhv_vnode_t *, bhv_vname_t *,
L
Linus Torvalds 已提交
161
				struct cred *);
162 163 164
typedef int	(*vop_rename_t)(bhv_desc_t *, bhv_vname_t *, bhv_vnode_t *,
				bhv_vname_t *, struct cred *);
typedef int	(*vop_mkdir_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr *,
165
				bhv_vnode_t **, struct cred *);
166
typedef int	(*vop_rmdir_t)(bhv_desc_t *, bhv_vname_t *, struct cred *);
L
Linus Torvalds 已提交
167 168
typedef int	(*vop_readdir_t)(bhv_desc_t *, struct uio *, struct cred *,
				int *);
169
typedef int	(*vop_symlink_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr*,
170
				char *, bhv_vnode_t **, struct cred *);
L
Linus Torvalds 已提交
171 172 173 174 175 176 177
typedef int	(*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
				struct cred *);
typedef int	(*vop_fsync_t)(bhv_desc_t *, int, struct cred *,
				xfs_off_t, xfs_off_t);
typedef int	(*vop_inactive_t)(bhv_desc_t *, struct cred *);
typedef int	(*vop_fid2_t)(bhv_desc_t *, struct fid *);
typedef int	(*vop_release_t)(bhv_desc_t *);
178 179
typedef int	(*vop_rwlock_t)(bhv_desc_t *, bhv_vrwlock_t);
typedef void	(*vop_rwunlock_t)(bhv_desc_t *, bhv_vrwlock_t);
L
Linus Torvalds 已提交
180 181 182
typedef int	(*vop_bmap_t)(bhv_desc_t *, xfs_off_t, ssize_t, int,
				struct xfs_iomap *, int *);
typedef int	(*vop_reclaim_t)(bhv_desc_t *);
183 184 185 186 187 188
typedef int	(*vop_attr_get_t)(bhv_desc_t *, const char *, char *, int *,
				int, struct cred *);
typedef	int	(*vop_attr_set_t)(bhv_desc_t *, const char *, char *, int,
				int, struct cred *);
typedef	int	(*vop_attr_remove_t)(bhv_desc_t *, const char *,
				int, struct cred *);
L
Linus Torvalds 已提交
189 190
typedef	int	(*vop_attr_list_t)(bhv_desc_t *, char *, int, int,
				struct attrlist_cursor_kern *, struct cred *);
191
typedef void	(*vop_link_removed_t)(bhv_desc_t *, bhv_vnode_t *, int);
192
typedef void	(*vop_vnode_change_t)(bhv_desc_t *, bhv_vchange_t, __psint_t);
L
Linus Torvalds 已提交
193
typedef void	(*vop_ptossvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
194
typedef int	(*vop_pflushinvalvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t, int);
L
Linus Torvalds 已提交
195 196 197 198 199
typedef int	(*vop_pflushvp_t)(bhv_desc_t *, xfs_off_t, xfs_off_t,
				uint64_t, int);
typedef int	(*vop_iflush_t)(bhv_desc_t *, int);


200
typedef struct bhv_vnodeops {
L
Linus Torvalds 已提交
201 202
	bhv_position_t  vn_position;    /* position within behavior chain */
	vop_open_t		vop_open;
203
	vop_close_t		vop_close;
L
Linus Torvalds 已提交
204 205
	vop_read_t		vop_read;
	vop_write_t		vop_write;
206 207
	vop_splice_read_t	vop_splice_read;
	vop_splice_write_t	vop_splice_write;
L
Linus Torvalds 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
	vop_ioctl_t		vop_ioctl;
	vop_getattr_t		vop_getattr;
	vop_setattr_t		vop_setattr;
	vop_access_t		vop_access;
	vop_lookup_t		vop_lookup;
	vop_create_t		vop_create;
	vop_remove_t		vop_remove;
	vop_link_t		vop_link;
	vop_rename_t		vop_rename;
	vop_mkdir_t		vop_mkdir;
	vop_rmdir_t		vop_rmdir;
	vop_readdir_t		vop_readdir;
	vop_symlink_t		vop_symlink;
	vop_readlink_t		vop_readlink;
	vop_fsync_t		vop_fsync;
	vop_inactive_t		vop_inactive;
	vop_fid2_t		vop_fid2;
	vop_rwlock_t		vop_rwlock;
	vop_rwunlock_t		vop_rwunlock;
	vop_bmap_t		vop_bmap;
	vop_reclaim_t		vop_reclaim;
	vop_attr_get_t		vop_attr_get;
	vop_attr_set_t		vop_attr_set;
	vop_attr_remove_t	vop_attr_remove;
	vop_attr_list_t		vop_attr_list;
	vop_link_removed_t	vop_link_removed;
	vop_vnode_change_t	vop_vnode_change;
	vop_ptossvp_t		vop_tosspages;
	vop_pflushinvalvp_t	vop_flushinval_pages;
	vop_pflushvp_t		vop_flush_pages;
	vop_release_t		vop_release;
	vop_iflush_t		vop_iflush;
240
} bhv_vnodeops_t;
L
Linus Torvalds 已提交
241 242

/*
243
 * Virtual node operations, operating from head bhv.
L
Linus Torvalds 已提交
244
 */
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
#define VNHEAD(vp)	((vp)->v_bh.bh_first)
#define VOP(op, vp)	(*((bhv_vnodeops_t *)VNHEAD(vp)->bd_ops)->op)
#define bhv_vop_open(vp, cr)		VOP(vop_open, vp)(VNHEAD(vp),cr)
#define bhv_vop_close(vp, f,last,cr)	VOP(vop_close, vp)(VNHEAD(vp),f,last,cr)
#define bhv_vop_read(vp,file,iov,segs,offset,ioflags,cr)		\
		VOP(vop_read, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr)
#define bhv_vop_write(vp,file,iov,segs,offset,ioflags,cr)		\
		VOP(vop_write, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr)
#define bhv_vop_splice_read(vp,f,o,pipe,cnt,fl,iofl,cr)			\
		VOP(vop_splice_read, vp)(VNHEAD(vp),f,o,pipe,cnt,fl,iofl,cr)
#define bhv_vop_splice_write(vp,f,o,pipe,cnt,fl,iofl,cr)		\
		VOP(vop_splice_write, vp)(VNHEAD(vp),f,o,pipe,cnt,fl,iofl,cr)
#define bhv_vop_bmap(vp,of,sz,rw,b,n)					\
		VOP(vop_bmap, vp)(VNHEAD(vp),of,sz,rw,b,n)
#define bhv_vop_getattr(vp, vap,f,cr)					\
		VOP(vop_getattr, vp)(VNHEAD(vp), vap,f,cr)
#define	bhv_vop_setattr(vp, vap,f,cr)					\
		VOP(vop_setattr, vp)(VNHEAD(vp), vap,f,cr)
#define	bhv_vop_access(vp, mode,cr)	VOP(vop_access, vp)(VNHEAD(vp), mode,cr)
#define	bhv_vop_lookup(vp,d,vpp,f,rdir,cr)				\
		VOP(vop_lookup, vp)(VNHEAD(vp),d,vpp,f,rdir,cr)
#define bhv_vop_create(dvp,d,vap,vpp,cr)				\
		VOP(vop_create, dvp)(VNHEAD(dvp),d,vap,vpp,cr)
#define bhv_vop_remove(dvp,d,cr)	VOP(vop_remove, dvp)(VNHEAD(dvp),d,cr)
#define	bhv_vop_link(dvp,fvp,d,cr)	VOP(vop_link, dvp)(VNHEAD(dvp),fvp,d,cr)
#define	bhv_vop_rename(fvp,fnm,tdvp,tnm,cr)				\
		VOP(vop_rename, fvp)(VNHEAD(fvp),fnm,tdvp,tnm,cr)
#define	bhv_vop_mkdir(dp,d,vap,vpp,cr)					\
		VOP(vop_mkdir, dp)(VNHEAD(dp),d,vap,vpp,cr)
#define	bhv_vop_rmdir(dp,d,cr)	 	VOP(vop_rmdir, dp)(VNHEAD(dp),d,cr)
#define	bhv_vop_readdir(vp,uiop,cr,eofp)				\
		VOP(vop_readdir, vp)(VNHEAD(vp),uiop,cr,eofp)
#define	bhv_vop_symlink(dvp,d,vap,tnm,vpp,cr)				\
		VOP(vop_symlink, dvp)(VNHEAD(dvp),d,vap,tnm,vpp,cr)
#define	bhv_vop_readlink(vp,uiop,fl,cr)					\
		VOP(vop_readlink, vp)(VNHEAD(vp),uiop,fl,cr)
#define	bhv_vop_fsync(vp,f,cr,b,e)	VOP(vop_fsync, vp)(VNHEAD(vp),f,cr,b,e)
#define bhv_vop_inactive(vp,cr)		VOP(vop_inactive, vp)(VNHEAD(vp),cr)
#define bhv_vop_release(vp)		VOP(vop_release, vp)(VNHEAD(vp))
#define bhv_vop_fid2(vp,fidp)		VOP(vop_fid2, vp)(VNHEAD(vp),fidp)
#define bhv_vop_rwlock(vp,i)		VOP(vop_rwlock, vp)(VNHEAD(vp),i)
#define bhv_vop_rwlock_try(vp,i)	VOP(vop_rwlock, vp)(VNHEAD(vp),i)
#define bhv_vop_rwunlock(vp,i)		VOP(vop_rwunlock, vp)(VNHEAD(vp),i)
#define bhv_vop_frlock(vp,c,fl,flags,offset,fr)				\
		VOP(vop_frlock, vp)(VNHEAD(vp),c,fl,flags,offset,fr)
#define bhv_vop_reclaim(vp)		VOP(vop_reclaim, vp)(VNHEAD(vp))
#define bhv_vop_attr_get(vp, name, val, vallenp, fl, cred)		\
		VOP(vop_attr_get, vp)(VNHEAD(vp),name,val,vallenp,fl,cred)
#define	bhv_vop_attr_set(vp, name, val, vallen, fl, cred)		\
		VOP(vop_attr_set, vp)(VNHEAD(vp),name,val,vallen,fl,cred)
#define	bhv_vop_attr_remove(vp, name, flags, cred)			\
		VOP(vop_attr_remove, vp)(VNHEAD(vp),name,flags,cred)
#define	bhv_vop_attr_list(vp, buf, buflen, fl, cursor, cred)		\
		VOP(vop_attr_list, vp)(VNHEAD(vp),buf,buflen,fl,cursor,cred)
#define bhv_vop_link_removed(vp, dvp, linkzero)				\
		VOP(vop_link_removed, vp)(VNHEAD(vp), dvp, linkzero)
#define bhv_vop_vnode_change(vp, cmd, val)				\
		VOP(vop_vnode_change, vp)(VNHEAD(vp), cmd, val)
#define bhv_vop_toss_pages(vp, first, last, fiopt)			\
		VOP(vop_tosspages, vp)(VNHEAD(vp), first, last, fiopt)
#define bhv_vop_flushinval_pages(vp, first, last, fiopt)		\
		VOP(vop_flushinval_pages, vp)(VNHEAD(vp),first,last,fiopt)
#define bhv_vop_flush_pages(vp, first, last, flags, fiopt)		\
		VOP(vop_flush_pages, vp)(VNHEAD(vp),first,last,flags,fiopt)
#define bhv_vop_ioctl(vp, inode, filp, fl, cmd, arg)			\
		VOP(vop_ioctl, vp)(VNHEAD(vp),inode,filp,fl,cmd,arg)
#define bhv_vop_iflush(vp, flags)	VOP(vop_iflush, vp)(VNHEAD(vp), flags)
L
Linus Torvalds 已提交
312 313 314 315 316 317 318 319 320

/*
 * Flags for read/write calls - same values as IRIX
 */
#define IO_ISAIO	0x00001		/* don't wait for completion */
#define IO_ISDIRECT	0x00004		/* bypass page cache */
#define IO_INVIS	0x00020		/* don't update inode timestamps */

/*
321
 * Flags for vop_iflush call
L
Linus Torvalds 已提交
322 323 324 325 326 327 328
 */
#define FLUSH_SYNC		1	/* wait for flush to complete	*/
#define FLUSH_INODE		2	/* flush the inode itself	*/
#define FLUSH_LOG		4	/* force the last log entry for
					 * this inode out to disk	*/

/*
329
 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
L
Linus Torvalds 已提交
330 331 332 333 334 335 336 337 338 339 340
 */
#define FI_NONE			0	/* none */
#define FI_REMAPF		1	/* Do a remapf prior to the operation */
#define FI_REMAPF_LOCKED	2	/* Do a remapf prior to the operation.
					   Prevent VM access to the pages until
					   the operation completes. */

/*
 * Vnode attributes.  va_mask indicates those attributes the caller
 * wants to set or extract.
 */
341
typedef struct bhv_vattr {
L
Linus Torvalds 已提交
342 343
	int		va_mask;	/* bit-mask of attributes present */
	mode_t		va_mode;	/* file access mode and type */
344
	xfs_nlink_t	va_nlink;	/* number of references to file */
L
Linus Torvalds 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
	uid_t		va_uid;		/* owner user id */
	gid_t		va_gid;		/* owner group id */
	xfs_ino_t	va_nodeid;	/* file id */
	xfs_off_t	va_size;	/* file size in bytes */
	u_long		va_blocksize;	/* blocksize preferred for i/o */
	struct timespec	va_atime;	/* time of last access */
	struct timespec	va_mtime;	/* time of last modification */
	struct timespec	va_ctime;	/* time file changed */
	u_int		va_gen;		/* generation number of file */
	xfs_dev_t	va_rdev;	/* device the special file represents */
	__int64_t	va_nblocks;	/* number of blocks allocated */
	u_long		va_xflags;	/* random extended file flags */
	u_long		va_extsize;	/* file extent size */
	u_long		va_nextents;	/* number of extents in file */
	u_long		va_anextents;	/* number of attr extents in file */
360
	prid_t		va_projid;	/* project id */
361
} bhv_vattr_t;
L
Linus Torvalds 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431

/*
 * setattr or getattr attributes
 */
#define XFS_AT_TYPE		0x00000001
#define XFS_AT_MODE		0x00000002
#define XFS_AT_UID		0x00000004
#define XFS_AT_GID		0x00000008
#define XFS_AT_FSID		0x00000010
#define XFS_AT_NODEID		0x00000020
#define XFS_AT_NLINK		0x00000040
#define XFS_AT_SIZE		0x00000080
#define XFS_AT_ATIME		0x00000100
#define XFS_AT_MTIME		0x00000200
#define XFS_AT_CTIME		0x00000400
#define XFS_AT_RDEV		0x00000800
#define XFS_AT_BLKSIZE		0x00001000
#define XFS_AT_NBLOCKS		0x00002000
#define XFS_AT_VCODE		0x00004000
#define XFS_AT_MAC		0x00008000
#define XFS_AT_UPDATIME		0x00010000
#define XFS_AT_UPDMTIME		0x00020000
#define XFS_AT_UPDCTIME		0x00040000
#define XFS_AT_ACL		0x00080000
#define XFS_AT_CAP		0x00100000
#define XFS_AT_INF		0x00200000
#define XFS_AT_XFLAGS		0x00400000
#define XFS_AT_EXTSIZE		0x00800000
#define XFS_AT_NEXTENTS		0x01000000
#define XFS_AT_ANEXTENTS	0x02000000
#define XFS_AT_PROJID		0x04000000
#define XFS_AT_SIZE_NOPERM	0x08000000
#define XFS_AT_GENCOUNT		0x10000000

#define XFS_AT_ALL	(XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
		XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
		XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
		XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
		XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
		XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)

#define XFS_AT_STAT	(XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
		XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
		XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
		XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)

#define XFS_AT_TIMES	(XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)

#define XFS_AT_UPDTIMES	(XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)

#define XFS_AT_NOSET	(XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
		XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
		XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)

/*
 *  Modes.
 */
#define VSUID	S_ISUID		/* set user id on execution */
#define VSGID	S_ISGID		/* set group id on execution */
#define VSVTX	S_ISVTX		/* save swapped text even after use */
#define VREAD	S_IRUSR		/* read, write, execute permissions */
#define VWRITE	S_IWUSR
#define VEXEC	S_IXUSR

#define MODEMASK S_IALLUGO	/* mode bits plus permission bits */

/*
 * Check whether mandatory file locking is enabled.
 */
#define MANDLOCK(vp, mode)	\
432
	(VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
L
Linus Torvalds 已提交
433 434

extern void	vn_init(void);
435 436
extern bhv_vnode_t	*vn_initialize(struct inode *);
extern int	vn_revalidate(struct bhv_vnode *);
437 438
extern int	__vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
extern void	vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
L
Linus Torvalds 已提交
439

440 441
extern void	vn_iowait(struct bhv_vnode *vp);
extern void	vn_iowake(struct bhv_vnode *vp);
442

443
extern void	vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
444

445
static inline int vn_count(struct bhv_vnode *vp)
L
Linus Torvalds 已提交
446
{
447
	return atomic_read(&vn_to_inode(vp)->i_count);
L
Linus Torvalds 已提交
448 449 450 451 452
}

/*
 * Vnode reference counting functions (and macros for compatibility).
 */
453
extern bhv_vnode_t	*vn_hold(struct bhv_vnode *);
L
Linus Torvalds 已提交
454 455 456 457 458 459 460

#if defined(XFS_VNODE_TRACE)
#define VN_HOLD(vp)		\
	((void)vn_hold(vp),	\
	  vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
#define VN_RELE(vp)		\
	  (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
461
	   iput(vn_to_inode(vp)))
L
Linus Torvalds 已提交
462 463
#else
#define VN_HOLD(vp)		((void)vn_hold(vp))
464
#define VN_RELE(vp)		(iput(vn_to_inode(vp)))
L
Linus Torvalds 已提交
465 466
#endif

467
static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
468
{
469 470
	struct inode *inode = igrab(vn_to_inode(vp));
	return inode ? vn_from_inode(inode) : NULL;
471 472
}

L
Linus Torvalds 已提交
473 474 475 476 477
/*
 * Vname handling macros.
 */
#define VNAME(dentry)		((char *) (dentry)->d_name.name)
#define VNAMELEN(dentry)	((dentry)->d_name.len)
478
#define VNAME_TO_VNODE(dentry)	(vn_from_inode((dentry)->d_inode))
L
Linus Torvalds 已提交
479 480 481 482 483 484 485

/*
 * Vnode spinlock manipulation.
 */
#define VN_LOCK(vp)		mutex_spinlock(&(vp)->v_lock)
#define VN_UNLOCK(vp, s)	mutex_spinunlock(&(vp)->v_lock, s)

486
STATIC_INLINE void vn_flagset(struct bhv_vnode *vp, uint flag)
L
Linus Torvalds 已提交
487 488 489 490 491 492
{
	spin_lock(&vp->v_lock);
	vp->v_flag |= flag;
	spin_unlock(&vp->v_lock);
}

493
STATIC_INLINE uint vn_flagclr(struct bhv_vnode *vp, uint flag)
L
Linus Torvalds 已提交
494
{
495 496
	uint	cleared;

L
Linus Torvalds 已提交
497
	spin_lock(&vp->v_lock);
498
	cleared = (vp->v_flag & flag);
L
Linus Torvalds 已提交
499 500
	vp->v_flag &= ~flag;
	spin_unlock(&vp->v_lock);
501
	return cleared;
L
Linus Torvalds 已提交
502 503
}

504 505 506 507 508
#define VMODIFY(vp)	vn_flagset(vp, VMODIFIED)
#define VUNMODIFY(vp)	vn_flagclr(vp, VMODIFIED)
#define VTRUNCATE(vp)	vn_flagset(vp, VTRUNCATED)
#define VUNTRUNCATE(vp)	vn_flagclr(vp, VTRUNCATED)

L
Linus Torvalds 已提交
509 510 511
/*
 * Dealing with bad inodes
 */
512
static inline void vn_mark_bad(struct bhv_vnode *vp)
L
Linus Torvalds 已提交
513
{
514
	make_bad_inode(vn_to_inode(vp));
L
Linus Torvalds 已提交
515 516
}

517
static inline int VN_BAD(struct bhv_vnode *vp)
L
Linus Torvalds 已提交
518
{
519
	return is_bad_inode(vn_to_inode(vp));
L
Linus Torvalds 已提交
520 521
}

522 523 524
/*
 * Extracting atime values in various formats
 */
525
static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
526 527 528 529 530
{
	bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
	bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
}

531
static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
532 533 534 535
{
	*ts = vp->v_inode.i_atime;
}

536
static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
537 538 539 540
{
	*tt = vp->v_inode.i_atime.tv_sec;
}

L
Linus Torvalds 已提交
541 542 543
/*
 * Some useful predicates.
 */
544 545 546
#define VN_MAPPED(vp)	mapping_mapped(vn_to_inode(vp)->i_mapping)
#define VN_CACHED(vp)	(vn_to_inode(vp)->i_mapping->nrpages)
#define VN_DIRTY(vp)	mapping_tagged(vn_to_inode(vp)->i_mapping, \
L
Linus Torvalds 已提交
547
					PAGECACHE_TAG_DIRTY)
548
#define VN_TRUNC(vp)	((vp)->v_flag & VTRUNCATED)
L
Linus Torvalds 已提交
549 550

/*
551
 * Flags to vop_setattr/getattr.
L
Linus Torvalds 已提交
552 553 554 555 556
 */
#define	ATTR_UTIME	0x01	/* non-default utime(2) request */
#define	ATTR_DMI	0x08	/* invocation from a DMI function */
#define	ATTR_LAZY	0x80	/* set/get attributes lazily */
#define	ATTR_NONBLOCK	0x100	/* return EAGAIN if operation would block */
557
#define ATTR_NOLOCK	0x200	/* Don't grab any conflicting locks */
558
#define ATTR_NOSIZETOK	0x400	/* Don't get the SIZE token */
L
Linus Torvalds 已提交
559 560

/*
561
 * Flags to vop_fsync/reclaim.
L
Linus Torvalds 已提交
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
 */
#define FSYNC_NOWAIT	0	/* asynchronous flush */
#define FSYNC_WAIT	0x1	/* synchronous fsync or forced reclaim */
#define FSYNC_INVAL	0x2	/* flush and invalidate cached data */
#define FSYNC_DATA	0x4	/* synchronous fsync of data only */

/*
 * Tracking vnode activity.
 */
#if defined(XFS_VNODE_TRACE)

#define	VNODE_TRACE_SIZE	16		/* number of trace entries */
#define	VNODE_KTRACE_ENTRY	1
#define	VNODE_KTRACE_EXIT	2
#define	VNODE_KTRACE_HOLD	3
#define	VNODE_KTRACE_REF	4
#define	VNODE_KTRACE_RELE	5

580 581 582 583 584
extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
L
Linus Torvalds 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597

#define	VN_TRACE(vp)		\
	vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
#else
#define	vn_trace_entry(a,b,c)
#define	vn_trace_exit(a,b,c)
#define	vn_trace_hold(a,b,c,d)
#define	vn_trace_ref(a,b,c,d)
#define	vn_trace_rele(a,b,c,d)
#define	VN_TRACE(vp)
#endif

#endif	/* __XFS_VNODE_H__ */