Home | History | Annotate | Line # | Download | only in ffs
ffs_vnops.c revision 1.18.4.1
      1  1.18.4.1       chs /*	$NetBSD: ffs_vnops.c,v 1.18.4.1 1999/06/07 04:25:34 chs 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.18.4.1       chs #if defined(_KERNEL) && !defined(_LKM)
     39  1.18.4.1       chs #include "opt_uvmhist.h"
     40  1.18.4.1       chs #endif
     41  1.18.4.1       chs 
     42       1.1   mycroft #include <sys/param.h>
     43       1.1   mycroft #include <sys/systm.h>
     44       1.1   mycroft #include <sys/resourcevar.h>
     45       1.1   mycroft #include <sys/kernel.h>
     46       1.1   mycroft #include <sys/file.h>
     47       1.1   mycroft #include <sys/stat.h>
     48       1.1   mycroft #include <sys/buf.h>
     49       1.1   mycroft #include <sys/proc.h>
     50       1.1   mycroft #include <sys/conf.h>
     51       1.1   mycroft #include <sys/mount.h>
     52       1.1   mycroft #include <sys/vnode.h>
     53      1.16   thorpej #include <sys/pool.h>
     54       1.6  christos #include <sys/signalvar.h>
     55  1.18.4.1       chs #include <sys/malloc.h>
     56       1.1   mycroft 
     57       1.1   mycroft #include <vm/vm.h>
     58      1.10       mrg #include <uvm/uvm_extern.h>
     59       1.1   mycroft 
     60       1.8   mycroft #include <miscfs/fifofs/fifo.h>
     61       1.8   mycroft #include <miscfs/genfs/genfs.h>
     62       1.1   mycroft #include <miscfs/specfs/specdev.h>
     63       1.1   mycroft 
     64       1.1   mycroft #include <ufs/ufs/quota.h>
     65       1.1   mycroft #include <ufs/ufs/inode.h>
     66       1.1   mycroft #include <ufs/ufs/dir.h>
     67       1.1   mycroft #include <ufs/ufs/ufs_extern.h>
     68       1.2   mycroft #include <ufs/ufs/ufsmount.h>
     69       1.1   mycroft 
     70       1.1   mycroft #include <ufs/ffs/fs.h>
     71       1.1   mycroft #include <ufs/ffs/ffs_extern.h>
     72       1.1   mycroft 
     73       1.1   mycroft /* Global vfs data structures for ufs. */
     74       1.6  christos int (**ffs_vnodeop_p) __P((void *));
     75       1.1   mycroft struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
     76       1.1   mycroft 	{ &vop_default_desc, vn_default_error },
     77       1.1   mycroft 	{ &vop_lookup_desc, ufs_lookup },		/* lookup */
     78       1.1   mycroft 	{ &vop_create_desc, ufs_create },		/* create */
     79       1.5   mycroft 	{ &vop_whiteout_desc, ufs_whiteout },		/* whiteout */
     80       1.1   mycroft 	{ &vop_mknod_desc, ufs_mknod },			/* mknod */
     81       1.1   mycroft 	{ &vop_open_desc, ufs_open },			/* open */
     82       1.1   mycroft 	{ &vop_close_desc, ufs_close },			/* close */
     83       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
     84       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
     85       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
     86       1.1   mycroft 	{ &vop_read_desc, ffs_read },			/* read */
     87       1.1   mycroft 	{ &vop_write_desc, ffs_write },			/* write */
     88       1.4   mycroft 	{ &vop_lease_desc, ufs_lease_check },		/* lease */
     89       1.1   mycroft 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
     90       1.9   mycroft 	{ &vop_poll_desc, ufs_poll },			/* poll */
     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.1   mycroft 	{ &vop_reallocblks_desc, ffs_reallocblks },	/* reallocblks */
    117       1.1   mycroft 	{ &vop_vfree_desc, ffs_vfree },			/* vfree */
    118       1.1   mycroft 	{ &vop_truncate_desc, ffs_truncate },		/* truncate */
    119       1.1   mycroft 	{ &vop_update_desc, ffs_update },		/* update */
    120       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    121  1.18.4.1       chs 	{ &vop_getpages_desc, ffs_getpages },		/* getpages */
    122  1.18.4.1       chs 	{ &vop_putpages_desc, ffs_putpages },		/* putpages */
    123  1.18.4.1       chs 	{ NULL, NULL }
    124       1.1   mycroft };
    125       1.1   mycroft struct vnodeopv_desc ffs_vnodeop_opv_desc =
    126       1.1   mycroft 	{ &ffs_vnodeop_p, ffs_vnodeop_entries };
    127       1.1   mycroft 
    128       1.6  christos int (**ffs_specop_p) __P((void *));
    129       1.1   mycroft struct vnodeopv_entry_desc ffs_specop_entries[] = {
    130       1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    131       1.1   mycroft 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
    132       1.1   mycroft 	{ &vop_create_desc, spec_create },		/* create */
    133       1.1   mycroft 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
    134       1.1   mycroft 	{ &vop_open_desc, spec_open },			/* open */
    135       1.1   mycroft 	{ &vop_close_desc, ufsspec_close },		/* close */
    136       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    137       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
    138       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    139       1.1   mycroft 	{ &vop_read_desc, ufsspec_read },		/* read */
    140       1.1   mycroft 	{ &vop_write_desc, ufsspec_write },		/* write */
    141       1.4   mycroft 	{ &vop_lease_desc, spec_lease_check },		/* lease */
    142       1.1   mycroft 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
    143       1.9   mycroft 	{ &vop_poll_desc, spec_poll },			/* poll */
    144      1.12      fvdl 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
    145       1.1   mycroft 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
    146       1.1   mycroft 	{ &vop_fsync_desc, ffs_fsync },			/* fsync */
    147       1.1   mycroft 	{ &vop_seek_desc, spec_seek },			/* seek */
    148       1.1   mycroft 	{ &vop_remove_desc, spec_remove },		/* remove */
    149       1.1   mycroft 	{ &vop_link_desc, spec_link },			/* link */
    150       1.1   mycroft 	{ &vop_rename_desc, spec_rename },		/* rename */
    151       1.1   mycroft 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
    152       1.1   mycroft 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
    153       1.1   mycroft 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
    154       1.1   mycroft 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
    155       1.1   mycroft 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
    156       1.1   mycroft 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
    157       1.1   mycroft 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
    158       1.1   mycroft 	{ &vop_reclaim_desc, ffs_reclaim },		/* reclaim */
    159       1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    160       1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    161       1.1   mycroft 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
    162       1.1   mycroft 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
    163       1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    164       1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    165       1.1   mycroft 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
    166       1.1   mycroft 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
    167       1.1   mycroft 	{ &vop_blkatoff_desc, spec_blkatoff },		/* blkatoff */
    168       1.1   mycroft 	{ &vop_valloc_desc, spec_valloc },		/* valloc */
    169       1.1   mycroft 	{ &vop_reallocblks_desc, spec_reallocblks },	/* reallocblks */
    170       1.1   mycroft 	{ &vop_vfree_desc, ffs_vfree },			/* vfree */
    171       1.1   mycroft 	{ &vop_truncate_desc, spec_truncate },		/* truncate */
    172       1.1   mycroft 	{ &vop_update_desc, ffs_update },		/* update */
    173       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    174       1.6  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    175       1.1   mycroft };
    176       1.1   mycroft struct vnodeopv_desc ffs_specop_opv_desc =
    177       1.1   mycroft 	{ &ffs_specop_p, ffs_specop_entries };
    178       1.1   mycroft 
    179       1.6  christos int (**ffs_fifoop_p) __P((void *));
    180       1.1   mycroft struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
    181       1.1   mycroft 	{ &vop_default_desc, vn_default_error },
    182       1.1   mycroft 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
    183       1.1   mycroft 	{ &vop_create_desc, fifo_create },		/* create */
    184       1.1   mycroft 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
    185       1.1   mycroft 	{ &vop_open_desc, fifo_open },			/* open */
    186       1.1   mycroft 	{ &vop_close_desc, ufsfifo_close },		/* close */
    187       1.1   mycroft 	{ &vop_access_desc, ufs_access },		/* access */
    188       1.1   mycroft 	{ &vop_getattr_desc, ufs_getattr },		/* getattr */
    189       1.1   mycroft 	{ &vop_setattr_desc, ufs_setattr },		/* setattr */
    190       1.1   mycroft 	{ &vop_read_desc, ufsfifo_read },		/* read */
    191       1.1   mycroft 	{ &vop_write_desc, ufsfifo_write },		/* write */
    192       1.4   mycroft 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
    193       1.1   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
    194       1.9   mycroft 	{ &vop_poll_desc, fifo_poll },			/* poll */
    195      1.12      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
    196       1.1   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
    197       1.1   mycroft 	{ &vop_fsync_desc, ffs_fsync },			/* fsync */
    198       1.1   mycroft 	{ &vop_seek_desc, fifo_seek },			/* seek */
    199       1.1   mycroft 	{ &vop_remove_desc, fifo_remove },		/* remove */
    200       1.1   mycroft 	{ &vop_link_desc, fifo_link },			/* link */
    201       1.1   mycroft 	{ &vop_rename_desc, fifo_rename },		/* rename */
    202       1.1   mycroft 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
    203       1.1   mycroft 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
    204       1.1   mycroft 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
    205       1.1   mycroft 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
    206       1.1   mycroft 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
    207       1.1   mycroft 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
    208       1.1   mycroft 	{ &vop_inactive_desc, ufs_inactive },		/* inactive */
    209       1.1   mycroft 	{ &vop_reclaim_desc, ffs_reclaim },		/* reclaim */
    210       1.1   mycroft 	{ &vop_lock_desc, ufs_lock },			/* lock */
    211       1.1   mycroft 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
    212       1.1   mycroft 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
    213       1.1   mycroft 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
    214       1.1   mycroft 	{ &vop_print_desc, ufs_print },			/* print */
    215       1.1   mycroft 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
    216       1.1   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    217       1.1   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    218       1.1   mycroft 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
    219       1.1   mycroft 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
    220       1.1   mycroft 	{ &vop_reallocblks_desc, fifo_reallocblks },	/* reallocblks */
    221       1.1   mycroft 	{ &vop_vfree_desc, ffs_vfree },			/* vfree */
    222       1.1   mycroft 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
    223       1.1   mycroft 	{ &vop_update_desc, ffs_update },		/* update */
    224       1.8   mycroft 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
    225       1.6  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    226       1.1   mycroft };
    227       1.1   mycroft struct vnodeopv_desc ffs_fifoop_opv_desc =
    228       1.1   mycroft 	{ &ffs_fifoop_p, ffs_fifoop_entries };
    229       1.1   mycroft 
    230  1.18.4.1       chs int doclusterread = 0;
    231  1.18.4.1       chs int doclusterwrite = 0;
    232       1.1   mycroft 
    233       1.1   mycroft #include <ufs/ufs/ufs_readwrite.c>
    234       1.1   mycroft 
    235       1.1   mycroft /*
    236       1.1   mycroft  * Reclaim an inode so that it can be used for other purposes.
    237       1.1   mycroft  */
    238       1.1   mycroft int
    239       1.6  christos ffs_reclaim(v)
    240       1.6  christos 	void *v;
    241       1.6  christos {
    242       1.1   mycroft 	struct vop_reclaim_args /* {
    243       1.1   mycroft 		struct vnode *a_vp;
    244      1.12      fvdl 		struct proc *a_p;
    245       1.6  christos 	} */ *ap = v;
    246       1.1   mycroft 	register struct vnode *vp = ap->a_vp;
    247       1.1   mycroft 	int error;
    248       1.1   mycroft 
    249      1.12      fvdl 	if ((error = ufs_reclaim(vp, ap->a_p)) != 0)
    250       1.1   mycroft 		return (error);
    251  1.18.4.1       chs 
    252      1.16   thorpej 	/*
    253      1.16   thorpej 	 * XXX MFS ends up here, too, to free an inode.  Should we create
    254      1.16   thorpej 	 * XXX a separate pool for MFS inodes?
    255      1.16   thorpej 	 */
    256      1.16   thorpej 	pool_put(&ffs_inode_pool, vp->v_data);
    257       1.1   mycroft 	vp->v_data = NULL;
    258       1.1   mycroft 	return (0);
    259  1.18.4.1       chs }
    260  1.18.4.1       chs 
    261  1.18.4.1       chs #include <uvm/uvm.h>
    262  1.18.4.1       chs 
    263  1.18.4.1       chs int
    264  1.18.4.1       chs ffs_getpages(v)
    265  1.18.4.1       chs 	void *v;
    266  1.18.4.1       chs {
    267  1.18.4.1       chs 	struct vop_getpages_args /* {
    268  1.18.4.1       chs 		struct vnode *a_vp;
    269  1.18.4.1       chs 		vaddr_t a_offset;
    270  1.18.4.1       chs 		vm_page_t *a_m;
    271  1.18.4.1       chs 		int *a_count;
    272  1.18.4.1       chs 		int a_centeridx;
    273  1.18.4.1       chs 		vm_prot_t a_access_type;
    274  1.18.4.1       chs 		int a_advice;
    275  1.18.4.1       chs 		int a_flags;
    276  1.18.4.1       chs 	} */ *ap = v;
    277  1.18.4.1       chs 
    278  1.18.4.1       chs 	int error, npages, cidx, i;
    279  1.18.4.1       chs 	struct buf tmpbuf, *bp;
    280  1.18.4.1       chs 	struct vnode *vp = ap->a_vp;
    281  1.18.4.1       chs 	struct uvm_object *uobj = &vp->v_uvm.u_obj;
    282  1.18.4.1       chs 	struct inode *ip = VTOI(vp);
    283  1.18.4.1       chs 	struct fs *fs = ip->i_fs;
    284  1.18.4.1       chs 	struct vm_page *pg, *pgs[16];  /* XXX 16 */
    285  1.18.4.1       chs 	struct ucred *cred = curproc->p_ucred;
    286  1.18.4.1       chs 	off_t offset;
    287  1.18.4.1       chs 	UVMHIST_FUNC("ffs_getpages"); UVMHIST_CALLED(ubchist);
    288  1.18.4.1       chs 
    289  1.18.4.1       chs #ifdef DIAGNOSTIC
    290  1.18.4.1       chs 	if (ap->a_centeridx < 0 || ap->a_centeridx > *ap->a_count) {
    291  1.18.4.1       chs 		panic("ffs_getpages: centeridx %d out of range",
    292  1.18.4.1       chs 		      ap->a_centeridx);
    293  1.18.4.1       chs 	}
    294  1.18.4.1       chs #endif
    295  1.18.4.1       chs 
    296  1.18.4.1       chs 	if (ap->a_flags & PGO_LOCKED) {
    297  1.18.4.1       chs 		uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m,
    298  1.18.4.1       chs 			      UFP_NOWAIT|UFP_NOALLOC|UFP_NORDONLY);
    299  1.18.4.1       chs 
    300  1.18.4.1       chs 		/* XXX PGO_ALLPAGES? */
    301  1.18.4.1       chs 		return ap->a_m[ap->a_centeridx] == NULL ?
    302  1.18.4.1       chs 			VM_PAGER_UNLOCK : VM_PAGER_OK;
    303  1.18.4.1       chs 	}
    304  1.18.4.1       chs 
    305  1.18.4.1       chs 	/* vnode is VOP_LOCKed, uobj is locked */
    306  1.18.4.1       chs 
    307  1.18.4.1       chs 
    308  1.18.4.1       chs 	/*
    309  1.18.4.1       chs 	 * XXX do the findpages for our 1 page first,
    310  1.18.4.1       chs 	 * change asyncget to take the one page as an arg and
    311  1.18.4.1       chs 	 * pretend that its findpages found it.
    312  1.18.4.1       chs 	 */
    313  1.18.4.1       chs 
    314  1.18.4.1       chs 	/*
    315  1.18.4.1       chs 	 * kick off a big read first to get some readahead, then
    316  1.18.4.1       chs 	 * get the one page we wanted.
    317  1.18.4.1       chs 	 */
    318  1.18.4.1       chs 
    319  1.18.4.1       chs 	if ((ap->a_flags & PGO_OVERWRITE) == 0 &&
    320  1.18.4.1       chs 	    (ap->a_offset & (MAXBSIZE - 1)) == 0) {
    321  1.18.4.1       chs 		/*
    322  1.18.4.1       chs 		 * XXX pretty sure unlocking here is wrong.
    323  1.18.4.1       chs 		 */
    324  1.18.4.1       chs 		simple_unlock(&uobj->vmobjlock);
    325  1.18.4.1       chs 		uvm_vnp_asyncget(vp, ap->a_offset, MAXBSIZE, fs->fs_bsize);
    326  1.18.4.1       chs 		simple_lock(&uobj->vmobjlock);
    327  1.18.4.1       chs 	}
    328  1.18.4.1       chs 
    329  1.18.4.1       chs 	/*
    330  1.18.4.1       chs 	 * the desired page isn't resident, we'll have to read it.
    331  1.18.4.1       chs 	 */
    332  1.18.4.1       chs 
    333  1.18.4.1       chs 	offset = ap->a_offset + (ap->a_centeridx << PAGE_SHIFT);
    334  1.18.4.1       chs 	npages = 1;
    335  1.18.4.1       chs 	pg = NULL;
    336  1.18.4.1       chs 	uvn_findpages(uobj, offset, &npages, &pg, 0);
    337  1.18.4.1       chs 	simple_unlock(&uobj->vmobjlock);
    338  1.18.4.1       chs 
    339  1.18.4.1       chs 	/*
    340  1.18.4.1       chs 	 * if the page is already resident, just return it.
    341  1.18.4.1       chs 	 */
    342  1.18.4.1       chs 
    343  1.18.4.1       chs 	if ((pg->flags & PG_FAKE) == 0 &&
    344  1.18.4.1       chs 	    !((ap->a_access_type & VM_PROT_WRITE) && (pg->flags & PG_RDONLY))) {
    345  1.18.4.1       chs 		ap->a_m[ap->a_centeridx] = pg;
    346  1.18.4.1       chs 		return VM_PAGER_OK;
    347  1.18.4.1       chs 	}
    348  1.18.4.1       chs 
    349  1.18.4.1       chs 	UVMHIST_LOG(ubchist, "pg %p flags 0x%x access_type 0x%x",
    350  1.18.4.1       chs 		    pg, (int)pg->flags, (int)ap->a_access_type, 0);
    351  1.18.4.1       chs 
    352  1.18.4.1       chs 	/*
    353  1.18.4.1       chs 	 * ok, really read the desired page.
    354  1.18.4.1       chs 	 */
    355  1.18.4.1       chs 
    356  1.18.4.1       chs 	bp = &tmpbuf;
    357  1.18.4.1       chs 	bzero(bp, sizeof *bp);
    358  1.18.4.1       chs 	bp->b_lblkno = lblkno(fs, offset);
    359  1.18.4.1       chs 	error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
    360  1.18.4.1       chs 	if (error) {
    361  1.18.4.1       chs 		UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%x -> %d\n",
    362  1.18.4.1       chs 			    bp->b_lblkno, error,0,0);
    363  1.18.4.1       chs 		goto out;
    364  1.18.4.1       chs 	}
    365  1.18.4.1       chs 	if (bp->b_blkno == (daddr_t)-1) {
    366  1.18.4.1       chs 		UVMHIST_LOG(ubchist, "lbn 0x%x -> HOLE", bp->b_lblkno,0,0,0);
    367  1.18.4.1       chs 
    368  1.18.4.1       chs 		/*
    369  1.18.4.1       chs 		 * for read faults, we can skip the block allocation
    370  1.18.4.1       chs 		 * by marking the page PG_RDONLY and PG_CLEAN.
    371  1.18.4.1       chs 		 */
    372  1.18.4.1       chs 
    373  1.18.4.1       chs 		if ((ap->a_access_type & VM_PROT_WRITE) == 0) {
    374  1.18.4.1       chs 			uvm_pagezero(pg);
    375  1.18.4.1       chs 			pg->flags |= PG_CLEAN|PG_RDONLY;
    376  1.18.4.1       chs 			UVMHIST_LOG(ubchist, "setting PG_RDONLY", 0,0,0,0);
    377  1.18.4.1       chs 			goto out;
    378  1.18.4.1       chs 		}
    379  1.18.4.1       chs 
    380  1.18.4.1       chs 		/*
    381  1.18.4.1       chs 		 * for write faults, we must now allocate the backing store
    382  1.18.4.1       chs 		 * and make sure the block is zeroed.
    383  1.18.4.1       chs 		 */
    384  1.18.4.1       chs 
    385  1.18.4.1       chs 		error = ffs_balloc(ip, bp->b_lblkno,
    386  1.18.4.1       chs 				   blksize(fs, ip, bp->b_lblkno),
    387  1.18.4.1       chs 				   cred, NULL, &bp->b_blkno, 0);
    388  1.18.4.1       chs 		if (error) {
    389  1.18.4.1       chs 			UVMHIST_LOG(ubchist, "ffs_balloc lbn 0x%x -> %d",
    390  1.18.4.1       chs 				    bp->b_lblkno, error,0,0);
    391  1.18.4.1       chs 			goto out;
    392  1.18.4.1       chs 		}
    393  1.18.4.1       chs 
    394  1.18.4.1       chs 		simple_lock(&uobj->vmobjlock);
    395  1.18.4.1       chs 		uvm_pager_dropcluster(uobj, NULL, &pg, &npages, 0, 0);
    396  1.18.4.1       chs 		npages = fs->fs_bsize >> PAGE_SHIFT;
    397  1.18.4.1       chs 		uvn_findpages(uobj, offset & ~((off_t)fs->fs_bsize - 1),
    398  1.18.4.1       chs 			      &npages, pgs, 0);
    399  1.18.4.1       chs 		for (i = 0; i < npages; i++) {
    400  1.18.4.1       chs 			uvm_pagezero(pgs[i]);
    401  1.18.4.1       chs 			uvm_pageactivate(pgs[i]);
    402  1.18.4.1       chs 
    403  1.18.4.1       chs 			/*
    404  1.18.4.1       chs 			 * don't bother clearing mod/ref, the block is
    405  1.18.4.1       chs 			 * being modified anyways.
    406  1.18.4.1       chs 			 */
    407  1.18.4.1       chs 
    408  1.18.4.1       chs 			pgs[i]->flags &= ~(PG_FAKE|PG_RDONLY);
    409  1.18.4.1       chs 		}
    410  1.18.4.1       chs 		cidx = (offset >> PAGE_SHIFT) - (pgs[0]->offset >> PAGE_SHIFT);
    411  1.18.4.1       chs 		pg = pgs[cidx];
    412  1.18.4.1       chs 		pgs[cidx] = NULL;
    413  1.18.4.1       chs 		uvm_pager_dropcluster(uobj, NULL, pgs, &npages, 0, 0);
    414  1.18.4.1       chs 		simple_unlock(&uobj->vmobjlock);
    415  1.18.4.1       chs 		UVMHIST_LOG(ubchist, "cleared pages",0,0,0,0);
    416  1.18.4.1       chs 		goto out;
    417  1.18.4.1       chs 	}
    418  1.18.4.1       chs 
    419  1.18.4.1       chs 	/* adjust physical blkno for partial blocks */
    420  1.18.4.1       chs 	bp->b_blkno += (offset - lblktosize(fs, bp->b_lblkno)) >> DEV_BSHIFT;
    421  1.18.4.1       chs 	UVMHIST_LOG(ubchist, "vp %p bp %p lblkno 0x%x blkno 0x%x",
    422  1.18.4.1       chs 		    vp, bp, bp->b_lblkno, bp->b_blkno);
    423  1.18.4.1       chs 
    424  1.18.4.1       chs 	/*
    425  1.18.4.1       chs 	 * don't bother reading the pages if we're just going to
    426  1.18.4.1       chs 	 * overwrite them.
    427  1.18.4.1       chs 	 */
    428  1.18.4.1       chs 	if (ap->a_flags & PGO_OVERWRITE) {
    429  1.18.4.1       chs 		UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
    430  1.18.4.1       chs 
    431  1.18.4.1       chs 		/* XXX for now, zero the page */
    432  1.18.4.1       chs 		if (pg->flags & PG_FAKE) {
    433  1.18.4.1       chs 			uvm_pagezero(pg);
    434  1.18.4.1       chs 		}
    435  1.18.4.1       chs 
    436  1.18.4.1       chs 		goto out;
    437  1.18.4.1       chs 	}
    438  1.18.4.1       chs 
    439  1.18.4.1       chs 	bp->b_bufsize = PAGE_SIZE;
    440  1.18.4.1       chs 	bp->b_data = (void *)uvm_pagermapin(&pg, 1, NULL, M_WAITOK);
    441  1.18.4.1       chs 	bp->b_bcount = bp->b_lblkno < 0 ? bp->b_bufsize :
    442  1.18.4.1       chs 		min(bp->b_bufsize, fragroundup(fs, vp->v_uvm.u_size - offset));
    443  1.18.4.1       chs 	bp->b_vp = vp;
    444  1.18.4.1       chs 	bp->b_flags = B_BUSY|B_READ;
    445  1.18.4.1       chs 	VOP_STRATEGY(bp);
    446  1.18.4.1       chs 	error = biowait(bp);
    447  1.18.4.1       chs 	uvm_pagermapout((vaddr_t)bp->b_data, *ap->a_count);
    448  1.18.4.1       chs 
    449  1.18.4.1       chs out:
    450  1.18.4.1       chs 	if (error) {
    451  1.18.4.1       chs 		simple_lock(&uobj->vmobjlock);
    452  1.18.4.1       chs 		if (pg->flags & PG_WANTED) {
    453  1.18.4.1       chs 			wakeup(pg);
    454  1.18.4.1       chs 		}
    455  1.18.4.1       chs 		UVM_PAGE_OWN(pg, NULL);
    456  1.18.4.1       chs 		uvm_lock_pageq();
    457  1.18.4.1       chs 		uvm_pagefree(pg);
    458  1.18.4.1       chs 		uvm_unlock_pageq();
    459  1.18.4.1       chs 		simple_unlock(&uobj->vmobjlock);
    460  1.18.4.1       chs 	} else {
    461  1.18.4.1       chs 		pg->flags &= ~(PG_FAKE);
    462  1.18.4.1       chs 		pmap_clear_modify(PMAP_PGARG(pg));
    463  1.18.4.1       chs 		pmap_clear_reference(PMAP_PGARG(pg));
    464  1.18.4.1       chs 		uvm_pageactivate(pg);
    465  1.18.4.1       chs 		ap->a_m[ap->a_centeridx] = pg;
    466  1.18.4.1       chs 	}
    467  1.18.4.1       chs 	UVMHIST_LOG(ubchist, "returning, error %d", error,0,0,0);
    468  1.18.4.1       chs 	return error ? VM_PAGER_ERROR : VM_PAGER_OK;
    469  1.18.4.1       chs }
    470  1.18.4.1       chs 
    471  1.18.4.1       chs /*
    472  1.18.4.1       chs  * Vnode op for VM putpages.
    473  1.18.4.1       chs  */
    474  1.18.4.1       chs int
    475  1.18.4.1       chs ffs_putpages(v)
    476  1.18.4.1       chs 	void *v;
    477  1.18.4.1       chs {
    478  1.18.4.1       chs 	struct vop_putpages_args /* {
    479  1.18.4.1       chs 		struct vnode *a_vp;
    480  1.18.4.1       chs 		struct vm_page **a_m;
    481  1.18.4.1       chs 		int a_count;
    482  1.18.4.1       chs 		int a_sync;
    483  1.18.4.1       chs 		int *a_rtvals;
    484  1.18.4.1       chs 	} */ *ap = v;
    485  1.18.4.1       chs 
    486  1.18.4.1       chs 	int s, error;
    487  1.18.4.1       chs 	int bsize;
    488  1.18.4.1       chs 	vaddr_t kva, offset;
    489  1.18.4.1       chs 	struct vm_page *pg;
    490  1.18.4.1       chs 	struct buf tmpbuf, *bp;
    491  1.18.4.1       chs 	struct vnode *vp = ap->a_vp;
    492  1.18.4.1       chs 	struct inode *ip = VTOI(vp);
    493  1.18.4.1       chs 	struct fs *fs = ip->i_fs;
    494  1.18.4.1       chs 	UVMHIST_FUNC("ffs_putpages"); UVMHIST_CALLED(ubchist);
    495  1.18.4.1       chs 
    496  1.18.4.1       chs 	pg = ap->a_m[0];
    497  1.18.4.1       chs 
    498  1.18.4.1       chs #ifdef DEBUG
    499  1.18.4.1       chs 	/* XXX verify that pages given are in fact physically contiguous. */
    500  1.18.4.1       chs #endif
    501  1.18.4.1       chs 
    502  1.18.4.1       chs 	kva = uvm_pagermapin(ap->a_m, ap->a_count, NULL, M_WAITOK);
    503  1.18.4.1       chs 	if (kva == 0) {
    504  1.18.4.1       chs 		return VM_PAGER_AGAIN;
    505  1.18.4.1       chs 	}
    506  1.18.4.1       chs 
    507  1.18.4.1       chs 	if (ap->a_sync) {
    508  1.18.4.1       chs 		bp = &tmpbuf;
    509  1.18.4.1       chs 		bzero(bp, sizeof *bp);
    510  1.18.4.1       chs 	}
    511  1.18.4.1       chs 	else {
    512  1.18.4.1       chs 		struct uvm_aiobuf *abp = pool_get(uvm_aiobuf_pool, PR_WAITOK);
    513  1.18.4.1       chs 		abp->aio.aiodone = uvm_aio_aiodone;
    514  1.18.4.1       chs 		abp->aio.kva = kva;
    515  1.18.4.1       chs 		abp->aio.npages = ap->a_count;
    516  1.18.4.1       chs 		abp->aio.pd_ptr = abp;
    517  1.18.4.1       chs 		/* XXX pagedaemon */
    518  1.18.4.1       chs 		abp->aio.flags = (curproc == uvm.pagedaemon_proc) ?
    519  1.18.4.1       chs 			UVM_AIO_PAGEDAEMON : 0;
    520  1.18.4.1       chs 		bp = &abp->buf;
    521  1.18.4.1       chs 		bzero(bp, sizeof *bp);
    522  1.18.4.1       chs 		bp->b_flags = B_CALL|B_ASYNC;
    523  1.18.4.1       chs 		bp->b_iodone = uvm_aio_biodone;
    524  1.18.4.1       chs 	}
    525  1.18.4.1       chs 
    526  1.18.4.1       chs 	offset = pg->offset;
    527  1.18.4.1       chs 	bp->b_bufsize = ap->a_count << PAGE_SHIFT;
    528  1.18.4.1       chs 	bp->b_data = (void *)kva;
    529  1.18.4.1       chs 	bp->b_lblkno = lblkno(fs, offset);
    530  1.18.4.1       chs 	bp->b_bcount = min(bp->b_bufsize,
    531  1.18.4.1       chs 			   fragroundup(fs, vp->v_uvm.u_size - offset));
    532  1.18.4.1       chs 	bp->b_flags |= B_BUSY|B_WRITE;
    533  1.18.4.1       chs 	bp->b_vp = vp;
    534  1.18.4.1       chs 
    535  1.18.4.1       chs 
    536  1.18.4.1       chs 	bsize = blksize(fs, ip, bp->b_lblkno);
    537  1.18.4.1       chs 	error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
    538  1.18.4.1       chs 	if (error) {
    539  1.18.4.1       chs 		UVMHIST_LOG(ubchist, "ffs_balloc -> %d", error, 0,0,0);
    540  1.18.4.1       chs 		goto out;
    541  1.18.4.1       chs 	}
    542  1.18.4.1       chs 
    543  1.18.4.1       chs 	/* this could be ifdef DIAGNOSTIC, but it's really important */
    544  1.18.4.1       chs 	if (bp->b_blkno == (daddr_t)-1) {
    545  1.18.4.1       chs 		panic("ffs_putpages: no backing store vp %p lbn 0x%x",
    546  1.18.4.1       chs 		      vp, bp->b_lblkno);
    547  1.18.4.1       chs 	}
    548  1.18.4.1       chs 
    549  1.18.4.1       chs 	/* adjust physical blkno for partial blocks */
    550  1.18.4.1       chs 	bp->b_blkno += (offset - lblktosize(fs, bp->b_lblkno)) >> DEV_BSHIFT;
    551  1.18.4.1       chs 	UVMHIST_LOG(ubchist, "pg %p vp %p lblkno 0x%x blkno 0x%x",
    552  1.18.4.1       chs 		    pg, vp, bp->b_lblkno, bp->b_blkno);
    553  1.18.4.1       chs 
    554  1.18.4.1       chs 	s = splbio();
    555  1.18.4.1       chs 	vp->v_numoutput++;
    556  1.18.4.1       chs 	splx(s);
    557  1.18.4.1       chs 	VOP_STRATEGY(bp);
    558  1.18.4.1       chs 	if (!ap->a_sync) {
    559  1.18.4.1       chs 		return VM_PAGER_PEND;
    560  1.18.4.1       chs 	}
    561  1.18.4.1       chs 	error = biowait(bp);
    562  1.18.4.1       chs 
    563  1.18.4.1       chs out:
    564  1.18.4.1       chs 	uvm_pagermapout(kva, ap->a_count);
    565  1.18.4.1       chs 	UVMHIST_LOG(ubchist, "returning, error %d", error,0,0,0);
    566  1.18.4.1       chs 
    567  1.18.4.1       chs 	return error ? VM_PAGER_ERROR : VM_PAGER_OK;
    568       1.1   mycroft }
    569