ffs_vnops.c revision 1.127 1 /* $NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $ */
2
3 /*-
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc, and by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1982, 1986, 1989, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
61 */
62
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.127 2017/03/01 21:55:07 hannken Exp $");
65
66 #if defined(_KERNEL_OPT)
67 #include "opt_ffs.h"
68 #include "opt_wapbl.h"
69 #endif
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/resourcevar.h>
74 #include <sys/kernel.h>
75 #include <sys/file.h>
76 #include <sys/stat.h>
77 #include <sys/buf.h>
78 #include <sys/event.h>
79 #include <sys/proc.h>
80 #include <sys/mount.h>
81 #include <sys/vnode.h>
82 #include <sys/pool.h>
83 #include <sys/signalvar.h>
84 #include <sys/kauth.h>
85 #include <sys/wapbl.h>
86
87 #include <miscfs/fifofs/fifo.h>
88 #include <miscfs/genfs/genfs.h>
89 #include <miscfs/specfs/specdev.h>
90
91 #include <ufs/ufs/inode.h>
92 #include <ufs/ufs/dir.h>
93 #include <ufs/ufs/ufs_extern.h>
94 #include <ufs/ufs/ufsmount.h>
95 #include <ufs/ufs/ufs_wapbl.h>
96
97 #include <ufs/ffs/fs.h>
98 #include <ufs/ffs/ffs_extern.h>
99
100 #include <uvm/uvm.h>
101
102 /* Global vfs data structures for ufs. */
103 int (**ffs_vnodeop_p)(void *);
104 const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
105 { &vop_default_desc, vn_default_error },
106 { &vop_lookup_desc, ufs_lookup }, /* lookup */
107 { &vop_create_desc, ufs_create }, /* create */
108 { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
109 { &vop_mknod_desc, ufs_mknod }, /* mknod */
110 { &vop_open_desc, ufs_open }, /* open */
111 { &vop_close_desc, ufs_close }, /* close */
112 { &vop_access_desc, ufs_access }, /* access */
113 { &vop_getattr_desc, ufs_getattr }, /* getattr */
114 { &vop_setattr_desc, ufs_setattr }, /* setattr */
115 { &vop_read_desc, ffs_read }, /* read */
116 { &vop_write_desc, ffs_write }, /* write */
117 { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
118 { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
119 { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
120 { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
121 { &vop_poll_desc, ufs_poll }, /* poll */
122 { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
123 { &vop_revoke_desc, ufs_revoke }, /* revoke */
124 { &vop_mmap_desc, ufs_mmap }, /* mmap */
125 { &vop_fsync_desc, ffs_fsync }, /* fsync */
126 { &vop_seek_desc, ufs_seek }, /* seek */
127 { &vop_remove_desc, ufs_remove }, /* remove */
128 { &vop_link_desc, ufs_link }, /* link */
129 { &vop_rename_desc, ufs_rename }, /* rename */
130 { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
131 { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
132 { &vop_symlink_desc, ufs_symlink }, /* symlink */
133 { &vop_readdir_desc, ufs_readdir }, /* readdir */
134 { &vop_readlink_desc, ufs_readlink }, /* readlink */
135 { &vop_abortop_desc, ufs_abortop }, /* abortop */
136 { &vop_inactive_desc, ufs_inactive }, /* inactive */
137 { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
138 { &vop_lock_desc, ufs_lock }, /* lock */
139 { &vop_unlock_desc, ufs_unlock }, /* unlock */
140 { &vop_bmap_desc, ufs_bmap }, /* bmap */
141 { &vop_strategy_desc, ufs_strategy }, /* strategy */
142 { &vop_print_desc, ufs_print }, /* print */
143 { &vop_islocked_desc, ufs_islocked }, /* islocked */
144 { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
145 { &vop_advlock_desc, ufs_advlock }, /* advlock */
146 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
147 { &vop_getpages_desc, genfs_getpages }, /* getpages */
148 { &vop_putpages_desc, genfs_putpages }, /* putpages */
149 { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
150 { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
151 { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
152 { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
153 { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
154 { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
155 { NULL, NULL }
156 };
157 const struct vnodeopv_desc ffs_vnodeop_opv_desc =
158 { &ffs_vnodeop_p, ffs_vnodeop_entries };
159
160 int (**ffs_specop_p)(void *);
161 const struct vnodeopv_entry_desc ffs_specop_entries[] = {
162 { &vop_default_desc, vn_default_error },
163 { &vop_lookup_desc, spec_lookup }, /* lookup */
164 { &vop_create_desc, spec_create }, /* create */
165 { &vop_mknod_desc, spec_mknod }, /* mknod */
166 { &vop_open_desc, spec_open }, /* open */
167 { &vop_close_desc, ufsspec_close }, /* close */
168 { &vop_access_desc, ufs_access }, /* access */
169 { &vop_getattr_desc, ufs_getattr }, /* getattr */
170 { &vop_setattr_desc, ufs_setattr }, /* setattr */
171 { &vop_read_desc, ufsspec_read }, /* read */
172 { &vop_write_desc, ufsspec_write }, /* write */
173 { &vop_fallocate_desc, spec_fallocate }, /* fallocate */
174 { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
175 { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
176 { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
177 { &vop_poll_desc, spec_poll }, /* poll */
178 { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
179 { &vop_revoke_desc, spec_revoke }, /* revoke */
180 { &vop_mmap_desc, spec_mmap }, /* mmap */
181 { &vop_fsync_desc, ffs_spec_fsync }, /* fsync */
182 { &vop_seek_desc, spec_seek }, /* seek */
183 { &vop_remove_desc, spec_remove }, /* remove */
184 { &vop_link_desc, spec_link }, /* link */
185 { &vop_rename_desc, spec_rename }, /* rename */
186 { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
187 { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
188 { &vop_symlink_desc, spec_symlink }, /* symlink */
189 { &vop_readdir_desc, spec_readdir }, /* readdir */
190 { &vop_readlink_desc, spec_readlink }, /* readlink */
191 { &vop_abortop_desc, spec_abortop }, /* abortop */
192 { &vop_inactive_desc, ufs_inactive }, /* inactive */
193 { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
194 { &vop_lock_desc, ufs_lock }, /* lock */
195 { &vop_unlock_desc, ufs_unlock }, /* unlock */
196 { &vop_bmap_desc, spec_bmap }, /* bmap */
197 { &vop_strategy_desc, spec_strategy }, /* strategy */
198 { &vop_print_desc, ufs_print }, /* print */
199 { &vop_islocked_desc, ufs_islocked }, /* islocked */
200 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
201 { &vop_advlock_desc, spec_advlock }, /* advlock */
202 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
203 { &vop_getpages_desc, spec_getpages }, /* getpages */
204 { &vop_putpages_desc, spec_putpages }, /* putpages */
205 { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
206 { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
207 { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
208 { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
209 { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
210 { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
211 { NULL, NULL }
212 };
213 const struct vnodeopv_desc ffs_specop_opv_desc =
214 { &ffs_specop_p, ffs_specop_entries };
215
216 int (**ffs_fifoop_p)(void *);
217 const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
218 { &vop_default_desc, vn_default_error },
219 { &vop_lookup_desc, vn_fifo_bypass }, /* lookup */
220 { &vop_create_desc, vn_fifo_bypass }, /* create */
221 { &vop_mknod_desc, vn_fifo_bypass }, /* mknod */
222 { &vop_open_desc, vn_fifo_bypass }, /* open */
223 { &vop_close_desc, ufsfifo_close }, /* close */
224 { &vop_access_desc, ufs_access }, /* access */
225 { &vop_getattr_desc, ufs_getattr }, /* getattr */
226 { &vop_setattr_desc, ufs_setattr }, /* setattr */
227 { &vop_read_desc, ufsfifo_read }, /* read */
228 { &vop_write_desc, ufsfifo_write }, /* write */
229 { &vop_fallocate_desc, vn_fifo_bypass }, /* fallocate */
230 { &vop_fdiscard_desc, vn_fifo_bypass }, /* fdiscard */
231 { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */
232 { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
233 { &vop_poll_desc, vn_fifo_bypass }, /* poll */
234 { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */
235 { &vop_revoke_desc, vn_fifo_bypass }, /* revoke */
236 { &vop_mmap_desc, vn_fifo_bypass }, /* mmap */
237 { &vop_fsync_desc, ffs_fsync }, /* fsync */
238 { &vop_seek_desc, vn_fifo_bypass }, /* seek */
239 { &vop_remove_desc, vn_fifo_bypass }, /* remove */
240 { &vop_link_desc, vn_fifo_bypass }, /* link */
241 { &vop_rename_desc, vn_fifo_bypass }, /* rename */
242 { &vop_mkdir_desc, vn_fifo_bypass }, /* mkdir */
243 { &vop_rmdir_desc, vn_fifo_bypass }, /* rmdir */
244 { &vop_symlink_desc, vn_fifo_bypass }, /* symlink */
245 { &vop_readdir_desc, vn_fifo_bypass }, /* readdir */
246 { &vop_readlink_desc, vn_fifo_bypass }, /* readlink */
247 { &vop_abortop_desc, vn_fifo_bypass }, /* abortop */
248 { &vop_inactive_desc, ufs_inactive }, /* inactive */
249 { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
250 { &vop_lock_desc, ufs_lock }, /* lock */
251 { &vop_unlock_desc, ufs_unlock }, /* unlock */
252 { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */
253 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */
254 { &vop_print_desc, ufs_print }, /* print */
255 { &vop_islocked_desc, ufs_islocked }, /* islocked */
256 { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */
257 { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */
258 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
259 { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */
260 { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
261 { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
262 { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
263 { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
264 { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
265 { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
266 { NULL, NULL }
267 };
268 const struct vnodeopv_desc ffs_fifoop_opv_desc =
269 { &ffs_fifoop_p, ffs_fifoop_entries };
270
271 #include <ufs/ufs/ufs_readwrite.c>
272
273 int
274 ffs_spec_fsync(void *v)
275 {
276 struct vop_fsync_args /* {
277 struct vnode *a_vp;
278 kauth_cred_t a_cred;
279 int a_flags;
280 off_t a_offlo;
281 off_t a_offhi;
282 struct lwp *a_l;
283 } */ *ap = v;
284 int error, flags, uflags;
285 struct vnode *vp;
286 #ifdef WAPBL
287 struct mount *mp;
288 #endif /* WAPBL */
289
290 flags = ap->a_flags;
291 uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
292 vp = ap->a_vp;
293
294 error = spec_fsync(v);
295 if (error)
296 goto out;
297
298 #ifdef WAPBL
299 mp = vp->v_mount;
300 if (mp && mp->mnt_wapbl) {
301 /*
302 * Don't bother writing out metadata if the syncer is
303 * making the request. We will let the sync vnode
304 * write it out in a single burst through a call to
305 * VFS_SYNC().
306 */
307 if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
308 goto out;
309 if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
310 | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
311 error = UFS_WAPBL_BEGIN(mp);
312 if (error != 0)
313 goto out;
314 error = ffs_update(vp, NULL, NULL, uflags);
315 UFS_WAPBL_END(mp);
316 }
317 goto out;
318 }
319 #endif /* WAPBL */
320
321 error = ffs_update(vp, NULL, NULL, uflags);
322
323 out:
324 return error;
325 }
326
327 int
328 ffs_fsync(void *v)
329 {
330 struct vop_fsync_args /* {
331 struct vnode *a_vp;
332 kauth_cred_t a_cred;
333 int a_flags;
334 off_t a_offlo;
335 off_t a_offhi;
336 struct lwp *a_l;
337 } */ *ap = v;
338 struct buf *bp;
339 int num, error, i;
340 struct indir ia[UFS_NIADDR + 1];
341 int bsize;
342 daddr_t blk_high;
343 struct vnode *vp;
344 struct mount *mp;
345
346 vp = ap->a_vp;
347 mp = vp->v_mount;
348
349 if ((ap->a_offlo == 0 && ap->a_offhi == 0) || (vp->v_type != VREG)) {
350 error = ffs_full_fsync(vp, ap->a_flags);
351 goto out;
352 }
353
354 bsize = mp->mnt_stat.f_iosize;
355 blk_high = ap->a_offhi / bsize;
356 if (ap->a_offhi % bsize != 0)
357 blk_high++;
358
359 /*
360 * First, flush all pages in range.
361 */
362
363 mutex_enter(vp->v_interlock);
364 error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
365 round_page(ap->a_offhi), PGO_CLEANIT |
366 ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
367 if (error) {
368 goto out;
369 }
370
371 #ifdef WAPBL
372 KASSERT(vp->v_type == VREG);
373 if (mp->mnt_wapbl) {
374 /*
375 * Don't bother writing out metadata if the syncer is
376 * making the request. We will let the sync vnode
377 * write it out in a single burst through a call to
378 * VFS_SYNC().
379 */
380 if ((ap->a_flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0) {
381 return 0;
382 }
383 error = 0;
384 if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
385 (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
386 IN_MODIFIED | IN_ACCESSED)) {
387 error = UFS_WAPBL_BEGIN(mp);
388 if (error) {
389 return error;
390 }
391 error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
392 ((ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0));
393 UFS_WAPBL_END(mp);
394 }
395 if (error || (ap->a_flags & FSYNC_NOLOG) != 0) {
396 return error;
397 }
398 error = wapbl_flush(mp->mnt_wapbl, 0);
399 return error;
400 }
401 #endif /* WAPBL */
402
403 /*
404 * Then, flush indirect blocks.
405 */
406
407 if (blk_high >= UFS_NDADDR) {
408 error = ufs_getlbns(vp, blk_high, ia, &num);
409 if (error)
410 goto out;
411
412 mutex_enter(&bufcache_lock);
413 for (i = 0; i < num; i++) {
414 if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
415 continue;
416 if ((bp->b_cflags & BC_BUSY) != 0 ||
417 (bp->b_oflags & BO_DELWRI) == 0)
418 continue;
419 bp->b_cflags |= BC_BUSY | BC_VFLUSH;
420 mutex_exit(&bufcache_lock);
421 bawrite(bp);
422 mutex_enter(&bufcache_lock);
423 }
424 mutex_exit(&bufcache_lock);
425 }
426
427 if (ap->a_flags & FSYNC_WAIT) {
428 mutex_enter(vp->v_interlock);
429 while (vp->v_numoutput > 0)
430 cv_wait(&vp->v_cv, vp->v_interlock);
431 mutex_exit(vp->v_interlock);
432 }
433
434 error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
435 (((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
436 ? UPDATE_WAIT : 0));
437
438 if (error == 0 && ap->a_flags & FSYNC_CACHE) {
439 int l = 0;
440 VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
441 curlwp->l_cred);
442 }
443
444 out:
445 return error;
446 }
447
448 /*
449 * Synch an open file. Called for VOP_FSYNC().
450 */
451 /* ARGSUSED */
452 int
453 ffs_full_fsync(struct vnode *vp, int flags)
454 {
455 int error, i, uflags;
456
457 KASSERT(vp->v_tag == VT_UFS);
458 KASSERT(VTOI(vp) != NULL);
459 KASSERT(vp->v_type != VCHR && vp->v_type != VBLK);
460
461 uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
462
463 #ifdef WAPBL
464 struct mount *mp = vp->v_mount;
465 if (mp && mp->mnt_wapbl) {
466
467 /*
468 * Flush all dirty data associated with the vnode.
469 */
470 if (vp->v_type == VREG) {
471 int pflags = PGO_ALLPAGES | PGO_CLEANIT;
472
473 if ((flags & FSYNC_LAZY))
474 pflags |= PGO_LAZY;
475 if ((flags & FSYNC_WAIT))
476 pflags |= PGO_SYNCIO;
477 mutex_enter(vp->v_interlock);
478 error = VOP_PUTPAGES(vp, 0, 0, pflags);
479 if (error)
480 return error;
481 }
482
483 /*
484 * Don't bother writing out metadata if the syncer is
485 * making the request. We will let the sync vnode
486 * write it out in a single burst through a call to
487 * VFS_SYNC().
488 */
489 if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
490 return 0;
491
492 if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
493 | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
494 error = UFS_WAPBL_BEGIN(mp);
495 if (error)
496 return error;
497 error = ffs_update(vp, NULL, NULL, uflags);
498 UFS_WAPBL_END(mp);
499 } else {
500 error = 0;
501 }
502 if (error || (flags & FSYNC_NOLOG) != 0)
503 return error;
504
505 /*
506 * Don't flush the log if the vnode being flushed
507 * contains no dirty buffers that could be in the log.
508 */
509 if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
510 error = wapbl_flush(mp->mnt_wapbl, 0);
511 if (error)
512 return error;
513 }
514
515 if ((flags & FSYNC_WAIT) != 0) {
516 mutex_enter(vp->v_interlock);
517 while (vp->v_numoutput != 0)
518 cv_wait(&vp->v_cv, vp->v_interlock);
519 mutex_exit(vp->v_interlock);
520 }
521
522 return error;
523 }
524 #endif /* WAPBL */
525
526 error = vflushbuf(vp, flags);
527 if (error == 0)
528 error = ffs_update(vp, NULL, NULL, uflags);
529 if (error == 0 && (flags & FSYNC_CACHE) != 0) {
530 i = 1;
531 (void)VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
532 kauth_cred_get());
533 }
534
535 return error;
536 }
537
538 /*
539 * Reclaim an inode so that it can be used for other purposes.
540 */
541 int
542 ffs_reclaim(void *v)
543 {
544 struct vop_reclaim_args /* {
545 struct vnode *a_vp;
546 struct lwp *a_l;
547 } */ *ap = v;
548 struct vnode *vp = ap->a_vp;
549 struct inode *ip = VTOI(vp);
550 struct mount *mp = vp->v_mount;
551 struct ufsmount *ump = ip->i_ump;
552 void *data;
553 int error;
554
555 /*
556 * The inode must be freed and updated before being removed
557 * from its hash chain. Other threads trying to gain a hold
558 * or lock on the inode will be stalled.
559 */
560 error = UFS_WAPBL_BEGIN(mp);
561 if (error) {
562 return error;
563 }
564 if (ip->i_nlink <= 0 && ip->i_omode != 0 &&
565 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
566 ffs_vfree(vp, ip->i_number, ip->i_omode);
567 UFS_WAPBL_END(mp);
568 if ((error = ufs_reclaim(vp)) != 0) {
569 return (error);
570 }
571 if (ip->i_din.ffs1_din != NULL) {
572 if (ump->um_fstype == UFS1)
573 pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
574 else
575 pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
576 }
577 /*
578 * To interlock with ffs_sync().
579 */
580 genfs_node_destroy(vp);
581 mutex_enter(vp->v_interlock);
582 data = vp->v_data;
583 vp->v_data = NULL;
584 mutex_exit(vp->v_interlock);
585
586 /*
587 * XXX MFS ends up here, too, to free an inode. Should we create
588 * XXX a separate pool for MFS inodes?
589 */
590 pool_cache_put(ffs_inode_cache, data);
591 return (0);
592 }
593
594 /*
595 * Return the last logical file offset that should be written for this file
596 * if we're doing a write that ends at "size".
597 */
598
599 void
600 ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
601 {
602 struct inode *ip = VTOI(vp);
603 struct fs *fs = ip->i_fs;
604 daddr_t olbn, nlbn;
605
606 olbn = ffs_lblkno(fs, ip->i_size);
607 nlbn = ffs_lblkno(fs, size);
608 if (nlbn < UFS_NDADDR && olbn <= nlbn) {
609 *eobp = ffs_fragroundup(fs, size);
610 } else {
611 *eobp = ffs_blkroundup(fs, size);
612 }
613 }
614
615 int
616 ffs_openextattr(void *v)
617 {
618 struct vop_openextattr_args /* {
619 struct vnode *a_vp;
620 kauth_cred_t a_cred;
621 struct proc *a_p;
622 } */ *ap = v;
623 struct inode *ip = VTOI(ap->a_vp);
624 struct fs *fs = ip->i_fs;
625
626 /* Not supported for UFS1 file systems. */
627 if (fs->fs_magic == FS_UFS1_MAGIC)
628 return (EOPNOTSUPP);
629
630 /* XXX Not implemented for UFS2 file systems. */
631 return (EOPNOTSUPP);
632 }
633
634 int
635 ffs_closeextattr(void *v)
636 {
637 struct vop_closeextattr_args /* {
638 struct vnode *a_vp;
639 int a_commit;
640 kauth_cred_t a_cred;
641 struct proc *a_p;
642 } */ *ap = v;
643 struct inode *ip = VTOI(ap->a_vp);
644 struct fs *fs = ip->i_fs;
645
646 /* Not supported for UFS1 file systems. */
647 if (fs->fs_magic == FS_UFS1_MAGIC)
648 return (EOPNOTSUPP);
649
650 /* XXX Not implemented for UFS2 file systems. */
651 return (EOPNOTSUPP);
652 }
653
654 int
655 ffs_getextattr(void *v)
656 {
657 struct vop_getextattr_args /* {
658 struct vnode *a_vp;
659 int a_attrnamespace;
660 const char *a_name;
661 struct uio *a_uio;
662 size_t *a_size;
663 kauth_cred_t a_cred;
664 struct proc *a_p;
665 } */ *ap = v;
666 struct vnode *vp = ap->a_vp;
667 struct inode *ip = VTOI(vp);
668 struct fs *fs = ip->i_fs;
669
670 if (fs->fs_magic == FS_UFS1_MAGIC) {
671 #ifdef UFS_EXTATTR
672 int error;
673
674 error = ufs_getextattr(ap);
675 return error;
676 #else
677 return (EOPNOTSUPP);
678 #endif
679 }
680
681 /* XXX Not implemented for UFS2 file systems. */
682 return (EOPNOTSUPP);
683 }
684
685 int
686 ffs_setextattr(void *v)
687 {
688 struct vop_setextattr_args /* {
689 struct vnode *a_vp;
690 int a_attrnamespace;
691 const char *a_name;
692 struct uio *a_uio;
693 kauth_cred_t a_cred;
694 struct proc *a_p;
695 } */ *ap = v;
696 struct vnode *vp = ap->a_vp;
697 struct inode *ip = VTOI(vp);
698 struct fs *fs = ip->i_fs;
699
700 if (fs->fs_magic == FS_UFS1_MAGIC) {
701 #ifdef UFS_EXTATTR
702 int error;
703
704 error = ufs_setextattr(ap);
705 return error;
706 #else
707 return (EOPNOTSUPP);
708 #endif
709 }
710
711 /* XXX Not implemented for UFS2 file systems. */
712 return (EOPNOTSUPP);
713 }
714
715 int
716 ffs_listextattr(void *v)
717 {
718 struct vop_listextattr_args /* {
719 struct vnode *a_vp;
720 int a_attrnamespace;
721 struct uio *a_uio;
722 size_t *a_size;
723 kauth_cred_t a_cred;
724 struct proc *a_p;
725 } */ *ap = v;
726 struct inode *ip = VTOI(ap->a_vp);
727 struct fs *fs = ip->i_fs;
728
729 if (fs->fs_magic == FS_UFS1_MAGIC) {
730 #ifdef UFS_EXTATTR
731 int error;
732
733 error = ufs_listextattr(ap);
734 return error;
735 #else
736 return (EOPNOTSUPP);
737 #endif
738 }
739
740 /* XXX Not implemented for UFS2 file systems. */
741 return (EOPNOTSUPP);
742 }
743
744 int
745 ffs_deleteextattr(void *v)
746 {
747 struct vop_deleteextattr_args /* {
748 struct vnode *a_vp;
749 int a_attrnamespace;
750 kauth_cred_t a_cred;
751 struct proc *a_p;
752 } */ *ap = v;
753 struct vnode *vp = ap->a_vp;
754 struct inode *ip = VTOI(vp);
755 struct fs *fs = ip->i_fs;
756
757 if (fs->fs_magic == FS_UFS1_MAGIC) {
758 #ifdef UFS_EXTATTR
759 int error;
760
761 error = ufs_deleteextattr(ap);
762 return error;
763 #else
764 return (EOPNOTSUPP);
765 #endif
766 }
767
768 /* XXX Not implemented for UFS2 file systems. */
769 return (EOPNOTSUPP);
770 }
771