Annotation of src/sys/ufs/ffs/ffs_vnops.c, Revision 1.127
1.127 ! hannken 1: /* $NetBSD: ffs_vnops.c,v 1.126 2017/03/01 10:42:45 hannken Exp $ */
1.100 simonb 2:
3: /*-
1.109 ad 4: * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
1.100 simonb 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
1.109 ad 8: * by Wasabi Systems, Inc, and by Andrew Doran.
1.100 simonb 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: */
1.3 cgd 31:
1.1 mycroft 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.
1.60 agc 44: * 3. Neither the name of the University nor the names of its contributors
1.1 mycroft 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: *
1.12 fvdl 60: * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
1.1 mycroft 61: */
1.44 lukem 62:
63: #include <sys/cdefs.h>
1.127 ! hannken 64: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.126 2017/03/01 10:42:45 hannken Exp $");
1.100 simonb 65:
66: #if defined(_KERNEL_OPT)
67: #include "opt_ffs.h"
68: #include "opt_wapbl.h"
69: #endif
1.11 mrg 70:
1.1 mycroft 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>
1.50 jdolecek 78: #include <sys/event.h>
1.1 mycroft 79: #include <sys/proc.h>
80: #include <sys/mount.h>
81: #include <sys/vnode.h>
1.16 thorpej 82: #include <sys/pool.h>
1.6 christos 83: #include <sys/signalvar.h>
1.80 elad 84: #include <sys/kauth.h>
1.100 simonb 85: #include <sys/wapbl.h>
1.1 mycroft 86:
1.8 mycroft 87: #include <miscfs/fifofs/fifo.h>
88: #include <miscfs/genfs/genfs.h>
1.1 mycroft 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>
1.2 mycroft 94: #include <ufs/ufs/ufsmount.h>
1.100 simonb 95: #include <ufs/ufs/ufs_wapbl.h>
1.1 mycroft 96:
97: #include <ufs/ffs/fs.h>
98: #include <ufs/ffs/ffs_extern.h>
99:
1.49 chs 100: #include <uvm/uvm.h>
101:
1.1 mycroft 102: /* Global vfs data structures for ufs. */
1.74 xtraeme 103: int (**ffs_vnodeop_p)(void *);
1.37 jdolecek 104: const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
1.1 mycroft 105: { &vop_default_desc, vn_default_error },
106: { &vop_lookup_desc, ufs_lookup }, /* lookup */
107: { &vop_create_desc, ufs_create }, /* create */
1.5 mycroft 108: { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
1.1 mycroft 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 */
1.125 dholland 117: { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
118: { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
1.1 mycroft 119: { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
1.19 wrstuden 120: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.9 mycroft 121: { &vop_poll_desc, ufs_poll }, /* poll */
1.50 jdolecek 122: { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
1.12 fvdl 123: { &vop_revoke_desc, ufs_revoke }, /* revoke */
1.1 mycroft 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 */
1.113 hannken 138: { &vop_lock_desc, ufs_lock }, /* lock */
139: { &vop_unlock_desc, ufs_unlock }, /* unlock */
1.1 mycroft 140: { &vop_bmap_desc, ufs_bmap }, /* bmap */
141: { &vop_strategy_desc, ufs_strategy }, /* strategy */
142: { &vop_print_desc, ufs_print }, /* print */
1.113 hannken 143: { &vop_islocked_desc, ufs_islocked }, /* islocked */
1.1 mycroft 144: { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
145: { &vop_advlock_desc, ufs_advlock }, /* advlock */
1.8 mycroft 146: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.88 yamt 147: { &vop_getpages_desc, genfs_getpages }, /* getpages */
1.75 yamt 148: { &vop_putpages_desc, genfs_putpages }, /* putpages */
1.73 thorpej 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 */
1.35 chs 155: { NULL, NULL }
1.1 mycroft 156: };
1.37 jdolecek 157: const struct vnodeopv_desc ffs_vnodeop_opv_desc =
1.1 mycroft 158: { &ffs_vnodeop_p, ffs_vnodeop_entries };
159:
1.74 xtraeme 160: int (**ffs_specop_p)(void *);
1.37 jdolecek 161: const struct vnodeopv_entry_desc ffs_specop_entries[] = {
1.1 mycroft 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 */
1.125 dholland 173: { &vop_fallocate_desc, spec_fallocate }, /* fallocate */
174: { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
1.1 mycroft 175: { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
1.19 wrstuden 176: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.9 mycroft 177: { &vop_poll_desc, spec_poll }, /* poll */
1.50 jdolecek 178: { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
1.12 fvdl 179: { &vop_revoke_desc, spec_revoke }, /* revoke */
1.1 mycroft 180: { &vop_mmap_desc, spec_mmap }, /* mmap */
1.118 hannken 181: { &vop_fsync_desc, ffs_spec_fsync }, /* fsync */
1.1 mycroft 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 */
1.113 hannken 194: { &vop_lock_desc, ufs_lock }, /* lock */
195: { &vop_unlock_desc, ufs_unlock }, /* unlock */
1.1 mycroft 196: { &vop_bmap_desc, spec_bmap }, /* bmap */
197: { &vop_strategy_desc, spec_strategy }, /* strategy */
198: { &vop_print_desc, ufs_print }, /* print */
1.113 hannken 199: { &vop_islocked_desc, ufs_islocked }, /* islocked */
1.1 mycroft 200: { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
201: { &vop_advlock_desc, spec_advlock }, /* advlock */
1.8 mycroft 202: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.38 chs 203: { &vop_getpages_desc, spec_getpages }, /* getpages */
204: { &vop_putpages_desc, spec_putpages }, /* putpages */
1.73 thorpej 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 */
1.35 chs 211: { NULL, NULL }
1.1 mycroft 212: };
1.37 jdolecek 213: const struct vnodeopv_desc ffs_specop_opv_desc =
1.1 mycroft 214: { &ffs_specop_p, ffs_specop_entries };
215:
1.74 xtraeme 216: int (**ffs_fifoop_p)(void *);
1.37 jdolecek 217: const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
1.1 mycroft 218: { &vop_default_desc, vn_default_error },
1.114 pooka 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 */
1.1 mycroft 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 */
1.125 dholland 229: { &vop_fallocate_desc, vn_fifo_bypass }, /* fallocate */
230: { &vop_fdiscard_desc, vn_fifo_bypass }, /* fdiscard */
1.114 pooka 231: { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */
1.19 wrstuden 232: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.114 pooka 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 */
1.1 mycroft 237: { &vop_fsync_desc, ffs_fsync }, /* fsync */
1.114 pooka 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 */
1.1 mycroft 248: { &vop_inactive_desc, ufs_inactive }, /* inactive */
249: { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
1.113 hannken 250: { &vop_lock_desc, ufs_lock }, /* lock */
251: { &vop_unlock_desc, ufs_unlock }, /* unlock */
1.114 pooka 252: { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */
253: { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */
1.1 mycroft 254: { &vop_print_desc, ufs_print }, /* print */
1.113 hannken 255: { &vop_islocked_desc, ufs_islocked }, /* islocked */
1.114 pooka 256: { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */
257: { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */
1.8 mycroft 258: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.114 pooka 259: { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */
1.73 thorpej 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 */
1.35 chs 266: { NULL, NULL }
1.1 mycroft 267: };
1.37 jdolecek 268: const struct vnodeopv_desc ffs_fifoop_opv_desc =
1.1 mycroft 269: { &ffs_fifoop_p, ffs_fifoop_entries };
270:
271: #include <ufs/ufs/ufs_readwrite.c>
1.20 fvdl 272:
1.33 fvdl 273: int
1.118 hannken 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;
1.127 ! hannken 286: #ifdef WAPBL
1.118 hannken 287: struct mount *mp;
1.127 ! hannken 288: #endif /* WAPBL */
1.118 hannken 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
1.127 ! hannken 299: mp = vp->v_mount;
1.118 hannken 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
1.70 thorpej 328: ffs_fsync(void *v)
1.33 fvdl 329: {
330: struct vop_fsync_args /* {
331: struct vnode *a_vp;
1.80 elad 332: kauth_cred_t a_cred;
1.33 fvdl 333: int a_flags;
1.46 chs 334: off_t a_offlo;
335: off_t a_offhi;
1.77 christos 336: struct lwp *a_l;
1.33 fvdl 337: } */ *ap = v;
1.35 chs 338: struct buf *bp;
1.94 ad 339: int num, error, i;
1.122 dholland 340: struct indir ia[UFS_NIADDR + 1];
1.33 fvdl 341: int bsize;
1.45 simonb 342: daddr_t blk_high;
1.33 fvdl 343: struct vnode *vp;
1.100 simonb 344: struct mount *mp;
1.33 fvdl 345:
1.84 hannken 346: vp = ap->a_vp;
1.117 hannken 347: mp = vp->v_mount;
1.84 hannken 348:
1.111 ad 349: if ((ap->a_offlo == 0 && ap->a_offhi == 0) || (vp->v_type != VREG)) {
350: error = ffs_full_fsync(vp, ap->a_flags);
1.84 hannken 351: goto out;
352: }
1.33 fvdl 353:
1.117 hannken 354: bsize = mp->mnt_stat.f_iosize;
1.33 fvdl 355: blk_high = ap->a_offhi / bsize;
356: if (ap->a_offhi % bsize != 0)
357: blk_high++;
358:
359: /*
1.35 chs 360: * First, flush all pages in range.
1.33 fvdl 361: */
1.35 chs 362:
1.119 rmind 363: mutex_enter(vp->v_interlock);
1.64 dbj 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) {
1.84 hannken 368: goto out;
1.39 chs 369: }
1.33 fvdl 370:
1.100 simonb 371: #ifdef WAPBL
1.117 hannken 372: KASSERT(vp->v_type == VREG);
1.100 simonb 373: if (mp->mnt_wapbl) {
1.110 ad 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) {
1.100 simonb 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: }
1.112 ad 391: error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
392: ((ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0));
1.100 simonb 393: UFS_WAPBL_END(mp);
394: }
1.110 ad 395: if (error || (ap->a_flags & FSYNC_NOLOG) != 0) {
1.100 simonb 396: return error;
397: }
398: error = wapbl_flush(mp->mnt_wapbl, 0);
399: return error;
400: }
401: #endif /* WAPBL */
402:
1.33 fvdl 403: /*
1.35 chs 404: * Then, flush indirect blocks.
1.33 fvdl 405: */
1.35 chs 406:
1.122 dholland 407: if (blk_high >= UFS_NDADDR) {
1.33 fvdl 408: error = ufs_getlbns(vp, blk_high, ia, &num);
1.94 ad 409: if (error)
1.84 hannken 410: goto out;
1.94 ad 411:
412: mutex_enter(&bufcache_lock);
1.33 fvdl 413: for (i = 0; i < num; i++) {
1.94 ad 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);
1.33 fvdl 423: }
1.94 ad 424: mutex_exit(&bufcache_lock);
1.33 fvdl 425: }
426:
427: if (ap->a_flags & FSYNC_WAIT) {
1.119 rmind 428: mutex_enter(vp->v_interlock);
1.94 ad 429: while (vp->v_numoutput > 0)
1.119 rmind 430: cv_wait(&vp->v_cv, vp->v_interlock);
431: mutex_exit(vp->v_interlock);
1.33 fvdl 432: }
433:
1.112 ad 434: error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
435: (((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
436: ? UPDATE_WAIT : 0));
1.67 wrstuden 437:
438: if (error == 0 && ap->a_flags & FSYNC_CACHE) {
439: int l = 0;
440: VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
1.93 pooka 441: curlwp->l_cred);
1.67 wrstuden 442: }
443:
1.84 hannken 444: out:
1.67 wrstuden 445: return error;
1.33 fvdl 446: }
447:
1.20 fvdl 448: /*
1.110 ad 449: * Synch an open file. Called for VOP_FSYNC().
1.20 fvdl 450: */
451: /* ARGSUSED */
1.94 ad 452: int
453: ffs_full_fsync(struct vnode *vp, int flags)
1.20 fvdl 454: {
1.118 hannken 455: int error, i, uflags;
1.99 ad 456:
1.118 hannken 457: KASSERT(vp->v_tag == VT_UFS);
1.110 ad 458: KASSERT(VTOI(vp) != NULL);
1.118 hannken 459: KASSERT(vp->v_type != VCHR && vp->v_type != VBLK);
1.110 ad 460:
1.118 hannken 461: uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
1.24 fvdl 462:
1.121 chs 463: #ifdef WAPBL
464: struct mount *mp = vp->v_mount;
465: if (mp && mp->mnt_wapbl) {
1.105 ad 466:
1.121 chs 467: /*
468: * Flush all dirty data associated with the vnode.
469: */
470: if (vp->v_type == VREG) {
471: int pflags = PGO_ALLPAGES | PGO_CLEANIT;
1.101 oster 472:
1.121 chs 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: }
1.100 simonb 482:
1.110 ad 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;
1.100 simonb 491:
1.110 ad 492: if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
1.109 ad 493: | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
1.100 simonb 494: error = UFS_WAPBL_BEGIN(mp);
495: if (error)
496: return error;
1.118 hannken 497: error = ffs_update(vp, NULL, NULL, uflags);
1.100 simonb 498: UFS_WAPBL_END(mp);
1.121 chs 499: } else {
500: error = 0;
1.100 simonb 501: }
1.110 ad 502: if (error || (flags & FSYNC_NOLOG) != 0)
1.100 simonb 503: return error;
1.106 ad 504:
1.100 simonb 505: /*
506: * Don't flush the log if the vnode being flushed
507: * contains no dirty buffers that could be in the log.
508: */
1.109 ad 509: if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
1.100 simonb 510: error = wapbl_flush(mp->mnt_wapbl, 0);
511: if (error)
512: return error;
513: }
514:
1.109 ad 515: if ((flags & FSYNC_WAIT) != 0) {
1.119 rmind 516: mutex_enter(vp->v_interlock);
1.110 ad 517: while (vp->v_numoutput != 0)
1.119 rmind 518: cv_wait(&vp->v_cv, vp->v_interlock);
519: mutex_exit(vp->v_interlock);
1.100 simonb 520: }
521:
522: return error;
523: }
524: #endif /* WAPBL */
1.35 chs 525:
1.121 chs 526: error = vflushbuf(vp, flags);
1.118 hannken 527: if (error == 0)
528: error = ffs_update(vp, NULL, NULL, uflags);
1.109 ad 529: if (error == 0 && (flags & FSYNC_CACHE) != 0) {
1.118 hannken 530: i = 1;
1.110 ad 531: (void)VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
532: kauth_cred_get());
1.67 wrstuden 533: }
534:
535: return error;
1.20 fvdl 536: }
1.1 mycroft 537:
538: /*
539: * Reclaim an inode so that it can be used for other purposes.
540: */
541: int
1.70 thorpej 542: ffs_reclaim(void *v)
1.6 christos 543: {
1.1 mycroft 544: struct vop_reclaim_args /* {
545: struct vnode *a_vp;
1.77 christos 546: struct lwp *a_l;
1.6 christos 547: } */ *ap = v;
1.26 augustss 548: struct vnode *vp = ap->a_vp;
1.56 fvdl 549: struct inode *ip = VTOI(vp);
1.84 hannken 550: struct mount *mp = vp->v_mount;
1.56 fvdl 551: struct ufsmount *ump = ip->i_ump;
1.94 ad 552: void *data;
1.1 mycroft 553: int error;
554:
1.115 hannken 555: /*
556: * The inode must be freed and updated before being removed
557: * from its hash chain. Other threads trying to gain a hold
1.124 hannken 558: * or lock on the inode will be stalled.
1.115 hannken 559: */
560: error = UFS_WAPBL_BEGIN(mp);
561: if (error) {
562: return error;
563: }
1.116 hannken 564: if (ip->i_nlink <= 0 && ip->i_omode != 0 &&
565: (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1.115 hannken 566: ffs_vfree(vp, ip->i_number, ip->i_omode);
567: UFS_WAPBL_END(mp);
1.93 pooka 568: if ((error = ufs_reclaim(vp)) != 0) {
1.1 mycroft 569: return (error);
1.84 hannken 570: }
1.57 fvdl 571: if (ip->i_din.ffs1_din != NULL) {
572: if (ump->um_fstype == UFS1)
1.95 ad 573: pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
1.57 fvdl 574: else
1.95 ad 575: pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
1.57 fvdl 576: }
1.16 thorpej 577: /*
1.94 ad 578: * To interlock with ffs_sync().
579: */
580: genfs_node_destroy(vp);
1.119 rmind 581: mutex_enter(vp->v_interlock);
1.94 ad 582: data = vp->v_data;
583: vp->v_data = NULL;
1.119 rmind 584: mutex_exit(vp->v_interlock);
1.94 ad 585:
586: /*
1.16 thorpej 587: * XXX MFS ends up here, too, to free an inode. Should we create
588: * XXX a separate pool for MFS inodes?
589: */
1.95 ad 590: pool_cache_put(ffs_inode_cache, data);
1.1 mycroft 591: return (0);
1.35 chs 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: */
1.39 chs 598:
599: void
1.83 christos 600: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35 chs 601: {
1.39 chs 602: struct inode *ip = VTOI(vp);
1.35 chs 603: struct fs *fs = ip->i_fs;
1.52 fvdl 604: daddr_t olbn, nlbn;
1.55 perseant 605:
1.123 dholland 606: olbn = ffs_lblkno(fs, ip->i_size);
607: nlbn = ffs_lblkno(fs, size);
1.122 dholland 608: if (nlbn < UFS_NDADDR && olbn <= nlbn) {
1.123 dholland 609: *eobp = ffs_fragroundup(fs, size);
1.35 chs 610: } else {
1.123 dholland 611: *eobp = ffs_blkroundup(fs, size);
1.35 chs 612: }
1.1 mycroft 613: }
1.73 thorpej 614:
615: int
616: ffs_openextattr(void *v)
617: {
618: struct vop_openextattr_args /* {
619: struct vnode *a_vp;
1.80 elad 620: kauth_cred_t a_cred;
1.73 thorpej 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;
1.80 elad 640: kauth_cred_t a_cred;
1.73 thorpej 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;
1.80 elad 663: kauth_cred_t a_cred;
1.73 thorpej 664: struct proc *a_p;
665: } */ *ap = v;
1.84 hannken 666: struct vnode *vp = ap->a_vp;
667: struct inode *ip = VTOI(vp);
1.73 thorpej 668: struct fs *fs = ip->i_fs;
669:
670: if (fs->fs_magic == FS_UFS1_MAGIC) {
671: #ifdef UFS_EXTATTR
1.84 hannken 672: int error;
673:
674: error = ufs_getextattr(ap);
675: return error;
1.73 thorpej 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;
1.80 elad 693: kauth_cred_t a_cred;
1.73 thorpej 694: struct proc *a_p;
695: } */ *ap = v;
1.84 hannken 696: struct vnode *vp = ap->a_vp;
697: struct inode *ip = VTOI(vp);
1.73 thorpej 698: struct fs *fs = ip->i_fs;
699:
700: if (fs->fs_magic == FS_UFS1_MAGIC) {
701: #ifdef UFS_EXTATTR
1.84 hannken 702: int error;
703:
704: error = ufs_setextattr(ap);
705: return error;
1.73 thorpej 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;
1.80 elad 723: kauth_cred_t a_cred;
1.73 thorpej 724: struct proc *a_p;
725: } */ *ap = v;
726: struct inode *ip = VTOI(ap->a_vp);
727: struct fs *fs = ip->i_fs;
728:
1.120 manu 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
1.73 thorpej 736: return (EOPNOTSUPP);
1.120 manu 737: #endif
738: }
1.73 thorpej 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;
1.80 elad 750: kauth_cred_t a_cred;
1.73 thorpej 751: struct proc *a_p;
752: } */ *ap = v;
1.84 hannken 753: struct vnode *vp = ap->a_vp;
754: struct inode *ip = VTOI(vp);
1.73 thorpej 755: struct fs *fs = ip->i_fs;
756:
757: if (fs->fs_magic == FS_UFS1_MAGIC) {
758: #ifdef UFS_EXTATTR
1.84 hannken 759: int error;
760:
761: error = ufs_deleteextattr(ap);
762: return error;
1.73 thorpej 763: #else
764: return (EOPNOTSUPP);
765: #endif
766: }
767:
768: /* XXX Not implemented for UFS2 file systems. */
769: return (EOPNOTSUPP);
770: }
CVSweb <webmaster@jp.NetBSD.org>