blob: 25eb2a9e8d9b6cfc1bd859f19476e9372631a857 [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
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100026typedef struct inode bhv_vnode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/*
29 * Vnode to Linux inode mapping.
30 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100031static inline bhv_vnode_t *vn_from_inode(struct inode *inode)
Nathan Scottec86dc02006-03-17 17:25:36 +110032{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100033 return inode;
Nathan Scottec86dc02006-03-17 17:25:36 +110034}
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100035static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
Nathan Scottec86dc02006-03-17 17:25:36 +110036{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100037 return vnode;
Nathan Scottec86dc02006-03-17 17:25:36 +110038}
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/*
Christoph Hellwig739bfb22007-08-29 10:58:01 +100041 * Return values for xfs_inactive. A return value of
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 * VN_INACTIVE_NOCACHE implies that the file system behavior
43 * has disassociated its state and bhv_desc_t from the vnode.
44 */
45#define VN_INACTIVE_CACHE 0
46#define VN_INACTIVE_NOCACHE 1
47
48/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * Flags for read/write calls - same values as IRIX
50 */
51#define IO_ISAIO 0x00001 /* don't wait for completion */
52#define IO_ISDIRECT 0x00004 /* bypass page cache */
53#define IO_INVIS 0x00020 /* don't update inode timestamps */
54
55/*
David Chinnera3f74ff2008-03-06 13:43:42 +110056 * Flags for xfs_inode_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
58#define FLUSH_SYNC 1 /* wait for flush to complete */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100061 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
63#define FI_NONE 0 /* none */
64#define FI_REMAPF 1 /* Do a remapf prior to the operation */
65#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
66 Prevent VM access to the pages until
67 the operation completes. */
68
69/*
70 * Vnode attributes. va_mask indicates those attributes the caller
71 * wants to set or extract.
72 */
Nathan Scott8285fb52006-06-09 17:07:12 +100073typedef struct bhv_vattr {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 int va_mask; /* bit-mask of attributes present */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 mode_t va_mode; /* file access mode and type */
Nathan Scott31b084a2005-05-05 13:25:00 -070076 xfs_nlink_t va_nlink; /* number of references to file */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 uid_t va_uid; /* owner user id */
78 gid_t va_gid; /* owner group id */
79 xfs_ino_t va_nodeid; /* file id */
80 xfs_off_t va_size; /* file size in bytes */
81 u_long va_blocksize; /* blocksize preferred for i/o */
82 struct timespec va_atime; /* time of last access */
83 struct timespec va_mtime; /* time of last modification */
84 struct timespec va_ctime; /* time file changed */
85 u_int va_gen; /* generation number of file */
86 xfs_dev_t va_rdev; /* device the special file represents */
87 __int64_t va_nblocks; /* number of blocks allocated */
88 u_long va_xflags; /* random extended file flags */
89 u_long va_extsize; /* file extent size */
90 u_long va_nextents; /* number of extents in file */
91 u_long va_anextents; /* number of attr extents in file */
Nathan Scottb74e2152005-06-21 13:21:49 +100092 prid_t va_projid; /* project id */
Nathan Scott8285fb52006-06-09 17:07:12 +100093} bhv_vattr_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/*
96 * setattr or getattr attributes
97 */
98#define XFS_AT_TYPE 0x00000001
99#define XFS_AT_MODE 0x00000002
100#define XFS_AT_UID 0x00000004
101#define XFS_AT_GID 0x00000008
102#define XFS_AT_FSID 0x00000010
103#define XFS_AT_NODEID 0x00000020
104#define XFS_AT_NLINK 0x00000040
105#define XFS_AT_SIZE 0x00000080
106#define XFS_AT_ATIME 0x00000100
107#define XFS_AT_MTIME 0x00000200
108#define XFS_AT_CTIME 0x00000400
109#define XFS_AT_RDEV 0x00000800
110#define XFS_AT_BLKSIZE 0x00001000
111#define XFS_AT_NBLOCKS 0x00002000
112#define XFS_AT_VCODE 0x00004000
113#define XFS_AT_MAC 0x00008000
114#define XFS_AT_UPDATIME 0x00010000
115#define XFS_AT_UPDMTIME 0x00020000
116#define XFS_AT_UPDCTIME 0x00040000
117#define XFS_AT_ACL 0x00080000
118#define XFS_AT_CAP 0x00100000
119#define XFS_AT_INF 0x00200000
120#define XFS_AT_XFLAGS 0x00400000
121#define XFS_AT_EXTSIZE 0x00800000
122#define XFS_AT_NEXTENTS 0x01000000
123#define XFS_AT_ANEXTENTS 0x02000000
124#define XFS_AT_PROJID 0x04000000
125#define XFS_AT_SIZE_NOPERM 0x08000000
126#define XFS_AT_GENCOUNT 0x10000000
127
128#define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
129 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
130 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
131 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
132 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
133 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
134
135#define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
136 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
137 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
138 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
139
140#define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
141
142#define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
143
144#define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
145 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
146 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148extern void vn_init(void);
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000149extern int vn_revalidate(bhv_vnode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Christoph Hellwigb677c212007-08-29 11:46:28 +1000151/*
152 * Yeah, these don't take vnode anymore at all, all this should be
153 * cleaned up at some point.
154 */
155extern void vn_iowait(struct xfs_inode *ip);
156extern void vn_iowake(struct xfs_inode *ip);
157extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000159static inline int vn_count(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Nathan Scottec86dc02006-03-17 17:25:36 +1100161 return atomic_read(&vn_to_inode(vp)->i_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164/*
165 * Vnode reference counting functions (and macros for compatibility).
166 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000167extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100169#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#define VN_HOLD(vp) \
171 ((void)vn_hold(vp), \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100172 xfs_itrace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define VN_RELE(vp) \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100174 (xfs_itrace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
Nathan Scottec86dc02006-03-17 17:25:36 +1100175 iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#else
177#define VN_HOLD(vp) ((void)vn_hold(vp))
Nathan Scottec86dc02006-03-17 17:25:36 +1100178#define VN_RELE(vp) (iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#endif
180
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000181static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000182{
Nathan Scottec86dc02006-03-17 17:25:36 +1100183 struct inode *inode = igrab(vn_to_inode(vp));
184 return inode ? vn_from_inode(inode) : NULL;
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * Dealing with bad inodes
189 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000190static inline int VN_BAD(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Nathan Scottec86dc02006-03-17 17:25:36 +1100192 return is_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195/*
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100196 * Extracting atime values in various formats
197 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000198static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100199{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000200 bs_atime->tv_sec = vp->i_atime.tv_sec;
201 bs_atime->tv_nsec = vp->i_atime.tv_nsec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100202}
203
Nathan Scott67fcaa72006-06-09 17:00:52 +1000204static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100205{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000206 *ts = vp->i_atime;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100207}
208
Nathan Scott67fcaa72006-06-09 17:00:52 +1000209static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100210{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000211 *tt = vp->i_atime.tv_sec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100212}
213
214/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 * Some useful predicates.
216 */
Nathan Scottec86dc02006-03-17 17:25:36 +1100217#define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
218#define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
219#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 PAGECACHE_TAG_DIRTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222/*
Nathan Scott67fcaa72006-06-09 17:00:52 +1000223 * Flags to vop_setattr/getattr.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 */
225#define ATTR_UTIME 0x01 /* non-default utime(2) request */
226#define ATTR_DMI 0x08 /* invocation from a DMI function */
227#define ATTR_LAZY 0x80 /* set/get attributes lazily */
228#define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
Dean Roehrich5fcbab32005-05-05 13:27:19 -0700229#define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
Eric Sandeen1f730e32005-11-02 15:08:10 +1100230#define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 * Tracking vnode activity.
234 */
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100235#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100237#define INODE_TRACE_SIZE 16 /* number of trace entries */
238#define INODE_KTRACE_ENTRY 1
239#define INODE_KTRACE_EXIT 2
240#define INODE_KTRACE_HOLD 3
241#define INODE_KTRACE_REF 4
242#define INODE_KTRACE_RELE 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100244extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
245extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
246extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
247extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
248extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
249#define xfs_itrace_entry(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000250 _xfs_itrace_entry(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100251#define xfs_itrace_exit(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000252 _xfs_itrace_exit(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000253#define xfs_itrace_exit_tag(ip, tag) \
254 _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100255#define xfs_itrace_ref(ip) \
256 _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#else
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100259#define xfs_itrace_entry(a)
260#define xfs_itrace_exit(a)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000261#define xfs_itrace_exit_tag(a, b)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100262#define xfs_itrace_hold(a, b, c, d)
263#define xfs_itrace_ref(a)
264#define xfs_itrace_rele(a, b, c, d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif
266
267#endif /* __XFS_VNODE_H__ */