blob: bb3983a1bbbd8bcdce2564e87810efe47a8a2049 [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_vattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct xfs_iomap;
24struct attrlist_cursor_kern;
25
Nathan Scott8285fb52006-06-09 17:07:12 +100026typedef struct dentry bhv_vname_t;
27typedef __u64 bhv_vnumber_t;
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100028typedef struct inode bhv_vnode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100030#define VN_ISLNK(vp) S_ISLNK((vp)->i_mode)
31#define VN_ISREG(vp) S_ISREG((vp)->i_mode)
32#define VN_ISDIR(vp) S_ISDIR((vp)->i_mode)
33#define VN_ISCHR(vp) S_ISCHR((vp)->i_mode)
34#define VN_ISBLK(vp) S_ISBLK((vp)->i_mode)
Christoph Hellwig0432dab2005-09-02 16:46:51 +100035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/*
37 * Vnode to Linux inode mapping.
38 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100039static inline bhv_vnode_t *vn_from_inode(struct inode *inode)
Nathan Scottec86dc02006-03-17 17:25:36 +110040{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100041 return inode;
Nathan Scottec86dc02006-03-17 17:25:36 +110042}
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100043static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
Nathan Scottec86dc02006-03-17 17:25:36 +110044{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100045 return vnode;
Nathan Scottec86dc02006-03-17 17:25:36 +110046}
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100049 * Values for the vop_rwlock/rwunlock flags parameter.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
Nathan Scott8285fb52006-06-09 17:07:12 +100051typedef enum bhv_vrwlock {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 VRWLOCK_NONE,
53 VRWLOCK_READ,
54 VRWLOCK_WRITE,
55 VRWLOCK_WRITE_DIRECT,
56 VRWLOCK_TRY_READ,
57 VRWLOCK_TRY_WRITE
Nathan Scott8285fb52006-06-09 17:07:12 +100058} bhv_vrwlock_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
Christoph Hellwig739bfb22007-08-29 10:58:01 +100061 * Return values for xfs_inactive. A return value of
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * VN_INACTIVE_NOCACHE implies that the file system behavior
63 * has disassociated its state and bhv_desc_t from the vnode.
64 */
65#define VN_INACTIVE_CACHE 0
66#define VN_INACTIVE_NOCACHE 1
67
68/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * Flags for read/write calls - same values as IRIX
70 */
71#define IO_ISAIO 0x00001 /* don't wait for completion */
72#define IO_ISDIRECT 0x00004 /* bypass page cache */
73#define IO_INVIS 0x00020 /* don't update inode timestamps */
74
75/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100076 * Flags for vop_iflush call
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 */
78#define FLUSH_SYNC 1 /* wait for flush to complete */
79#define FLUSH_INODE 2 /* flush the inode itself */
80#define FLUSH_LOG 4 /* force the last log entry for
81 * this inode out to disk */
82
83/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100084 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86#define FI_NONE 0 /* none */
87#define FI_REMAPF 1 /* Do a remapf prior to the operation */
88#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
89 Prevent VM access to the pages until
90 the operation completes. */
91
92/*
93 * Vnode attributes. va_mask indicates those attributes the caller
94 * wants to set or extract.
95 */
Nathan Scott8285fb52006-06-09 17:07:12 +100096typedef struct bhv_vattr {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 int va_mask; /* bit-mask of attributes present */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 mode_t va_mode; /* file access mode and type */
Nathan Scott31b084a2005-05-05 13:25:00 -070099 xfs_nlink_t va_nlink; /* number of references to file */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 uid_t va_uid; /* owner user id */
101 gid_t va_gid; /* owner group id */
102 xfs_ino_t va_nodeid; /* file id */
103 xfs_off_t va_size; /* file size in bytes */
104 u_long va_blocksize; /* blocksize preferred for i/o */
105 struct timespec va_atime; /* time of last access */
106 struct timespec va_mtime; /* time of last modification */
107 struct timespec va_ctime; /* time file changed */
108 u_int va_gen; /* generation number of file */
109 xfs_dev_t va_rdev; /* device the special file represents */
110 __int64_t va_nblocks; /* number of blocks allocated */
111 u_long va_xflags; /* random extended file flags */
112 u_long va_extsize; /* file extent size */
113 u_long va_nextents; /* number of extents in file */
114 u_long va_anextents; /* number of attr extents in file */
Nathan Scottb74e2152005-06-21 13:21:49 +1000115 prid_t va_projid; /* project id */
Nathan Scott8285fb52006-06-09 17:07:12 +1000116} bhv_vattr_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/*
119 * setattr or getattr attributes
120 */
121#define XFS_AT_TYPE 0x00000001
122#define XFS_AT_MODE 0x00000002
123#define XFS_AT_UID 0x00000004
124#define XFS_AT_GID 0x00000008
125#define XFS_AT_FSID 0x00000010
126#define XFS_AT_NODEID 0x00000020
127#define XFS_AT_NLINK 0x00000040
128#define XFS_AT_SIZE 0x00000080
129#define XFS_AT_ATIME 0x00000100
130#define XFS_AT_MTIME 0x00000200
131#define XFS_AT_CTIME 0x00000400
132#define XFS_AT_RDEV 0x00000800
133#define XFS_AT_BLKSIZE 0x00001000
134#define XFS_AT_NBLOCKS 0x00002000
135#define XFS_AT_VCODE 0x00004000
136#define XFS_AT_MAC 0x00008000
137#define XFS_AT_UPDATIME 0x00010000
138#define XFS_AT_UPDMTIME 0x00020000
139#define XFS_AT_UPDCTIME 0x00040000
140#define XFS_AT_ACL 0x00080000
141#define XFS_AT_CAP 0x00100000
142#define XFS_AT_INF 0x00200000
143#define XFS_AT_XFLAGS 0x00400000
144#define XFS_AT_EXTSIZE 0x00800000
145#define XFS_AT_NEXTENTS 0x01000000
146#define XFS_AT_ANEXTENTS 0x02000000
147#define XFS_AT_PROJID 0x04000000
148#define XFS_AT_SIZE_NOPERM 0x08000000
149#define XFS_AT_GENCOUNT 0x10000000
150
151#define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
152 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
153 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
154 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
155 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
156 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
157
158#define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
159 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
160 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
161 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
162
163#define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
164
165#define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
166
167#define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
168 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
169 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
170
171/*
172 * Modes.
173 */
174#define VSUID S_ISUID /* set user id on execution */
175#define VSGID S_ISGID /* set group id on execution */
176#define VSVTX S_ISVTX /* save swapped text even after use */
177#define VREAD S_IRUSR /* read, write, execute permissions */
178#define VWRITE S_IWUSR
179#define VEXEC S_IXUSR
180
181#define MODEMASK S_IALLUGO /* mode bits plus permission bits */
182
183/*
184 * Check whether mandatory file locking is enabled.
185 */
186#define MANDLOCK(vp, mode) \
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000187 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189extern void vn_init(void);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000190extern bhv_vnode_t *vn_initialize(struct inode *);
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000191extern int vn_revalidate(bhv_vnode_t *);
192extern int __vn_revalidate(bhv_vnode_t *, bhv_vattr_t *);
193extern void vn_revalidate_core(bhv_vnode_t *, bhv_vattr_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Christoph Hellwigb677c212007-08-29 11:46:28 +1000195/*
196 * Yeah, these don't take vnode anymore at all, all this should be
197 * cleaned up at some point.
198 */
199extern void vn_iowait(struct xfs_inode *ip);
200extern void vn_iowake(struct xfs_inode *ip);
201extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000203static inline int vn_count(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Nathan Scottec86dc02006-03-17 17:25:36 +1100205 return atomic_read(&vn_to_inode(vp)->i_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208/*
209 * Vnode reference counting functions (and macros for compatibility).
210 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000211extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100213#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define VN_HOLD(vp) \
215 ((void)vn_hold(vp), \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100216 xfs_itrace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#define VN_RELE(vp) \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100218 (xfs_itrace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
Nathan Scottec86dc02006-03-17 17:25:36 +1100219 iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#else
221#define VN_HOLD(vp) ((void)vn_hold(vp))
Nathan Scottec86dc02006-03-17 17:25:36 +1100222#define VN_RELE(vp) (iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#endif
224
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000225static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000226{
Nathan Scottec86dc02006-03-17 17:25:36 +1100227 struct inode *inode = igrab(vn_to_inode(vp));
228 return inode ? vn_from_inode(inode) : NULL;
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000229}
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231/*
232 * Vname handling macros.
233 */
234#define VNAME(dentry) ((char *) (dentry)->d_name.name)
235#define VNAMELEN(dentry) ((dentry)->d_name.len)
Nathan Scottec86dc02006-03-17 17:25:36 +1100236#define VNAME_TO_VNODE(dentry) (vn_from_inode((dentry)->d_inode))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 * Dealing with bad inodes
240 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000241static inline void vn_mark_bad(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Nathan Scottec86dc02006-03-17 17:25:36 +1100243 make_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000246static inline int VN_BAD(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Nathan Scottec86dc02006-03-17 17:25:36 +1100248 return is_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251/*
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100252 * Extracting atime values in various formats
253 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000254static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100255{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000256 bs_atime->tv_sec = vp->i_atime.tv_sec;
257 bs_atime->tv_nsec = vp->i_atime.tv_nsec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100258}
259
Nathan Scott67fcaa72006-06-09 17:00:52 +1000260static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100261{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000262 *ts = vp->i_atime;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100263}
264
Nathan Scott67fcaa72006-06-09 17:00:52 +1000265static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100266{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000267 *tt = vp->i_atime.tv_sec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100268}
269
270/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 * Some useful predicates.
272 */
Nathan Scottec86dc02006-03-17 17:25:36 +1100273#define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
274#define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
275#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 PAGECACHE_TAG_DIRTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278/*
Nathan Scott67fcaa72006-06-09 17:00:52 +1000279 * Flags to vop_setattr/getattr.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 */
281#define ATTR_UTIME 0x01 /* non-default utime(2) request */
282#define ATTR_DMI 0x08 /* invocation from a DMI function */
283#define ATTR_LAZY 0x80 /* set/get attributes lazily */
284#define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
Dean Roehrich5fcbab32005-05-05 13:27:19 -0700285#define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
Eric Sandeen1f730e32005-11-02 15:08:10 +1100286#define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288/*
Nathan Scott67fcaa72006-06-09 17:00:52 +1000289 * Flags to vop_fsync/reclaim.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
291#define FSYNC_NOWAIT 0 /* asynchronous flush */
292#define FSYNC_WAIT 0x1 /* synchronous fsync or forced reclaim */
293#define FSYNC_INVAL 0x2 /* flush and invalidate cached data */
294#define FSYNC_DATA 0x4 /* synchronous fsync of data only */
295
296/*
297 * Tracking vnode activity.
298 */
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100299#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100301#define INODE_TRACE_SIZE 16 /* number of trace entries */
302#define INODE_KTRACE_ENTRY 1
303#define INODE_KTRACE_EXIT 2
304#define INODE_KTRACE_HOLD 3
305#define INODE_KTRACE_REF 4
306#define INODE_KTRACE_RELE 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100308extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
309extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
310extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
311extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
312extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
313#define xfs_itrace_entry(ip) \
314 _xfs_itrace_entry(ip, __FUNCTION__, (inst_t *)__return_address)
315#define xfs_itrace_exit(ip) \
316 _xfs_itrace_exit(ip, __FUNCTION__, (inst_t *)__return_address)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000317#define xfs_itrace_exit_tag(ip, tag) \
318 _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100319#define xfs_itrace_ref(ip) \
320 _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#else
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100323#define xfs_itrace_entry(a)
324#define xfs_itrace_exit(a)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000325#define xfs_itrace_exit_tag(a, b)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100326#define xfs_itrace_hold(a, b, c, d)
327#define xfs_itrace_ref(a)
328#define xfs_itrace_rele(a, b, c, d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#endif
330
331#endif /* __XFS_VNODE_H__ */