]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/gnu/fs/xfs/FreeBSD/xfs_vnode.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / gnu / fs / xfs / FreeBSD / xfs_vnode.c
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 #include "xfs_types.h"
35 #include "xfs_bit.h"
36 #include "xfs_inum.h"
37 #include "xfs_log.h"
38 #include "xfs_trans.h"
39 #include "xfs_trans_priv.h"
40 #include "xfs_sb.h"
41 #include "xfs_ag.h"
42 #include "xfs_dir.h"
43 #include "xfs_dir2.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_imap.h"
51 #include "xfs_alloc.h"
52 #include "xfs_attr_sf.h"
53 #include "xfs_dir_sf.h"
54 #include "xfs_dir2_sf.h"
55 #include "xfs_dinode.h"
56 #include "xfs_ialloc.h"
57 #include "xfs_inode.h"
58 #include "xfs_inode_item.h"
59
60 void
61 vn_init(void)
62 {
63 }
64
65 void
66 vn_iowait(
67           struct xfs_vnode *vp)
68 {
69         printf("vn_iowait doing nothing on FreeBSD?\n");
70 }
71
72 struct xfs_vnode *
73 vn_initialize(
74         xfs_vnode_t     *vp)
75 {
76         XFS_STATS_INC(vn_active);
77         XFS_STATS_INC(vn_alloc);
78
79         /* Initialize the first behavior and the behavior chain head. */
80         vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode");
81
82 #ifdef  CONFIG_XFS_VNODE_TRACING
83         vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP);
84 #endif  /* CONFIG_XFS_VNODE_TRACING */
85
86         vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address);
87         return vp;
88 }
89
90 /*
91  * Get a reference on a vnode. Need to drop vnode reference
92  * to accomodate for vhold by VMAP regardless of whether or
93  * not we were able to successfully grab the vnode.
94  */
95 xfs_vnode_t *
96 vn_get(
97         struct xfs_vnode        *xfs_vp,
98         vmap_t                  *vmap)
99 {
100         struct vnode *vp;
101         int error;
102
103         XFS_STATS_INC(vn_get);
104
105         vp = vmap->v_vp;
106
107         error = vget(vp, 0, curthread);
108         if (error) {
109                 vdrop(vp);
110                 return (NULL);
111         }
112
113         vdrop(vp);
114         if (vp->v_data != xfs_vp) {
115                 vput(vp);
116                 return (NULL);
117         }
118
119         vn_trace_exit(vp, "vn_get", (inst_t *)__return_address);
120         return xfs_vp;
121 }
122
123 /*
124  * purge a vnode from the cache
125  * At this point the vnode is guaranteed to have no references (vn_count == 0)
126  * The caller has to make sure that there are no ways someone could
127  * get a handle (via vn_get) on the vnode (usually done via a mount/vfs lock).
128  */
129 void
130 vn_purge(struct xfs_vnode        *xfs_vp)
131 {
132         struct vnode *vp;
133
134         vn_trace_entry(vp, "vn_purge", (inst_t *)__return_address);
135
136         vp = xfs_vp->v_vnode;
137
138         vn_lock(vp, LK_EXCLUSIVE, curthread);
139         if (vp->v_holdcnt == 0)
140                 vhold(vp);
141         vgone(vp);
142         VOP_UNLOCK(vp, 0, curthread);
143 }
144
145 void xfs_ichgtime(
146         xfs_inode_t     *ip,
147         int             flags)
148 {
149         timespec_t  tv;
150         
151         vfs_timestamp(&tv);
152         if (flags & XFS_ICHGTIME_MOD) {
153                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
154                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
155         }
156         if (flags & XFS_ICHGTIME_ACC) {
157                 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
158                 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
159         }
160         if (flags & XFS_ICHGTIME_CHG) {
161                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
162                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
163         }
164         
165 //printf ("xfs_ichgtime NI\n");
166
167 }
168
169
170 /*
171  * Bring the atime in the XFS inode uptodate.
172  * Used before logging the inode to disk or when the Linux inode goes away.
173  */
174
175 /*
176  * It's unclear if we need this since this is for syncing the linux inode's atime
177  * to the xfs inode's atime.
178  * Since FreeBSD doesn't have atime in the vnode is there anything to really
179  * sync over?
180  * For now just make this a update atime call
181  */
182
183 void
184 xfs_synchronize_atime(
185         xfs_inode_t     *ip)
186 {
187 #if 0
188         xfs_vnode_t     *vp;
189 #endif
190
191         timespec_t  tv;
192         
193 /* vfs_timestamp looks at the system time accuracy variable */
194         vfs_timestamp(&tv);
195 #if 0
196         printf("xfs_synchronize_atime old (%d,%d) new (%d,%ld)\n",
197                ip->i_d.di_atime.t_sec,
198                ip->i_d.di_atime.t_nsec,
199                tv.tv_sec,
200                tv.tv_nsec);
201 #endif
202
203         ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
204         ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
205 }
206
207 #ifdef RMC
208 /*
209  * Extracting atime values in various formats
210  */
211 void vn_atime_to_bstime(struct xfs_vnode *vp, xfs_bstime_t *bs_atime)
212 {
213         bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec;
214         bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec;
215         printf("vn_atime_to_bstime NI\n");
216 }
217 #endif
218
219
220 #ifdef  CONFIG_XFS_VNODE_TRACING
221
222 #define KTRACE_ENTER(vp, vk, s, line, ra)                       \
223         ktrace_enter(   (vp)->v_trace,                          \
224 /*  0 */                (void *)(__psint_t)(vk),                \
225 /*  1 */                (void *)(s),                            \
226 /*  2 */                (void *)(__psint_t) line,               \
227 /*  3 */                (void *)(vn_count(vp)), \
228 /*  4 */                (void *)(ra),                           \
229 /*  5 */                (void *)(__psunsigned_t)(vp)->v_flag,   \
230 /*  6 */                (void *)(__psint_t)smp_processor_id(),  \
231 /*  7 */                (void *)(__psint_t)(current->pid),      \
232 /*  8 */                (void *)__return_address,               \
233 /*  9 */                0, 0, 0, 0, 0, 0, 0)
234
235 /*
236  * Vnode tracing code.
237  */
238 void
239 vn_trace_entry(xfs_vnode_t *vp, char *func, inst_t *ra)
240 {
241         KTRACE_ENTER(vp, VNODE_KTRACE_ENTRY, func, 0, ra);
242 }
243
244 void
245 vn_trace_exit(xfs_vnode_t *vp, char *func, inst_t *ra)
246 {
247         KTRACE_ENTER(vp, VNODE_KTRACE_EXIT, func, 0, ra);
248 }
249
250 void
251 vn_trace_hold(xfs_vnode_t *vp, char *file, int line, inst_t *ra)
252 {
253         KTRACE_ENTER(vp, VNODE_KTRACE_HOLD, file, line, ra);
254 }
255
256 void
257 vn_trace_ref(xfs_vnode_t *vp, char *file, int line, inst_t *ra)
258 {
259         KTRACE_ENTER(vp, VNODE_KTRACE_REF, file, line, ra);
260 }
261
262 void
263 vn_trace_rele(xfs_vnode_t *vp, char *file, int line, inst_t *ra)
264 {
265         KTRACE_ENTER(vp, VNODE_KTRACE_RELE, file, line, ra);
266 }
267 #endif  /* CONFIG_XFS_VNODE_TRACING */