[XFS] Remove xfs_macros.c, xfs_macros.h, rework headers a whole lot.
[deliverable/linux.git] / fs / xfs / linux-2.6 / xfs_vnode.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include "xfs.h"
34
35
36uint64_t vn_generation; /* vnode generation number */
37DEFINE_SPINLOCK(vnumber_lock);
38
39/*
40 * Dedicated vnode inactive/reclaim sync semaphores.
41 * Prime number of hash buckets since address is used as the key.
42 */
43#define NVSYNC 37
44#define vptosync(v) (&vsync[((unsigned long)v) % NVSYNC])
51c91ed5 45STATIC wait_queue_head_t vsync[NVSYNC];
1da177e4 46
1da177e4
LT
47
48void
49vn_init(void)
50{
51c91ed5 51 int i;
1da177e4 52
51c91ed5
CH
53 for (i = 0; i < NVSYNC; i++)
54 init_waitqueue_head(&vsync[i]);
55}
56
57void
58vn_iowait(
59 struct vnode *vp)
60{
61 wait_queue_head_t *wq = vptosync(vp);
62
63 wait_event(*wq, (atomic_read(&vp->v_iocount) == 0));
64}
65
66void
67vn_iowake(
68 struct vnode *vp)
69{
70 if (atomic_dec_and_test(&vp->v_iocount))
71 wake_up(vptosync(vp));
1da177e4
LT
72}
73
1da177e4
LT
74struct vnode *
75vn_initialize(
76 struct inode *inode)
77{
78 struct vnode *vp = LINVFS_GET_VP(inode);
79
80 XFS_STATS_INC(vn_active);
81 XFS_STATS_INC(vn_alloc);
82
83 vp->v_flag = VMODIFIED;
84 spinlock_init(&vp->v_lock, "v_lock");
85
86 spin_lock(&vnumber_lock);
87 if (!++vn_generation) /* v_number shouldn't be zero */
88 vn_generation++;
89 vp->v_number = vn_generation;
90 spin_unlock(&vnumber_lock);
91
92 ASSERT(VN_CACHED(vp) == 0);
93
94 /* Initialize the first behavior and the behavior chain head. */
95 vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode");
96
51c91ed5
CH
97 atomic_set(&vp->v_iocount, 0);
98
1da177e4
LT
99#ifdef XFS_VNODE_TRACE
100 vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP);
1da177e4
LT
101#endif /* XFS_VNODE_TRACE */
102
103 vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address);
104 return vp;
105}
106
1da177e4
LT
107/*
108 * Revalidate the Linux inode from the vattr.
109 * Note: i_size _not_ updated; we must hold the inode
110 * semaphore when doing that - callers responsibility.
111 */
112void
113vn_revalidate_core(
114 struct vnode *vp,
115 vattr_t *vap)
116{
117 struct inode *inode = LINVFS_GET_IP(vp);
118
0432dab2 119 inode->i_mode = vap->va_mode;
1da177e4
LT
120 inode->i_nlink = vap->va_nlink;
121 inode->i_uid = vap->va_uid;
122 inode->i_gid = vap->va_gid;
123 inode->i_blocks = vap->va_nblocks;
124 inode->i_mtime = vap->va_mtime;
125 inode->i_ctime = vap->va_ctime;
126 inode->i_atime = vap->va_atime;
e8c8b3a7 127 inode->i_blksize = vap->va_blocksize;
1da177e4
LT
128 if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
129 inode->i_flags |= S_IMMUTABLE;
130 else
131 inode->i_flags &= ~S_IMMUTABLE;
132 if (vap->va_xflags & XFS_XFLAG_APPEND)
133 inode->i_flags |= S_APPEND;
134 else
135 inode->i_flags &= ~S_APPEND;
136 if (vap->va_xflags & XFS_XFLAG_SYNC)
137 inode->i_flags |= S_SYNC;
138 else
139 inode->i_flags &= ~S_SYNC;
140 if (vap->va_xflags & XFS_XFLAG_NOATIME)
141 inode->i_flags |= S_NOATIME;
142 else
143 inode->i_flags &= ~S_NOATIME;
144}
145
146/*
147 * Revalidate the Linux inode from the vnode.
148 */
149int
150vn_revalidate(
151 struct vnode *vp)
152{
153 vattr_t va;
154 int error;
155
156 vn_trace_entry(vp, "vn_revalidate", (inst_t *)__return_address);
157 ASSERT(vp->v_fbhv != NULL);
158
159 va.va_mask = XFS_AT_STAT|XFS_AT_XFLAGS;
160 VOP_GETATTR(vp, &va, 0, NULL, error);
161 if (!error) {
162 vn_revalidate_core(vp, &va);
163 VUNMODIFY(vp);
164 }
165 return -error;
166}
167
1da177e4
LT
168/*
169 * Add a reference to a referenced vnode.
170 */
171struct vnode *
172vn_hold(
173 struct vnode *vp)
174{
175 struct inode *inode;
176
177 XFS_STATS_INC(vn_hold);
178
179 VN_LOCK(vp);
180 inode = igrab(LINVFS_GET_IP(vp));
181 ASSERT(inode);
182 VN_UNLOCK(vp, 0);
183
184 return vp;
185}
186
1da177e4
LT
187#ifdef XFS_VNODE_TRACE
188
189#define KTRACE_ENTER(vp, vk, s, line, ra) \
190 ktrace_enter( (vp)->v_trace, \
191/* 0 */ (void *)(__psint_t)(vk), \
192/* 1 */ (void *)(s), \
193/* 2 */ (void *)(__psint_t) line, \
02de1f0a 194/* 3 */ (void *)(__psint_t)(vn_count(vp)), \
1da177e4
LT
195/* 4 */ (void *)(ra), \
196/* 5 */ (void *)(__psunsigned_t)(vp)->v_flag, \
197/* 6 */ (void *)(__psint_t)current_cpu(), \
198/* 7 */ (void *)(__psint_t)current_pid(), \
199/* 8 */ (void *)__return_address, \
02de1f0a 200/* 9 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL)
1da177e4
LT
201
202/*
203 * Vnode tracing code.
204 */
205void
764433b7 206vn_trace_entry(vnode_t *vp, const char *func, inst_t *ra)
1da177e4
LT
207{
208 KTRACE_ENTER(vp, VNODE_KTRACE_ENTRY, func, 0, ra);
209}
210
211void
764433b7 212vn_trace_exit(vnode_t *vp, const char *func, inst_t *ra)
1da177e4
LT
213{
214 KTRACE_ENTER(vp, VNODE_KTRACE_EXIT, func, 0, ra);
215}
216
217void
218vn_trace_hold(vnode_t *vp, char *file, int line, inst_t *ra)
219{
220 KTRACE_ENTER(vp, VNODE_KTRACE_HOLD, file, line, ra);
221}
222
223void
224vn_trace_ref(vnode_t *vp, char *file, int line, inst_t *ra)
225{
226 KTRACE_ENTER(vp, VNODE_KTRACE_REF, file, line, ra);
227}
228
229void
230vn_trace_rele(vnode_t *vp, char *file, int line, inst_t *ra)
231{
232 KTRACE_ENTER(vp, VNODE_KTRACE_RELE, file, line, ra);
233}
234#endif /* XFS_VNODE_TRACE */
This page took 0.076791 seconds and 5 git commands to generate.