blob: cc53687ff82674dda0ea6bc4f70faadb0b94aacb [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022struct xfs_iomap;
23struct attrlist_cursor_kern;
24
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100025typedef struct inode bhv_vnode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/*
Christoph Hellwig739bfb22007-08-29 10:58:01 +100028 * Return values for xfs_inactive. A return value of
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * VN_INACTIVE_NOCACHE implies that the file system behavior
30 * has disassociated its state and bhv_desc_t from the vnode.
31 */
32#define VN_INACTIVE_CACHE 0
33#define VN_INACTIVE_NOCACHE 1
34
35/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 * Flags for read/write calls - same values as IRIX
37 */
38#define IO_ISAIO 0x00001 /* don't wait for completion */
39#define IO_ISDIRECT 0x00004 /* bypass page cache */
40#define IO_INVIS 0x00020 /* don't update inode timestamps */
41
42/*
David Chinnera3f74ff2008-03-06 13:43:42 +110043 * Flags for xfs_inode_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 */
45#define FLUSH_SYNC 1 /* wait for flush to complete */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100048 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 */
50#define FI_NONE 0 /* none */
51#define FI_REMAPF 1 /* Do a remapf prior to the operation */
52#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
53 Prevent VM access to the pages until
54 the operation completes. */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057extern void vn_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Christoph Hellwigb677c212007-08-29 11:46:28 +100059/*
60 * Yeah, these don't take vnode anymore at all, all this should be
61 * cleaned up at some point.
62 */
63extern void vn_iowait(struct xfs_inode *ip);
64extern void vn_iowake(struct xfs_inode *ip);
65extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100067static inline int vn_count(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Christoph Hellwig863890c2008-08-13 16:12:05 +100069 return atomic_read(&vp->i_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
72/*
73 * Vnode reference counting functions (and macros for compatibility).
74 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100075extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Lachlan McIlroycf441ee2008-02-07 16:42:19 +110077#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define VN_HOLD(vp) \
79 ((void)vn_hold(vp), \
David Chinnere6064d32008-08-13 16:01:45 +100080 xfs_itrace_hold(XFS_I(vp), __FILE__, __LINE__, (inst_t *)__return_address))
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define VN_RELE(vp) \
David Chinnere6064d32008-08-13 16:01:45 +100082 (xfs_itrace_rele(XFS_I(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
Christoph Hellwig863890c2008-08-13 16:12:05 +100083 iput(vp))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#else
85#define VN_HOLD(vp) ((void)vn_hold(vp))
Christoph Hellwig863890c2008-08-13 16:12:05 +100086#define VN_RELE(vp) (iput(vp))
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif
88
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100089static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
Christoph Hellwigcdb62682005-09-02 16:24:19 +100090{
Christoph Hellwig863890c2008-08-13 16:12:05 +100091 return igrab(vp);
Christoph Hellwigcdb62682005-09-02 16:24:19 +100092}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 * Dealing with bad inodes
96 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100097static inline int VN_BAD(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Christoph Hellwig863890c2008-08-13 16:12:05 +100099 return is_bad_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102/*
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100103 * Extracting atime values in various formats
104 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000105static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100106{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000107 bs_atime->tv_sec = vp->i_atime.tv_sec;
108 bs_atime->tv_nsec = vp->i_atime.tv_nsec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100109}
110
Nathan Scott67fcaa72006-06-09 17:00:52 +1000111static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100112{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000113 *ts = vp->i_atime;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100114}
115
Nathan Scott67fcaa72006-06-09 17:00:52 +1000116static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100117{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000118 *tt = vp->i_atime.tv_sec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100119}
120
121/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * Some useful predicates.
123 */
Christoph Hellwig863890c2008-08-13 16:12:05 +1000124#define VN_MAPPED(vp) mapping_mapped(vp->i_mapping)
125#define VN_CACHED(vp) (vp->i_mapping->nrpages)
126#define VN_DIRTY(vp) mapping_tagged(vp->i_mapping, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 PAGECACHE_TAG_DIRTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 * Tracking vnode activity.
132 */
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100133#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100135#define INODE_TRACE_SIZE 16 /* number of trace entries */
136#define INODE_KTRACE_ENTRY 1
137#define INODE_KTRACE_EXIT 2
138#define INODE_KTRACE_HOLD 3
139#define INODE_KTRACE_REF 4
140#define INODE_KTRACE_RELE 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100142extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
143extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
144extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
145extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
146extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
147#define xfs_itrace_entry(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000148 _xfs_itrace_entry(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100149#define xfs_itrace_exit(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000150 _xfs_itrace_exit(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000151#define xfs_itrace_exit_tag(ip, tag) \
152 _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100153#define xfs_itrace_ref(ip) \
154 _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#else
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100157#define xfs_itrace_entry(a)
158#define xfs_itrace_exit(a)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000159#define xfs_itrace_exit_tag(a, b)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100160#define xfs_itrace_hold(a, b, c, d)
161#define xfs_itrace_ref(a)
162#define xfs_itrace_rele(a, b, c, d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif
164
165#endif /* __XFS_VNODE_H__ */