Home | History | Annotate | Line # | Download | only in uvm
uvm_vnode.c revision 1.46.2.10
      1  1.46.2.10  nathanw /*	$NetBSD: uvm_vnode.c,v 1.46.2.10 2002/06/24 22:13:01 nathanw Exp $	*/
      2        1.1      mrg 
      3        1.1      mrg /*
      4        1.1      mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5        1.1      mrg  * Copyright (c) 1991, 1993
      6   1.46.2.3  nathanw  *      The Regents of the University of California.
      7        1.1      mrg  * Copyright (c) 1990 University of Utah.
      8        1.1      mrg  *
      9        1.1      mrg  * All rights reserved.
     10        1.1      mrg  *
     11        1.1      mrg  * This code is derived from software contributed to Berkeley by
     12        1.1      mrg  * the Systems Programming Group of the University of Utah Computer
     13        1.1      mrg  * Science Department.
     14        1.1      mrg  *
     15        1.1      mrg  * Redistribution and use in source and binary forms, with or without
     16        1.1      mrg  * modification, are permitted provided that the following conditions
     17        1.1      mrg  * are met:
     18        1.1      mrg  * 1. Redistributions of source code must retain the above copyright
     19        1.1      mrg  *    notice, this list of conditions and the following disclaimer.
     20        1.1      mrg  * 2. Redistributions in binary form must reproduce the above copyright
     21        1.1      mrg  *    notice, this list of conditions and the following disclaimer in the
     22        1.1      mrg  *    documentation and/or other materials provided with the distribution.
     23        1.1      mrg  * 3. All advertising materials mentioning features or use of this software
     24        1.1      mrg  *    must display the following acknowledgement:
     25        1.1      mrg  *      This product includes software developed by Charles D. Cranor,
     26   1.46.2.3  nathanw  *	Washington University, the University of California, Berkeley and
     27        1.1      mrg  *	its contributors.
     28        1.1      mrg  * 4. Neither the name of the University nor the names of its contributors
     29        1.1      mrg  *    may be used to endorse or promote products derived from this software
     30        1.1      mrg  *    without specific prior written permission.
     31        1.1      mrg  *
     32        1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33        1.1      mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34        1.1      mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35        1.1      mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36        1.1      mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37        1.1      mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38        1.1      mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39        1.1      mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40        1.1      mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41        1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42        1.1      mrg  * SUCH DAMAGE.
     43        1.1      mrg  *
     44        1.1      mrg  *      @(#)vnode_pager.c       8.8 (Berkeley) 2/13/94
     45        1.3      mrg  * from: Id: uvm_vnode.c,v 1.1.2.26 1998/02/02 20:38:07 chuck Exp
     46        1.1      mrg  */
     47        1.1      mrg 
     48        1.1      mrg /*
     49        1.1      mrg  * uvm_vnode.c: the vnode pager.
     50        1.1      mrg  */
     51   1.46.2.7  nathanw 
     52   1.46.2.7  nathanw #include <sys/cdefs.h>
     53  1.46.2.10  nathanw __KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.46.2.10 2002/06/24 22:13:01 nathanw Exp $");
     54   1.46.2.7  nathanw 
     55   1.46.2.7  nathanw #include "fs_nfs.h"
     56   1.46.2.7  nathanw #include "opt_uvmhist.h"
     57   1.46.2.7  nathanw #include "opt_ddb.h"
     58        1.1      mrg 
     59        1.1      mrg #include <sys/param.h>
     60        1.1      mrg #include <sys/systm.h>
     61   1.46.2.1  nathanw #include <sys/lwp.h>
     62       1.37      chs #include <sys/kernel.h>
     63        1.1      mrg #include <sys/proc.h>
     64        1.1      mrg #include <sys/malloc.h>
     65        1.1      mrg #include <sys/vnode.h>
     66       1.13  thorpej #include <sys/disklabel.h>
     67       1.13  thorpej #include <sys/ioctl.h>
     68       1.13  thorpej #include <sys/fcntl.h>
     69       1.13  thorpej #include <sys/conf.h>
     70       1.37      chs #include <sys/pool.h>
     71       1.37      chs #include <sys/mount.h>
     72       1.13  thorpej 
     73       1.13  thorpej #include <miscfs/specfs/specdev.h>
     74        1.1      mrg 
     75        1.1      mrg #include <uvm/uvm.h>
     76        1.1      mrg 
     77        1.1      mrg /*
     78        1.1      mrg  * functions
     79        1.1      mrg  */
     80        1.1      mrg 
     81   1.46.2.5  nathanw void	uvn_detach __P((struct uvm_object *));
     82   1.46.2.5  nathanw int	uvn_get __P((struct uvm_object *, voff_t, struct vm_page **, int *, int,
     83   1.46.2.5  nathanw 	    vm_prot_t, int, int));
     84   1.46.2.5  nathanw int	uvn_put __P((struct uvm_object *, voff_t, voff_t, int));
     85   1.46.2.5  nathanw void	uvn_reference __P((struct uvm_object *));
     86   1.46.2.5  nathanw 
     87   1.46.2.5  nathanw int	uvn_findpage __P((struct uvm_object *, voff_t, struct vm_page **, int));
     88        1.1      mrg 
     89        1.1      mrg /*
     90        1.1      mrg  * master pager structure
     91        1.1      mrg  */
     92        1.1      mrg 
     93        1.1      mrg struct uvm_pagerops uvm_vnodeops = {
     94       1.37      chs 	NULL,
     95        1.8      mrg 	uvn_reference,
     96        1.8      mrg 	uvn_detach,
     97       1.37      chs 	NULL,
     98        1.8      mrg 	uvn_get,
     99        1.8      mrg 	uvn_put,
    100        1.1      mrg };
    101        1.1      mrg 
    102        1.1      mrg /*
    103        1.1      mrg  * the ops!
    104        1.1      mrg  */
    105        1.1      mrg 
    106        1.1      mrg /*
    107        1.1      mrg  * uvn_attach
    108        1.1      mrg  *
    109        1.1      mrg  * attach a vnode structure to a VM object.  if the vnode is already
    110        1.1      mrg  * attached, then just bump the reference count by one and return the
    111        1.1      mrg  * VM object.   if not already attached, attach and return the new VM obj.
    112        1.1      mrg  * the "accessprot" tells the max access the attaching thread wants to
    113        1.1      mrg  * our pages.
    114        1.1      mrg  *
    115        1.1      mrg  * => caller must _not_ already be holding the lock on the uvm_object.
    116        1.1      mrg  * => in fact, nothing should be locked so that we can sleep here.
    117        1.1      mrg  * => note that uvm_object is first thing in vnode structure, so their
    118        1.1      mrg  *    pointers are equiv.
    119        1.1      mrg  */
    120        1.1      mrg 
    121        1.8      mrg struct uvm_object *
    122        1.8      mrg uvn_attach(arg, accessprot)
    123        1.8      mrg 	void *arg;
    124        1.8      mrg 	vm_prot_t accessprot;
    125        1.8      mrg {
    126        1.8      mrg 	struct vnode *vp = arg;
    127   1.46.2.5  nathanw 	struct uvm_object *uobj = &vp->v_uobj;
    128        1.8      mrg 	struct vattr vattr;
    129       1.37      chs 	int result;
    130       1.13  thorpej 	struct partinfo pi;
    131       1.37      chs 	voff_t used_vnode_size;
    132        1.8      mrg 	UVMHIST_FUNC("uvn_attach"); UVMHIST_CALLED(maphist);
    133        1.8      mrg 
    134        1.8      mrg 	UVMHIST_LOG(maphist, "(vn=0x%x)", arg,0,0,0);
    135       1.37      chs 	used_vnode_size = (voff_t)0;
    136       1.13  thorpej 
    137        1.8      mrg 	/*
    138   1.46.2.5  nathanw 	 * first get a lock on the uobj.
    139        1.8      mrg 	 */
    140   1.46.2.5  nathanw 
    141   1.46.2.5  nathanw 	simple_lock(&uobj->vmobjlock);
    142   1.46.2.5  nathanw 	while (vp->v_flag & VXLOCK) {
    143   1.46.2.5  nathanw 		vp->v_flag |= VXWANT;
    144        1.8      mrg 		UVMHIST_LOG(maphist, "  SLEEPING on blocked vn",0,0,0,0);
    145   1.46.2.5  nathanw 		UVM_UNLOCK_AND_WAIT(uobj, &uobj->vmobjlock, FALSE,
    146        1.8      mrg 		    "uvn_attach", 0);
    147   1.46.2.5  nathanw 		simple_lock(&uobj->vmobjlock);
    148        1.8      mrg 		UVMHIST_LOG(maphist,"  WOKE UP",0,0,0,0);
    149        1.8      mrg 	}
    150        1.1      mrg 
    151        1.8      mrg 	/*
    152       1.18   bouyer 	 * if we're mapping a BLK device, make sure it is a disk.
    153       1.13  thorpej 	 */
    154       1.13  thorpej 	if (vp->v_type == VBLK && bdevsw[major(vp->v_rdev)].d_type != D_DISK) {
    155   1.46.2.5  nathanw 		simple_unlock(&uobj->vmobjlock);
    156       1.13  thorpej 		UVMHIST_LOG(maphist,"<- done (VBLK not D_DISK!)", 0,0,0,0);
    157       1.13  thorpej 		return(NULL);
    158       1.13  thorpej 	}
    159   1.46.2.4  nathanw 	KASSERT(vp->v_type == VREG || vp->v_type == VBLK);
    160       1.37      chs 
    161       1.13  thorpej 	/*
    162       1.37      chs 	 * set up our idea of the size
    163       1.37      chs 	 * if this hasn't been done already.
    164        1.8      mrg 	 */
    165   1.46.2.5  nathanw 	if (vp->v_size == VSIZENOTSET) {
    166        1.8      mrg 
    167   1.46.2.5  nathanw 
    168   1.46.2.5  nathanw 	vp->v_flag |= VXLOCK;
    169   1.46.2.5  nathanw 	simple_unlock(&uobj->vmobjlock); /* drop lock in case we sleep */
    170  1.46.2.10  nathanw 		/* XXX: curlwp? */
    171       1.13  thorpej 	if (vp->v_type == VBLK) {
    172       1.13  thorpej 		/*
    173       1.13  thorpej 		 * We could implement this as a specfs getattr call, but:
    174       1.13  thorpej 		 *
    175       1.13  thorpej 		 *	(1) VOP_GETATTR() would get the file system
    176       1.13  thorpej 		 *	    vnode operation, not the specfs operation.
    177       1.13  thorpej 		 *
    178       1.13  thorpej 		 *	(2) All we want is the size, anyhow.
    179       1.13  thorpej 		 */
    180       1.13  thorpej 		result = (*bdevsw[major(vp->v_rdev)].d_ioctl)(vp->v_rdev,
    181  1.46.2.10  nathanw 		    DIOCGPART, (caddr_t)&pi, FREAD, curproc);
    182       1.13  thorpej 		if (result == 0) {
    183       1.13  thorpej 			/* XXX should remember blocksize */
    184       1.37      chs 			used_vnode_size = (voff_t)pi.disklab->d_secsize *
    185       1.37      chs 			    (voff_t)pi.part->p_size;
    186       1.13  thorpej 		}
    187       1.13  thorpej 	} else {
    188  1.46.2.10  nathanw 		result = VOP_GETATTR(vp, &vattr, curproc->p_ucred,
    189  1.46.2.10  nathanw 		    curproc);
    190       1.13  thorpej 		if (result == 0)
    191       1.13  thorpej 			used_vnode_size = vattr.va_size;
    192        1.8      mrg 	}
    193        1.1      mrg 
    194        1.8      mrg 	/* relock object */
    195   1.46.2.5  nathanw 	simple_lock(&uobj->vmobjlock);
    196       1.37      chs 
    197   1.46.2.5  nathanw 	if (vp->v_flag & VXWANT) {
    198   1.46.2.5  nathanw 		wakeup(vp);
    199   1.46.2.5  nathanw 	}
    200   1.46.2.5  nathanw 	vp->v_flag &= ~(VXLOCK|VXWANT);
    201        1.1      mrg 
    202        1.8      mrg 	if (result != 0) {
    203   1.46.2.5  nathanw 		simple_unlock(&uobj->vmobjlock);
    204        1.8      mrg 		UVMHIST_LOG(maphist,"<- done (VOP_GETATTR FAILED!)", 0,0,0,0);
    205        1.8      mrg 		return(NULL);
    206        1.8      mrg 	}
    207   1.46.2.5  nathanw 	vp->v_size = used_vnode_size;
    208        1.8      mrg 
    209        1.8      mrg 	}
    210        1.8      mrg 
    211   1.46.2.5  nathanw 	simple_unlock(&uobj->vmobjlock);
    212   1.46.2.5  nathanw 	UVMHIST_LOG(maphist,"<- done, refcnt=%d", vp->v_usecount,
    213       1.37      chs 	    0, 0, 0);
    214   1.46.2.5  nathanw 	return uobj;
    215        1.1      mrg }
    216        1.1      mrg 
    217        1.1      mrg 
    218        1.1      mrg /*
    219        1.1      mrg  * uvn_reference
    220        1.1      mrg  *
    221        1.1      mrg  * duplicate a reference to a VM object.  Note that the reference
    222   1.46.2.3  nathanw  * count must already be at least one (the passed in reference) so
    223        1.1      mrg  * there is no chance of the uvn being killed or locked out here.
    224        1.1      mrg  *
    225   1.46.2.3  nathanw  * => caller must call with object unlocked.
    226        1.1      mrg  * => caller must be using the same accessprot as was used at attach time
    227        1.1      mrg  */
    228        1.1      mrg 
    229   1.46.2.5  nathanw void
    230        1.8      mrg uvn_reference(uobj)
    231        1.8      mrg 	struct uvm_object *uobj;
    232        1.1      mrg {
    233       1.37      chs 	VREF((struct vnode *)uobj);
    234        1.1      mrg }
    235        1.1      mrg 
    236   1.46.2.5  nathanw 
    237        1.1      mrg /*
    238        1.1      mrg  * uvn_detach
    239        1.1      mrg  *
    240        1.1      mrg  * remove a reference to a VM object.
    241        1.1      mrg  *
    242        1.1      mrg  * => caller must call with object unlocked and map locked.
    243        1.1      mrg  */
    244   1.46.2.5  nathanw 
    245   1.46.2.5  nathanw void
    246        1.8      mrg uvn_detach(uobj)
    247        1.8      mrg 	struct uvm_object *uobj;
    248        1.8      mrg {
    249       1.37      chs 	vrele((struct vnode *)uobj);
    250        1.1      mrg }
    251        1.1      mrg 
    252        1.1      mrg /*
    253        1.1      mrg  * uvn_put: flush page data to backing store.
    254        1.1      mrg  *
    255   1.46.2.6  nathanw  * => object must be locked on entry!   VOP_PUTPAGES must unlock it.
    256        1.1      mrg  * => flags: PGO_SYNCIO -- use sync. I/O
    257        1.1      mrg  * => note: caller must set PG_CLEAN and pmap_clear_modify (if needed)
    258        1.1      mrg  */
    259        1.1      mrg 
    260   1.46.2.5  nathanw int
    261   1.46.2.6  nathanw uvn_put(uobj, offlo, offhi, flags)
    262        1.8      mrg 	struct uvm_object *uobj;
    263   1.46.2.6  nathanw 	voff_t offlo;
    264   1.46.2.6  nathanw 	voff_t offhi;
    265   1.46.2.5  nathanw 	int flags;
    266        1.1      mrg {
    267       1.37      chs 	struct vnode *vp = (struct vnode *)uobj;
    268       1.37      chs 	int error;
    269        1.1      mrg 
    270   1.46.2.6  nathanw 	LOCK_ASSERT(simple_lock_held(&vp->v_interlock));
    271   1.46.2.6  nathanw 	error = VOP_PUTPAGES(vp, offlo, offhi, flags);
    272   1.46.2.6  nathanw 	LOCK_ASSERT(!simple_lock_held(&vp->v_interlock));
    273   1.46.2.2  nathanw 	return error;
    274        1.1      mrg }
    275        1.1      mrg 
    276        1.1      mrg 
    277        1.1      mrg /*
    278        1.1      mrg  * uvn_get: get pages (synchronously) from backing store
    279        1.1      mrg  *
    280        1.1      mrg  * => prefer map unlocked (not required)
    281        1.1      mrg  * => object must be locked!  we will _unlock_ it before starting any I/O.
    282        1.1      mrg  * => flags: PGO_ALLPAGES: get all of the pages
    283        1.1      mrg  *           PGO_LOCKED: fault data structures are locked
    284        1.1      mrg  * => NOTE: offset is the offset of pps[0], _NOT_ pps[centeridx]
    285        1.1      mrg  * => NOTE: caller must check for released pages!!
    286        1.1      mrg  */
    287   1.46.2.3  nathanw 
    288   1.46.2.5  nathanw int
    289        1.8      mrg uvn_get(uobj, offset, pps, npagesp, centeridx, access_type, advice, flags)
    290        1.8      mrg 	struct uvm_object *uobj;
    291       1.30   kleink 	voff_t offset;
    292        1.8      mrg 	struct vm_page **pps;		/* IN/OUT */
    293        1.8      mrg 	int *npagesp;			/* IN (OUT if PGO_LOCKED) */
    294       1.37      chs 	int centeridx;
    295        1.8      mrg 	vm_prot_t access_type;
    296       1.37      chs 	int advice, flags;
    297        1.8      mrg {
    298       1.37      chs 	struct vnode *vp = (struct vnode *)uobj;
    299       1.37      chs 	int error;
    300       1.37      chs 	UVMHIST_FUNC("uvn_get"); UVMHIST_CALLED(ubchist);
    301       1.37      chs 
    302       1.37      chs 	UVMHIST_LOG(ubchist, "vp %p off 0x%x", vp, (int)offset, 0,0);
    303       1.37      chs 	error = VOP_GETPAGES(vp, offset, pps, npagesp, centeridx,
    304       1.37      chs 			     access_type, advice, flags);
    305   1.46.2.2  nathanw 	return error;
    306       1.37      chs }
    307        1.8      mrg 
    308        1.8      mrg 
    309       1.37      chs /*
    310       1.37      chs  * uvn_findpages:
    311       1.37      chs  * return the page for the uobj and offset requested, allocating if needed.
    312       1.37      chs  * => uobj must be locked.
    313   1.46.2.5  nathanw  * => returned pages will be BUSY.
    314       1.37      chs  */
    315        1.1      mrg 
    316   1.46.2.9  nathanw int
    317   1.46.2.5  nathanw uvn_findpages(uobj, offset, npagesp, pgs, flags)
    318       1.37      chs 	struct uvm_object *uobj;
    319       1.37      chs 	voff_t offset;
    320       1.37      chs 	int *npagesp;
    321   1.46.2.5  nathanw 	struct vm_page **pgs;
    322       1.37      chs 	int flags;
    323       1.37      chs {
    324   1.46.2.9  nathanw 	int i, count, found, npages, rv;
    325        1.8      mrg 
    326   1.46.2.9  nathanw 	count = found = 0;
    327       1.37      chs 	npages = *npagesp;
    328   1.46.2.5  nathanw 	if (flags & UFP_BACKWARD) {
    329   1.46.2.5  nathanw 		for (i = npages - 1; i >= 0; i--, offset -= PAGE_SIZE) {
    330   1.46.2.5  nathanw 			rv = uvn_findpage(uobj, offset, &pgs[i], flags);
    331   1.46.2.9  nathanw 			if (rv == 0) {
    332   1.46.2.9  nathanw 				if (flags & UFP_DIRTYONLY)
    333   1.46.2.9  nathanw 					break;
    334   1.46.2.9  nathanw 			} else
    335   1.46.2.9  nathanw 				found++;
    336   1.46.2.5  nathanw 			count++;
    337   1.46.2.5  nathanw 		}
    338   1.46.2.5  nathanw 	} else {
    339   1.46.2.5  nathanw 		for (i = 0; i < npages; i++, offset += PAGE_SIZE) {
    340   1.46.2.5  nathanw 			rv = uvn_findpage(uobj, offset, &pgs[i], flags);
    341   1.46.2.9  nathanw 			if (rv == 0) {
    342   1.46.2.9  nathanw 				if (flags & UFP_DIRTYONLY)
    343   1.46.2.9  nathanw 					break;
    344   1.46.2.9  nathanw 			} else
    345   1.46.2.9  nathanw 				found++;
    346   1.46.2.5  nathanw 			count++;
    347   1.46.2.5  nathanw 		}
    348       1.37      chs 	}
    349   1.46.2.5  nathanw 	*npagesp = count;
    350   1.46.2.9  nathanw 	return (found);
    351       1.37      chs }
    352        1.8      mrg 
    353   1.46.2.5  nathanw int
    354       1.37      chs uvn_findpage(uobj, offset, pgp, flags)
    355       1.37      chs 	struct uvm_object *uobj;
    356       1.37      chs 	voff_t offset;
    357       1.37      chs 	struct vm_page **pgp;
    358       1.37      chs 	int flags;
    359       1.37      chs {
    360       1.37      chs 	struct vm_page *pg;
    361   1.46.2.5  nathanw 	boolean_t dirty;
    362       1.37      chs 	UVMHIST_FUNC("uvn_findpage"); UVMHIST_CALLED(ubchist);
    363       1.37      chs 	UVMHIST_LOG(ubchist, "vp %p off 0x%lx", uobj, offset,0,0);
    364        1.8      mrg 
    365       1.37      chs 	if (*pgp != NULL) {
    366       1.37      chs 		UVMHIST_LOG(ubchist, "dontcare", 0,0,0,0);
    367       1.37      chs 		return 0;
    368       1.37      chs 	}
    369       1.37      chs 	for (;;) {
    370       1.37      chs 		/* look for an existing page */
    371       1.37      chs 		pg = uvm_pagelookup(uobj, offset);
    372       1.37      chs 
    373   1.46.2.5  nathanw 		/* nope?  allocate one now */
    374       1.37      chs 		if (pg == NULL) {
    375       1.37      chs 			if (flags & UFP_NOALLOC) {
    376       1.37      chs 				UVMHIST_LOG(ubchist, "noalloc", 0,0,0,0);
    377       1.37      chs 				return 0;
    378       1.37      chs 			}
    379   1.46.2.2  nathanw 			pg = uvm_pagealloc(uobj, offset, NULL, 0);
    380       1.37      chs 			if (pg == NULL) {
    381       1.37      chs 				if (flags & UFP_NOWAIT) {
    382       1.37      chs 					UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
    383       1.37      chs 					return 0;
    384        1.8      mrg 				}
    385       1.37      chs 				simple_unlock(&uobj->vmobjlock);
    386       1.37      chs 				uvm_wait("uvn_fp1");
    387        1.8      mrg 				simple_lock(&uobj->vmobjlock);
    388       1.37      chs 				continue;
    389        1.8      mrg 			}
    390   1.46.2.2  nathanw 			if (UVM_OBJ_IS_VTEXT(uobj)) {
    391   1.46.2.8  nathanw 				uvmexp.execpages++;
    392   1.46.2.2  nathanw 			} else {
    393   1.46.2.8  nathanw 				uvmexp.filepages++;
    394   1.46.2.2  nathanw 			}
    395   1.46.2.5  nathanw 			UVMHIST_LOG(ubchist, "alloced %p", pg,0,0,0);
    396       1.37      chs 			break;
    397       1.37      chs 		} else if (flags & UFP_NOCACHE) {
    398       1.37      chs 			UVMHIST_LOG(ubchist, "nocache",0,0,0,0);
    399       1.37      chs 			return 0;
    400        1.8      mrg 		}
    401        1.8      mrg 
    402       1.37      chs 		/* page is there, see if we need to wait on it */
    403   1.46.2.5  nathanw 		if ((pg->flags & PG_BUSY) != 0) {
    404       1.37      chs 			if (flags & UFP_NOWAIT) {
    405       1.37      chs 				UVMHIST_LOG(ubchist, "nowait",0,0,0,0);
    406       1.37      chs 				return 0;
    407       1.37      chs 			}
    408       1.37      chs 			pg->flags |= PG_WANTED;
    409   1.46.2.9  nathanw 			UVMHIST_LOG(ubchist, "wait %p", pg,0,0,0);
    410       1.37      chs 			UVM_UNLOCK_AND_WAIT(pg, &uobj->vmobjlock, 0,
    411       1.37      chs 					    "uvn_fp2", 0);
    412       1.37      chs 			simple_lock(&uobj->vmobjlock);
    413       1.37      chs 			continue;
    414        1.8      mrg 		}
    415   1.46.2.3  nathanw 
    416       1.37      chs 		/* skip PG_RDONLY pages if requested */
    417       1.37      chs 		if ((flags & UFP_NORDONLY) && (pg->flags & PG_RDONLY)) {
    418       1.37      chs 			UVMHIST_LOG(ubchist, "nordonly",0,0,0,0);
    419       1.37      chs 			return 0;
    420        1.8      mrg 		}
    421        1.8      mrg 
    422   1.46.2.5  nathanw 		/* stop on clean pages if requested */
    423   1.46.2.5  nathanw 		if (flags & UFP_DIRTYONLY) {
    424   1.46.2.5  nathanw 			dirty = pmap_clear_modify(pg) ||
    425   1.46.2.5  nathanw 				(pg->flags & PG_CLEAN) == 0;
    426   1.46.2.5  nathanw 			pg->flags |= PG_CLEAN;
    427   1.46.2.5  nathanw 			if (!dirty) {
    428   1.46.2.9  nathanw 				UVMHIST_LOG(ubchist, "dirtonly", 0,0,0,0);
    429   1.46.2.5  nathanw 				return 0;
    430   1.46.2.5  nathanw 			}
    431   1.46.2.5  nathanw 		}
    432   1.46.2.5  nathanw 
    433       1.37      chs 		/* mark the page BUSY and we're done. */
    434       1.37      chs 		pg->flags |= PG_BUSY;
    435       1.37      chs 		UVM_PAGE_OWN(pg, "uvn_findpage");
    436   1.46.2.5  nathanw 		UVMHIST_LOG(ubchist, "found %p", pg,0,0,0);
    437       1.37      chs 		break;
    438        1.8      mrg 	}
    439       1.37      chs 	*pgp = pg;
    440       1.37      chs 	return 1;
    441        1.1      mrg }
    442        1.1      mrg 
    443        1.1      mrg /*
    444   1.46.2.5  nathanw  * uvm_vnp_setsize: grow or shrink a vnode uobj
    445        1.1      mrg  *
    446        1.1      mrg  * grow   => just update size value
    447        1.1      mrg  * shrink => toss un-needed pages
    448        1.1      mrg  *
    449   1.46.2.3  nathanw  * => we assume that the caller has a reference of some sort to the
    450        1.1      mrg  *	vnode in question so that it will not be yanked out from under
    451        1.1      mrg  *	us.
    452        1.1      mrg  */
    453        1.1      mrg 
    454        1.8      mrg void
    455        1.8      mrg uvm_vnp_setsize(vp, newsize)
    456        1.8      mrg 	struct vnode *vp;
    457       1.30   kleink 	voff_t newsize;
    458        1.8      mrg {
    459   1.46.2.5  nathanw 	struct uvm_object *uobj = &vp->v_uobj;
    460       1.46    enami 	voff_t pgend = round_page(newsize);
    461       1.37      chs 	UVMHIST_FUNC("uvm_vnp_setsize"); UVMHIST_CALLED(ubchist);
    462       1.37      chs 
    463   1.46.2.5  nathanw 	simple_lock(&uobj->vmobjlock);
    464   1.46.2.5  nathanw 	UVMHIST_LOG(ubchist, "vp %p old 0x%x new 0x%x",
    465   1.46.2.5  nathanw 	    vp, vp->v_size, newsize, 0);
    466        1.1      mrg 
    467        1.8      mrg 	/*
    468       1.37      chs 	 * now check if the size has changed: if we shrink we had better
    469       1.37      chs 	 * toss some pages...
    470        1.8      mrg 	 */
    471        1.1      mrg 
    472   1.46.2.5  nathanw 	if (vp->v_size > pgend && vp->v_size != VSIZENOTSET) {
    473   1.46.2.8  nathanw 		(void) uvn_put(uobj, pgend, 0, PGO_FREE | PGO_SYNCIO);
    474   1.46.2.5  nathanw 	} else {
    475   1.46.2.5  nathanw 		simple_unlock(&uobj->vmobjlock);
    476        1.8      mrg 	}
    477   1.46.2.5  nathanw 	vp->v_size = newsize;
    478        1.1      mrg }
    479        1.1      mrg 
    480        1.1      mrg /*
    481       1.37      chs  * uvm_vnp_zerorange:  set a range of bytes in a file to zero.
    482        1.1      mrg  */
    483        1.1      mrg 
    484        1.8      mrg void
    485       1.37      chs uvm_vnp_zerorange(vp, off, len)
    486       1.37      chs 	struct vnode *vp;
    487       1.37      chs 	off_t off;
    488       1.37      chs 	size_t len;
    489        1.8      mrg {
    490       1.37      chs         void *win;
    491        1.8      mrg 
    492       1.37      chs         /*
    493       1.37      chs          * XXXUBC invent kzero() and use it
    494       1.37      chs          */
    495       1.37      chs 
    496       1.37      chs         while (len) {
    497       1.37      chs                 vsize_t bytelen = len;
    498       1.37      chs 
    499   1.46.2.5  nathanw                 win = ubc_alloc(&vp->v_uobj, off, &bytelen, UBC_WRITE);
    500       1.37      chs                 memset(win, 0, bytelen);
    501       1.37      chs                 ubc_release(win, 0);
    502       1.37      chs 
    503       1.37      chs                 off += bytelen;
    504       1.37      chs                 len -= bytelen;
    505       1.37      chs         }
    506        1.1      mrg }
    507