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