lfs_vnops.c revision 1.50.6.8 1 1.50.6.8 jdolecek /* $NetBSD: lfs_vnops.c,v 1.50.6.8 2002/09/26 20:40:09 jdolecek Exp $ */
2 1.2 cgd
3 1.22 perseant /*-
4 1.44 perseant * Copyright (c) 1999, 2000 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.50.6.3 thorpej #include <sys/cdefs.h>
74 1.50.6.8 jdolecek __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.50.6.8 2002/09/26 20:40:09 jdolecek Exp $");
75 1.50.6.3 thorpej
76 1.1 mycroft #include <sys/param.h>
77 1.1 mycroft #include <sys/systm.h>
78 1.1 mycroft #include <sys/namei.h>
79 1.1 mycroft #include <sys/resourcevar.h>
80 1.1 mycroft #include <sys/kernel.h>
81 1.1 mycroft #include <sys/file.h>
82 1.1 mycroft #include <sys/stat.h>
83 1.1 mycroft #include <sys/buf.h>
84 1.1 mycroft #include <sys/proc.h>
85 1.1 mycroft #include <sys/conf.h>
86 1.1 mycroft #include <sys/mount.h>
87 1.1 mycroft #include <sys/vnode.h>
88 1.1 mycroft #include <sys/malloc.h>
89 1.19 thorpej #include <sys/pool.h>
90 1.10 christos #include <sys/signalvar.h>
91 1.1 mycroft
92 1.12 mycroft #include <miscfs/fifofs/fifo.h>
93 1.12 mycroft #include <miscfs/genfs/genfs.h>
94 1.1 mycroft #include <miscfs/specfs/specdev.h>
95 1.1 mycroft
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.50.6.1 lukem int (**lfs_vnodeop_p)(void *);
106 1.50 jdolecek const 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.50.6.4 jdolecek { &vop_setattr_desc, lfs_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.50.6.8 jdolecek { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
124 1.15 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
125 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
126 1.1 mycroft { &vop_fsync_desc, lfs_fsync }, /* fsync */
127 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
128 1.22 perseant { &vop_remove_desc, lfs_remove }, /* remove */
129 1.22 perseant { &vop_link_desc, lfs_link }, /* link */
130 1.22 perseant { &vop_rename_desc, lfs_rename }, /* rename */
131 1.22 perseant { &vop_mkdir_desc, lfs_mkdir }, /* mkdir */
132 1.22 perseant { &vop_rmdir_desc, lfs_rmdir }, /* rmdir */
133 1.22 perseant { &vop_symlink_desc, lfs_symlink }, /* symlink */
134 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
135 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
136 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
137 1.40 perseant { &vop_inactive_desc, lfs_inactive }, /* inactive */
138 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
139 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
140 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
141 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
142 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
143 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
144 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
145 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
146 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
147 1.1 mycroft { &vop_blkatoff_desc, lfs_blkatoff }, /* blkatoff */
148 1.1 mycroft { &vop_valloc_desc, lfs_valloc }, /* valloc */
149 1.32 fvdl { &vop_balloc_desc, lfs_balloc }, /* balloc */
150 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
151 1.1 mycroft { &vop_truncate_desc, lfs_truncate }, /* truncate */
152 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
153 1.1 mycroft { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
154 1.50.6.3 thorpej { &vop_getpages_desc, lfs_getpages }, /* getpages */
155 1.50.6.3 thorpej { &vop_putpages_desc, lfs_putpages }, /* putpages */
156 1.50.6.2 thorpej { NULL, NULL }
157 1.1 mycroft };
158 1.50 jdolecek const struct vnodeopv_desc lfs_vnodeop_opv_desc =
159 1.1 mycroft { &lfs_vnodeop_p, lfs_vnodeop_entries };
160 1.1 mycroft
161 1.50.6.1 lukem int (**lfs_specop_p)(void *);
162 1.50 jdolecek const struct vnodeopv_entry_desc lfs_specop_entries[] = {
163 1.1 mycroft { &vop_default_desc, vn_default_error },
164 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
165 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
166 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
167 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
168 1.50.6.5 jdolecek { &vop_close_desc, lfsspec_close }, /* close */
169 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
170 1.1 mycroft { &vop_getattr_desc, lfs_getattr }, /* getattr */
171 1.50.6.4 jdolecek { &vop_setattr_desc, lfs_setattr }, /* setattr */
172 1.1 mycroft { &vop_read_desc, ufsspec_read }, /* read */
173 1.1 mycroft { &vop_write_desc, ufsspec_write }, /* write */
174 1.4 mycroft { &vop_lease_desc, spec_lease_check }, /* lease */
175 1.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
176 1.27 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
177 1.13 mycroft { &vop_poll_desc, spec_poll }, /* poll */
178 1.50.6.7 jdolecek { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
179 1.15 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
180 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
181 1.1 mycroft { &vop_fsync_desc, spec_fsync }, /* fsync */
182 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
183 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
184 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
185 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
186 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
187 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
188 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
189 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
190 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
191 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
192 1.40 perseant { &vop_inactive_desc, lfs_inactive }, /* inactive */
193 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
194 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
195 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
196 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
197 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
198 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
199 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
200 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
201 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
202 1.1 mycroft { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
203 1.1 mycroft { &vop_valloc_desc, spec_valloc }, /* valloc */
204 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
205 1.1 mycroft { &vop_truncate_desc, spec_truncate }, /* truncate */
206 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
207 1.28 perseant { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
208 1.50.6.2 thorpej { &vop_getpages_desc, spec_getpages }, /* getpages */
209 1.50.6.2 thorpej { &vop_putpages_desc, spec_putpages }, /* putpages */
210 1.50.6.2 thorpej { NULL, NULL }
211 1.1 mycroft };
212 1.50 jdolecek const struct vnodeopv_desc lfs_specop_opv_desc =
213 1.1 mycroft { &lfs_specop_p, lfs_specop_entries };
214 1.1 mycroft
215 1.50.6.1 lukem int (**lfs_fifoop_p)(void *);
216 1.50 jdolecek const struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
217 1.1 mycroft { &vop_default_desc, vn_default_error },
218 1.1 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
219 1.1 mycroft { &vop_create_desc, fifo_create }, /* create */
220 1.1 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
221 1.1 mycroft { &vop_open_desc, fifo_open }, /* open */
222 1.50.6.5 jdolecek { &vop_close_desc, lfsfifo_close }, /* close */
223 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
224 1.1 mycroft { &vop_getattr_desc, lfs_getattr }, /* getattr */
225 1.50.6.4 jdolecek { &vop_setattr_desc, lfs_setattr }, /* setattr */
226 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
227 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
228 1.4 mycroft { &vop_lease_desc, fifo_lease_check }, /* lease */
229 1.1 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
230 1.27 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
231 1.13 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
232 1.50.6.6 jdolecek { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */
233 1.15 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
234 1.1 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
235 1.1 mycroft { &vop_fsync_desc, fifo_fsync }, /* fsync */
236 1.1 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
237 1.1 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
238 1.1 mycroft { &vop_link_desc, fifo_link }, /* link */
239 1.1 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
240 1.1 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
241 1.1 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
242 1.1 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
243 1.1 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
244 1.1 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
245 1.1 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
246 1.40 perseant { &vop_inactive_desc, lfs_inactive }, /* inactive */
247 1.1 mycroft { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
248 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
249 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
250 1.1 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
251 1.1 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
252 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
253 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
254 1.1 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
255 1.1 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
256 1.1 mycroft { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
257 1.1 mycroft { &vop_valloc_desc, fifo_valloc }, /* valloc */
258 1.1 mycroft { &vop_vfree_desc, lfs_vfree }, /* vfree */
259 1.1 mycroft { &vop_truncate_desc, fifo_truncate }, /* truncate */
260 1.1 mycroft { &vop_update_desc, lfs_update }, /* update */
261 1.1 mycroft { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
262 1.50.6.3 thorpej { &vop_putpages_desc, fifo_putpages }, /* putpages */
263 1.50.6.2 thorpej { NULL, NULL }
264 1.1 mycroft };
265 1.50 jdolecek const struct vnodeopv_desc lfs_fifoop_opv_desc =
266 1.1 mycroft { &lfs_fifoop_p, lfs_fifoop_entries };
267 1.1 mycroft
268 1.43 perseant /*
269 1.43 perseant * A function version of LFS_ITIMES, for the UFS functions which call ITIMES
270 1.43 perseant */
271 1.43 perseant void
272 1.50.6.1 lukem lfs_itimes(struct inode *ip, struct timespec *acc, struct timespec *mod, struct timespec *cre)
273 1.43 perseant {
274 1.43 perseant LFS_ITIMES(ip, acc, mod, cre);
275 1.43 perseant }
276 1.43 perseant
277 1.1 mycroft #define LFS_READWRITE
278 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
279 1.1 mycroft #undef LFS_READWRITE
280 1.1 mycroft
281 1.1 mycroft /*
282 1.1 mycroft * Synch an open file.
283 1.1 mycroft */
284 1.1 mycroft /* ARGSUSED */
285 1.10 christos int
286 1.50.6.1 lukem lfs_fsync(void *v)
287 1.10 christos {
288 1.1 mycroft struct vop_fsync_args /* {
289 1.1 mycroft struct vnode *a_vp;
290 1.1 mycroft struct ucred *a_cred;
291 1.22 perseant int a_flags;
292 1.49 toshii off_t offlo;
293 1.49 toshii off_t offhi;
294 1.1 mycroft struct proc *a_p;
295 1.10 christos } */ *ap = v;
296 1.50.6.3 thorpej struct vnode *vp = ap->a_vp;
297 1.50.6.3 thorpej int error;
298 1.22 perseant
299 1.47 perseant /* Ignore the trickle syncer */
300 1.47 perseant if (ap->a_flags & FSYNC_LAZY)
301 1.47 perseant return 0;
302 1.47 perseant
303 1.50.6.3 thorpej simple_lock(&vp->v_interlock);
304 1.50.6.5 jdolecek error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
305 1.50.6.5 jdolecek round_page(ap->a_offhi), PGO_CLEANIT | PGO_SYNCIO);
306 1.50.6.5 jdolecek if (error)
307 1.50.6.3 thorpej return error;
308 1.50.6.5 jdolecek error = VOP_UPDATE(vp, NULL, NULL,
309 1.50.6.5 jdolecek (ap->a_flags & FSYNC_WAIT) != 0 ? UPDATE_WAIT : 0);
310 1.50.6.5 jdolecek #ifdef DEBUG
311 1.50.6.5 jdolecek /*
312 1.50.6.5 jdolecek * If we were called from vinvalbuf and lfs_update
313 1.50.6.5 jdolecek * didn't flush all our buffers, we're in trouble.
314 1.50.6.5 jdolecek */
315 1.50.6.5 jdolecek if ((ap->a_flags & FSYNC_WAIT) && LIST_FIRST(&vp->v_dirtyblkhd) != NULL) {
316 1.50.6.5 jdolecek struct buf *bp;
317 1.50.6.5 jdolecek
318 1.50.6.5 jdolecek bp = LIST_FIRST(&vp->v_dirtyblkhd);
319 1.50.6.5 jdolecek printf("lfs_fsync: ino %d failed to sync", VTOI(vp)->i_number);
320 1.50.6.5 jdolecek printf("lfs_fsync: iocount = %d\n", VTOI(vp)->i_lfs->lfs_iocount);
321 1.50.6.5 jdolecek printf("lfs_fsync: flags are 0x%x, numoutput=%d\n",
322 1.50.6.5 jdolecek VTOI(vp)->i_flag, vp->v_numoutput);
323 1.50.6.5 jdolecek printf("lfs_fsync: writecount=%ld\n", vp->v_writecount);
324 1.50.6.5 jdolecek printf("lfs_fsync: first bp: %p, flags=0x%lx, lbn=%d\n",
325 1.50.6.5 jdolecek bp, bp->b_flags, bp->b_lblkno);
326 1.50.6.3 thorpej }
327 1.50.6.5 jdolecek #endif
328 1.50.6.5 jdolecek return error;
329 1.1 mycroft }
330 1.1 mycroft
331 1.1 mycroft /*
332 1.40 perseant * Take IN_ADIROP off, then call ufs_inactive.
333 1.40 perseant */
334 1.40 perseant int
335 1.50.6.1 lukem lfs_inactive(void *v)
336 1.40 perseant {
337 1.40 perseant struct vop_inactive_args /* {
338 1.40 perseant struct vnode *a_vp;
339 1.40 perseant struct proc *a_p;
340 1.40 perseant } */ *ap = v;
341 1.40 perseant struct inode *ip = VTOI(ap->a_vp);
342 1.40 perseant
343 1.40 perseant if (ip->i_flag & IN_ADIROP)
344 1.40 perseant --ip->i_lfs->lfs_nadirop;
345 1.40 perseant ip->i_flag &= ~IN_ADIROP;
346 1.40 perseant return ufs_inactive(v);
347 1.40 perseant }
348 1.40 perseant
349 1.40 perseant /*
350 1.1 mycroft * These macros are used to bracket UFS directory ops, so that we can
351 1.1 mycroft * identify all the pages touched during directory ops which need to
352 1.1 mycroft * be ordered and flushed atomically, so that they may be recovered.
353 1.1 mycroft */
354 1.22 perseant /*
355 1.22 perseant * XXX KS - Because we have to mark nodes VDIROP in order to prevent
356 1.22 perseant * the cache from reclaiming them while a dirop is in progress, we must
357 1.22 perseant * also manage the number of nodes so marked (otherwise we can run out).
358 1.22 perseant * We do this by setting lfs_dirvcount to the number of marked vnodes; it
359 1.22 perseant * is decremented during segment write, when VDIROP is taken off.
360 1.22 perseant */
361 1.40 perseant #define SET_DIROP(vp) lfs_set_dirop(vp)
362 1.50.6.1 lukem static int lfs_set_dirop(struct vnode *);
363 1.31 perseant extern int lfs_dirvcount;
364 1.24 perseant
365 1.46 perseant static int
366 1.50.6.1 lukem lfs_set_dirop(struct vnode *vp)
367 1.40 perseant {
368 1.24 perseant struct lfs *fs;
369 1.24 perseant int error;
370 1.24 perseant
371 1.40 perseant fs = VTOI(vp)->i_lfs;
372 1.44 perseant /*
373 1.44 perseant * We might need one directory block plus supporting indirect blocks,
374 1.44 perseant * plus an inode block and ifile page for the new vnode.
375 1.44 perseant */
376 1.50.6.1 lukem if ((error = lfs_reserve(fs, vp, btofsb(fs, (NIADDR + 3) << fs->lfs_bshift))) != 0)
377 1.44 perseant return (error);
378 1.40 perseant if (fs->lfs_dirops == 0)
379 1.40 perseant lfs_check(vp, LFS_UNUSED_LBN, 0);
380 1.40 perseant while (fs->lfs_writer || lfs_dirvcount > LFS_MAXDIROP) {
381 1.50.6.3 thorpej if (fs->lfs_writer)
382 1.50.6.5 jdolecek tsleep(&fs->lfs_dirops, PRIBIO + 1, "lfs_sdirop", 0);
383 1.50.6.3 thorpej if (lfs_dirvcount > LFS_MAXDIROP && fs->lfs_dirops == 0) {
384 1.33 perseant ++fs->lfs_writer;
385 1.33 perseant lfs_flush(fs, 0);
386 1.50.6.3 thorpej if (--fs->lfs_writer == 0)
387 1.33 perseant wakeup(&fs->lfs_dirops);
388 1.33 perseant }
389 1.33 perseant
390 1.50.6.3 thorpej if (lfs_dirvcount > LFS_MAXDIROP) {
391 1.24 perseant #ifdef DEBUG_LFS
392 1.44 perseant printf("lfs_set_dirop: sleeping with dirops=%d, "
393 1.44 perseant "dirvcount=%d\n", fs->lfs_dirops,
394 1.44 perseant lfs_dirvcount);
395 1.24 perseant #endif
396 1.50.6.3 thorpej if ((error = tsleep(&lfs_dirvcount, PCATCH|PUSER,
397 1.50.6.3 thorpej "lfs_maxdirop", 0)) != 0) {
398 1.50.6.1 lukem lfs_reserve(fs, vp, -btofsb(fs, (NIADDR + 3) << fs->lfs_bshift));
399 1.24 perseant return error;
400 1.44 perseant }
401 1.24 perseant }
402 1.24 perseant }
403 1.24 perseant ++fs->lfs_dirops;
404 1.24 perseant fs->lfs_doifile = 1;
405 1.24 perseant
406 1.46 perseant /* Hold a reference so SET_ENDOP will be happy */
407 1.46 perseant lfs_vref(vp);
408 1.46 perseant
409 1.24 perseant return 0;
410 1.1 mycroft }
411 1.1 mycroft
412 1.26 perseant #define SET_ENDOP(fs,vp,str) { \
413 1.1 mycroft --(fs)->lfs_dirops; \
414 1.22 perseant if (!(fs)->lfs_dirops) { \
415 1.40 perseant if ((fs)->lfs_nadirop) { \
416 1.40 perseant panic("SET_ENDOP: %s: no dirops but nadirop=%d\n", \
417 1.40 perseant (str), (fs)->lfs_nadirop); \
418 1.40 perseant } \
419 1.1 mycroft wakeup(&(fs)->lfs_writer); \
420 1.26 perseant lfs_check((vp),LFS_UNUSED_LBN,0); \
421 1.22 perseant } \
422 1.50.6.1 lukem lfs_reserve((fs), vp, -btofsb((fs), (NIADDR + 3) << (fs)->lfs_bshift)); /* XXX */ \
423 1.46 perseant lfs_vunref(vp); \
424 1.1 mycroft }
425 1.1 mycroft
426 1.22 perseant #define MARK_VNODE(dvp) do { \
427 1.37 perseant if (!((dvp)->v_flag & VDIROP)) { \
428 1.39 perseant (void)lfs_vref(dvp); \
429 1.31 perseant ++lfs_dirvcount; \
430 1.22 perseant } \
431 1.22 perseant (dvp)->v_flag |= VDIROP; \
432 1.37 perseant if (!(VTOI(dvp)->i_flag & IN_ADIROP)) { \
433 1.37 perseant ++VTOI(dvp)->i_lfs->lfs_nadirop; \
434 1.37 perseant } \
435 1.37 perseant VTOI(dvp)->i_flag |= IN_ADIROP; \
436 1.50.6.3 thorpej } while (0)
437 1.37 perseant
438 1.40 perseant #define UNMARK_VNODE(vp) lfs_unmark_vnode(vp)
439 1.40 perseant
440 1.50.6.1 lukem void lfs_unmark_vnode(struct vnode *vp)
441 1.40 perseant {
442 1.40 perseant struct inode *ip;
443 1.40 perseant
444 1.40 perseant ip = VTOI(vp);
445 1.40 perseant
446 1.40 perseant if (ip->i_flag & IN_ADIROP)
447 1.40 perseant --ip->i_lfs->lfs_nadirop;
448 1.40 perseant ip->i_flag &= ~IN_ADIROP;
449 1.40 perseant }
450 1.15 fvdl
451 1.1 mycroft int
452 1.50.6.1 lukem lfs_symlink(void *v)
453 1.10 christos {
454 1.1 mycroft struct vop_symlink_args /* {
455 1.1 mycroft struct vnode *a_dvp;
456 1.1 mycroft struct vnode **a_vpp;
457 1.1 mycroft struct componentname *a_cnp;
458 1.1 mycroft struct vattr *a_vap;
459 1.1 mycroft char *a_target;
460 1.10 christos } */ *ap = v;
461 1.37 perseant int error;
462 1.1 mycroft
463 1.40 perseant if ((error = SET_DIROP(ap->a_dvp)) != 0) {
464 1.34 perseant vput(ap->a_dvp);
465 1.37 perseant return error;
466 1.34 perseant }
467 1.1 mycroft MARK_VNODE(ap->a_dvp);
468 1.37 perseant error = ufs_symlink(ap);
469 1.37 perseant UNMARK_VNODE(ap->a_dvp);
470 1.40 perseant if (*(ap->a_vpp))
471 1.37 perseant UNMARK_VNODE(*(ap->a_vpp));
472 1.37 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"symlink");
473 1.37 perseant return (error);
474 1.1 mycroft }
475 1.1 mycroft
476 1.1 mycroft int
477 1.50.6.1 lukem lfs_mknod(void *v)
478 1.10 christos {
479 1.22 perseant struct vop_mknod_args /* {
480 1.1 mycroft struct vnode *a_dvp;
481 1.1 mycroft struct vnode **a_vpp;
482 1.1 mycroft struct componentname *a_cnp;
483 1.1 mycroft struct vattr *a_vap;
484 1.22 perseant } */ *ap = v;
485 1.28 perseant struct vattr *vap = ap->a_vap;
486 1.28 perseant struct vnode **vpp = ap->a_vpp;
487 1.28 perseant struct inode *ip;
488 1.28 perseant int error;
489 1.50.6.1 lukem struct mount *mp;
490 1.50.6.1 lukem ino_t ino;
491 1.1 mycroft
492 1.40 perseant if ((error = SET_DIROP(ap->a_dvp)) != 0) {
493 1.34 perseant vput(ap->a_dvp);
494 1.28 perseant return error;
495 1.34 perseant }
496 1.1 mycroft MARK_VNODE(ap->a_dvp);
497 1.28 perseant error = ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
498 1.28 perseant ap->a_dvp, vpp, ap->a_cnp);
499 1.37 perseant UNMARK_VNODE(ap->a_dvp);
500 1.40 perseant if (*(ap->a_vpp))
501 1.37 perseant UNMARK_VNODE(*(ap->a_vpp));
502 1.28 perseant
503 1.28 perseant /* Either way we're done with the dirop at this point */
504 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mknod");
505 1.28 perseant
506 1.28 perseant if (error)
507 1.28 perseant return (error);
508 1.28 perseant
509 1.28 perseant ip = VTOI(*vpp);
510 1.50.6.1 lukem mp = (*vpp)->v_mount;
511 1.50.6.1 lukem ino = ip->i_number;
512 1.28 perseant ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
513 1.28 perseant if (vap->va_rdev != VNOVAL) {
514 1.28 perseant /*
515 1.28 perseant * Want to be able to use this to make badblock
516 1.28 perseant * inodes, so don't truncate the dev number.
517 1.28 perseant */
518 1.28 perseant #if 0
519 1.28 perseant ip->i_ffs_rdev = ufs_rw32(vap->va_rdev,
520 1.28 perseant UFS_MPNEEDSWAP((*vpp)->v_mount));
521 1.28 perseant #else
522 1.28 perseant ip->i_ffs_rdev = vap->va_rdev;
523 1.28 perseant #endif
524 1.28 perseant }
525 1.28 perseant /*
526 1.28 perseant * Call fsync to write the vnode so that we don't have to deal with
527 1.28 perseant * flushing it when it's marked VDIROP|VXLOCK.
528 1.28 perseant *
529 1.28 perseant * XXX KS - If we can't flush we also can't call vgone(), so must
530 1.28 perseant * return. But, that leaves this vnode in limbo, also not good.
531 1.28 perseant * Can this ever happen (barring hardware failure)?
532 1.28 perseant */
533 1.49 toshii if ((error = VOP_FSYNC(*vpp, NOCRED, FSYNC_WAIT, 0, 0, curproc)) != 0) {
534 1.40 perseant printf("Couldn't fsync in mknod (ino %d)---what do I do?\n",
535 1.40 perseant VTOI(*vpp)->i_number);
536 1.28 perseant return (error);
537 1.40 perseant }
538 1.28 perseant /*
539 1.40 perseant * Remove vnode so that it will be reloaded by VFS_VGET and
540 1.28 perseant * checked to see if it is an alias of an existing entry in
541 1.28 perseant * the inode cache.
542 1.28 perseant */
543 1.28 perseant /* Used to be vput, but that causes us to call VOP_INACTIVE twice. */
544 1.40 perseant VOP_UNLOCK(*vpp, 0);
545 1.28 perseant lfs_vunref(*vpp);
546 1.28 perseant (*vpp)->v_type = VNON;
547 1.28 perseant vgone(*vpp);
548 1.50.6.1 lukem error = VFS_VGET(mp, ino, vpp);
549 1.50.6.1 lukem if (error != 0) {
550 1.50.6.1 lukem *vpp = NULL;
551 1.50.6.1 lukem return (error);
552 1.50.6.1 lukem }
553 1.28 perseant return (0);
554 1.1 mycroft }
555 1.1 mycroft
556 1.1 mycroft int
557 1.50.6.1 lukem lfs_create(void *v)
558 1.10 christos {
559 1.22 perseant struct vop_create_args /* {
560 1.1 mycroft struct vnode *a_dvp;
561 1.1 mycroft struct vnode **a_vpp;
562 1.1 mycroft struct componentname *a_cnp;
563 1.1 mycroft struct vattr *a_vap;
564 1.10 christos } */ *ap = v;
565 1.37 perseant int error;
566 1.1 mycroft
567 1.50.6.3 thorpej if ((error = SET_DIROP(ap->a_dvp)) != 0) {
568 1.34 perseant vput(ap->a_dvp);
569 1.37 perseant return error;
570 1.34 perseant }
571 1.1 mycroft MARK_VNODE(ap->a_dvp);
572 1.37 perseant error = ufs_create(ap);
573 1.37 perseant UNMARK_VNODE(ap->a_dvp);
574 1.40 perseant if (*(ap->a_vpp))
575 1.37 perseant UNMARK_VNODE(*(ap->a_vpp));
576 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"create");
577 1.37 perseant return (error);
578 1.1 mycroft }
579 1.1 mycroft
580 1.1 mycroft int
581 1.50.6.1 lukem lfs_whiteout(void *v)
582 1.22 perseant {
583 1.22 perseant struct vop_whiteout_args /* {
584 1.22 perseant struct vnode *a_dvp;
585 1.22 perseant struct componentname *a_cnp;
586 1.22 perseant int a_flags;
587 1.22 perseant } */ *ap = v;
588 1.37 perseant int error;
589 1.22 perseant
590 1.40 perseant if ((error = SET_DIROP(ap->a_dvp)) != 0)
591 1.34 perseant /* XXX no unlock here? */
592 1.37 perseant return error;
593 1.22 perseant MARK_VNODE(ap->a_dvp);
594 1.37 perseant error = ufs_whiteout(ap);
595 1.37 perseant UNMARK_VNODE(ap->a_dvp);
596 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"whiteout");
597 1.37 perseant return (error);
598 1.22 perseant }
599 1.22 perseant
600 1.22 perseant int
601 1.50.6.1 lukem lfs_mkdir(void *v)
602 1.10 christos {
603 1.22 perseant struct vop_mkdir_args /* {
604 1.1 mycroft struct vnode *a_dvp;
605 1.1 mycroft struct vnode **a_vpp;
606 1.1 mycroft struct componentname *a_cnp;
607 1.1 mycroft struct vattr *a_vap;
608 1.10 christos } */ *ap = v;
609 1.37 perseant int error;
610 1.1 mycroft
611 1.50.6.3 thorpej if ((error = SET_DIROP(ap->a_dvp)) != 0) {
612 1.34 perseant vput(ap->a_dvp);
613 1.37 perseant return error;
614 1.34 perseant }
615 1.1 mycroft MARK_VNODE(ap->a_dvp);
616 1.37 perseant error = ufs_mkdir(ap);
617 1.37 perseant UNMARK_VNODE(ap->a_dvp);
618 1.40 perseant if (*(ap->a_vpp))
619 1.37 perseant UNMARK_VNODE(*(ap->a_vpp));
620 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"mkdir");
621 1.37 perseant return (error);
622 1.1 mycroft }
623 1.1 mycroft
624 1.1 mycroft int
625 1.50.6.1 lukem lfs_remove(void *v)
626 1.10 christos {
627 1.22 perseant struct vop_remove_args /* {
628 1.1 mycroft struct vnode *a_dvp;
629 1.1 mycroft struct vnode *a_vp;
630 1.1 mycroft struct componentname *a_cnp;
631 1.10 christos } */ *ap = v;
632 1.34 perseant struct vnode *dvp, *vp;
633 1.37 perseant int error;
634 1.34 perseant
635 1.34 perseant dvp = ap->a_dvp;
636 1.34 perseant vp = ap->a_vp;
637 1.40 perseant if ((error = SET_DIROP(dvp)) != 0) {
638 1.34 perseant if (dvp == vp)
639 1.34 perseant vrele(vp);
640 1.34 perseant else
641 1.34 perseant vput(vp);
642 1.34 perseant vput(dvp);
643 1.37 perseant return error;
644 1.34 perseant }
645 1.34 perseant MARK_VNODE(dvp);
646 1.34 perseant MARK_VNODE(vp);
647 1.37 perseant error = ufs_remove(ap);
648 1.37 perseant UNMARK_VNODE(dvp);
649 1.37 perseant UNMARK_VNODE(vp);
650 1.40 perseant
651 1.40 perseant /*
652 1.40 perseant * If ufs_remove failed, vp doesn't need to be VDIROP any more.
653 1.40 perseant * If it succeeded, we can go ahead and wipe out vp, since
654 1.40 perseant * its loss won't appear on disk until checkpoint, and by then
655 1.40 perseant * dvp will have been written, completing the dirop.
656 1.40 perseant */
657 1.40 perseant --lfs_dirvcount;
658 1.40 perseant vp->v_flag &= ~VDIROP;
659 1.40 perseant wakeup(&lfs_dirvcount);
660 1.40 perseant vrele(vp);
661 1.40 perseant
662 1.42 perseant SET_ENDOP(VTOI(dvp)->i_lfs,dvp,"remove");
663 1.37 perseant return (error);
664 1.1 mycroft }
665 1.1 mycroft
666 1.1 mycroft int
667 1.50.6.1 lukem lfs_rmdir(void *v)
668 1.10 christos {
669 1.22 perseant struct vop_rmdir_args /* {
670 1.1 mycroft struct vnodeop_desc *a_desc;
671 1.1 mycroft struct vnode *a_dvp;
672 1.1 mycroft struct vnode *a_vp;
673 1.1 mycroft struct componentname *a_cnp;
674 1.10 christos } */ *ap = v;
675 1.37 perseant int error;
676 1.1 mycroft
677 1.40 perseant if ((error = SET_DIROP(ap->a_dvp)) != 0) {
678 1.34 perseant vrele(ap->a_dvp);
679 1.34 perseant if (ap->a_vp->v_mountedhere != NULL)
680 1.34 perseant VOP_UNLOCK(ap->a_dvp, 0);
681 1.34 perseant vput(ap->a_vp);
682 1.37 perseant return error;
683 1.34 perseant }
684 1.1 mycroft MARK_VNODE(ap->a_dvp);
685 1.1 mycroft MARK_VNODE(ap->a_vp);
686 1.37 perseant error = ufs_rmdir(ap);
687 1.37 perseant UNMARK_VNODE(ap->a_dvp);
688 1.37 perseant UNMARK_VNODE(ap->a_vp);
689 1.40 perseant
690 1.40 perseant /*
691 1.40 perseant * If ufs_rmdir failed, vp doesn't need to be VDIROP any more.
692 1.40 perseant * If it succeeded, we can go ahead and wipe out vp, since
693 1.40 perseant * its loss won't appear on disk until checkpoint, and by then
694 1.40 perseant * dvp will have been written, completing the dirop.
695 1.40 perseant */
696 1.40 perseant --lfs_dirvcount;
697 1.40 perseant ap->a_vp->v_flag &= ~VDIROP;
698 1.40 perseant wakeup(&lfs_dirvcount);
699 1.40 perseant vrele(ap->a_vp);
700 1.40 perseant
701 1.42 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"rmdir");
702 1.37 perseant return (error);
703 1.1 mycroft }
704 1.1 mycroft
705 1.1 mycroft int
706 1.50.6.1 lukem lfs_link(void *v)
707 1.10 christos {
708 1.22 perseant struct vop_link_args /* {
709 1.9 mycroft struct vnode *a_dvp;
710 1.1 mycroft struct vnode *a_vp;
711 1.1 mycroft struct componentname *a_cnp;
712 1.10 christos } */ *ap = v;
713 1.37 perseant int error;
714 1.1 mycroft
715 1.40 perseant if ((error = SET_DIROP(ap->a_dvp)) != 0) {
716 1.34 perseant vput(ap->a_dvp);
717 1.37 perseant return error;
718 1.34 perseant }
719 1.9 mycroft MARK_VNODE(ap->a_dvp);
720 1.37 perseant error = ufs_link(ap);
721 1.37 perseant UNMARK_VNODE(ap->a_dvp);
722 1.26 perseant SET_ENDOP(VTOI(ap->a_dvp)->i_lfs,ap->a_dvp,"link");
723 1.37 perseant return (error);
724 1.1 mycroft }
725 1.22 perseant
726 1.1 mycroft int
727 1.50.6.1 lukem lfs_rename(void *v)
728 1.10 christos {
729 1.22 perseant struct vop_rename_args /* {
730 1.1 mycroft struct vnode *a_fdvp;
731 1.1 mycroft struct vnode *a_fvp;
732 1.1 mycroft struct componentname *a_fcnp;
733 1.1 mycroft struct vnode *a_tdvp;
734 1.1 mycroft struct vnode *a_tvp;
735 1.1 mycroft struct componentname *a_tcnp;
736 1.10 christos } */ *ap = v;
737 1.30 perseant struct vnode *tvp, *fvp, *tdvp, *fdvp;
738 1.30 perseant int error;
739 1.29 perseant struct lfs *fs;
740 1.29 perseant
741 1.29 perseant fs = VTOI(ap->a_fdvp)->i_lfs;
742 1.30 perseant tvp = ap->a_tvp;
743 1.30 perseant tdvp = ap->a_tdvp;
744 1.30 perseant fvp = ap->a_fvp;
745 1.30 perseant fdvp = ap->a_fdvp;
746 1.30 perseant
747 1.30 perseant /*
748 1.30 perseant * Check for cross-device rename.
749 1.30 perseant * If it is, we don't want to set dirops, just error out.
750 1.30 perseant * (In particular note that MARK_VNODE(tdvp) will DTWT on
751 1.30 perseant * a cross-device rename.)
752 1.30 perseant *
753 1.30 perseant * Copied from ufs_rename.
754 1.30 perseant */
755 1.30 perseant if ((fvp->v_mount != tdvp->v_mount) ||
756 1.30 perseant (tvp && (fvp->v_mount != tvp->v_mount))) {
757 1.30 perseant error = EXDEV;
758 1.34 perseant goto errout;
759 1.30 perseant }
760 1.50.6.3 thorpej if ((error = SET_DIROP(fdvp)) != 0)
761 1.34 perseant goto errout;
762 1.30 perseant MARK_VNODE(fdvp);
763 1.30 perseant MARK_VNODE(tdvp);
764 1.30 perseant error = ufs_rename(ap);
765 1.37 perseant UNMARK_VNODE(fdvp);
766 1.37 perseant UNMARK_VNODE(tdvp);
767 1.30 perseant SET_ENDOP(fs,fdvp,"rename");
768 1.34 perseant return (error);
769 1.34 perseant
770 1.34 perseant errout:
771 1.34 perseant VOP_ABORTOP(tdvp, ap->a_tcnp); /* XXX, why not in NFS? */
772 1.34 perseant if (tdvp == tvp)
773 1.34 perseant vrele(tdvp);
774 1.34 perseant else
775 1.34 perseant vput(tdvp);
776 1.34 perseant if (tvp)
777 1.34 perseant vput(tvp);
778 1.34 perseant VOP_ABORTOP(fdvp, ap->a_fcnp); /* XXX, why not in NFS? */
779 1.34 perseant vrele(fdvp);
780 1.34 perseant vrele(fvp);
781 1.30 perseant return (error);
782 1.1 mycroft }
783 1.22 perseant
784 1.1 mycroft /* XXX hack to avoid calling ITIMES in getattr */
785 1.1 mycroft int
786 1.50.6.1 lukem lfs_getattr(void *v)
787 1.10 christos {
788 1.1 mycroft struct vop_getattr_args /* {
789 1.1 mycroft struct vnode *a_vp;
790 1.1 mycroft struct vattr *a_vap;
791 1.1 mycroft struct ucred *a_cred;
792 1.1 mycroft struct proc *a_p;
793 1.10 christos } */ *ap = v;
794 1.35 augustss struct vnode *vp = ap->a_vp;
795 1.35 augustss struct inode *ip = VTOI(vp);
796 1.35 augustss struct vattr *vap = ap->a_vap;
797 1.50.6.1 lukem struct lfs *fs = ip->i_lfs;
798 1.1 mycroft /*
799 1.1 mycroft * Copy from inode table
800 1.1 mycroft */
801 1.1 mycroft vap->va_fsid = ip->i_dev;
802 1.1 mycroft vap->va_fileid = ip->i_number;
803 1.14 bouyer vap->va_mode = ip->i_ffs_mode & ~IFMT;
804 1.14 bouyer vap->va_nlink = ip->i_ffs_nlink;
805 1.14 bouyer vap->va_uid = ip->i_ffs_uid;
806 1.14 bouyer vap->va_gid = ip->i_ffs_gid;
807 1.14 bouyer vap->va_rdev = (dev_t)ip->i_ffs_rdev;
808 1.50.6.3 thorpej vap->va_size = vp->v_size;
809 1.14 bouyer vap->va_atime.tv_sec = ip->i_ffs_atime;
810 1.14 bouyer vap->va_atime.tv_nsec = ip->i_ffs_atimensec;
811 1.14 bouyer vap->va_mtime.tv_sec = ip->i_ffs_mtime;
812 1.14 bouyer vap->va_mtime.tv_nsec = ip->i_ffs_mtimensec;
813 1.14 bouyer vap->va_ctime.tv_sec = ip->i_ffs_ctime;
814 1.14 bouyer vap->va_ctime.tv_nsec = ip->i_ffs_ctimensec;
815 1.14 bouyer vap->va_flags = ip->i_ffs_flags;
816 1.14 bouyer vap->va_gen = ip->i_ffs_gen;
817 1.1 mycroft /* this doesn't belong here */
818 1.1 mycroft if (vp->v_type == VBLK)
819 1.1 mycroft vap->va_blocksize = BLKDEV_IOSIZE;
820 1.1 mycroft else if (vp->v_type == VCHR)
821 1.1 mycroft vap->va_blocksize = MAXBSIZE;
822 1.1 mycroft else
823 1.1 mycroft vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
824 1.50.6.1 lukem vap->va_bytes = fsbtob(fs, (u_quad_t)ip->i_ffs_blocks);
825 1.1 mycroft vap->va_type = vp->v_type;
826 1.1 mycroft vap->va_filerev = ip->i_modrev;
827 1.1 mycroft return (0);
828 1.50.6.4 jdolecek }
829 1.50.6.4 jdolecek
830 1.50.6.4 jdolecek /*
831 1.50.6.4 jdolecek * Check to make sure the inode blocks won't choke the buffer
832 1.50.6.4 jdolecek * cache, then call ufs_setattr as usual.
833 1.50.6.4 jdolecek */
834 1.50.6.4 jdolecek int
835 1.50.6.4 jdolecek lfs_setattr(void *v)
836 1.50.6.4 jdolecek {
837 1.50.6.4 jdolecek struct vop_getattr_args /* {
838 1.50.6.4 jdolecek struct vnode *a_vp;
839 1.50.6.4 jdolecek struct vattr *a_vap;
840 1.50.6.4 jdolecek struct ucred *a_cred;
841 1.50.6.4 jdolecek struct proc *a_p;
842 1.50.6.4 jdolecek } */ *ap = v;
843 1.50.6.4 jdolecek struct vnode *vp = ap->a_vp;
844 1.50.6.4 jdolecek
845 1.50.6.4 jdolecek lfs_check(vp, LFS_UNUSED_LBN, 0);
846 1.50.6.4 jdolecek return ufs_setattr(v);
847 1.1 mycroft }
848 1.22 perseant
849 1.1 mycroft /*
850 1.1 mycroft * Close called
851 1.1 mycroft *
852 1.1 mycroft * XXX -- we were using ufs_close, but since it updates the
853 1.1 mycroft * times on the inode, we might need to bump the uinodes
854 1.1 mycroft * count.
855 1.1 mycroft */
856 1.1 mycroft /* ARGSUSED */
857 1.1 mycroft int
858 1.50.6.1 lukem lfs_close(void *v)
859 1.10 christos {
860 1.1 mycroft struct vop_close_args /* {
861 1.1 mycroft struct vnode *a_vp;
862 1.1 mycroft int a_fflag;
863 1.1 mycroft struct ucred *a_cred;
864 1.1 mycroft struct proc *a_p;
865 1.10 christos } */ *ap = v;
866 1.35 augustss struct vnode *vp = ap->a_vp;
867 1.35 augustss struct inode *ip = VTOI(vp);
868 1.12 mycroft struct timespec ts;
869 1.1 mycroft
870 1.15 fvdl if (vp->v_usecount > 1) {
871 1.12 mycroft TIMEVAL_TO_TIMESPEC(&time, &ts);
872 1.22 perseant LFS_ITIMES(ip, &ts, &ts, &ts);
873 1.1 mycroft }
874 1.1 mycroft return (0);
875 1.50.6.5 jdolecek }
876 1.50.6.5 jdolecek
877 1.50.6.5 jdolecek /*
878 1.50.6.5 jdolecek * Close wrapper for special devices.
879 1.50.6.5 jdolecek *
880 1.50.6.5 jdolecek * Update the times on the inode then do device close.
881 1.50.6.5 jdolecek */
882 1.50.6.5 jdolecek int
883 1.50.6.5 jdolecek lfsspec_close(void *v)
884 1.50.6.5 jdolecek {
885 1.50.6.5 jdolecek struct vop_close_args /* {
886 1.50.6.5 jdolecek struct vnode *a_vp;
887 1.50.6.5 jdolecek int a_fflag;
888 1.50.6.5 jdolecek struct ucred *a_cred;
889 1.50.6.5 jdolecek struct proc *a_p;
890 1.50.6.5 jdolecek } */ *ap = v;
891 1.50.6.5 jdolecek struct vnode *vp;
892 1.50.6.5 jdolecek struct inode *ip;
893 1.50.6.5 jdolecek struct timespec ts;
894 1.50.6.5 jdolecek
895 1.50.6.5 jdolecek vp = ap->a_vp;
896 1.50.6.5 jdolecek ip = VTOI(vp);
897 1.50.6.5 jdolecek if (vp->v_usecount > 1) {
898 1.50.6.5 jdolecek TIMEVAL_TO_TIMESPEC(&time, &ts);
899 1.50.6.5 jdolecek LFS_ITIMES(ip, &ts, &ts, &ts);
900 1.50.6.5 jdolecek }
901 1.50.6.5 jdolecek return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
902 1.50.6.5 jdolecek }
903 1.50.6.5 jdolecek
904 1.50.6.5 jdolecek /*
905 1.50.6.5 jdolecek * Close wrapper for fifo's.
906 1.50.6.5 jdolecek *
907 1.50.6.5 jdolecek * Update the times on the inode then do device close.
908 1.50.6.5 jdolecek */
909 1.50.6.5 jdolecek int
910 1.50.6.5 jdolecek lfsfifo_close(void *v)
911 1.50.6.5 jdolecek {
912 1.50.6.5 jdolecek struct vop_close_args /* {
913 1.50.6.5 jdolecek struct vnode *a_vp;
914 1.50.6.5 jdolecek int a_fflag;
915 1.50.6.5 jdolecek struct ucred *a_cred;
916 1.50.6.5 jdolecek struct proc *a_p;
917 1.50.6.5 jdolecek } */ *ap = v;
918 1.50.6.5 jdolecek struct vnode *vp;
919 1.50.6.5 jdolecek struct inode *ip;
920 1.50.6.5 jdolecek struct timespec ts;
921 1.50.6.5 jdolecek
922 1.50.6.5 jdolecek vp = ap->a_vp;
923 1.50.6.5 jdolecek ip = VTOI(vp);
924 1.50.6.5 jdolecek if (ap->a_vp->v_usecount > 1) {
925 1.50.6.5 jdolecek TIMEVAL_TO_TIMESPEC(&time, &ts);
926 1.50.6.5 jdolecek LFS_ITIMES(ip, &ts, &ts, &ts);
927 1.50.6.5 jdolecek }
928 1.50.6.5 jdolecek return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));
929 1.1 mycroft }
930 1.1 mycroft
931 1.1 mycroft /*
932 1.15 fvdl * Reclaim an inode so that it can be used for other purposes.
933 1.1 mycroft */
934 1.1 mycroft int lfs_no_inactive = 0;
935 1.1 mycroft
936 1.1 mycroft int
937 1.50.6.1 lukem lfs_reclaim(void *v)
938 1.10 christos {
939 1.1 mycroft struct vop_reclaim_args /* {
940 1.1 mycroft struct vnode *a_vp;
941 1.15 fvdl struct proc *a_p;
942 1.10 christos } */ *ap = v;
943 1.15 fvdl struct vnode *vp = ap->a_vp;
944 1.1 mycroft int error;
945 1.1 mycroft
946 1.43 perseant LFS_CLR_UINO(VTOI(vp), IN_ALLMOD);
947 1.15 fvdl if ((error = ufs_reclaim(vp, ap->a_p)))
948 1.1 mycroft return (error);
949 1.19 thorpej pool_put(&lfs_inode_pool, vp->v_data);
950 1.1 mycroft vp->v_data = NULL;
951 1.1 mycroft return (0);
952 1.50.6.3 thorpej }
953 1.50.6.3 thorpej
954 1.50.6.3 thorpej int
955 1.50.6.3 thorpej lfs_getpages(void *v)
956 1.50.6.3 thorpej {
957 1.50.6.3 thorpej struct vop_getpages_args /* {
958 1.50.6.3 thorpej struct vnode *a_vp;
959 1.50.6.3 thorpej voff_t a_offset;
960 1.50.6.3 thorpej struct vm_page **a_m;
961 1.50.6.3 thorpej int *a_count;
962 1.50.6.3 thorpej int a_centeridx;
963 1.50.6.3 thorpej vm_prot_t a_access_type;
964 1.50.6.3 thorpej int a_advice;
965 1.50.6.3 thorpej int a_flags;
966 1.50.6.3 thorpej } */ *ap = v;
967 1.50.6.3 thorpej
968 1.50.6.3 thorpej if ((ap->a_access_type & VM_PROT_WRITE) != 0) {
969 1.50.6.3 thorpej LFS_SET_UINO(VTOI(ap->a_vp), IN_MODIFIED);
970 1.50.6.3 thorpej }
971 1.50.6.3 thorpej return genfs_compat_getpages(v);
972 1.50.6.3 thorpej }
973 1.50.6.3 thorpej
974 1.50.6.3 thorpej int
975 1.50.6.3 thorpej lfs_putpages(void *v)
976 1.50.6.3 thorpej {
977 1.50.6.3 thorpej int error;
978 1.50.6.3 thorpej
979 1.50.6.3 thorpej error = genfs_putpages(v);
980 1.50.6.3 thorpej return error;
981 1.1 mycroft }
982