lfs_vnops.c revision 1.27 1 1.27 wrstuden /* $NetBSD: lfs_vnops.c,v 1.27 1999/08/03 20:19:22 wrstuden Exp $ */
2 1.2 cgd
3 1.22 perseant /*-
4 1.22 perseant * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.22 perseant * All rights reserved.
6 1.22 perseant *
7 1.22 perseant * This code is derived from software contributed to The NetBSD Foundation
8 1.22 perseant * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 1.22 perseant *
10 1.22 perseant * Redistribution and use in source and binary forms, with or without
11 1.22 perseant * modification, are permitted provided that the following conditions
12 1.22 perseant * are met:
13 1.22 perseant * 1. Redistributions of source code must retain the above copyright
14 1.22 perseant * notice, this list of conditions and the following disclaimer.
15 1.22 perseant * 2. Redistributions in binary form must reproduce the above copyright
16 1.22 perseant * notice, this list of conditions and the following disclaimer in the
17 1.22 perseant * documentation and/or other materials provided with the distribution.
18 1.22 perseant * 3. All advertising materials mentioning features or use of this software
19 1.22 perseant * must display the following acknowledgement:
20 1.22 perseant * This product includes software developed by the NetBSD
21 1.22 perseant * Foundation, Inc. and its contributors.
22 1.22 perseant * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.22 perseant * contributors may be used to endorse or promote products derived
24 1.22 perseant * from this software without specific prior written permission.
25 1.22 perseant *
26 1.22 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.22 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.22 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.22 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.22 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.22 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.22 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.22 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.22 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.22 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.22 perseant * POSSIBILITY OF SUCH DAMAGE.
37 1.22 perseant */
38 1.1 mycroft /*
39 1.15 fvdl * Copyright (c) 1986, 1989, 1991, 1993, 1995
40 1.1 mycroft * The Regents of the University of California. All rights reserved.
41 1.1 mycroft *
42 1.1 mycroft * Redistribution and use in source and binary forms, with or without
43 1.1 mycroft * modification, are permitted provided that the following conditions
44 1.1 mycroft * are met:
45 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
46 1.1 mycroft * notice, this list of conditions and the following disclaimer.
47 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
49 1.1 mycroft * documentation and/or other materials provided with the distribution.
50 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
51 1.1 mycroft * must display the following acknowledgement:
52 1.1 mycroft * This product includes software developed by the University of
53 1.1 mycroft * California, Berkeley and its contributors.
54 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
55 1.1 mycroft * may be used to endorse or promote products derived from this software
56 1.1 mycroft * without specific prior written permission.
57 1.1 mycroft *
58 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 mycroft * SUCH DAMAGE.
69 1.1 mycroft *
70 1.15 fvdl * @(#)lfs_vnops.c 8.13 (Berkeley) 6/10/95
71 1.1 mycroft */
72 1.17 sommerfe
73 1.1 mycroft #include <sys/param.h>
74 1.1 mycroft #include <sys/systm.h>
75 1.1 mycroft #include <sys/namei.h>
76 1.1 mycroft #include <sys/resourcevar.h>
77 1.1 mycroft #include <sys/kernel.h>
78 1.1 mycroft #include <sys/file.h>
79 1.1 mycroft #include <sys/stat.h>
80 1.1 mycroft #include <sys/buf.h>
81 1.1 mycroft #include <sys/proc.h>
82 1.1 mycroft #include <sys/conf.h>
83 1.1 mycroft #include <sys/mount.h>
84 1.1 mycroft #include <sys/vnode.h>
85 1.1 mycroft #include <sys/malloc.h>
86 1.19 thorpej #include <sys/pool.h>
87 1.10 christos #include <sys/signalvar.h>
88 1.1 mycroft
89 1.1 mycroft #include <vm/vm.h>
90 1.1 mycroft
91 1.12 mycroft #include <miscfs/fifofs/fifo.h>
92 1.12 mycroft #include <miscfs/genfs/genfs.h>
93 1.1 mycroft #include <miscfs/specfs/specdev.h>
94 1.1 mycroft
95 1.1 mycroft #include <ufs/ufs/quota.h>
96 1.1 mycroft #include <ufs/ufs/inode.h>
97 1.1 mycroft #include <ufs/ufs/dir.h>
98 1.1 mycroft #include <ufs/ufs/ufsmount.h>
99 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
100 1.1 mycroft
101 1.1 mycroft #include <ufs/lfs/lfs.h>
102 1.1 mycroft #include <ufs/lfs/lfs_extern.h>
103 1.1 mycroft
104 1.1 mycroft /* Global vfs data structures for lfs. */
105 1.10 christos int (**lfs_vnodeop_p) __P((void *));
106 1.1 mycroft struct vnodeopv_entry_desc lfs_vnodeop_entries[] = {
107 1.1 mycroft { &vop_default_desc, vn_default_error },
108 1.1 mycroft { &vop_lookup_desc, ufs_lookup }, /* lookup */
109 1.22 perseant { &vop_create_desc, lfs_create }, /* create */
110 1.22 perseant { &vop_whiteout_desc, lfs_whiteout }, /* whiteout */
111 1.22 perseant { &vop_mknod_desc, lfs_mknod }, /* mknod */
112 1.1 mycroft { &vop_open_desc, ufs_open }, /* open */
113 1.1 mycroft { &vop_close_desc, lfs_close }, /* close */
114 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
115 1.1 mycroft { &vop_getattr_desc, lfs_getattr }, /* getattr */
116 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
117 1.1 mycroft { &vop_read_desc, lfs_read }, /* read */
118 1.1 mycroft { &vop_write_desc, lfs_write }, /* write */
119 1.4 mycroft { &vop_lease_desc, ufs_lease_check }, /* lease */
120 1.1 mycroft { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
121 1.27 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
122 1.13 mycroft { &vop_poll_desc, ufs_poll }, /* poll */
123 1.15 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
124 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
125 1.1 mycroft { &vop_fsync_desc, lfs_fsync }, /* fsync */
126 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
127 1.22 perseant { &vop_remove_desc, lfs_remove }, /* remove */
128 1.22 perseant { &vop_link_desc, lfs_link }, /* link */
129 1.22 perseant { &vop_rename_desc, lfs_rename }, /* rename */
130 1.22 perseant { &vop_mkdir_desc, lfs_mkdir }, /* mkdir */
131 1.22 perseant { &vop_rmdir_desc, lfs_rmdir }, /* rmdir */
132 1.22 perseant { &vop_symlink_desc, lfs_symlink }, /* symlink */
133 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
134 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
135 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
136 1.15 fvdl { &vop_inactive_desc, ufs_inactive }, /* inactive */
137 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
138 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
139 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
140 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
141 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
142 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
143 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
144 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
145 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
146 1.1 mycroft { &vop_blkatoff_desc, lfs_blkatoff }, /* blkatoff */
147 1.1 mycroft { &vop_valloc_desc, lfs_valloc }, /* valloc */
148 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
149 1.1 mycroft { &vop_truncate_desc, lfs_truncate }, /* truncate */
150 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
151 1.1 mycroft { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
152 1.10 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
153 1.1 mycroft };
154 1.1 mycroft struct vnodeopv_desc lfs_vnodeop_opv_desc =
155 1.1 mycroft { &lfs_vnodeop_p, lfs_vnodeop_entries };
156 1.1 mycroft
157 1.10 christos int (**lfs_specop_p) __P((void *));
158 1.1 mycroft struct vnodeopv_entry_desc lfs_specop_entries[] = {
159 1.1 mycroft { &vop_default_desc, vn_default_error },
160 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
161 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
162 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
163 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
164 1.1 mycroft { &vop_close_desc, ufsspec_close }, /* close */
165 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
166 1.1 mycroft { &vop_getattr_desc, lfs_getattr }, /* getattr */
167 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
168 1.1 mycroft { &vop_read_desc, ufsspec_read }, /* read */
169 1.1 mycroft { &vop_write_desc, ufsspec_write }, /* write */
170 1.4 mycroft { &vop_lease_desc, spec_lease_check }, /* lease */
171 1.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
172 1.27 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
173 1.13 mycroft { &vop_poll_desc, spec_poll }, /* poll */
174 1.15 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
175 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
176 1.1 mycroft { &vop_fsync_desc, spec_fsync }, /* fsync */
177 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
178 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
179 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
180 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
181 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
182 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
183 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
184 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
185 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
186 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
187 1.15 fvdl { &vop_inactive_desc, ufs_inactive }, /* inactive */
188 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
189 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
190 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
191 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
192 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
193 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
194 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
195 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
196 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
197 1.1 mycroft { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
198 1.1 mycroft { &vop_valloc_desc, spec_valloc }, /* valloc */
199 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
200 1.1 mycroft { &vop_truncate_desc, spec_truncate }, /* truncate */
201 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
202 1.1 mycroft { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
203 1.10 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
204 1.1 mycroft };
205 1.1 mycroft struct vnodeopv_desc lfs_specop_opv_desc =
206 1.1 mycroft { &lfs_specop_p, lfs_specop_entries };
207 1.1 mycroft
208 1.10 christos int (**lfs_fifoop_p) __P((void *));
209 1.1 mycroft struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
210 1.1 mycroft { &vop_default_desc, vn_default_error },
211 1.1 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
212 1.1 mycroft { &vop_create_desc, fifo_create }, /* create */
213 1.1 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
214 1.1 mycroft { &vop_open_desc, fifo_open }, /* open */
215 1.1 mycroft { &vop_close_desc, ufsfifo_close }, /* close */
216 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
217 1.1 mycroft { &vop_getattr_desc, lfs_getattr }, /* getattr */
218 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
219 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
220 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
221 1.4 mycroft { &vop_lease_desc, fifo_lease_check }, /* lease */
222 1.1 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
223 1.27 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
224 1.13 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
225 1.15 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
226 1.1 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
227 1.1 mycroft { &vop_fsync_desc, fifo_fsync }, /* fsync */
228 1.1 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
229 1.1 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
230 1.1 mycroft { &vop_link_desc, fifo_link }, /* link */
231 1.1 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
232 1.1 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
233 1.1 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
234 1.1 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
235 1.1 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
236 1.1 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
237 1.1 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
238 1.15 fvdl { &vop_inactive_desc, ufs_inactive }, /* inactive */
239 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
240 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
241 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
242 1.1 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
243 1.1 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
244 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
245 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
246 1.1 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
247 1.1 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
248 1.1 mycroft { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
249 1.1 mycroft { &vop_valloc_desc, fifo_valloc }, /* valloc */
250 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
251 1.1 mycroft { &vop_truncate_desc, fifo_truncate }, /* truncate */
252 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
253 1.1 mycroft { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
254 1.10 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
255 1.1 mycroft };
256 1.1 mycroft struct vnodeopv_desc lfs_fifoop_opv_desc =
257 1.1 mycroft { &lfs_fifoop_p, lfs_fifoop_entries };
258 1.1 mycroft
259 1.1 mycroft #define LFS_READWRITE
260 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
261 1.1 mycroft #undef LFS_READWRITE
262 1.1 mycroft
263 1.1 mycroft /*
264 1.1 mycroft * Synch an open file.
265 1.1 mycroft */
266 1.1 mycroft /* ARGSUSED */
267 1.10 christos int
268 1.10 christos lfs_fsync(v)
269 1.10 christos void *v;
270 1.10 christos {
271 1.1 mycroft struct vop_fsync_args /* {
272 1.1 mycroft struct vnode *a_vp;
273 1.1 mycroft struct ucred *a_cred;
274 1.22 perseant int a_flags;
275 1.1 mycroft struct proc *a_p;
276 1.10 christos } */ *ap = v;
277 1.22 perseant
278 1.21 mycroft return (VOP_UPDATE(ap->a_vp, NULL, NULL,
279 1.22 perseant (ap->a_flags & FSYNC_WAIT) != 0 ? LFS_SYNC : 0)); /* XXX */
280 1.1 mycroft }
281 1.1 mycroft
282 1.1 mycroft /*
283 1.1 mycroft * These macros are used to bracket UFS directory ops, so that we can
284 1.1 mycroft * identify all the pages touched during directory ops which need to
285 1.1 mycroft * be ordered and flushed atomically, so that they may be recovered.
286 1.1 mycroft */
287 1.22 perseant /*
288 1.22 perseant * XXX KS - Because we have to mark nodes VDIROP in order to prevent
289 1.22 perseant * the cache from reclaiming them while a dirop is in progress, we must
290 1.22 perseant * also manage the number of nodes so marked (otherwise we can run out).
291 1.22 perseant * We do this by setting lfs_dirvcount to the number of marked vnodes; it
292 1.22 perseant * is decremented during segment write, when VDIROP is taken off.
293 1.22 perseant */
294 1.24 perseant #define SET_DIROP(fs) lfs_set_dirop(fs)
295 1.24 perseant static int lfs_set_dirop __P((struct lfs *));
296 1.24 perseant
297 1.24 perseant static int lfs_set_dirop(fs)
298 1.24 perseant struct lfs *fs;
299 1.24 perseant {
300 1.24 perseant int error;
301 1.24 perseant
302 1.24 perseant while (fs->lfs_writer || fs->lfs_dirvcount>LFS_MAXDIROP) {
303 1.24 perseant if(fs->lfs_writer)
304 1.24 perseant tsleep(&fs->lfs_dirops, PRIBIO + 1, "lfs_dirop", 0);
305 1.24 perseant if(fs->lfs_dirvcount > LFS_MAXDIROP) {
306 1.24 perseant #ifdef DEBUG_LFS
307 1.24 perseant printf("(dirvcount=%d)\n",fs->lfs_dirvcount);
308 1.24 perseant #endif
309 1.24 perseant if((error=tsleep(&fs->lfs_dirvcount, PCATCH|PUSER, "lfs_maxdirop", 0))!=0)
310 1.24 perseant return error;
311 1.24 perseant }
312 1.24 perseant }
313 1.24 perseant ++fs->lfs_dirops;
314 1.24 perseant fs->lfs_doifile = 1;
315 1.24 perseant
316 1.24 perseant return 0;
317 1.1 mycroft }
318 1.1 mycroft
319 1.26 perseant #define SET_ENDOP(fs,vp,str) { \
320 1.1 mycroft --(fs)->lfs_dirops; \
321 1.22 perseant if (!(fs)->lfs_dirops) { \
322 1.1 mycroft wakeup(&(fs)->lfs_writer); \
323 1.26 perseant lfs_check((vp),LFS_UNUSED_LBN,0); \
324 1.22 perseant } \
325 1.1 mycroft }
326 1.1 mycroft
327 1.22 perseant #define MARK_VNODE(dvp) do { \
328 1.22 perseant if(!((dvp)->v_flag & VDIROP)) { \
329 1.22 perseant lfs_vref(dvp); \
330 1.22 perseant ++VTOI((dvp))->i_lfs->lfs_dirvcount; \
331 1.22 perseant } \
332 1.22 perseant (dvp)->v_flag |= VDIROP; \
333 1.22 perseant } while(0)
334 1.15 fvdl
335 1.24 perseant #define MAYBE_INACTIVE(fs,vp) do { \
336 1.24 perseant if((vp) && ((vp)->v_flag & VDIROP) && (vp)->v_usecount == 1 \
337 1.24 perseant && VTOI(vp) && VTOI(vp)->i_ffs_nlink == 0) \
338 1.24 perseant { \
339 1.24 perseant if (VOP_LOCK((vp), LK_EXCLUSIVE) == 0) { \
340 1.24 perseant VOP_INACTIVE((vp),curproc); \
341 1.24 perseant } \
342 1.24 perseant } \
343 1.24 perseant } while(0)
344 1.24 perseant
345 1.1 mycroft int
346 1.10 christos lfs_symlink(v)
347 1.10 christos void *v;
348 1.10 christos {
349 1.1 mycroft struct vop_symlink_args /* {
350 1.1 mycroft struct vnode *a_dvp;
351 1.1 mycroft struct vnode **a_vpp;
352 1.1 mycroft struct componentname *a_cnp;
353 1.1 mycroft struct vattr *a_vap;
354 1.1 mycroft char *a_target;
355 1.10 christos } */ *ap = v;
356 1.1 mycroft int ret;
357 1.1 mycroft
358 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
359 1.24 perseant return ret;
360 1.1 mycroft MARK_VNODE(ap->a_dvp);
361 1.1 mycroft ret = ufs_symlink(ap);
362 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,*(ap->a_vpp)); /* XXX KS */
363 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"symilnk");
364 1.1 mycroft return (ret);
365 1.1 mycroft }
366 1.1 mycroft
367 1.1 mycroft int
368 1.10 christos lfs_mknod(v)
369 1.10 christos void *v;
370 1.10 christos {
371 1.22 perseant struct vop_mknod_args /* {
372 1.1 mycroft struct vnode *a_dvp;
373 1.1 mycroft struct vnode **a_vpp;
374 1.1 mycroft struct componentname *a_cnp;
375 1.1 mycroft struct vattr *a_vap;
376 1.22 perseant } */ *ap = v;
377 1.1 mycroft int ret;
378 1.1 mycroft
379 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
380 1.24 perseant return ret;
381 1.1 mycroft MARK_VNODE(ap->a_dvp);
382 1.1 mycroft ret = ufs_mknod(ap);
383 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,*(ap->a_vpp)); /* XXX KS */
384 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mknod");
385 1.1 mycroft return (ret);
386 1.1 mycroft }
387 1.1 mycroft
388 1.1 mycroft int
389 1.10 christos lfs_create(v)
390 1.10 christos void *v;
391 1.10 christos {
392 1.22 perseant struct vop_create_args /* {
393 1.1 mycroft struct vnode *a_dvp;
394 1.1 mycroft struct vnode **a_vpp;
395 1.1 mycroft struct componentname *a_cnp;
396 1.1 mycroft struct vattr *a_vap;
397 1.10 christos } */ *ap = v;
398 1.1 mycroft int ret;
399 1.1 mycroft
400 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
401 1.24 perseant return ret;
402 1.1 mycroft MARK_VNODE(ap->a_dvp);
403 1.1 mycroft ret = ufs_create(ap);
404 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,*(ap->a_vpp)); /* XXX KS */
405 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"create");
406 1.1 mycroft return (ret);
407 1.1 mycroft }
408 1.1 mycroft
409 1.1 mycroft int
410 1.22 perseant lfs_whiteout(v)
411 1.22 perseant void *v;
412 1.22 perseant {
413 1.22 perseant struct vop_whiteout_args /* {
414 1.22 perseant struct vnode *a_dvp;
415 1.22 perseant struct componentname *a_cnp;
416 1.22 perseant int a_flags;
417 1.22 perseant } */ *ap = v;
418 1.22 perseant int ret;
419 1.22 perseant
420 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
421 1.24 perseant return ret;
422 1.22 perseant MARK_VNODE(ap->a_dvp);
423 1.22 perseant ret = ufs_whiteout(ap);
424 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"whiteout");
425 1.22 perseant return (ret);
426 1.22 perseant }
427 1.22 perseant
428 1.22 perseant int
429 1.10 christos lfs_mkdir(v)
430 1.10 christos void *v;
431 1.10 christos {
432 1.22 perseant struct vop_mkdir_args /* {
433 1.1 mycroft struct vnode *a_dvp;
434 1.1 mycroft struct vnode **a_vpp;
435 1.1 mycroft struct componentname *a_cnp;
436 1.1 mycroft struct vattr *a_vap;
437 1.10 christos } */ *ap = v;
438 1.1 mycroft int ret;
439 1.1 mycroft
440 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
441 1.24 perseant return ret;
442 1.1 mycroft MARK_VNODE(ap->a_dvp);
443 1.1 mycroft ret = ufs_mkdir(ap);
444 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,*(ap->a_vpp)); /* XXX KS */
445 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mkdir");
446 1.1 mycroft return (ret);
447 1.1 mycroft }
448 1.1 mycroft
449 1.1 mycroft int
450 1.10 christos lfs_remove(v)
451 1.10 christos void *v;
452 1.10 christos {
453 1.22 perseant struct vop_remove_args /* {
454 1.1 mycroft struct vnode *a_dvp;
455 1.1 mycroft struct vnode *a_vp;
456 1.1 mycroft struct componentname *a_cnp;
457 1.10 christos } */ *ap = v;
458 1.1 mycroft int ret;
459 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
460 1.24 perseant return ret;
461 1.1 mycroft MARK_VNODE(ap->a_dvp);
462 1.1 mycroft MARK_VNODE(ap->a_vp);
463 1.1 mycroft ret = ufs_remove(ap);
464 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,ap->a_vp);
465 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"remove");
466 1.1 mycroft return (ret);
467 1.1 mycroft }
468 1.1 mycroft
469 1.1 mycroft int
470 1.10 christos lfs_rmdir(v)
471 1.10 christos void *v;
472 1.10 christos {
473 1.22 perseant struct vop_rmdir_args /* {
474 1.1 mycroft struct vnodeop_desc *a_desc;
475 1.1 mycroft struct vnode *a_dvp;
476 1.1 mycroft struct vnode *a_vp;
477 1.1 mycroft struct componentname *a_cnp;
478 1.10 christos } */ *ap = v;
479 1.1 mycroft int ret;
480 1.1 mycroft
481 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
482 1.24 perseant return ret;
483 1.1 mycroft MARK_VNODE(ap->a_dvp);
484 1.1 mycroft MARK_VNODE(ap->a_vp);
485 1.1 mycroft ret = ufs_rmdir(ap);
486 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,ap->a_vp);
487 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"rmdir");
488 1.1 mycroft return (ret);
489 1.1 mycroft }
490 1.1 mycroft
491 1.1 mycroft int
492 1.10 christos lfs_link(v)
493 1.10 christos void *v;
494 1.10 christos {
495 1.22 perseant struct vop_link_args /* {
496 1.9 mycroft struct vnode *a_dvp;
497 1.1 mycroft struct vnode *a_vp;
498 1.1 mycroft struct componentname *a_cnp;
499 1.10 christos } */ *ap = v;
500 1.1 mycroft int ret;
501 1.1 mycroft
502 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_dvp)->i_lfs))!=0)
503 1.24 perseant return ret;
504 1.9 mycroft MARK_VNODE(ap->a_dvp);
505 1.1 mycroft ret = ufs_link(ap);
506 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"link");
507 1.1 mycroft return (ret);
508 1.1 mycroft }
509 1.22 perseant
510 1.1 mycroft int
511 1.10 christos lfs_rename(v)
512 1.10 christos void *v;
513 1.10 christos {
514 1.22 perseant struct vop_rename_args /* {
515 1.1 mycroft struct vnode *a_fdvp;
516 1.1 mycroft struct vnode *a_fvp;
517 1.1 mycroft struct componentname *a_fcnp;
518 1.1 mycroft struct vnode *a_tdvp;
519 1.1 mycroft struct vnode *a_tvp;
520 1.1 mycroft struct componentname *a_tcnp;
521 1.10 christos } */ *ap = v;
522 1.1 mycroft int ret;
523 1.22 perseant
524 1.24 perseant if((ret=SET_DIROP(VTOI(ap->a_fdvp)->i_lfs))!=0)
525 1.24 perseant return ret;
526 1.1 mycroft MARK_VNODE(ap->a_fdvp);
527 1.1 mycroft MARK_VNODE(ap->a_tdvp);
528 1.1 mycroft ret = ufs_rename(ap);
529 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,ap->a_fvp);
530 1.24 perseant MAYBE_INACTIVE(VTOI(ap->a_dvp)->i_lfs,ap->a_tvp);
531 1.26 perseant SET_ENDOP(VTOI(ap->a_fdvp)->i_lfs,ap->a_fdvp,"rename");
532 1.1 mycroft return (ret);
533 1.1 mycroft }
534 1.22 perseant
535 1.1 mycroft /* XXX hack to avoid calling ITIMES in getattr */
536 1.1 mycroft int
537 1.10 christos lfs_getattr(v)
538 1.10 christos void *v;
539 1.10 christos {
540 1.1 mycroft struct vop_getattr_args /* {
541 1.1 mycroft struct vnode *a_vp;
542 1.1 mycroft struct vattr *a_vap;
543 1.1 mycroft struct ucred *a_cred;
544 1.1 mycroft struct proc *a_p;
545 1.10 christos } */ *ap = v;
546 1.1 mycroft register struct vnode *vp = ap->a_vp;
547 1.1 mycroft register struct inode *ip = VTOI(vp);
548 1.1 mycroft register struct vattr *vap = ap->a_vap;
549 1.1 mycroft /*
550 1.1 mycroft * Copy from inode table
551 1.1 mycroft */
552 1.1 mycroft vap->va_fsid = ip->i_dev;
553 1.1 mycroft vap->va_fileid = ip->i_number;
554 1.14 bouyer vap->va_mode = ip->i_ffs_mode & ~IFMT;
555 1.14 bouyer vap->va_nlink = ip->i_ffs_nlink;
556 1.14 bouyer vap->va_uid = ip->i_ffs_uid;
557 1.14 bouyer vap->va_gid = ip->i_ffs_gid;
558 1.14 bouyer vap->va_rdev = (dev_t)ip->i_ffs_rdev;
559 1.14 bouyer vap->va_size = ip->i_ffs_size;
560 1.14 bouyer vap->va_atime.tv_sec = ip->i_ffs_atime;
561 1.14 bouyer vap->va_atime.tv_nsec = ip->i_ffs_atimensec;
562 1.14 bouyer vap->va_mtime.tv_sec = ip->i_ffs_mtime;
563 1.14 bouyer vap->va_mtime.tv_nsec = ip->i_ffs_mtimensec;
564 1.14 bouyer vap->va_ctime.tv_sec = ip->i_ffs_ctime;
565 1.14 bouyer vap->va_ctime.tv_nsec = ip->i_ffs_ctimensec;
566 1.14 bouyer vap->va_flags = ip->i_ffs_flags;
567 1.14 bouyer vap->va_gen = ip->i_ffs_gen;
568 1.1 mycroft /* this doesn't belong here */
569 1.1 mycroft if (vp->v_type == VBLK)
570 1.1 mycroft vap->va_blocksize = BLKDEV_IOSIZE;
571 1.1 mycroft else if (vp->v_type == VCHR)
572 1.1 mycroft vap->va_blocksize = MAXBSIZE;
573 1.1 mycroft else
574 1.1 mycroft vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
575 1.20 cgd vap->va_bytes = dbtob((u_quad_t)ip->i_ffs_blocks);
576 1.1 mycroft vap->va_type = vp->v_type;
577 1.1 mycroft vap->va_filerev = ip->i_modrev;
578 1.1 mycroft return (0);
579 1.1 mycroft }
580 1.22 perseant
581 1.1 mycroft /*
582 1.1 mycroft * Close called
583 1.1 mycroft *
584 1.1 mycroft * XXX -- we were using ufs_close, but since it updates the
585 1.1 mycroft * times on the inode, we might need to bump the uinodes
586 1.1 mycroft * count.
587 1.1 mycroft */
588 1.1 mycroft /* ARGSUSED */
589 1.1 mycroft int
590 1.10 christos lfs_close(v)
591 1.10 christos void *v;
592 1.10 christos {
593 1.1 mycroft struct vop_close_args /* {
594 1.1 mycroft struct vnode *a_vp;
595 1.1 mycroft int a_fflag;
596 1.1 mycroft struct ucred *a_cred;
597 1.1 mycroft struct proc *a_p;
598 1.10 christos } */ *ap = v;
599 1.1 mycroft register struct vnode *vp = ap->a_vp;
600 1.1 mycroft register struct inode *ip = VTOI(vp);
601 1.1 mycroft int mod;
602 1.12 mycroft struct timespec ts;
603 1.1 mycroft
604 1.15 fvdl simple_lock(&vp->v_interlock);
605 1.15 fvdl if (vp->v_usecount > 1) {
606 1.1 mycroft mod = ip->i_flag & IN_MODIFIED;
607 1.12 mycroft TIMEVAL_TO_TIMESPEC(&time, &ts);
608 1.22 perseant LFS_ITIMES(ip, &ts, &ts, &ts);
609 1.1 mycroft if (!mod && ip->i_flag & IN_MODIFIED)
610 1.1 mycroft ip->i_lfs->lfs_uinodes++;
611 1.1 mycroft }
612 1.15 fvdl simple_unlock(&vp->v_interlock);
613 1.1 mycroft return (0);
614 1.1 mycroft }
615 1.1 mycroft
616 1.1 mycroft /*
617 1.15 fvdl * Reclaim an inode so that it can be used for other purposes.
618 1.1 mycroft */
619 1.1 mycroft int lfs_no_inactive = 0;
620 1.1 mycroft
621 1.1 mycroft int
622 1.10 christos lfs_reclaim(v)
623 1.10 christos void *v;
624 1.10 christos {
625 1.1 mycroft struct vop_reclaim_args /* {
626 1.1 mycroft struct vnode *a_vp;
627 1.15 fvdl struct proc *a_p;
628 1.10 christos } */ *ap = v;
629 1.15 fvdl struct vnode *vp = ap->a_vp;
630 1.1 mycroft int error;
631 1.1 mycroft
632 1.15 fvdl if ((error = ufs_reclaim(vp, ap->a_p)))
633 1.1 mycroft return (error);
634 1.19 thorpej pool_put(&lfs_inode_pool, vp->v_data);
635 1.1 mycroft vp->v_data = NULL;
636 1.1 mycroft return (0);
637 1.1 mycroft }
638