blob: 41ca2cec5d310da74c6b285c8cec9783e3b9e797 [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/*
28 * Vnode to Linux inode mapping.
29 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100030static inline bhv_vnode_t *vn_from_inode(struct inode *inode)
Nathan Scottec86dc02006-03-17 17:25:36 +110031{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100032 return inode;
Nathan Scottec86dc02006-03-17 17:25:36 +110033}
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100034static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
Nathan Scottec86dc02006-03-17 17:25:36 +110035{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100036 return vnode;
Nathan Scottec86dc02006-03-17 17:25:36 +110037}
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/*
Christoph Hellwig739bfb22007-08-29 10:58:01 +100040 * Return values for xfs_inactive. A return value of
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * VN_INACTIVE_NOCACHE implies that the file system behavior
42 * has disassociated its state and bhv_desc_t from the vnode.
43 */
44#define VN_INACTIVE_CACHE 0
45#define VN_INACTIVE_NOCACHE 1
46
47/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 * Flags for read/write calls - same values as IRIX
49 */
50#define IO_ISAIO 0x00001 /* don't wait for completion */
51#define IO_ISDIRECT 0x00004 /* bypass page cache */
52#define IO_INVIS 0x00020 /* don't update inode timestamps */
53
54/*
David Chinnera3f74ff2008-03-06 13:43:42 +110055 * Flags for xfs_inode_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 */
57#define FLUSH_SYNC 1 /* wait for flush to complete */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*
Nathan Scott67fcaa72006-06-09 17:00:52 +100060 * Flush/Invalidate options for vop_toss/flush/flushinval_pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
62#define FI_NONE 0 /* none */
63#define FI_REMAPF 1 /* Do a remapf prior to the operation */
64#define FI_REMAPF_LOCKED 2 /* Do a remapf prior to the operation.
65 Prevent VM access to the pages until
66 the operation completes. */
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern void vn_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Christoph Hellwigb677c212007-08-29 11:46:28 +100071/*
72 * Yeah, these don't take vnode anymore at all, all this should be
73 * cleaned up at some point.
74 */
75extern void vn_iowait(struct xfs_inode *ip);
76extern void vn_iowake(struct xfs_inode *ip);
77extern void vn_ioerror(struct xfs_inode *ip, int error, char *f, int l);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100079static inline int vn_count(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Nathan Scottec86dc02006-03-17 17:25:36 +110081 return atomic_read(&vn_to_inode(vp)->i_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
84/*
85 * Vnode reference counting functions (and macros for compatibility).
86 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +100087extern bhv_vnode_t *vn_hold(bhv_vnode_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Lachlan McIlroycf441ee2008-02-07 16:42:19 +110089#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define VN_HOLD(vp) \
91 ((void)vn_hold(vp), \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +110092 xfs_itrace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define VN_RELE(vp) \
Lachlan McIlroycf441ee2008-02-07 16:42:19 +110094 (xfs_itrace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
Nathan Scottec86dc02006-03-17 17:25:36 +110095 iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#else
97#define VN_HOLD(vp) ((void)vn_hold(vp))
Nathan Scottec86dc02006-03-17 17:25:36 +110098#define VN_RELE(vp) (iput(vn_to_inode(vp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#endif
100
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000101static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000102{
Nathan Scottec86dc02006-03-17 17:25:36 +1100103 struct inode *inode = igrab(vn_to_inode(vp));
104 return inode ? vn_from_inode(inode) : NULL;
Christoph Hellwigcdb62682005-09-02 16:24:19 +1000105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * Dealing with bad inodes
109 */
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000110static inline int VN_BAD(bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Nathan Scottec86dc02006-03-17 17:25:36 +1100112 return is_bad_inode(vn_to_inode(vp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
115/*
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100116 * Extracting atime values in various formats
117 */
Nathan Scott67fcaa72006-06-09 17:00:52 +1000118static inline void vn_atime_to_bstime(bhv_vnode_t *vp, xfs_bstime_t *bs_atime)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100119{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000120 bs_atime->tv_sec = vp->i_atime.tv_sec;
121 bs_atime->tv_nsec = vp->i_atime.tv_nsec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100122}
123
Nathan Scott67fcaa72006-06-09 17:00:52 +1000124static inline void vn_atime_to_timespec(bhv_vnode_t *vp, struct timespec *ts)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100125{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000126 *ts = vp->i_atime;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100127}
128
Nathan Scott67fcaa72006-06-09 17:00:52 +1000129static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100130{
Christoph Hellwig0a74cd12007-08-29 11:53:12 +1000131 *tt = vp->i_atime.tv_sec;
Nathan Scottca5ccbf2006-01-11 21:03:04 +1100132}
133
134/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 * Some useful predicates.
136 */
Nathan Scottec86dc02006-03-17 17:25:36 +1100137#define VN_MAPPED(vp) mapping_mapped(vn_to_inode(vp)->i_mapping)
138#define VN_CACHED(vp) (vn_to_inode(vp)->i_mapping->nrpages)
139#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 PAGECACHE_TAG_DIRTY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 * Tracking vnode activity.
145 */
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100146#if defined(XFS_INODE_TRACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100148#define INODE_TRACE_SIZE 16 /* number of trace entries */
149#define INODE_KTRACE_ENTRY 1
150#define INODE_KTRACE_EXIT 2
151#define INODE_KTRACE_HOLD 3
152#define INODE_KTRACE_REF 4
153#define INODE_KTRACE_RELE 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100155extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
156extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
157extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
158extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
159extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
160#define xfs_itrace_entry(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000161 _xfs_itrace_entry(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100162#define xfs_itrace_exit(ip) \
Harvey Harrison34a622b2008-04-10 12:19:21 +1000163 _xfs_itrace_exit(ip, __func__, (inst_t *)__return_address)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000164#define xfs_itrace_exit_tag(ip, tag) \
165 _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100166#define xfs_itrace_ref(ip) \
167 _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#else
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100170#define xfs_itrace_entry(a)
171#define xfs_itrace_exit(a)
Lachlan McIlroy15947f22007-09-17 13:11:58 +1000172#define xfs_itrace_exit_tag(a, b)
Lachlan McIlroycf441ee2008-02-07 16:42:19 +1100173#define xfs_itrace_hold(a, b, c, d)
174#define xfs_itrace_ref(a)
175#define xfs_itrace_rele(a, b, c, d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#endif
177
178#endif /* __XFS_VNODE_H__ */