Annotation of src/sys/ufs/ffs/ffs_vnops.c, Revision 1.56
1.56 ! fvdl 1: /* $NetBSD: ffs_vnops.c,v 1.55 2003/02/17 23:48:15 perseant Exp $ */
1.3 cgd 2:
1.1 mycroft 3: /*
4: * Copyright (c) 1982, 1986, 1989, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
1.12 fvdl 35: * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
1.1 mycroft 36: */
1.44 lukem 37:
38: #include <sys/cdefs.h>
1.56 ! fvdl 39: __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.55 2003/02/17 23:48:15 perseant Exp $");
1.11 mrg 40:
1.1 mycroft 41: #include <sys/param.h>
42: #include <sys/systm.h>
43: #include <sys/resourcevar.h>
44: #include <sys/kernel.h>
45: #include <sys/file.h>
46: #include <sys/stat.h>
47: #include <sys/buf.h>
1.50 jdolecek 48: #include <sys/event.h>
1.1 mycroft 49: #include <sys/proc.h>
50: #include <sys/mount.h>
51: #include <sys/vnode.h>
1.16 thorpej 52: #include <sys/pool.h>
1.6 christos 53: #include <sys/signalvar.h>
1.1 mycroft 54:
1.8 mycroft 55: #include <miscfs/fifofs/fifo.h>
56: #include <miscfs/genfs/genfs.h>
1.1 mycroft 57: #include <miscfs/specfs/specdev.h>
58:
59: #include <ufs/ufs/inode.h>
60: #include <ufs/ufs/dir.h>
61: #include <ufs/ufs/ufs_extern.h>
1.2 mycroft 62: #include <ufs/ufs/ufsmount.h>
1.1 mycroft 63:
64: #include <ufs/ffs/fs.h>
65: #include <ufs/ffs/ffs_extern.h>
66:
1.49 chs 67: #include <uvm/uvm.h>
68:
1.33 fvdl 69: static int ffs_full_fsync __P((void *));
70:
1.1 mycroft 71: /* Global vfs data structures for ufs. */
1.6 christos 72: int (**ffs_vnodeop_p) __P((void *));
1.37 jdolecek 73: const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
1.1 mycroft 74: { &vop_default_desc, vn_default_error },
75: { &vop_lookup_desc, ufs_lookup }, /* lookup */
76: { &vop_create_desc, ufs_create }, /* create */
1.5 mycroft 77: { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
1.1 mycroft 78: { &vop_mknod_desc, ufs_mknod }, /* mknod */
79: { &vop_open_desc, ufs_open }, /* open */
80: { &vop_close_desc, ufs_close }, /* close */
81: { &vop_access_desc, ufs_access }, /* access */
82: { &vop_getattr_desc, ufs_getattr }, /* getattr */
83: { &vop_setattr_desc, ufs_setattr }, /* setattr */
84: { &vop_read_desc, ffs_read }, /* read */
85: { &vop_write_desc, ffs_write }, /* write */
1.4 mycroft 86: { &vop_lease_desc, ufs_lease_check }, /* lease */
1.1 mycroft 87: { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
1.19 wrstuden 88: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.9 mycroft 89: { &vop_poll_desc, ufs_poll }, /* poll */
1.50 jdolecek 90: { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
1.12 fvdl 91: { &vop_revoke_desc, ufs_revoke }, /* revoke */
1.1 mycroft 92: { &vop_mmap_desc, ufs_mmap }, /* mmap */
93: { &vop_fsync_desc, ffs_fsync }, /* fsync */
94: { &vop_seek_desc, ufs_seek }, /* seek */
95: { &vop_remove_desc, ufs_remove }, /* remove */
96: { &vop_link_desc, ufs_link }, /* link */
97: { &vop_rename_desc, ufs_rename }, /* rename */
98: { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
99: { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
100: { &vop_symlink_desc, ufs_symlink }, /* symlink */
101: { &vop_readdir_desc, ufs_readdir }, /* readdir */
102: { &vop_readlink_desc, ufs_readlink }, /* readlink */
103: { &vop_abortop_desc, ufs_abortop }, /* abortop */
104: { &vop_inactive_desc, ufs_inactive }, /* inactive */
105: { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
106: { &vop_lock_desc, ufs_lock }, /* lock */
107: { &vop_unlock_desc, ufs_unlock }, /* unlock */
108: { &vop_bmap_desc, ufs_bmap }, /* bmap */
109: { &vop_strategy_desc, ufs_strategy }, /* strategy */
110: { &vop_print_desc, ufs_print }, /* print */
111: { &vop_islocked_desc, ufs_islocked }, /* islocked */
112: { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
113: { &vop_advlock_desc, ufs_advlock }, /* advlock */
114: { &vop_blkatoff_desc, ffs_blkatoff }, /* blkatoff */
115: { &vop_valloc_desc, ffs_valloc }, /* valloc */
1.20 fvdl 116: { &vop_balloc_desc, ffs_balloc }, /* balloc */
1.1 mycroft 117: { &vop_reallocblks_desc, ffs_reallocblks }, /* reallocblks */
118: { &vop_vfree_desc, ffs_vfree }, /* vfree */
119: { &vop_truncate_desc, ffs_truncate }, /* truncate */
120: { &vop_update_desc, ffs_update }, /* update */
1.8 mycroft 121: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.39 chs 122: { &vop_getpages_desc, ffs_getpages }, /* getpages */
1.49 chs 123: { &vop_putpages_desc, ffs_putpages }, /* putpages */
1.35 chs 124: { NULL, NULL }
1.1 mycroft 125: };
1.37 jdolecek 126: const struct vnodeopv_desc ffs_vnodeop_opv_desc =
1.1 mycroft 127: { &ffs_vnodeop_p, ffs_vnodeop_entries };
128:
1.6 christos 129: int (**ffs_specop_p) __P((void *));
1.37 jdolecek 130: const struct vnodeopv_entry_desc ffs_specop_entries[] = {
1.1 mycroft 131: { &vop_default_desc, vn_default_error },
132: { &vop_lookup_desc, spec_lookup }, /* lookup */
133: { &vop_create_desc, spec_create }, /* create */
134: { &vop_mknod_desc, spec_mknod }, /* mknod */
135: { &vop_open_desc, spec_open }, /* open */
136: { &vop_close_desc, ufsspec_close }, /* close */
137: { &vop_access_desc, ufs_access }, /* access */
138: { &vop_getattr_desc, ufs_getattr }, /* getattr */
139: { &vop_setattr_desc, ufs_setattr }, /* setattr */
140: { &vop_read_desc, ufsspec_read }, /* read */
141: { &vop_write_desc, ufsspec_write }, /* write */
1.4 mycroft 142: { &vop_lease_desc, spec_lease_check }, /* lease */
1.1 mycroft 143: { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
1.19 wrstuden 144: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.9 mycroft 145: { &vop_poll_desc, spec_poll }, /* poll */
1.50 jdolecek 146: { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
1.12 fvdl 147: { &vop_revoke_desc, spec_revoke }, /* revoke */
1.1 mycroft 148: { &vop_mmap_desc, spec_mmap }, /* mmap */
149: { &vop_fsync_desc, ffs_fsync }, /* fsync */
150: { &vop_seek_desc, spec_seek }, /* seek */
151: { &vop_remove_desc, spec_remove }, /* remove */
152: { &vop_link_desc, spec_link }, /* link */
153: { &vop_rename_desc, spec_rename }, /* rename */
154: { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
155: { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
156: { &vop_symlink_desc, spec_symlink }, /* symlink */
157: { &vop_readdir_desc, spec_readdir }, /* readdir */
158: { &vop_readlink_desc, spec_readlink }, /* readlink */
159: { &vop_abortop_desc, spec_abortop }, /* abortop */
160: { &vop_inactive_desc, ufs_inactive }, /* inactive */
161: { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
162: { &vop_lock_desc, ufs_lock }, /* lock */
163: { &vop_unlock_desc, ufs_unlock }, /* unlock */
164: { &vop_bmap_desc, spec_bmap }, /* bmap */
165: { &vop_strategy_desc, spec_strategy }, /* strategy */
166: { &vop_print_desc, ufs_print }, /* print */
167: { &vop_islocked_desc, ufs_islocked }, /* islocked */
168: { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
169: { &vop_advlock_desc, spec_advlock }, /* advlock */
170: { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
171: { &vop_valloc_desc, spec_valloc }, /* valloc */
172: { &vop_reallocblks_desc, spec_reallocblks }, /* reallocblks */
173: { &vop_vfree_desc, ffs_vfree }, /* vfree */
174: { &vop_truncate_desc, spec_truncate }, /* truncate */
175: { &vop_update_desc, ffs_update }, /* update */
1.8 mycroft 176: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.38 chs 177: { &vop_getpages_desc, spec_getpages }, /* getpages */
178: { &vop_putpages_desc, spec_putpages }, /* putpages */
1.35 chs 179: { NULL, NULL }
1.1 mycroft 180: };
1.37 jdolecek 181: const struct vnodeopv_desc ffs_specop_opv_desc =
1.1 mycroft 182: { &ffs_specop_p, ffs_specop_entries };
183:
1.6 christos 184: int (**ffs_fifoop_p) __P((void *));
1.37 jdolecek 185: const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
1.1 mycroft 186: { &vop_default_desc, vn_default_error },
187: { &vop_lookup_desc, fifo_lookup }, /* lookup */
188: { &vop_create_desc, fifo_create }, /* create */
189: { &vop_mknod_desc, fifo_mknod }, /* mknod */
190: { &vop_open_desc, fifo_open }, /* open */
191: { &vop_close_desc, ufsfifo_close }, /* close */
192: { &vop_access_desc, ufs_access }, /* access */
193: { &vop_getattr_desc, ufs_getattr }, /* getattr */
194: { &vop_setattr_desc, ufs_setattr }, /* setattr */
195: { &vop_read_desc, ufsfifo_read }, /* read */
196: { &vop_write_desc, ufsfifo_write }, /* write */
1.4 mycroft 197: { &vop_lease_desc, fifo_lease_check }, /* lease */
1.1 mycroft 198: { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
1.19 wrstuden 199: { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
1.9 mycroft 200: { &vop_poll_desc, fifo_poll }, /* poll */
1.50 jdolecek 201: { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */
1.12 fvdl 202: { &vop_revoke_desc, fifo_revoke }, /* revoke */
1.1 mycroft 203: { &vop_mmap_desc, fifo_mmap }, /* mmap */
204: { &vop_fsync_desc, ffs_fsync }, /* fsync */
205: { &vop_seek_desc, fifo_seek }, /* seek */
206: { &vop_remove_desc, fifo_remove }, /* remove */
207: { &vop_link_desc, fifo_link }, /* link */
208: { &vop_rename_desc, fifo_rename }, /* rename */
209: { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
210: { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
211: { &vop_symlink_desc, fifo_symlink }, /* symlink */
212: { &vop_readdir_desc, fifo_readdir }, /* readdir */
213: { &vop_readlink_desc, fifo_readlink }, /* readlink */
214: { &vop_abortop_desc, fifo_abortop }, /* abortop */
215: { &vop_inactive_desc, ufs_inactive }, /* inactive */
216: { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
217: { &vop_lock_desc, ufs_lock }, /* lock */
218: { &vop_unlock_desc, ufs_unlock }, /* unlock */
219: { &vop_bmap_desc, fifo_bmap }, /* bmap */
220: { &vop_strategy_desc, fifo_strategy }, /* strategy */
221: { &vop_print_desc, ufs_print }, /* print */
222: { &vop_islocked_desc, ufs_islocked }, /* islocked */
223: { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
224: { &vop_advlock_desc, fifo_advlock }, /* advlock */
225: { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
226: { &vop_valloc_desc, fifo_valloc }, /* valloc */
227: { &vop_reallocblks_desc, fifo_reallocblks }, /* reallocblks */
228: { &vop_vfree_desc, ffs_vfree }, /* vfree */
229: { &vop_truncate_desc, fifo_truncate }, /* truncate */
230: { &vop_update_desc, ffs_update }, /* update */
1.8 mycroft 231: { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1.40 sommerfe 232: { &vop_putpages_desc, fifo_putpages }, /* putpages */
1.35 chs 233: { NULL, NULL }
1.1 mycroft 234: };
1.37 jdolecek 235: const struct vnodeopv_desc ffs_fifoop_opv_desc =
1.1 mycroft 236: { &ffs_fifoop_p, ffs_fifoop_entries };
237:
238: #include <ufs/ufs/ufs_readwrite.c>
1.20 fvdl 239:
1.33 fvdl 240: int
241: ffs_fsync(v)
242: void *v;
243: {
244: struct vop_fsync_args /* {
245: struct vnode *a_vp;
246: struct ucred *a_cred;
247: int a_flags;
1.46 chs 248: off_t a_offlo;
249: off_t a_offhi;
1.33 fvdl 250: struct proc *a_p;
251: } */ *ap = v;
1.35 chs 252: struct buf *bp;
1.33 fvdl 253: int s, num, error, i;
254: struct indir ia[NIADDR + 1];
255: int bsize;
1.45 simonb 256: daddr_t blk_high;
1.33 fvdl 257: struct vnode *vp;
258:
259: /*
260: * XXX no easy way to sync a range in a file with softdep.
261: */
262: if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(ap->a_vp))
263: return ffs_full_fsync(v);
264:
265: vp = ap->a_vp;
266:
267: bsize = ap->a_vp->v_mount->mnt_stat.f_iosize;
268: blk_high = ap->a_offhi / bsize;
269: if (ap->a_offhi % bsize != 0)
270: blk_high++;
271:
272: /*
1.35 chs 273: * First, flush all pages in range.
1.33 fvdl 274: */
1.35 chs 275:
1.42 chs 276: if (vp->v_type == VREG) {
1.46 chs 277: simple_lock(&vp->v_interlock);
278: error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
279: round_page(ap->a_offhi), PGO_CLEANIT|PGO_SYNCIO);
1.41 chs 280: if (error) {
281: return error;
282: }
1.39 chs 283: }
1.33 fvdl 284:
285: /*
1.35 chs 286: * Then, flush indirect blocks.
1.33 fvdl 287: */
1.35 chs 288:
1.41 chs 289: s = splbio();
1.33 fvdl 290: if (!(ap->a_flags & FSYNC_DATAONLY) && blk_high >= NDADDR) {
291: error = ufs_getlbns(vp, blk_high, ia, &num);
1.42 chs 292: if (error) {
293: splx(s);
1.33 fvdl 294: return error;
1.42 chs 295: }
1.33 fvdl 296: for (i = 0; i < num; i++) {
1.35 chs 297: bp = incore(vp, ia[i].in_lbn);
298: if (bp != NULL && !(bp->b_flags & B_BUSY) &&
299: (bp->b_flags & B_DELWRI)) {
300: bp->b_flags |= B_BUSY | B_VFLUSH;
1.33 fvdl 301: splx(s);
1.35 chs 302: bawrite(bp);
1.33 fvdl 303: s = splbio();
304: }
305: }
306: }
307:
308: if (ap->a_flags & FSYNC_WAIT) {
1.54 pk 309: simple_lock(&global_v_numoutput_slock);
1.33 fvdl 310: while (vp->v_numoutput > 0) {
311: vp->v_flag |= VBWAIT;
1.54 pk 312: ltsleep(&vp->v_numoutput, PRIBIO + 1, "fsync_range", 0,
313: &global_v_numoutput_slock);
1.33 fvdl 314: }
1.54 pk 315: simple_unlock(&global_v_numoutput_slock);
1.33 fvdl 316: }
1.34 fvdl 317: splx(s);
1.33 fvdl 318:
319: return (VOP_UPDATE(vp, NULL, NULL,
320: (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0));
321: }
322:
1.20 fvdl 323: /*
324: * Synch an open file.
325: */
326: /* ARGSUSED */
1.33 fvdl 327: static int
328: ffs_full_fsync(v)
1.20 fvdl 329: void *v;
330: {
1.29 mycroft 331: struct vop_fsync_args /* {
1.20 fvdl 332: struct vnode *a_vp;
333: struct ucred *a_cred;
334: int a_flags;
1.46 chs 335: off_t a_offlo;
336: off_t a_offhi;
1.20 fvdl 337: struct proc *a_p;
338: } */ *ap = v;
339: struct vnode *vp = ap->a_vp;
340: struct buf *bp, *nbp;
1.47 fvdl 341: int s, error, passes, skipmeta, inodedeps_only, waitfor;
1.24 fvdl 342:
1.20 fvdl 343: if (vp->v_type == VBLK &&
344: vp->v_specmountpoint != NULL &&
345: (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
346: softdep_fsync_mountdev(vp);
1.21 perseant 347:
1.47 fvdl 348: inodedeps_only = DOINGSOFTDEP(vp) && (ap->a_flags & FSYNC_RECLAIM)
1.48 thorpej 349: && vp->v_uobj.uo_npages == 0 && LIST_EMPTY(&vp->v_dirtyblkhd);
1.47 fvdl 350:
1.35 chs 351: /*
352: * Flush all dirty data associated with a vnode.
1.20 fvdl 353: */
1.35 chs 354:
1.42 chs 355: if (vp->v_type == VREG) {
1.46 chs 356: simple_lock(&vp->v_interlock);
357: error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT |
1.35 chs 358: ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
1.39 chs 359: if (error) {
360: return error;
361: }
1.35 chs 362: }
363:
1.20 fvdl 364: passes = NIADDR + 1;
365: skipmeta = 0;
366: if (ap->a_flags & (FSYNC_DATAONLY|FSYNC_WAIT))
367: skipmeta = 1;
368: s = splbio();
1.35 chs 369:
1.20 fvdl 370: loop:
1.35 chs 371: LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs)
1.20 fvdl 372: bp->b_flags &= ~B_SCANNED;
1.29 mycroft 373: for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
374: nbp = LIST_NEXT(bp, b_vnbufs);
1.20 fvdl 375: if (bp->b_flags & (B_BUSY | B_SCANNED))
376: continue;
377: if ((bp->b_flags & B_DELWRI) == 0)
378: panic("ffs_fsync: not dirty");
379: if (skipmeta && bp->b_lblkno < 0)
380: continue;
381: bp->b_flags |= B_BUSY | B_VFLUSH | B_SCANNED;
382: splx(s);
383: /*
384: * On our final pass through, do all I/O synchronously
385: * so that we can find out if our flush is failing
386: * because of write errors.
387: */
388: if (passes > 0 || !(ap->a_flags & FSYNC_WAIT))
389: (void) bawrite(bp);
390: else if ((error = bwrite(bp)) != 0)
391: return (error);
392: s = splbio();
393: /*
394: * Since we may have slept during the I/O, we need
395: * to start from a known point.
396: */
1.29 mycroft 397: nbp = LIST_FIRST(&vp->v_dirtyblkhd);
1.20 fvdl 398: }
399: if (skipmeta && !(ap->a_flags & FSYNC_DATAONLY)) {
400: skipmeta = 0;
401: goto loop;
402: }
403: if (ap->a_flags & FSYNC_WAIT) {
1.54 pk 404: simple_lock(&global_v_numoutput_slock);
1.20 fvdl 405: while (vp->v_numoutput) {
406: vp->v_flag |= VBWAIT;
1.54 pk 407: (void) ltsleep(&vp->v_numoutput, PRIBIO + 1,
408: "ffsfsync", 0, &global_v_numoutput_slock);
1.20 fvdl 409: }
1.54 pk 410: simple_unlock(&global_v_numoutput_slock);
1.29 mycroft 411: splx(s);
1.20 fvdl 412:
1.29 mycroft 413: if (ap->a_flags & FSYNC_DATAONLY)
414: return (0);
1.20 fvdl 415:
416: /*
417: * Ensure that any filesystem metadata associated
418: * with the vnode has been written.
419: */
1.31 mycroft 420: if ((error = softdep_sync_metadata(ap)) != 0)
1.20 fvdl 421: return (error);
1.29 mycroft 422:
1.20 fvdl 423: s = splbio();
1.29 mycroft 424: if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
425: /*
426: * Block devices associated with filesystems may
427: * have new I/O requests posted for them even if
428: * the vnode is locked, so no amount of trying will
429: * get them clean. Thus we give block devices a
430: * good effort, then just give up. For all other file
431: * types, go around and try again until it is clean.
432: */
433: if (passes > 0) {
434: passes--;
435: goto loop;
436: }
1.20 fvdl 437: #ifdef DIAGNOSTIC
1.29 mycroft 438: if (vp->v_type != VBLK)
439: vprint("ffs_fsync: dirty", vp);
1.20 fvdl 440: #endif
1.29 mycroft 441: }
442: }
443: splx(s);
1.47 fvdl 444:
445: if (inodedeps_only)
446: waitfor = 0;
447: else
448: waitfor = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
449: return (VOP_UPDATE(vp, NULL, NULL, waitfor));
1.20 fvdl 450: }
1.1 mycroft 451:
452: /*
453: * Reclaim an inode so that it can be used for other purposes.
454: */
455: int
1.6 christos 456: ffs_reclaim(v)
457: void *v;
458: {
1.1 mycroft 459: struct vop_reclaim_args /* {
460: struct vnode *a_vp;
1.12 fvdl 461: struct proc *a_p;
1.6 christos 462: } */ *ap = v;
1.26 augustss 463: struct vnode *vp = ap->a_vp;
1.56 ! fvdl 464: struct inode *ip = VTOI(vp);
! 465: struct ufsmount *ump = ip->i_ump;
1.1 mycroft 466: int error;
467:
1.12 fvdl 468: if ((error = ufs_reclaim(vp, ap->a_p)) != 0)
1.1 mycroft 469: return (error);
1.56 ! fvdl 470: if (ump->um_fstype == UFS1)
! 471: pool_put(&ffs_dinode1_pool, ip->i_din.ffs1_din);
! 472: else
! 473: pool_put(&ffs_dinode2_pool, ip->i_din.ffs2_din);
1.16 thorpej 474: /*
475: * XXX MFS ends up here, too, to free an inode. Should we create
476: * XXX a separate pool for MFS inodes?
477: */
478: pool_put(&ffs_inode_pool, vp->v_data);
1.1 mycroft 479: vp->v_data = NULL;
480: return (0);
1.35 chs 481: }
482:
1.39 chs 483: int
484: ffs_getpages(void *v)
485: {
486: struct vop_getpages_args /* {
487: struct vnode *a_vp;
488: voff_t a_offset;
489: struct vm_page **a_m;
490: int *a_count;
491: int a_centeridx;
492: vm_prot_t a_access_type;
493: int a_advice;
494: int a_flags;
495: } */ *ap = v;
496: struct vnode *vp = ap->a_vp;
497: struct inode *ip = VTOI(vp);
498: struct fs *fs = ip->i_fs;
499:
500: /*
501: * don't allow a softdep write to create pages for only part of a block.
502: * the dependency tracking requires that all pages be in memory for
503: * a block involved in a dependency.
504: */
505:
506: if (ap->a_flags & PGO_OVERWRITE &&
507: (blkoff(fs, ap->a_offset) != 0 ||
508: blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) &&
509: DOINGSOFTDEP(ap->a_vp)) {
510: if ((ap->a_flags & PGO_LOCKED) == 0) {
1.46 chs 511: simple_unlock(&vp->v_interlock);
1.39 chs 512: }
513: return EINVAL;
514: }
515: return genfs_getpages(v);
1.49 chs 516: }
517:
518: int
519: ffs_putpages(void *v)
520: {
521: struct vop_putpages_args /* {
522: struct vnode *a_vp;
523: voff_t a_offlo;
524: voff_t a_offhi;
525: int a_flags;
526: } */ *ap = v;
527: struct vnode *vp = ap->a_vp;
528: struct uvm_object *uobj = &vp->v_uobj;
529: struct inode *ip = VTOI(vp);
530: struct fs *fs = ip->i_fs;
531: struct vm_page *pg;
532: off_t off;
533:
534: if (!DOINGSOFTDEP(vp) || (ap->a_flags & PGO_CLEANIT) == 0) {
535: return genfs_putpages(v);
536: }
537:
538: /*
539: * for softdep files, force the pages in a block to be written together.
540: * if we're the pagedaemon and we would have to wait for other pages,
541: * just fail the request. the pagedaemon will pick a different page.
542: */
543:
544: ap->a_offlo &= ~fs->fs_qbmask;
545: ap->a_offhi = blkroundup(fs, ap->a_offhi);
546: if (curproc == uvm.pagedaemon_proc) {
547: for (off = ap->a_offlo; off < ap->a_offhi; off += PAGE_SIZE) {
548: pg = uvm_pagelookup(uobj, off);
549:
550: /*
551: * we only have missing pages here because the
552: * calculation of offhi above doesn't account for
553: * fragments. so once we see one missing page,
554: * the rest should be missing as well, but we'll
555: * check for the rest just to be paranoid.
556: */
557:
558: if (pg == NULL) {
559: continue;
560: }
561: if (pg->flags & PG_BUSY) {
562: simple_unlock(&uobj->vmobjlock);
563: return EBUSY;
564: }
565: }
566: }
567: return genfs_putpages(v);
1.39 chs 568: }
569:
1.35 chs 570: /*
571: * Return the last logical file offset that should be written for this file
572: * if we're doing a write that ends at "size".
573: */
1.39 chs 574:
575: void
1.55 perseant 576: ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
1.35 chs 577: {
1.39 chs 578: struct inode *ip = VTOI(vp);
1.35 chs 579: struct fs *fs = ip->i_fs;
1.52 fvdl 580: daddr_t olbn, nlbn;
1.55 perseant 581:
582: KASSERT(flags & (GOP_SIZE_READ | GOP_SIZE_WRITE));
583: KASSERT((flags & (GOP_SIZE_READ | GOP_SIZE_WRITE))
584: != (GOP_SIZE_READ | GOP_SIZE_WRITE));
1.35 chs 585:
1.56 ! fvdl 586: olbn = lblkno(fs, ip->i_size);
1.39 chs 587: nlbn = lblkno(fs, size);
1.35 chs 588: if (nlbn < NDADDR && olbn <= nlbn) {
1.39 chs 589: *eobp = fragroundup(fs, size);
1.35 chs 590: } else {
1.39 chs 591: *eobp = blkroundup(fs, size);
1.35 chs 592: }
1.1 mycroft 593: }
CVSweb <webmaster@jp.NetBSD.org>