2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
18 #ifndef __XFS_VNODE_H__
19 #define __XFS_VNODE_H__
25 struct attrlist_cursor_kern;
27 typedef struct dentry bhv_vname_t;
28 typedef __u64 bhv_vnumber_t;
30 typedef enum bhv_vflags {
31 VMODIFIED = 0x08, /* XFS inode state possibly differs */
32 /* to the Linux inode state. */
33 VTRUNCATED = 0x40, /* truncated down so flush-on-close */
37 * MP locking protocols:
38 * v_flag, VN_LOCK/VN_UNLOCK
40 typedef struct bhv_vnode {
41 bhv_vflags_t v_flag; /* vnode flags (see above) */
42 bhv_vnumber_t v_number; /* in-core vnode number */
43 spinlock_t v_lock; /* VN_LOCK/VN_UNLOCK */
44 atomic_t v_iocount; /* outstanding I/O count */
45 #ifdef XFS_VNODE_TRACE
46 struct ktrace *v_trace; /* trace header structure */
48 struct inode v_inode; /* Linux inode */
49 /* inode MUST be last */
52 #define VN_ISLNK(vp) S_ISLNK((vp)->v_inode.i_mode)
53 #define VN_ISREG(vp) S_ISREG((vp)->v_inode.i_mode)
54 #define VN_ISDIR(vp) S_ISDIR((vp)->v_inode.i_mode)
55 #define VN_ISCHR(vp) S_ISCHR((vp)->v_inode.i_mode)
56 #define VN_ISBLK(vp) S_ISBLK((vp)->v_inode.i_mode)
59 * Vnode to Linux inode mapping.
61 static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
63 return container_of(inode, bhv_vnode_t, v_inode);
65 static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
67 return &vnode->v_inode;
71 * Values for the vop_rwlock/rwunlock flags parameter.
73 typedef enum bhv_vrwlock {
83 * Return values for xfs_inactive. A return value of
84 * VN_INACTIVE_NOCACHE implies that the file system behavior
85 * has disassociated its state and bhv_desc_t from the vnode.
87 #define VN_INACTIVE_CACHE 0
88 #define VN_INACTIVE_NOCACHE 1
91 * Flags for read/write calls - same values as IRIX
93 #define IO_ISAIO 0x00001 /* don't wait for completion */
94 #define IO_ISDIRECT 0x00004 /* bypass page cache */
95 #define IO_INVIS 0x00020 /* don't update inode timestamps */
98 * Flags for vop_iflush call
100 #define FLUSH_SYNC 1 /* wait for flush to complete */
101 #define FLUSH_INODE 2 /* flush the inode itself */
102 #define FLUSH_LOG 4 /* force the last log entry for
103 * this inode out to disk */
106 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
108 #define FI_NONE 0 /* none */
109 #define FI_REMAPF 1 /* Do a remapf prior to the operation */
110 #define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
111 Prevent VM access to the pages until
112 the operation completes. */
115 * Vnode attributes. va_mask indicates those attributes the caller
116 * wants to set or extract.
118 typedef struct bhv_vattr {
119 int va_mask; /* bit-mask of attributes present */
120 mode_t va_mode; /* file access mode and type */
121 xfs_nlink_t va_nlink; /* number of references to file */
122 uid_t va_uid; /* owner user id */
123 gid_t va_gid; /* owner group id */
124 xfs_ino_t va_nodeid; /* file id */
125 xfs_off_t va_size; /* file size in bytes */
126 u_long va_blocksize; /* blocksize preferred for i/o */
127 struct timespec va_atime; /* time of last access */
128 struct timespec va_mtime; /* time of last modification */
129 struct timespec va_ctime; /* time file changed */
130 u_int va_gen; /* generation number of file */
131 xfs_dev_t va_rdev; /* device the special file represents */
132 __int64_t va_nblocks; /* number of blocks allocated */
133 u_long va_xflags; /* random extended file flags */
134 u_long va_extsize; /* file extent size */
135 u_long va_nextents; /* number of extents in file */
136 u_long va_anextents; /* number of attr extents in file */
137 prid_t va_projid; /* project id */
141 * setattr or getattr attributes
143 #define XFS_AT_TYPE 0x00000001
144 #define XFS_AT_MODE 0x00000002
145 #define XFS_AT_UID 0x00000004
146 #define XFS_AT_GID 0x00000008
147 #define XFS_AT_FSID 0x00000010
148 #define XFS_AT_NODEID 0x00000020
149 #define XFS_AT_NLINK 0x00000040
150 #define XFS_AT_SIZE 0x00000080
151 #define XFS_AT_ATIME 0x00000100
152 #define XFS_AT_MTIME 0x00000200
153 #define XFS_AT_CTIME 0x00000400
154 #define XFS_AT_RDEV 0x00000800
155 #define XFS_AT_BLKSIZE 0x00001000
156 #define XFS_AT_NBLOCKS 0x00002000
157 #define XFS_AT_VCODE 0x00004000
158 #define XFS_AT_MAC 0x00008000
159 #define XFS_AT_UPDATIME 0x00010000
160 #define XFS_AT_UPDMTIME 0x00020000
161 #define XFS_AT_UPDCTIME 0x00040000
162 #define XFS_AT_ACL 0x00080000
163 #define XFS_AT_CAP 0x00100000
164 #define XFS_AT_INF 0x00200000
165 #define XFS_AT_XFLAGS 0x00400000
166 #define XFS_AT_EXTSIZE 0x00800000
167 #define XFS_AT_NEXTENTS 0x01000000
168 #define XFS_AT_ANEXTENTS 0x02000000
169 #define XFS_AT_PROJID 0x04000000
170 #define XFS_AT_SIZE_NOPERM 0x08000000
171 #define XFS_AT_GENCOUNT 0x10000000
173 #define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
174 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
175 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
176 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
177 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
178 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
180 #define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
181 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
182 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
183 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
185 #define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
187 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
189 #define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
190 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
191 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
196 #define VSUID S_ISUID /* set user id on execution */
197 #define VSGID S_ISGID /* set group id on execution */
198 #define VSVTX S_ISVTX /* save swapped text even after use */
199 #define VREAD S_IRUSR /* read, write, execute permissions */
200 #define VWRITE S_IWUSR
201 #define VEXEC S_IXUSR
203 #define MODEMASK S_IALLUGO /* mode bits plus permission bits */
206 * Check whether mandatory file locking is enabled.
208 #define MANDLOCK(vp, mode) \
209 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
211 extern void vn_init(void);
212 extern bhv_vnode_t *vn_initialize(struct inode *);
213 extern int vn_revalidate(struct bhv_vnode *);
214 extern int __vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
215 extern void vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
217 extern void vn_iowait(struct bhv_vnode *vp);
218 extern void vn_iowake(struct bhv_vnode *vp);
220 extern void vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
222 static inline int vn_count(struct bhv_vnode *vp)
224 return atomic_read(&vn_to_inode(vp)->i_count);
228 * Vnode reference counting functions (and macros for compatibility).
230 extern bhv_vnode_t *vn_hold(struct bhv_vnode *);
232 #if defined(XFS_VNODE_TRACE)
233 #define VN_HOLD(vp) \
234 ((void)vn_hold(vp), \
235 vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
236 #define VN_RELE(vp) \
237 (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
238 iput(vn_to_inode(vp)))
240 #define VN_HOLD(vp) ((void)vn_hold(vp))
241 #define VN_RELE(vp) (iput(vn_to_inode(vp)))
244 static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
246 struct inode *inode = igrab(vn_to_inode(vp));
247 return inode ? vn_from_inode(inode) : NULL;
251 * Vname handling macros.
253 #define VNAME(dentry) ((char *) (dentry)->d_name.name)
254 #define VNAMELEN(dentry) ((dentry)->d_name.len)
255 #define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
258 * Vnode spinlock manipulation.
260 #define VN_LOCK(vp) mutex_spinlock(&(vp)->v_lock)
261 #define VN_UNLOCK(vp, s) mutex_spinunlock(&(vp)->v_lock, s)
263 STATIC_INLINE void vn_flagset(struct bhv_vnode *vp, uint flag)
265 spin_lock(&vp->v_lock);
267 spin_unlock(&vp->v_lock);
270 STATIC_INLINE uint vn_flagclr(struct bhv_vnode *vp, uint flag)
274 spin_lock(&vp->v_lock);
275 cleared = (vp->v_flag & flag);
277 spin_unlock(&vp->v_lock);
281 #define VMODIFY(vp) vn_flagset(vp, VMODIFIED)
282 #define VUNMODIFY(vp) vn_flagclr(vp, VMODIFIED)
283 #define VTRUNCATE(vp) vn_flagset(vp, VTRUNCATED)
284 #define VUNTRUNCATE(vp) vn_flagclr(vp, VTRUNCATED)
287 * Dealing with bad inodes
289 static inline void vn_mark_bad(struct bhv_vnode *vp)
291 make_bad_inode(vn_to_inode(vp));
294 static inline int VN_BAD(struct bhv_vnode *vp)
296 return is_bad_inode(vn_to_inode(vp));
300 * Extracting atime values in various formats
302 static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
304 bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
305 bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
308 static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
310 *ts = vp->v_inode.i_atime;
313 static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
315 *tt = vp->v_inode.i_atime.tv_sec;
319 * Some useful predicates.
321 #define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
322 #define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
323 #define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
325 #define VN_TRUNC(vp) ((vp)->v_flag & VTRUNCATED)
328 * Flags to vop_setattr/getattr.
330 #define ATTR_UTIME 0x01 /* non-default utime(2) request */
331 #define ATTR_DMI 0x08 /* invocation from a DMI function */
332 #define ATTR_LAZY 0x80 /* set/get attributes lazily */
333 #define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
334 #define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
335 #define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
338 * Flags to vop_fsync/reclaim.
340 #define FSYNC_NOWAIT 0 /* asynchronous flush */
341 #define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
342 #define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
343 #define FSYNC_DATA 0x4 /* synchronous fsync of data only */
346 * Tracking vnode activity.
348 #if defined(XFS_VNODE_TRACE)
350 #define VNODE_TRACE_SIZE 16 /* number of trace entries */
351 #define VNODE_KTRACE_ENTRY 1
352 #define VNODE_KTRACE_EXIT 2
353 #define VNODE_KTRACE_HOLD 3
354 #define VNODE_KTRACE_REF 4
355 #define VNODE_KTRACE_RELE 5
357 extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
358 extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
359 extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
360 extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
361 extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
363 #define VN_TRACE(vp) \
364 vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
366 #define vn_trace_entry(a,b,c)
367 #define vn_trace_exit(a,b,c)
368 #define vn_trace_hold(a,b,c,d)
369 #define vn_trace_ref(a,b,c,d)
370 #define vn_trace_rele(a,b,c,d)
374 #endif /* __XFS_VNODE_H__ */