blob: 321346d95267ed7d812882fffe7fad2b9ea9cdcb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_VNODE_H__
19#define __XFS_VNODE_H__
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct file;
Nathan Scott8285fb52006-06-09 17:07:12 +100022struct bhv_vfs;
23struct bhv_vattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct xfs_iomap;
25struct attrlist_cursor_kern;
26
Nathan Scott8285fb52006-06-09 17:07:12 +100027typedef struct dentry bhv_vname_t;
28typedef __u64 bhv_vnumber_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Nathan Scott67fcaa72006-06-09 17:00:52 +100030typedef struct bhv_vnode {
Nathan Scott8285fb52006-06-09 17:07:12 +100031 bhv_vnumber_t v_number; /* in-core vnode number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#ifdef XFS_VNODE_TRACE
33 struct ktrace *v_trace; /* trace header structure */
34#endif
Eric Sandeen9effd8e2005-05-05 13:26:18 -070035 struct inode v_inode; /* Linux inode */
36 /* inode MUST be last */
Nathan Scott67fcaa72006-06-09 17:00:52 +100037} bhv_vnode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Christoph Hellwig0432dab2005-09-02 16:46:51 +100039#define VN_ISLNK(vp) S_ISLNK((vp)->v_inode.i_mode)
40#define VN_ISREG(vp) S_ISREG((vp)->v_inode.i_mode)
41#define VN_ISDIR(vp) S_ISDIR((vp)->v_inode.i_mode)
42#define VN_ISCHR(vp) S_ISCHR((vp)->v_inode.i_mode)
43#define VN_ISBLK(vp) S_ISBLK((vp)->v_inode.i_mode)
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*
46 * Vnode to Linux inode mapping.
47 */
Nathan Scott67fcaa72006-06-09 17:00:52 +100048static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
Nathan Scottec86dc02006-03-17 17:25:36 +110049{
Alexey Dobriyan71306f32006-06-27 14:10:29 +100050 return container_of(inode, bhv_vnode_t, v_inode);
Nathan Scottec86dc02006-03-17 17:25:36 +110051}
Nathan Scott67fcaa72006-06-09 17:00:52 +100052static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
Nathan Scottec86dc02006-03-17 17:25:36 +110053{
54 return &vnode->v_inode;
55}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100058 * Values for the vop_rwlock/rwunlock flags parameter.
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
Nathan Scott8285fb52006-06-09 17:07:12 +100060typedef enum bhv_vrwlock {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 VRWLOCK_NONE,
62 VRWLOCK_READ,
63 VRWLOCK_WRITE,
64 VRWLOCK_WRITE_DIRECT,
65 VRWLOCK_TRY_READ,
66 VRWLOCK_TRY_WRITE
Nathan Scott8285fb52006-06-09 17:07:12 +100067} bhv_vrwlock_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/*
Christoph Hellwig739bfb22007-08-29 10:58:01 +100070 * Return values for xfs_inactive. A return value of
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * VN_INACTIVE_NOCACHE implies that the file system behavior
72 * has disassociated its state and bhv_desc_t from the vnode.
73 */
74#define VN_INACTIVE_CACHE 0
75#define VN_INACTIVE_NOCACHE 1
76
77/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * Flags for read/write calls - same values as IRIX
79 */
80#define IO_ISAIO 0x00001 /* don't wait for completion */
81#define IO_ISDIRECT 0x00004 /* bypass page cache */
82#define IO_INVIS 0x00020 /* don't update inode timestamps */
83
84/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100085 * Flags for vop_iflush call
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87#define FLUSH_SYNC 1 /* wait for flush to complete */
88#define FLUSH_INODE 2 /* flush the inode itself */
89#define FLUSH_LOG 4 /* force the last log entry for
90 * this inode out to disk */
91
92/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100093 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 */
95#define FI_NONE 0 /* none */
96#define FI_REMAPF 1 /* Do a remapf prior to the operation */
97#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
98 Prevent VM access to the pages until
99 the operation completes. */
100
101/*
102 * Vnode attributes. va_mask indicates those attributes the caller
103 * wants to set or extract.
104 */
Nathan Scott8285fb52006-06-09 17:07:12 +1000105typedef struct bhv_vattr {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 int va_mask; /* bit-mask of attributes present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 mode_t va_mode; /* file access mode and type */
Nathan Scott31b084a2005-05-05 13:25:00 -0700108 xfs_nlink_t va_nlink; /* number of references to file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 uid_t va_uid; /* owner user id */
110 gid_t va_gid; /* owner group id */
111 xfs_ino_t va_nodeid; /* file id */
112 xfs_off_t va_size; /* file size in bytes */
113 u_long va_blocksize; /* blocksize preferred for i/o */
114 struct timespec va_atime; /* time of last access */
115 struct timespec va_mtime; /* time of last modification */
116 struct timespec va_ctime; /* time file changed */
117 u_int va_gen; /* generation number of file */
118 xfs_dev_t va_rdev; /* device the special file represents */
119 __int64_t va_nblocks; /* number of blocks allocated */
120 u_long va_xflags; /* random extended file flags */
121 u_long va_extsize; /* file extent size */
122 u_long va_nextents; /* number of extents in file */
123 u_long va_anextents; /* number of attr extents in file */
Nathan Scottb74e2152005-06-21 13:21:49 +1000124 prid_t va_projid; /* project id */
Nathan Scott8285fb52006-06-09 17:07:12 +1000125} bhv_vattr_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127/*
128 * setattr or getattr attributes
129 */
130#define XFS_AT_TYPE 0x00000001
131#define XFS_AT_MODE 0x00000002
132#define XFS_AT_UID 0x00000004
133#define XFS_AT_GID 0x00000008
134#define XFS_AT_FSID 0x00000010
135#define XFS_AT_NODEID 0x00000020
136#define XFS_AT_NLINK 0x00000040
137#define XFS_AT_SIZE 0x00000080
138#define XFS_AT_ATIME 0x00000100
139#define XFS_AT_MTIME 0x00000200
140#define XFS_AT_CTIME 0x00000400
141#define XFS_AT_RDEV 0x00000800
142#define XFS_AT_BLKSIZE 0x00001000
143#define XFS_AT_NBLOCKS 0x00002000
144#define XFS_AT_VCODE 0x00004000
145#define XFS_AT_MAC 0x00008000
146#define XFS_AT_UPDATIME 0x00010000
147#define XFS_AT_UPDMTIME 0x00020000
148#define XFS_AT_UPDCTIME 0x00040000
149#define XFS_AT_ACL 0x00080000
150#define XFS_AT_CAP 0x00100000
151#define XFS_AT_INF 0x00200000
152#define XFS_AT_XFLAGS 0x00400000
153#define XFS_AT_EXTSIZE 0x00800000
154#define XFS_AT_NEXTENTS 0x01000000
155#define XFS_AT_ANEXTENTS 0x02000000
156#define XFS_AT_PROJID 0x04000000
157#define XFS_AT_SIZE_NOPERM 0x08000000
158#define XFS_AT_GENCOUNT 0x10000000
159
160#define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
161 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
162 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
163 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
164 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
165 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
166
167#define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
168 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
169 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
170 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
171
172#define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
173
174#define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
175
176#define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
177 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
178 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
179
180/*
181 * Modes.
182 */
183#define VSUID S_ISUID /* set user id on execution */
184#define VSGID S_ISGID /* set group id on execution */
185#define VSVTX S_ISVTX /* save swapped text even after use */
186#define VREAD S_IRUSR /* read, write, execute permissions */
187#define VWRITE S_IWUSR
188#define VEXEC S_IXUSR
189
190#define MODEMASK S_IALLUGO /* mode bits plus permission bits */
191
192/*
193 * Check whether mandatory file locking is enabled.
194 */
195#define MANDLOCK(vp, mode) \
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000196 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198extern void vn_init(void);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000199extern bhv_vnode_t *vn_initialize(struct inode *);
200extern int vn_revalidate(struct bhv_vnode *);
Nathan Scott8285fb52006-06-09 17:07:12 +1000201extern int __vn_revalidate(struct bhv_vnode *, bhv_vattr_t *);
202extern void vn_revalidate_core(struct bhv_vnode *, bhv_vattr_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Christoph Hellwigb677c212007-08-29 11:46:28 +1000204/*
205 * Yeah, these don't take vnode anymore at all, all this should be
206 * cleaned up at some point.
207 */
208extern void vn_iowait(struct xfs_inode *ip);
209extern void vn_iowake(struct xfs_inode *ip);
210extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Nathan Scott67fcaa72006-06-09 17:00:52 +1000212static inline int vn_count(struct bhv_vnode *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Nathan Scottec86dc02006-03-17 17:25:36 +1100214 return atomic_read(&vn_to_inode(vp)->i_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217/*
218 * Vnode reference counting functions (and macros for compatibility).
219 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000220extern bhv_vnode_t *vn_hold(struct bhv_vnode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222#if defined(XFS_VNODE_TRACE)
223#define VN_HOLD(vp) \
224 ((void)vn_hold(vp), \
225 vn_trace_hold(vp, __FILE__, __LINE__, (inst_t *)__return_address))
226#define VN_RELE(vp) \
227 (vn_trace_rele(vp, __FILE__, __LINE__, (inst_t *)__return_address), \
Nathan Scottec86dc02006-03-17 17:25:36 +1100228 iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#else
230#define VN_HOLD(vp) ((void)vn_hold(vp))
Nathan Scottec86dc02006-03-17 17:25:36 +1100231#define VN_RELE(vp) (iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#endif
233
Nathan Scott67fcaa72006-06-09 17:00:52 +1000234static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000235{
Nathan Scottec86dc02006-03-17 17:25:36 +1100236 struct inode *inode = igrab(vn_to_inode(vp));
237 return inode ? vn_from_inode(inode) : NULL;
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/*
241 * Vname handling macros.
242 */
243#define VNAME(dentry) ((char *) (dentry)->d_name.name)
244#define VNAMELEN(dentry) ((dentry)->d_name.len)
Nathan Scottec86dc02006-03-17 17:25:36 +1100245#define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 * Dealing with bad inodes
249 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000250static inline void vn_mark_bad(struct bhv_vnode *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Nathan Scottec86dc02006-03-17 17:25:36 +1100252 make_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Nathan Scott67fcaa72006-06-09 17:00:52 +1000255static inline int VN_BAD(struct bhv_vnode *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Nathan Scottec86dc02006-03-17 17:25:36 +1100257 return is_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
260/*
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100261 * Extracting atime values in various formats
262 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000263static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100264{
265 bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
266 bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
267}
268
Nathan Scott67fcaa72006-06-09 17:00:52 +1000269static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100270{
271 *ts = vp->v_inode.i_atime;
272}
273
Nathan Scott67fcaa72006-06-09 17:00:52 +1000274static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100275{
276 *tt = vp->v_inode.i_atime.tv_sec;
277}
278
279/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 * Some useful predicates.
281 */
Nathan Scottec86dc02006-03-17 17:25:36 +1100282#define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
283#define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
284#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 PAGECACHE_TAG_DIRTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/*
Nathan Scott67fcaa72006-06-09 17:00:52 +1000288 * Flags to vop_setattr/getattr.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 */
290#define ATTR_UTIME 0x01 /* non-default utime(2) request */
291#define ATTR_DMI 0x08 /* invocation from a DMI function */
292#define ATTR_LAZY 0x80 /* set/get attributes lazily */
293#define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
Dean Roehrich5fcbab32005-05-05 13:27:19 -0700294#define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
Eric Sandeen1f730e32005-11-02 15:08:10 +1100295#define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297/*
Nathan Scott67fcaa72006-06-09 17:00:52 +1000298 * Flags to vop_fsync/reclaim.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 */
300#define FSYNC_NOWAIT 0 /* asynchronous flush */
301#define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
302#define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
303#define FSYNC_DATA 0x4 /* synchronous fsync of data only */
304
305/*
306 * Tracking vnode activity.
307 */
308#if defined(XFS_VNODE_TRACE)
309
310#define VNODE_TRACE_SIZE 16 /* number of trace entries */
311#define VNODE_KTRACE_ENTRY 1
312#define VNODE_KTRACE_EXIT 2
313#define VNODE_KTRACE_HOLD 3
314#define VNODE_KTRACE_REF 4
315#define VNODE_KTRACE_RELE 5
316
Nathan Scott67fcaa72006-06-09 17:00:52 +1000317extern void vn_trace_entry(struct bhv_vnode *, const char *, inst_t *);
318extern void vn_trace_exit(struct bhv_vnode *, const char *, inst_t *);
319extern void vn_trace_hold(struct bhv_vnode *, char *, int, inst_t *);
320extern void vn_trace_ref(struct bhv_vnode *, char *, int, inst_t *);
321extern void vn_trace_rele(struct bhv_vnode *, char *, int, inst_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323#define VN_TRACE(vp) \
324 vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
325#else
326#define vn_trace_entry(a,b,c)
327#define vn_trace_exit(a,b,c)
328#define vn_trace_hold(a,b,c,d)
329#define vn_trace_ref(a,b,c,d)
330#define vn_trace_rele(a,b,c,d)
331#define VN_TRACE(vp)
332#endif
333
334#endif /* __XFS_VNODE_H__ */