vnode_pager.c revision 83366
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1990 University of Utah. 31549Srgrimes * Copyright (c) 1991 The Regents of the University of California. 41549Srgrimes * All rights reserved. 59507Sdg * Copyright (c) 1993, 1994 John S. Dyson 69507Sdg * Copyright (c) 1995, David Greenman 71541Srgrimes * 81541Srgrimes * This code is derived from software contributed to Berkeley by 91541Srgrimes * the Systems Programming Group of the University of Utah Computer 101541Srgrimes * Science Department. 111541Srgrimes * 121541Srgrimes * Redistribution and use in source and binary forms, with or without 131541Srgrimes * modification, are permitted provided that the following conditions 141541Srgrimes * are met: 151541Srgrimes * 1. Redistributions of source code must retain the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer. 171541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 181541Srgrimes * notice, this list of conditions and the following disclaimer in the 191541Srgrimes * documentation and/or other materials provided with the distribution. 201541Srgrimes * 3. All advertising materials mentioning features or use of this software 2158705Scharnier * must display the following acknowledgement: 221541Srgrimes * This product includes software developed by the University of 231541Srgrimes * California, Berkeley and its contributors. 241541Srgrimes * 4. Neither the name of the University nor the names of its contributors 251541Srgrimes * may be used to endorse or promote products derived from this software 261541Srgrimes * without specific prior written permission. 271541Srgrimes * 281541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 291541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 301541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 311541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 321541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 331541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 341541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 351541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 361541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 371541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 381541Srgrimes * SUCH DAMAGE. 391541Srgrimes * 401549Srgrimes * from: @(#)vnode_pager.c 7.5 (Berkeley) 4/20/91 4150477Speter * $FreeBSD: head/sys/vm/vnode_pager.c 83366 2001-09-12 08:38:13Z julian $ 421541Srgrimes */ 431541Srgrimes 441541Srgrimes/* 451541Srgrimes * Page to/from files (vnodes). 461541Srgrimes */ 471541Srgrimes 481549Srgrimes/* 491549Srgrimes * TODO: 509507Sdg * Implement VOP_GETPAGES/PUTPAGES interface for filesystems. Will 517695Sdg * greatly re-simplify the vnode_pager. 521549Srgrimes */ 531549Srgrimes 541541Srgrimes#include <sys/param.h> 551541Srgrimes#include <sys/systm.h> 561541Srgrimes#include <sys/proc.h> 571541Srgrimes#include <sys/vnode.h> 581541Srgrimes#include <sys/mount.h> 5960041Sphk#include <sys/bio.h> 609507Sdg#include <sys/buf.h> 6112662Sdg#include <sys/vmmeter.h> 6251340Sdillon#include <sys/conf.h> 631541Srgrimes 641541Srgrimes#include <vm/vm.h> 6512662Sdg#include <vm/vm_object.h> 661541Srgrimes#include <vm/vm_page.h> 679507Sdg#include <vm/vm_pager.h> 6831853Sdyson#include <vm/vm_map.h> 691541Srgrimes#include <vm/vnode_pager.h> 7012662Sdg#include <vm/vm_extern.h> 711541Srgrimes 7279127Sjhbstatic void vnode_pager_init __P((void)); 7312820Sphkstatic vm_offset_t vnode_pager_addr __P((struct vnode *vp, vm_ooffset_t address, 7411943Sbde int *run)); 7512820Sphkstatic void vnode_pager_iodone __P((struct buf *bp)); 7612820Sphkstatic int vnode_pager_input_smlfs __P((vm_object_t object, vm_page_t m)); 7712820Sphkstatic int vnode_pager_input_old __P((vm_object_t object, vm_page_t m)); 7812820Sphkstatic void vnode_pager_dealloc __P((vm_object_t)); 7912820Sphkstatic int vnode_pager_getpages __P((vm_object_t, vm_page_t *, int, int)); 8043129Sdillonstatic void vnode_pager_putpages __P((vm_object_t, vm_page_t *, int, boolean_t, int *)); 8112820Sphkstatic boolean_t vnode_pager_haspage __P((vm_object_t, vm_pindex_t, int *, int *)); 8211943Sbde 831541Srgrimesstruct pagerops vnodepagerops = { 8479127Sjhb vnode_pager_init, 851541Srgrimes vnode_pager_alloc, 861541Srgrimes vnode_pager_dealloc, 879507Sdg vnode_pager_getpages, 889507Sdg vnode_pager_putpages, 899507Sdg vnode_pager_haspage, 909507Sdg NULL 911541Srgrimes}; 921541Srgrimes 9379127Sjhbint vnode_pbuf_freecnt; 9410556Sdyson 9579127Sjhbvoid 9679127Sjhbvnode_pager_init(void) 9779127Sjhb{ 9842957Sdillon 9979127Sjhb vnode_pbuf_freecnt = nswbuf / 2 + 1; 10079127Sjhb} 10179127Sjhb 1021541Srgrimes/* 1031541Srgrimes * Allocate (or lookup) pager for a vnode. 1041541Srgrimes * Handle is a vnode pointer. 1051541Srgrimes */ 1069507Sdgvm_object_t 10740286Sdgvnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, 10828751Sbde vm_ooffset_t offset) 1091541Srgrimes{ 1109456Sdg vm_object_t object; 1111541Srgrimes struct vnode *vp; 1121541Srgrimes 11379224Sdillon GIANT_REQUIRED; 11479224Sdillon 1151541Srgrimes /* 1161541Srgrimes * Pageout to vnode, no can do yet. 1171541Srgrimes */ 1181541Srgrimes if (handle == NULL) 1191827Sdg return (NULL); 1201541Srgrimes 1219411Sdg vp = (struct vnode *) handle; 1229411Sdg 1231541Srgrimes /* 1249411Sdg * Prevent race condition when allocating the object. This 1259411Sdg * can happen with NFS vnodes since the nfsnode isn't locked. 1261541Srgrimes */ 1279411Sdg while (vp->v_flag & VOLOCK) { 1289411Sdg vp->v_flag |= VOWANT; 1299411Sdg tsleep(vp, PVM, "vnpobj", 0); 1309411Sdg } 1319411Sdg vp->v_flag |= VOLOCK; 1329411Sdg 1339411Sdg /* 1349411Sdg * If the object is being terminated, wait for it to 1359411Sdg * go away. 1369411Sdg */ 13713490Sdyson while (((object = vp->v_object) != NULL) && 13813490Sdyson (object->flags & OBJ_DEAD)) { 13979224Sdillon tsleep(object, PVM, "vadead", 0); 1409507Sdg } 1415455Sdg 14232071Sdyson if (vp->v_usecount == 0) 14332071Sdyson panic("vnode_pager_alloc: no vnode reference"); 14432071Sdyson 1459507Sdg if (object == NULL) { 1461541Srgrimes /* 1471541Srgrimes * And an object of the appropriate size 1481541Srgrimes */ 14940286Sdg object = vm_object_allocate(OBJT_VNODE, OFF_TO_IDX(round_page(size))); 15032286Sdyson object->flags = 0; 1511827Sdg 15240286Sdg object->un_pager.vnp.vnp_size = size; 1531549Srgrimes 1549507Sdg object->handle = handle; 1559507Sdg vp->v_object = object; 15632286Sdyson vp->v_usecount++; 1571541Srgrimes } else { 15832286Sdyson object->ref_count++; 15932286Sdyson vp->v_usecount++; 1601541Srgrimes } 1619411Sdg 1629411Sdg vp->v_flag &= ~VOLOCK; 1639411Sdg if (vp->v_flag & VOWANT) { 1649411Sdg vp->v_flag &= ~VOWANT; 1659411Sdg wakeup(vp); 1669411Sdg } 1679507Sdg return (object); 1681541Srgrimes} 1691541Srgrimes 17012820Sphkstatic void 1719507Sdgvnode_pager_dealloc(object) 1729507Sdg vm_object_t object; 1731541Srgrimes{ 17479242Sdillon struct vnode *vp = object->handle; 1751541Srgrimes 17679224Sdillon GIANT_REQUIRED; 1779507Sdg if (vp == NULL) 1789507Sdg panic("vnode_pager_dealloc: pager already dealloced"); 1799507Sdg 18033817Sdyson vm_object_pip_wait(object, "vnpdea"); 1811541Srgrimes 1829507Sdg object->handle = NULL; 18333109Sdyson object->type = OBJT_DEAD; 1849507Sdg vp->v_object = NULL; 18533109Sdyson vp->v_flag &= ~(VTEXT | VOBJBUF); 1861549Srgrimes} 1871541Srgrimes 18812820Sphkstatic boolean_t 18912767Sdysonvnode_pager_haspage(object, pindex, before, after) 1909507Sdg vm_object_t object; 19112767Sdyson vm_pindex_t pindex; 1929507Sdg int *before; 1939507Sdg int *after; 1941541Srgrimes{ 1959507Sdg struct vnode *vp = object->handle; 1961541Srgrimes daddr_t bn; 19712423Sphk int err; 19810556Sdyson daddr_t reqblock; 19911701Sdyson int poff; 20011701Sdyson int bsize; 20112914Sdyson int pagesperblock, blocksperpage; 2021541Srgrimes 20379224Sdillon GIANT_REQUIRED; 20451340Sdillon /* 20551340Sdillon * If no vp or vp is doomed or marked transparent to VM, we do not 20651340Sdillon * have the page. 20751340Sdillon */ 20832585Sdyson if ((vp == NULL) || (vp->v_flag & VDOOMED)) 20932585Sdyson return FALSE; 21032585Sdyson 2111541Srgrimes /* 2125455Sdg * If filesystem no longer mounted or offset beyond end of file we do 2135455Sdg * not have the page. 2141541Srgrimes */ 21512767Sdyson if ((vp->v_mount == NULL) || 21681140Sjhb (IDX_TO_OFF(pindex) >= object->un_pager.vnp.vnp_size)) 2174797Sdg return FALSE; 2181541Srgrimes 21911576Sdg bsize = vp->v_mount->mnt_stat.f_iosize; 22010556Sdyson pagesperblock = bsize / PAGE_SIZE; 22112914Sdyson blocksperpage = 0; 22212914Sdyson if (pagesperblock > 0) { 22312914Sdyson reqblock = pindex / pagesperblock; 22412914Sdyson } else { 22512914Sdyson blocksperpage = (PAGE_SIZE / bsize); 22612914Sdyson reqblock = pindex * blocksperpage; 22712914Sdyson } 22810556Sdyson err = VOP_BMAP(vp, reqblock, (struct vnode **) 0, &bn, 22910556Sdyson after, before); 2308876Srgrimes if (err) 2319507Sdg return TRUE; 23210702Sdyson if ( bn == -1) 23310576Sdyson return FALSE; 23412914Sdyson if (pagesperblock > 0) { 23512914Sdyson poff = pindex - (reqblock * pagesperblock); 23612914Sdyson if (before) { 23712914Sdyson *before *= pagesperblock; 23812914Sdyson *before += poff; 23910669Sdyson } 24012914Sdyson if (after) { 24112914Sdyson int numafter; 24212914Sdyson *after *= pagesperblock; 24312914Sdyson numafter = pagesperblock - (poff + 1); 24412914Sdyson if (IDX_TO_OFF(pindex + numafter) > object->un_pager.vnp.vnp_size) { 24512914Sdyson numafter = OFF_TO_IDX((object->un_pager.vnp.vnp_size - IDX_TO_OFF(pindex))); 24612914Sdyson } 24712914Sdyson *after += numafter; 24812914Sdyson } 24912914Sdyson } else { 25012914Sdyson if (before) { 25112914Sdyson *before /= blocksperpage; 25212914Sdyson } 25312914Sdyson 25412914Sdyson if (after) { 25512914Sdyson *after /= blocksperpage; 25612914Sdyson } 25710556Sdyson } 25810576Sdyson return TRUE; 2591541Srgrimes} 2601541Srgrimes 2611541Srgrimes/* 2621541Srgrimes * Lets the VM system know about a change in size for a file. 2639507Sdg * We adjust our own internal size and flush any cached pages in 2641541Srgrimes * the associated object that are affected by the size change. 2651541Srgrimes * 2661541Srgrimes * Note: this routine may be invoked as a result of a pager put 2671541Srgrimes * operation (possibly at object termination time), so we must be careful. 2681541Srgrimes */ 2691541Srgrimesvoid 2701541Srgrimesvnode_pager_setsize(vp, nsize) 2711541Srgrimes struct vnode *vp; 27212767Sdyson vm_ooffset_t nsize; 2731541Srgrimes{ 27438542Sluoqi vm_pindex_t nobjsize; 2759507Sdg vm_object_t object = vp->v_object; 2761541Srgrimes 27779224Sdillon GIANT_REQUIRED; 27879224Sdillon 2799507Sdg if (object == NULL) 2801541Srgrimes return; 2811827Sdg 2821541Srgrimes /* 2831541Srgrimes * Hasn't changed size 2841541Srgrimes */ 2859507Sdg if (nsize == object->un_pager.vnp.vnp_size) 2863374Sdg return; 2871827Sdg 28838542Sluoqi nobjsize = OFF_TO_IDX(nsize + PAGE_MASK); 28938542Sluoqi 2901541Srgrimes /* 2911827Sdg * File has shrunk. Toss any cached pages beyond the new EOF. 2921541Srgrimes */ 2939507Sdg if (nsize < object->un_pager.vnp.vnp_size) { 29438542Sluoqi vm_freeze_copyopts(object, OFF_TO_IDX(nsize), object->size); 29538542Sluoqi if (nobjsize < object->size) { 29638542Sluoqi vm_object_page_remove(object, nobjsize, object->size, 29738542Sluoqi FALSE); 2985455Sdg } 2991827Sdg /* 3001827Sdg * this gets rid of garbage at the end of a page that is now 3011827Sdg * only partially backed by the vnode... 3021827Sdg */ 3031827Sdg if (nsize & PAGE_MASK) { 3041827Sdg vm_offset_t kva; 3051827Sdg vm_page_t m; 3061827Sdg 30712767Sdyson m = vm_page_lookup(object, OFF_TO_IDX(nsize)); 3081827Sdg if (m) { 30970374Sdillon int base = (int)nsize & PAGE_MASK; 31070374Sdillon int size = PAGE_SIZE - base; 31170374Sdillon 31270374Sdillon /* 31370374Sdillon * Clear out partial-page garbage in case 31470374Sdillon * the page has been mapped. 31570374Sdillon */ 3161827Sdg kva = vm_pager_map_page(m); 31770374Sdillon bzero((caddr_t)kva + base, size); 3181827Sdg vm_pager_unmap_page(kva); 31970374Sdillon 32070374Sdillon /* 32170374Sdillon * Clear out partial-page dirty bits. This 32270374Sdillon * has the side effect of setting the valid 32370374Sdillon * bits, but that is ok. There are a bunch 32470374Sdillon * of places in the VM system where we expected 32570374Sdillon * m->dirty == VM_PAGE_BITS_ALL. The file EOF 32670374Sdillon * case is one of them. If the page is still 32770374Sdillon * partially dirty, make it fully dirty. 32870374Sdillon */ 32970374Sdillon vm_page_set_validclean(m, base, size); 33070374Sdillon if (m->dirty != 0) 33170374Sdillon m->dirty = VM_PAGE_BITS_ALL; 3321827Sdg } 3331827Sdg } 3341541Srgrimes } 33512767Sdyson object->un_pager.vnp.vnp_size = nsize; 33638542Sluoqi object->size = nobjsize; 3371541Srgrimes} 3381541Srgrimes 3391549Srgrimes/* 3401549Srgrimes * calculate the linear (byte) disk address of specified virtual 3411549Srgrimes * file address 3421549Srgrimes */ 34312820Sphkstatic vm_offset_t 3446151Sdgvnode_pager_addr(vp, address, run) 3451549Srgrimes struct vnode *vp; 34612767Sdyson vm_ooffset_t address; 3476151Sdg int *run; 3481549Srgrimes{ 3495455Sdg int rtaddress; 3505455Sdg int bsize; 35112767Sdyson daddr_t block; 3521549Srgrimes struct vnode *rtvp; 3535455Sdg int err; 35412767Sdyson daddr_t vblock; 35512767Sdyson int voffset; 3561549Srgrimes 35779224Sdillon GIANT_REQUIRED; 3585455Sdg if ((int) address < 0) 3595455Sdg return -1; 3605455Sdg 36111701Sdyson if (vp->v_mount == NULL) 36211701Sdyson return -1; 36311701Sdyson 3641549Srgrimes bsize = vp->v_mount->mnt_stat.f_iosize; 3651549Srgrimes vblock = address / bsize; 3661549Srgrimes voffset = address % bsize; 3671549Srgrimes 36810551Sdyson err = VOP_BMAP(vp, vblock, &rtvp, &block, run, NULL); 3691549Srgrimes 3706151Sdg if (err || (block == -1)) 3711549Srgrimes rtaddress = -1; 3726151Sdg else { 3736626Sdg rtaddress = block + voffset / DEV_BSIZE; 3746151Sdg if( run) { 3756151Sdg *run += 1; 3766151Sdg *run *= bsize/PAGE_SIZE; 3776151Sdg *run -= voffset/PAGE_SIZE; 3786151Sdg } 3796151Sdg } 3801549Srgrimes 3811549Srgrimes return rtaddress; 3821549Srgrimes} 3831549Srgrimes 3841549Srgrimes/* 3851549Srgrimes * interrupt routine for I/O completion 3861549Srgrimes */ 38712820Sphkstatic void 3881549Srgrimesvnode_pager_iodone(bp) 3891549Srgrimes struct buf *bp; 3901549Srgrimes{ 3911549Srgrimes bp->b_flags |= B_DONE; 3929507Sdg wakeup(bp); 3931549Srgrimes} 3941549Srgrimes 3951549Srgrimes/* 3961549Srgrimes * small block file system vnode pager input 3971549Srgrimes */ 39812820Sphkstatic int 3999507Sdgvnode_pager_input_smlfs(object, m) 4009507Sdg vm_object_t object; 4011549Srgrimes vm_page_t m; 4021549Srgrimes{ 4035455Sdg int i; 4045455Sdg int s; 4051549Srgrimes struct vnode *dp, *vp; 4061549Srgrimes struct buf *bp; 4071549Srgrimes vm_offset_t kva; 4085455Sdg int fileaddr; 4091549Srgrimes vm_offset_t bsize; 4105455Sdg int error = 0; 4111549Srgrimes 41279224Sdillon GIANT_REQUIRED; 41379224Sdillon 4149507Sdg vp = object->handle; 41511701Sdyson if (vp->v_mount == NULL) 41611701Sdyson return VM_PAGER_BAD; 41711701Sdyson 4181549Srgrimes bsize = vp->v_mount->mnt_stat.f_iosize; 4191549Srgrimes 42010551Sdyson VOP_BMAP(vp, 0, &dp, 0, NULL, NULL); 4211549Srgrimes 4221549Srgrimes kva = vm_pager_map_page(m); 4231549Srgrimes 4241827Sdg for (i = 0; i < PAGE_SIZE / bsize; i++) { 4251827Sdg 42645561Sdt if (vm_page_bits(i * bsize, bsize) & m->valid) 4275455Sdg continue; 4281549Srgrimes 42912767Sdyson fileaddr = vnode_pager_addr(vp, 43012767Sdyson IDX_TO_OFF(m->pindex) + i * bsize, (int *)0); 4311827Sdg if (fileaddr != -1) { 43242957Sdillon bp = getpbuf(&vnode_pbuf_freecnt); 4331549Srgrimes 4341827Sdg /* build a minimal buffer header */ 43558345Sphk bp->b_iocmd = BIO_READ; 4361549Srgrimes bp->b_iodone = vnode_pager_iodone; 43783366Sjulian bp->b_rcred = bp->b_wcred = curthread->td_proc->p_ucred; 4381827Sdg if (bp->b_rcred != NOCRED) 4391549Srgrimes crhold(bp->b_rcred); 4401827Sdg if (bp->b_wcred != NOCRED) 4411549Srgrimes crhold(bp->b_wcred); 44231493Sphk bp->b_data = (caddr_t) kva + i * bsize; 4436626Sdg bp->b_blkno = fileaddr; 4445455Sdg pbgetvp(dp, bp); 4451549Srgrimes bp->b_bcount = bsize; 4461549Srgrimes bp->b_bufsize = bsize; 44770374Sdillon bp->b_runningbufspace = bp->b_bufsize; 44870374Sdillon runningbufspace += bp->b_runningbufspace; 4491827Sdg 4501827Sdg /* do the input */ 45158349Sphk BUF_STRATEGY(bp); 4521549Srgrimes 45333758Sdyson /* we definitely need to be at splvm here */ 4541549Srgrimes 45533758Sdyson s = splvm(); 4561549Srgrimes while ((bp->b_flags & B_DONE) == 0) { 4579356Sdg tsleep(bp, PVM, "vnsrd", 0); 4581549Srgrimes } 4591549Srgrimes splx(s); 46058934Sphk if ((bp->b_ioflags & BIO_ERROR) != 0) 4611549Srgrimes error = EIO; 4621549Srgrimes 4631827Sdg /* 4641827Sdg * free the buffer header back to the swap buffer pool 4651827Sdg */ 46642957Sdillon relpbuf(bp, &vnode_pbuf_freecnt); 4671827Sdg if (error) 4681549Srgrimes break; 4695455Sdg 47015583Sphk vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize); 4711549Srgrimes } else { 47215583Sphk vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize); 4731549Srgrimes bzero((caddr_t) kva + i * bsize, bsize); 4741549Srgrimes } 4751549Srgrimes } 4761549Srgrimes vm_pager_unmap_page(kva); 47760755Speter pmap_clear_modify(m); 47838799Sdfr vm_page_flag_clear(m, PG_ZERO); 4791827Sdg if (error) { 4804207Sdg return VM_PAGER_ERROR; 4811549Srgrimes } 4821549Srgrimes return VM_PAGER_OK; 4831549Srgrimes 4841549Srgrimes} 4851549Srgrimes 4861549Srgrimes 4871549Srgrimes/* 4881549Srgrimes * old style vnode pager output routine 4891549Srgrimes */ 49012820Sphkstatic int 4919507Sdgvnode_pager_input_old(object, m) 4929507Sdg vm_object_t object; 4931549Srgrimes vm_page_t m; 4941549Srgrimes{ 4951541Srgrimes struct uio auio; 4961541Srgrimes struct iovec aiov; 4975455Sdg int error; 4985455Sdg int size; 4991549Srgrimes vm_offset_t kva; 50077398Sjhb struct vnode *vp; 5011549Srgrimes 50279224Sdillon GIANT_REQUIRED; 5031549Srgrimes error = 0; 5041827Sdg 5051549Srgrimes /* 5061549Srgrimes * Return failure if beyond current EOF 5071549Srgrimes */ 50812767Sdyson if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) { 5091549Srgrimes return VM_PAGER_BAD; 5101549Srgrimes } else { 5111549Srgrimes size = PAGE_SIZE; 51212767Sdyson if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size) 51312767Sdyson size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex); 5147178Sdg 5155455Sdg /* 5165455Sdg * Allocate a kernel virtual address and initialize so that 5175455Sdg * we can use VOP_READ/WRITE routines. 5185455Sdg */ 5191549Srgrimes kva = vm_pager_map_page(m); 5207178Sdg 52177398Sjhb vp = object->handle; 5221827Sdg aiov.iov_base = (caddr_t) kva; 5231549Srgrimes aiov.iov_len = size; 5241549Srgrimes auio.uio_iov = &aiov; 5251549Srgrimes auio.uio_iovcnt = 1; 52612767Sdyson auio.uio_offset = IDX_TO_OFF(m->pindex); 5271549Srgrimes auio.uio_segflg = UIO_SYSSPACE; 5281549Srgrimes auio.uio_rw = UIO_READ; 5291549Srgrimes auio.uio_resid = size; 53083366Sjulian auio.uio_td = curthread; 5311549Srgrimes 53283366Sjulian error = VOP_READ(vp, &auio, 0, curthread->td_proc->p_ucred); 5331549Srgrimes if (!error) { 53479242Sdillon int count = size - auio.uio_resid; 5351549Srgrimes 5361549Srgrimes if (count == 0) 5371549Srgrimes error = EINVAL; 5381549Srgrimes else if (count != PAGE_SIZE) 5391827Sdg bzero((caddr_t) kva + count, PAGE_SIZE - count); 5401549Srgrimes } 5411549Srgrimes vm_pager_unmap_page(kva); 5421549Srgrimes } 54360755Speter pmap_clear_modify(m); 54449945Salc vm_page_undirty(m); 54538799Sdfr vm_page_flag_clear(m, PG_ZERO); 54639739Srvb if (!error) 54739739Srvb m->valid = VM_PAGE_BITS_ALL; 5484207Sdg return error ? VM_PAGER_ERROR : VM_PAGER_OK; 5491549Srgrimes} 5501549Srgrimes 5511549Srgrimes/* 5521549Srgrimes * generic vnode pager input routine 5531549Srgrimes */ 55410556Sdyson 55533847Smsmith/* 55676827Salfred * Local media VFS's that do not implement their own VOP_GETPAGES 55776827Salfred * should have their VOP_GETPAGES should call to 55833847Smsmith * vnode_pager_generic_getpages() to implement the previous behaviour. 55933847Smsmith * 56033847Smsmith * All other FS's should use the bypass to get to the local media 56133847Smsmith * backing vp's VOP_GETPAGES. 56233847Smsmith */ 56312820Sphkstatic int 5649507Sdgvnode_pager_getpages(object, m, count, reqpage) 5659507Sdg vm_object_t object; 5661549Srgrimes vm_page_t *m; 5679507Sdg int count; 5689507Sdg int reqpage; 5691549Srgrimes{ 57010556Sdyson int rtval; 57110556Sdyson struct vnode *vp; 57234403Smsmith int bytes = count * PAGE_SIZE; 57332286Sdyson 57479224Sdillon GIANT_REQUIRED; 57510556Sdyson vp = object->handle; 57634403Smsmith rtval = VOP_GETPAGES(vp, m, bytes, reqpage, 0); 57776827Salfred KASSERT(rtval != EOPNOTSUPP, 57876827Salfred ("vnode_pager: FS getpages not implemented\n")); 57933847Smsmith return rtval; 58010556Sdyson} 58110556Sdyson 58233847Smsmith 58333847Smsmith/* 58433847Smsmith * This is now called from local media FS's to operate against their 58533847Smsmith * own vnodes if they fail to implement VOP_GETPAGES. 58633847Smsmith */ 58733847Smsmithint 58833847Smsmithvnode_pager_generic_getpages(vp, m, bytecount, reqpage) 58933847Smsmith struct vnode *vp; 59010556Sdyson vm_page_t *m; 59133847Smsmith int bytecount; 59210556Sdyson int reqpage; 59310556Sdyson{ 59433847Smsmith vm_object_t object; 59512767Sdyson vm_offset_t kva; 59634206Sdyson off_t foff, tfoff, nextoff; 5979507Sdg int i, size, bsize, first, firstaddr; 59833847Smsmith struct vnode *dp; 5996151Sdg int runpg; 6006151Sdg int runend; 6017178Sdg struct buf *bp; 6025455Sdg int s; 60333847Smsmith int count; 6045455Sdg int error = 0; 6051549Srgrimes 60679224Sdillon GIANT_REQUIRED; 60733847Smsmith object = vp->v_object; 60833847Smsmith count = bytecount / PAGE_SIZE; 60933847Smsmith 61011701Sdyson if (vp->v_mount == NULL) 61111701Sdyson return VM_PAGER_BAD; 61211701Sdyson 6131549Srgrimes bsize = vp->v_mount->mnt_stat.f_iosize; 6141549Srgrimes 6151549Srgrimes /* get the UNDERLYING device for the file with VOP_BMAP() */ 6161827Sdg 6171549Srgrimes /* 6181827Sdg * originally, we did not check for an error return value -- assuming 6191827Sdg * an fs always has a bmap entry point -- that assumption is wrong!!! 6201549Srgrimes */ 62112767Sdyson foff = IDX_TO_OFF(m[reqpage]->pindex); 6221827Sdg 6231549Srgrimes /* 6241887Sdg * if we can't bmap, use old VOP code 6251549Srgrimes */ 62610551Sdyson if (VOP_BMAP(vp, 0, &dp, 0, NULL, NULL)) { 6271549Srgrimes for (i = 0; i < count; i++) { 6281549Srgrimes if (i != reqpage) { 62975692Salfred vm_page_free(m[i]); 6301549Srgrimes } 6311549Srgrimes } 6323612Sdg cnt.v_vnodein++; 6333612Sdg cnt.v_vnodepgsin++; 6349507Sdg return vnode_pager_input_old(object, m[reqpage]); 6351549Srgrimes 6361827Sdg /* 6371827Sdg * if the blocksize is smaller than a page size, then use 6381827Sdg * special small filesystem code. NFS sometimes has a small 6391827Sdg * blocksize, but it can handle large reads itself. 6401827Sdg */ 6411827Sdg } else if ((PAGE_SIZE / bsize) > 1 && 64238866Sbde (vp->v_mount->mnt_stat.f_type != nfs_mount_type)) { 6431549Srgrimes for (i = 0; i < count; i++) { 6441549Srgrimes if (i != reqpage) { 64575692Salfred vm_page_free(m[i]); 6461549Srgrimes } 6471549Srgrimes } 6483612Sdg cnt.v_vnodein++; 6493612Sdg cnt.v_vnodepgsin++; 6509507Sdg return vnode_pager_input_smlfs(object, m[reqpage]); 6511549Srgrimes } 65245347Sjulian 6531549Srgrimes /* 65445347Sjulian * If we have a completely valid page available to us, we can 65545347Sjulian * clean up and return. Otherwise we have to re-read the 65645347Sjulian * media. 6571549Srgrimes */ 65825930Sdfr 65945347Sjulian if (m[reqpage]->valid == VM_PAGE_BITS_ALL) { 6605455Sdg for (i = 0; i < count; i++) { 6615455Sdg if (i != reqpage) 66275692Salfred vm_page_free(m[i]); 6631549Srgrimes } 6645455Sdg return VM_PAGER_OK; 6651549Srgrimes } 66645347Sjulian m[reqpage]->valid = 0; 6677178Sdg 6685455Sdg /* 6695455Sdg * here on direct device I/O 6705455Sdg */ 6711549Srgrimes 6726151Sdg firstaddr = -1; 6731549Srgrimes /* 6746151Sdg * calculate the run that includes the required page 6751549Srgrimes */ 6766151Sdg for(first = 0, i = 0; i < count; i = runend) { 67712767Sdyson firstaddr = vnode_pager_addr(vp, 67812767Sdyson IDX_TO_OFF(m[i]->pindex), &runpg); 6796151Sdg if (firstaddr == -1) { 6809507Sdg if (i == reqpage && foff < object->un_pager.vnp.vnp_size) { 68137562Sbde /* XXX no %qd in kernel. */ 68237562Sbde panic("vnode_pager_getpages: unexpected missing page: firstaddr: %d, foff: 0x%lx%08lx, vnp_size: 0x%lx%08lx", 68337562Sbde firstaddr, (u_long)(foff >> 32), 68437562Sbde (u_long)(u_int32_t)foff, 68537562Sbde (u_long)(u_int32_t) 68637562Sbde (object->un_pager.vnp.vnp_size >> 32), 68737562Sbde (u_long)(u_int32_t) 68837562Sbde object->un_pager.vnp.vnp_size); 6896151Sdg } 69075692Salfred vm_page_free(m[i]); 6916151Sdg runend = i + 1; 6926151Sdg first = runend; 6936151Sdg continue; 6941549Srgrimes } 6956151Sdg runend = i + runpg; 6969507Sdg if (runend <= reqpage) { 6976151Sdg int j; 6989507Sdg for (j = i; j < runend; j++) { 69975692Salfred vm_page_free(m[j]); 7006151Sdg } 7011549Srgrimes } else { 7029507Sdg if (runpg < (count - first)) { 7039507Sdg for (i = first + runpg; i < count; i++) 70475692Salfred vm_page_free(m[i]); 7056151Sdg count = first + runpg; 7066151Sdg } 7076151Sdg break; 7081549Srgrimes } 7096151Sdg first = runend; 7101549Srgrimes } 7111549Srgrimes 7121549Srgrimes /* 7131827Sdg * the first and last page have been calculated now, move input pages 7141827Sdg * to be zero based... 7151549Srgrimes */ 7161549Srgrimes if (first != 0) { 7171549Srgrimes for (i = first; i < count; i++) { 7181549Srgrimes m[i - first] = m[i]; 7191549Srgrimes } 7201549Srgrimes count -= first; 7211549Srgrimes reqpage -= first; 7221549Srgrimes } 7236151Sdg 7241549Srgrimes /* 7251549Srgrimes * calculate the file virtual address for the transfer 7261549Srgrimes */ 72712767Sdyson foff = IDX_TO_OFF(m[0]->pindex); 7281827Sdg 7291549Srgrimes /* 7301549Srgrimes * calculate the size of the transfer 7311549Srgrimes */ 7321549Srgrimes size = count * PAGE_SIZE; 7339507Sdg if ((foff + size) > object->un_pager.vnp.vnp_size) 7349507Sdg size = object->un_pager.vnp.vnp_size - foff; 7351549Srgrimes 7361549Srgrimes /* 73751340Sdillon * round up physical size for real devices. 7381549Srgrimes */ 73951340Sdillon if (dp->v_type == VBLK || dp->v_type == VCHR) { 74051340Sdillon int secmask = dp->v_rdev->si_bsize_phys - 1; 74151340Sdillon KASSERT(secmask < PAGE_SIZE, ("vnode_pager_generic_getpages: sector size %d too large\n", secmask + 1)); 74251340Sdillon size = (size + secmask) & ~secmask; 74351340Sdillon } 7441549Srgrimes 74542957Sdillon bp = getpbuf(&vnode_pbuf_freecnt); 7465455Sdg kva = (vm_offset_t) bp->b_data; 7471887Sdg 7481549Srgrimes /* 7491549Srgrimes * and map the pages to be read into the kva 7501549Srgrimes */ 7511887Sdg pmap_qenter(kva, m, count); 7521549Srgrimes 7531549Srgrimes /* build a minimal buffer header */ 75458345Sphk bp->b_iocmd = BIO_READ; 7551549Srgrimes bp->b_iodone = vnode_pager_iodone; 7561549Srgrimes /* B_PHYS is not set, but it is nice to fill this in */ 75783366Sjulian bp->b_rcred = bp->b_wcred = curthread->td_proc->p_ucred; 7581827Sdg if (bp->b_rcred != NOCRED) 7591549Srgrimes crhold(bp->b_rcred); 7601827Sdg if (bp->b_wcred != NOCRED) 7611549Srgrimes crhold(bp->b_wcred); 7626626Sdg bp->b_blkno = firstaddr; 7635455Sdg pbgetvp(dp, bp); 7641549Srgrimes bp->b_bcount = size; 7651549Srgrimes bp->b_bufsize = size; 76670374Sdillon bp->b_runningbufspace = bp->b_bufsize; 76770374Sdillon runningbufspace += bp->b_runningbufspace; 7681549Srgrimes 7693612Sdg cnt.v_vnodein++; 7703612Sdg cnt.v_vnodepgsin += count; 7713612Sdg 7721549Srgrimes /* do the input */ 77358349Sphk BUF_STRATEGY(bp); 7743612Sdg 77533758Sdyson s = splvm(); 77633758Sdyson /* we definitely need to be at splvm here */ 7771549Srgrimes 7781549Srgrimes while ((bp->b_flags & B_DONE) == 0) { 7799356Sdg tsleep(bp, PVM, "vnread", 0); 7801549Srgrimes } 7811549Srgrimes splx(s); 78258934Sphk if ((bp->b_ioflags & BIO_ERROR) != 0) 7831549Srgrimes error = EIO; 7841549Srgrimes 7851549Srgrimes if (!error) { 7861549Srgrimes if (size != count * PAGE_SIZE) 7871827Sdg bzero((caddr_t) kva + size, PAGE_SIZE * count - size); 7881549Srgrimes } 7895455Sdg pmap_qremove(kva, count); 7901549Srgrimes 7911549Srgrimes /* 7921549Srgrimes * free the buffer header back to the swap buffer pool 7931549Srgrimes */ 79442957Sdillon relpbuf(bp, &vnode_pbuf_freecnt); 7951549Srgrimes 79634206Sdyson for (i = 0, tfoff = foff; i < count; i++, tfoff = nextoff) { 79734206Sdyson vm_page_t mt; 79834206Sdyson 79934206Sdyson nextoff = tfoff + PAGE_SIZE; 80034206Sdyson mt = m[i]; 80134206Sdyson 80247239Sdt if (nextoff <= object->un_pager.vnp.vnp_size) { 80345347Sjulian /* 80445347Sjulian * Read filled up entire page. 80545347Sjulian */ 80634206Sdyson mt->valid = VM_PAGE_BITS_ALL; 80749945Salc vm_page_undirty(mt); /* should be an assert? XXX */ 80860755Speter pmap_clear_modify(mt); 80934206Sdyson } else { 81045347Sjulian /* 81145347Sjulian * Read did not fill up entire page. Since this 81245347Sjulian * is getpages, the page may be mapped, so we have 81345347Sjulian * to zero the invalid portions of the page even 81445347Sjulian * though we aren't setting them valid. 81545347Sjulian * 81645347Sjulian * Currently we do not set the entire page valid, 81745347Sjulian * we just try to clear the piece that we couldn't 81845347Sjulian * read. 81945347Sjulian */ 82047239Sdt vm_page_set_validclean(mt, 0, 82147239Sdt object->un_pager.vnp.vnp_size - tfoff); 82246349Salc /* handled by vm_fault now */ 82346349Salc /* vm_page_zero_invalid(mt, FALSE); */ 82434206Sdyson } 82534206Sdyson 82638799Sdfr vm_page_flag_clear(mt, PG_ZERO); 8271549Srgrimes if (i != reqpage) { 8281827Sdg 8291549Srgrimes /* 8301827Sdg * whether or not to leave the page activated is up in 8311827Sdg * the air, but we should put the page on a page queue 8321827Sdg * somewhere. (it already is in the object). Result: 83358634Scharnier * It appears that empirical results show that 8341827Sdg * deactivating pages is best. 8351549Srgrimes */ 8361827Sdg 8371549Srgrimes /* 8381827Sdg * just in case someone was asking for this page we 8391827Sdg * now tell them that it is ok to use 8401549Srgrimes */ 8411549Srgrimes if (!error) { 84234206Sdyson if (mt->flags & PG_WANTED) 84334206Sdyson vm_page_activate(mt); 84433109Sdyson else 84534206Sdyson vm_page_deactivate(mt); 84638799Sdfr vm_page_wakeup(mt); 8471549Srgrimes } else { 84875692Salfred vm_page_free(mt); 8491549Srgrimes } 8501549Srgrimes } 8511549Srgrimes } 8521549Srgrimes if (error) { 8539507Sdg printf("vnode_pager_getpages: I/O read error\n"); 8541549Srgrimes } 8554207Sdg return (error ? VM_PAGER_ERROR : VM_PAGER_OK); 8561549Srgrimes} 8571549Srgrimes 85833847Smsmith/* 85933847Smsmith * EOPNOTSUPP is no longer legal. For local media VFS's that do not 86033847Smsmith * implement their own VOP_PUTPAGES, their VOP_PUTPAGES should call to 86133847Smsmith * vnode_pager_generic_putpages() to implement the previous behaviour. 86233847Smsmith * 86333847Smsmith * All other FS's should use the bypass to get to the local media 86433847Smsmith * backing vp's VOP_PUTPAGES. 86533847Smsmith */ 86643129Sdillonstatic void 86710556Sdysonvnode_pager_putpages(object, m, count, sync, rtvals) 86810556Sdyson vm_object_t object; 86910556Sdyson vm_page_t *m; 87010556Sdyson int count; 87110556Sdyson boolean_t sync; 87210556Sdyson int *rtvals; 87310556Sdyson{ 87410556Sdyson int rtval; 87510556Sdyson struct vnode *vp; 87662976Smckusick struct mount *mp; 87734403Smsmith int bytes = count * PAGE_SIZE; 87818973Sdyson 87979224Sdillon GIANT_REQUIRED; 88044321Salc /* 88144321Salc * Force synchronous operation if we are extremely low on memory 88244321Salc * to prevent a low-memory deadlock. VOP operations often need to 88344321Salc * allocate more memory to initiate the I/O ( i.e. do a BMAP 88444321Salc * operation ). The swapper handles the case by limiting the amount 88544321Salc * of asynchronous I/O, but that sort of solution doesn't scale well 88644321Salc * for the vnode pager without a lot of work. 88744321Salc * 88844321Salc * Also, the backing vnode's iodone routine may not wake the pageout 88944321Salc * daemon up. This should be probably be addressed XXX. 89044321Salc */ 89144321Salc 89244321Salc if ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_pageout_free_min) 89344321Salc sync |= OBJPC_SYNC; 89444321Salc 89544321Salc /* 89644321Salc * Call device-specific putpages function 89744321Salc */ 89844321Salc 89910556Sdyson vp = object->handle; 90062976Smckusick if (vp->v_type != VREG) 90162976Smckusick mp = NULL; 90262976Smckusick (void)vn_start_write(vp, &mp, V_WAIT); 90334403Smsmith rtval = VOP_PUTPAGES(vp, m, bytes, sync, rtvals, 0); 90476827Salfred KASSERT(rtval != EOPNOTSUPP, 90576827Salfred ("vnode_pager: stale FS putpages\n")); 90662976Smckusick vn_finished_write(mp); 90710556Sdyson} 90810556Sdyson 90933847Smsmith 9101549Srgrimes/* 91133847Smsmith * This is now called from local media FS's to operate against their 91245057Seivind * own vnodes if they fail to implement VOP_PUTPAGES. 91370374Sdillon * 91470374Sdillon * This is typically called indirectly via the pageout daemon and 91570374Sdillon * clustering has already typically occured, so in general we ask the 91670374Sdillon * underlying filesystem to write the data out asynchronously rather 91770374Sdillon * then delayed. 9181549Srgrimes */ 91933847Smsmithint 92034206Sdysonvnode_pager_generic_putpages(vp, m, bytecount, flags, rtvals) 92133847Smsmith struct vnode *vp; 9221549Srgrimes vm_page_t *m; 92333847Smsmith int bytecount; 92434206Sdyson int flags; 9255455Sdg int *rtvals; 9261549Srgrimes{ 9277695Sdg int i; 92833847Smsmith vm_object_t object; 92933847Smsmith int count; 9301549Srgrimes 9317695Sdg int maxsize, ncount; 93212767Sdyson vm_ooffset_t poffset; 9337695Sdg struct uio auio; 9347695Sdg struct iovec aiov; 9357695Sdg int error; 93634206Sdyson int ioflags; 9371549Srgrimes 93879224Sdillon GIANT_REQUIRED; 93933847Smsmith object = vp->v_object; 94033847Smsmith count = bytecount / PAGE_SIZE; 94133847Smsmith 9421827Sdg for (i = 0; i < count; i++) 9431549Srgrimes rtvals[i] = VM_PAGER_AGAIN; 9441549Srgrimes 94512767Sdyson if ((int) m[0]->pindex < 0) { 94648409Speter printf("vnode_pager_putpages: attempt to write meta-data!!! -- 0x%lx(%x)\n", 94748409Speter (long)m[0]->pindex, m[0]->dirty); 9487695Sdg rtvals[0] = VM_PAGER_BAD; 9497695Sdg return VM_PAGER_BAD; 9505455Sdg } 9517178Sdg 9527695Sdg maxsize = count * PAGE_SIZE; 9537695Sdg ncount = count; 9541549Srgrimes 95512767Sdyson poffset = IDX_TO_OFF(m[0]->pindex); 95612767Sdyson if (maxsize + poffset > object->un_pager.vnp.vnp_size) { 95712767Sdyson if (object->un_pager.vnp.vnp_size > poffset) 95812767Sdyson maxsize = object->un_pager.vnp.vnp_size - poffset; 9598585Sdg else 9608585Sdg maxsize = 0; 96115583Sphk ncount = btoc(maxsize); 9628585Sdg if (ncount < count) { 9638585Sdg for (i = ncount; i < count; i++) { 9647695Sdg rtvals[i] = VM_PAGER_BAD; 9651549Srgrimes } 9661549Srgrimes } 9671541Srgrimes } 9687695Sdg 96970374Sdillon /* 97070374Sdillon * pageouts are already clustered, use IO_ASYNC t o force a bawrite() 97170374Sdillon * rather then a bdwrite() to prevent paging I/O from saturating 97270374Sdillon * the buffer cache. 97370374Sdillon */ 97434206Sdyson ioflags = IO_VMIO; 97570374Sdillon ioflags |= (flags & (VM_PAGER_PUT_SYNC | VM_PAGER_PUT_INVAL)) ? IO_SYNC: IO_ASYNC; 97634206Sdyson ioflags |= (flags & VM_PAGER_PUT_INVAL) ? IO_INVAL: 0; 9771827Sdg 9787695Sdg aiov.iov_base = (caddr_t) 0; 9797695Sdg aiov.iov_len = maxsize; 9807695Sdg auio.uio_iov = &aiov; 9817695Sdg auio.uio_iovcnt = 1; 98212767Sdyson auio.uio_offset = poffset; 9837695Sdg auio.uio_segflg = UIO_NOCOPY; 9847695Sdg auio.uio_rw = UIO_WRITE; 9857695Sdg auio.uio_resid = maxsize; 98683366Sjulian auio.uio_td = (struct thread *) 0; 98783366Sjulian error = VOP_WRITE(vp, &auio, ioflags, curthread->td_proc->p_ucred); 9883612Sdg cnt.v_vnodeout++; 9897695Sdg cnt.v_vnodepgsout += ncount; 9903612Sdg 9918585Sdg if (error) { 9929507Sdg printf("vnode_pager_putpages: I/O error %d\n", error); 9937695Sdg } 9948585Sdg if (auio.uio_resid) { 99537555Sbde printf("vnode_pager_putpages: residual I/O %d at %lu\n", 99637555Sbde auio.uio_resid, (u_long)m[0]->pindex); 9977695Sdg } 99833936Sdyson for (i = 0; i < ncount; i++) { 99933936Sdyson rtvals[i] = VM_PAGER_OK; 10007695Sdg } 10017695Sdg return rtvals[0]; 10027695Sdg} 10031549Srgrimes 10047695Sdgstruct vnode * 10059507Sdgvnode_pager_lock(object) 10069507Sdg vm_object_t object; 10079507Sdg{ 100883366Sjulian struct thread *td = curthread; /* XXX */ 100922521Sdyson 101079224Sdillon GIANT_REQUIRED; 101179224Sdillon 10129507Sdg for (; object != NULL; object = object->backing_object) { 10139507Sdg if (object->type != OBJT_VNODE) 10147695Sdg continue; 101577094Sjhb if (object->flags & OBJ_DEAD) { 101632585Sdyson return NULL; 101777094Sjhb } 10181549Srgrimes 101977094Sjhb /* XXX; If object->handle can change, we need to cache it. */ 102032585Sdyson while (vget(object->handle, 102183366Sjulian LK_NOPAUSE | LK_SHARED | LK_RETRY | LK_CANRECURSE, td)){ 102234611Sdyson if ((object->flags & OBJ_DEAD) || (object->type != OBJT_VNODE)) 102334611Sdyson return NULL; 102432585Sdyson printf("vnode_pager_lock: retrying\n"); 102532585Sdyson } 10269507Sdg return object->handle; 10271549Srgrimes } 10289507Sdg return NULL; 10297695Sdg} 1030