2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 uint64_t vn_generation; /* vnode generation number */
37 DEFINE_SPINLOCK(vnumber_lock);
40 * Dedicated vnode inactive/reclaim sync semaphores.
41 * Prime number of hash buckets since address is used as the key.
44 #define vptosync(v) (&vsync[((unsigned long)v) % NVSYNC])
45 STATIC wait_queue_head_t vsync[NVSYNC];
53 for (i = 0; i < NVSYNC; i++)
54 init_waitqueue_head(&vsync[i]);
61 wait_queue_head_t *wq = vptosync(vp);
63 wait_event(*wq, (atomic_read(&vp->v_iocount) == 0));
70 if (atomic_dec_and_test(&vp->v_iocount))
71 wake_up(vptosync(vp));
78 struct vnode *vp = LINVFS_GET_VP(inode);
80 XFS_STATS_INC(vn_active);
81 XFS_STATS_INC(vn_alloc);
83 vp->v_flag = VMODIFIED;
84 spinlock_init(&vp->v_lock, "v_lock");
86 spin_lock(&vnumber_lock);
87 if (!++vn_generation) /* v_number shouldn't be zero */
89 vp->v_number = vn_generation;
90 spin_unlock(&vnumber_lock);
92 ASSERT(VN_CACHED(vp) == 0);
94 /* Initialize the first behavior and the behavior chain head. */
95 vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode");
97 atomic_set(&vp->v_iocount, 0);
99 #ifdef XFS_VNODE_TRACE
100 vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP);
101 #endif /* XFS_VNODE_TRACE */
103 vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address);
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.
117 struct inode *inode = LINVFS_GET_IP(vp);
119 inode->i_mode = vap->va_mode;
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;
127 if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
128 inode->i_flags |= S_IMMUTABLE;
130 inode->i_flags &= ~S_IMMUTABLE;
131 if (vap->va_xflags & XFS_XFLAG_APPEND)
132 inode->i_flags |= S_APPEND;
134 inode->i_flags &= ~S_APPEND;
135 if (vap->va_xflags & XFS_XFLAG_SYNC)
136 inode->i_flags |= S_SYNC;
138 inode->i_flags &= ~S_SYNC;
139 if (vap->va_xflags & XFS_XFLAG_NOATIME)
140 inode->i_flags |= S_NOATIME;
142 inode->i_flags &= ~S_NOATIME;
146 * Revalidate the Linux inode from the vnode.
155 vn_trace_entry(vp, "vn_revalidate", (inst_t *)__return_address);
156 ASSERT(vp->v_fbhv != NULL);
158 va.va_mask = XFS_AT_STAT|XFS_AT_XFLAGS;
159 VOP_GETATTR(vp, &va, 0, NULL, error);
161 vn_revalidate_core(vp, &va);
168 * Add a reference to a referenced vnode.
176 XFS_STATS_INC(vn_hold);
179 inode = igrab(LINVFS_GET_IP(vp));
186 #ifdef XFS_VNODE_TRACE
188 #define KTRACE_ENTER(vp, vk, s, line, ra) \
189 ktrace_enter( (vp)->v_trace, \
190 /* 0 */ (void *)(__psint_t)(vk), \
191 /* 1 */ (void *)(s), \
192 /* 2 */ (void *)(__psint_t) line, \
193 /* 3 */ (void *)(__psint_t)(vn_count(vp)), \
194 /* 4 */ (void *)(ra), \
195 /* 5 */ (void *)(__psunsigned_t)(vp)->v_flag, \
196 /* 6 */ (void *)(__psint_t)current_cpu(), \
197 /* 7 */ (void *)(__psint_t)current_pid(), \
198 /* 8 */ (void *)__return_address, \
199 /* 9 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL)
202 * Vnode tracing code.
205 vn_trace_entry(vnode_t *vp, const char *func, inst_t *ra)
207 KTRACE_ENTER(vp, VNODE_KTRACE_ENTRY, func, 0, ra);
211 vn_trace_exit(vnode_t *vp, const char *func, inst_t *ra)
213 KTRACE_ENTER(vp, VNODE_KTRACE_EXIT, func, 0, ra);
217 vn_trace_hold(vnode_t *vp, char *file, int line, inst_t *ra)
219 KTRACE_ENTER(vp, VNODE_KTRACE_HOLD, file, line, ra);
223 vn_trace_ref(vnode_t *vp, char *file, int line, inst_t *ra)
225 KTRACE_ENTER(vp, VNODE_KTRACE_REF, file, line, ra);
229 vn_trace_rele(vnode_t *vp, char *file, int line, inst_t *ra)
231 KTRACE_ENTER(vp, VNODE_KTRACE_RELE, file, line, ra);
233 #endif /* XFS_VNODE_TRACE */