0f9ba6585c86b04ef9009f7b9a065ba703ef0d05
[linux-2.6-block.git] / fs / xfs / linux-2.6 / xfs_vnode.h
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18 #ifndef __XFS_VNODE_H__
19 #define __XFS_VNODE_H__
20
21 struct file;
22 struct bhv_vfs;
23 struct bhv_vattr;
24 struct xfs_iomap;
25 struct attrlist_cursor_kern;
26
27 typedef struct dentry   bhv_vname_t;
28 typedef __u64           bhv_vnumber_t;
29
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 */
34 } bhv_vflags_t;
35
36 /*
37  * MP locking protocols:
38  *      v_flag,                                 VN_LOCK/VN_UNLOCK
39  */
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    */
47 #endif
48         struct inode    v_inode;                /* Linux inode */
49         /* inode MUST be last */
50 } bhv_vnode_t;
51
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)
57
58 /*
59  * Vnode to Linux inode mapping.
60  */
61 static inline struct bhv_vnode *vn_from_inode(struct inode *inode)
62 {
63         return container_of(inode, bhv_vnode_t, v_inode);
64 }
65 static inline struct inode *vn_to_inode(struct bhv_vnode *vnode)
66 {
67         return &vnode->v_inode;
68 }
69
70 /*
71  * Values for the vop_rwlock/rwunlock flags parameter.
72  */
73 typedef enum bhv_vrwlock {
74         VRWLOCK_NONE,
75         VRWLOCK_READ,
76         VRWLOCK_WRITE,
77         VRWLOCK_WRITE_DIRECT,
78         VRWLOCK_TRY_READ,
79         VRWLOCK_TRY_WRITE
80 } bhv_vrwlock_t;
81
82 /*
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.
86  */
87 #define VN_INACTIVE_CACHE       0
88 #define VN_INACTIVE_NOCACHE     1
89
90 /*
91  * Flags for read/write calls - same values as IRIX
92  */
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 */
96
97 /*
98  * Flags for vop_iflush call
99  */
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       */
104
105 /*
106  * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
107  */
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. */
113
114 /*
115  * Vnode attributes.  va_mask indicates those attributes the caller
116  * wants to set or extract.
117  */
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 */
138 } bhv_vattr_t;
139
140 /*
141  * setattr or getattr attributes
142  */
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
172
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)
179
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)
184
185 #define XFS_AT_TIMES    (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
186
187 #define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
188
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)
192
193 /*
194  *  Modes.
195  */
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
202
203 #define MODEMASK S_IALLUGO      /* mode bits plus permission bits */
204
205 /*
206  * Check whether mandatory file locking is enabled.
207  */
208 #define MANDLOCK(vp, mode)      \
209         (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
210
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 *);
216
217 extern void     vn_iowait(struct bhv_vnode *vp);
218 extern void     vn_iowake(struct bhv_vnode *vp);
219
220 extern void     vn_ioerror(struct bhv_vnode *vp, int error, char *f, int l);
221
222 static inline int vn_count(struct bhv_vnode *vp)
223 {
224         return atomic_read(&vn_to_inode(vp)->i_count);
225 }
226
227 /*
228  * Vnode reference counting functions (and macros for compatibility).
229  */
230 extern bhv_vnode_t      *vn_hold(struct bhv_vnode *);
231
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)))
239 #else
240 #define VN_HOLD(vp)             ((void)vn_hold(vp))
241 #define VN_RELE(vp)             (iput(vn_to_inode(vp)))
242 #endif
243
244 static inline struct bhv_vnode *vn_grab(struct bhv_vnode *vp)
245 {
246         struct inode *inode = igrab(vn_to_inode(vp));
247         return inode ? vn_from_inode(inode) : NULL;
248 }
249
250 /*
251  * Vname handling macros.
252  */
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))
256
257 /*
258  * Vnode spinlock manipulation.
259  */
260 #define VN_LOCK(vp)             mutex_spinlock(&(vp)->v_lock)
261 #define VN_UNLOCK(vp, s)        mutex_spinunlock(&(vp)->v_lock, s)
262
263 STATIC_INLINE void vn_flagset(struct bhv_vnode *vp, uint flag)
264 {
265         spin_lock(&vp->v_lock);
266         vp->v_flag |= flag;
267         spin_unlock(&vp->v_lock);
268 }
269
270 STATIC_INLINE uint vn_flagclr(struct bhv_vnode *vp, uint flag)
271 {
272         uint    cleared;
273
274         spin_lock(&vp->v_lock);
275         cleared = (vp->v_flag & flag);
276         vp->v_flag &= ~flag;
277         spin_unlock(&vp->v_lock);
278         return cleared;
279 }
280
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)
285
286 /*
287  * Dealing with bad inodes
288  */
289 static inline void vn_mark_bad(struct bhv_vnode *vp)
290 {
291         make_bad_inode(vn_to_inode(vp));
292 }
293
294 static inline int VN_BAD(struct bhv_vnode *vp)
295 {
296         return is_bad_inode(vn_to_inode(vp));
297 }
298
299 /*
300  * Extracting atime values in various formats
301  */
302 static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
303 {
304         bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
305         bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
306 }
307
308 static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
309 {
310         *ts = vp->v_inode.i_atime;
311 }
312
313 static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
314 {
315         *tt = vp->v_inode.i_atime.tv_sec;
316 }
317
318 /*
319  * Some useful predicates.
320  */
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, \
324                                         PAGECACHE_TAG_DIRTY)
325 #define VN_TRUNC(vp)    ((vp)->v_flag & VTRUNCATED)
326
327 /*
328  * Flags to vop_setattr/getattr.
329  */
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 */
336
337 /*
338  * Flags to vop_fsync/reclaim.
339  */
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 */
344
345 /*
346  * Tracking vnode activity.
347  */
348 #if defined(XFS_VNODE_TRACE)
349
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
356
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 *);
362
363 #define VN_TRACE(vp)            \
364         vn_trace_ref(vp, __FILE__, __LINE__, (inst_t *)__return_address)
365 #else
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)
371 #define VN_TRACE(vp)
372 #endif
373
374 #endif  /* __XFS_VNODE_H__ */