2 * Copyright (c) 1990 University of Utah.
3 * Copyright (c) 1991 The Regents of the University of California.
5 * Copyright (c) 1993, 1994 John S. Dyson
6 * Copyright (c) 1995, David Greenman
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * from: @(#)vnode_pager.c 7.5 (Berkeley) 4/20/91
45 * Page to/from files (vnodes).
50 * Implement VOP_GETPAGES/PUTPAGES interface for filesystems. Will
51 * greatly re-simplify the vnode_pager.
54 #include <sys/param.h>
55 #include <sys/systm.h>
57 #include <sys/vnode.h>
58 #include <sys/mount.h>
61 #include <sys/vmmeter.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_page.h>
67 #include <vm/vm_pager.h>
68 #include <vm/vm_map.h>
69 #include <vm/vnode_pager.h>
70 #include <vm/vm_extern.h>
72 static vm_offset_t vnode_pager_addr __P((struct vnode *vp, vm_ooffset_t address,
74 static void vnode_pager_iodone __P((struct buf *bp));
75 static int vnode_pager_input_smlfs __P((vm_object_t object, vm_page_t m));
76 static int vnode_pager_input_old __P((vm_object_t object, vm_page_t m));
77 static void vnode_pager_dealloc __P((vm_object_t));
78 static int vnode_pager_getpages __P((vm_object_t, vm_page_t *, int, int));
79 static void vnode_pager_putpages __P((vm_object_t, vm_page_t *, int, boolean_t, int *));
80 static boolean_t vnode_pager_haspage __P((vm_object_t, vm_pindex_t, int *, int *));
82 struct pagerops vnodepagerops = {
92 int vnode_pbuf_freecnt = -1; /* start out unlimited */
96 * Allocate (or lookup) pager for a vnode.
97 * Handle is a vnode pointer.
100 vnode_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
106 mtx_assert(&Giant, MA_OWNED);
108 * Pageout to vnode, no can do yet.
114 * XXX hack - This initialization should be put somewhere else.
116 if (vnode_pbuf_freecnt < 0) {
117 vnode_pbuf_freecnt = nswbuf / 2 + 1;
120 vp = (struct vnode *) handle;
123 * Prevent race condition when allocating the object. This
124 * can happen with NFS vnodes since the nfsnode isn't locked.
127 while (vp->v_flag & VOLOCK) {
128 vp->v_flag |= VOWANT;
129 tsleep(vp, PVM, "vnpobj", 0);
131 vp->v_flag |= VOLOCK;
135 * If the object is being terminated, wait for it to
138 while (((object = vp->v_object) != NULL) &&
139 (object->flags & OBJ_DEAD)) {
140 msleep(object, &vm_mtx, PVM, "vadead", 0);
143 if (vp->v_usecount == 0)
144 panic("vnode_pager_alloc: no vnode reference");
146 if (object == NULL) {
148 * And an object of the appropriate size
150 object = vm_object_allocate(OBJT_VNODE, OFF_TO_IDX(round_page(size)));
153 object->un_pager.vnp.vnp_size = size;
155 object->handle = handle;
156 vp->v_object = object;
164 vp->v_flag &= ~VOLOCK;
165 if (vp->v_flag & VOWANT) {
166 vp->v_flag &= ~VOWANT;
174 vnode_pager_dealloc(object)
177 register struct vnode *vp = object->handle;
179 mtx_assert(&Giant, MA_OWNED);
181 panic("vnode_pager_dealloc: pager already dealloced");
183 vm_object_pip_wait(object, "vnpdea");
185 object->handle = NULL;
186 object->type = OBJT_DEAD;
188 vp->v_flag &= ~(VTEXT | VOBJBUF);
192 vnode_pager_haspage(object, pindex, before, after)
198 struct vnode *vp = object->handle;
204 int pagesperblock, blocksperpage;
206 mtx_assert(&Giant, MA_OWNED);
208 * If no vp or vp is doomed or marked transparent to VM, we do not
211 if ((vp == NULL) || (vp->v_flag & VDOOMED))
215 * If filesystem no longer mounted or offset beyond end of file we do
218 if ((vp->v_mount == NULL) ||
219 (IDX_TO_OFF(pindex) >= object->un_pager.vnp.vnp_size))
222 bsize = vp->v_mount->mnt_stat.f_iosize;
223 pagesperblock = bsize / PAGE_SIZE;
225 if (pagesperblock > 0) {
226 reqblock = pindex / pagesperblock;
228 blocksperpage = (PAGE_SIZE / bsize);
229 reqblock = pindex * blocksperpage;
232 err = VOP_BMAP(vp, reqblock, (struct vnode **) 0, &bn,
239 if (pagesperblock > 0) {
240 poff = pindex - (reqblock * pagesperblock);
242 *before *= pagesperblock;
247 *after *= pagesperblock;
248 numafter = pagesperblock - (poff + 1);
249 if (IDX_TO_OFF(pindex + numafter) > object->un_pager.vnp.vnp_size) {
250 numafter = OFF_TO_IDX((object->un_pager.vnp.vnp_size - IDX_TO_OFF(pindex)));
256 *before /= blocksperpage;
260 *after /= blocksperpage;
267 * Lets the VM system know about a change in size for a file.
268 * We adjust our own internal size and flush any cached pages in
269 * the associated object that are affected by the size change.
271 * Note: this routine may be invoked as a result of a pager put
272 * operation (possibly at object termination time), so we must be careful.
275 vnode_pager_setsize(vp, nsize)
279 vm_pindex_t nobjsize;
280 vm_object_t object = vp->v_object;
286 * Hasn't changed size
288 if (nsize == object->un_pager.vnp.vnp_size)
291 nobjsize = OFF_TO_IDX(nsize + PAGE_MASK);
294 * File has shrunk. Toss any cached pages beyond the new EOF.
296 if (nsize < object->un_pager.vnp.vnp_size) {
299 hadvmlock = mtx_owned(&vm_mtx);
302 vm_freeze_copyopts(object, OFF_TO_IDX(nsize), object->size);
303 if (nobjsize < object->size) {
304 vm_object_page_remove(object, nobjsize, object->size,
308 * this gets rid of garbage at the end of a page that is now
309 * only partially backed by the vnode...
311 if (nsize & PAGE_MASK) {
315 m = vm_page_lookup(object, OFF_TO_IDX(nsize));
317 int base = (int)nsize & PAGE_MASK;
318 int size = PAGE_SIZE - base;
321 * Clear out partial-page garbage in case
322 * the page has been mapped.
324 kva = vm_pager_map_page(m);
325 bzero((caddr_t)kva + base, size);
326 vm_pager_unmap_page(kva);
329 * Clear out partial-page dirty bits. This
330 * has the side effect of setting the valid
331 * bits, but that is ok. There are a bunch
332 * of places in the VM system where we expected
333 * m->dirty == VM_PAGE_BITS_ALL. The file EOF
334 * case is one of them. If the page is still
335 * partially dirty, make it fully dirty.
337 vm_page_set_validclean(m, base, size);
339 m->dirty = VM_PAGE_BITS_ALL;
345 object->un_pager.vnp.vnp_size = nsize;
346 object->size = nobjsize;
350 * calculate the linear (byte) disk address of specified virtual
354 vnode_pager_addr(vp, address, run)
356 vm_ooffset_t address;
367 mtx_assert(&Giant, MA_OWNED);
368 if ((int) address < 0)
371 if (vp->v_mount == NULL)
374 bsize = vp->v_mount->mnt_stat.f_iosize;
375 vblock = address / bsize;
376 voffset = address % bsize;
379 err = VOP_BMAP(vp, vblock, &rtvp, &block, run, NULL);
382 if (err || (block == -1))
385 rtaddress = block + voffset / DEV_BSIZE;
388 *run *= bsize/PAGE_SIZE;
389 *run -= voffset/PAGE_SIZE;
397 * interrupt routine for I/O completion
400 vnode_pager_iodone(bp)
403 bp->b_flags |= B_DONE;
408 * small block file system vnode pager input
411 vnode_pager_input_smlfs(object, m)
417 struct vnode *dp, *vp;
424 mtx_assert(&Giant, MA_OWNED);
426 if (vp->v_mount == NULL)
429 bsize = vp->v_mount->mnt_stat.f_iosize;
432 VOP_BMAP(vp, 0, &dp, 0, NULL, NULL);
435 kva = vm_pager_map_page(m);
437 for (i = 0; i < PAGE_SIZE / bsize; i++) {
439 if (vm_page_bits(i * bsize, bsize) & m->valid)
442 fileaddr = vnode_pager_addr(vp,
443 IDX_TO_OFF(m->pindex) + i * bsize, (int *)0);
444 if (fileaddr != -1) {
446 bp = getpbuf(&vnode_pbuf_freecnt);
448 /* build a minimal buffer header */
449 bp->b_iocmd = BIO_READ;
450 bp->b_iodone = vnode_pager_iodone;
451 bp->b_rcred = bp->b_wcred = curproc->p_ucred;
452 if (bp->b_rcred != NOCRED)
454 if (bp->b_wcred != NOCRED)
456 bp->b_data = (caddr_t) kva + i * bsize;
457 bp->b_blkno = fileaddr;
459 bp->b_bcount = bsize;
460 bp->b_bufsize = bsize;
461 bp->b_runningbufspace = bp->b_bufsize;
462 runningbufspace += bp->b_runningbufspace;
467 /* we definitely need to be at splvm here */
470 while ((bp->b_flags & B_DONE) == 0) {
471 tsleep(bp, PVM, "vnsrd", 0);
474 if ((bp->b_ioflags & BIO_ERROR) != 0)
478 * free the buffer header back to the swap buffer pool
480 relpbuf(bp, &vnode_pbuf_freecnt);
485 vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize);
487 vm_page_set_validclean(m, (i * bsize) & PAGE_MASK, bsize);
488 bzero((caddr_t) kva + i * bsize, bsize);
491 vm_pager_unmap_page(kva);
492 pmap_clear_modify(m);
493 vm_page_flag_clear(m, PG_ZERO);
495 return VM_PAGER_ERROR;
503 * old style vnode pager output routine
506 vnode_pager_input_old(object, m)
517 mtx_assert(&Giant, MA_OWNED);
521 * Return failure if beyond current EOF
523 if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) {
527 if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size)
528 size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex);
531 * Allocate a kernel virtual address and initialize so that
532 * we can use VOP_READ/WRITE routines.
534 kva = vm_pager_map_page(m);
538 aiov.iov_base = (caddr_t) kva;
540 auio.uio_iov = &aiov;
542 auio.uio_offset = IDX_TO_OFF(m->pindex);
543 auio.uio_segflg = UIO_SYSSPACE;
544 auio.uio_rw = UIO_READ;
545 auio.uio_resid = size;
546 auio.uio_procp = curproc;
548 error = VOP_READ(vp, &auio, 0, curproc->p_ucred);
550 register int count = size - auio.uio_resid;
554 else if (count != PAGE_SIZE)
555 bzero((caddr_t) kva + count, PAGE_SIZE - count);
558 vm_pager_unmap_page(kva);
560 pmap_clear_modify(m);
562 vm_page_flag_clear(m, PG_ZERO);
564 m->valid = VM_PAGE_BITS_ALL;
565 return error ? VM_PAGER_ERROR : VM_PAGER_OK;
569 * generic vnode pager input routine
573 * Local media VFS's that do not implement their own VOP_GETPAGES
574 * should have their VOP_GETPAGES should call to
575 * vnode_pager_generic_getpages() to implement the previous behaviour.
577 * All other FS's should use the bypass to get to the local media
578 * backing vp's VOP_GETPAGES.
581 vnode_pager_getpages(object, m, count, reqpage)
589 int bytes = count * PAGE_SIZE;
591 mtx_assert(&Giant, MA_OWNED);
593 rtval = VOP_GETPAGES(vp, m, bytes, reqpage, 0);
594 KASSERT(rtval != EOPNOTSUPP,
595 ("vnode_pager: FS getpages not implemented\n"));
601 * This is now called from local media FS's to operate against their
602 * own vnodes if they fail to implement VOP_GETPAGES.
605 vnode_pager_generic_getpages(vp, m, bytecount, reqpage)
613 off_t foff, tfoff, nextoff;
614 int i, size, bsize, first, firstaddr;
623 mtx_assert(&Giant, MA_OWNED);
624 object = vp->v_object;
625 count = bytecount / PAGE_SIZE;
627 if (vp->v_mount == NULL)
630 bsize = vp->v_mount->mnt_stat.f_iosize;
632 /* get the UNDERLYING device for the file with VOP_BMAP() */
635 * originally, we did not check for an error return value -- assuming
636 * an fs always has a bmap entry point -- that assumption is wrong!!!
638 foff = IDX_TO_OFF(m[reqpage]->pindex);
641 * if we can't bmap, use old VOP code
644 if (VOP_BMAP(vp, 0, &dp, 0, NULL, NULL)) {
646 for (i = 0; i < count; i++) {
653 return vnode_pager_input_old(object, m[reqpage]);
656 * if the blocksize is smaller than a page size, then use
657 * special small filesystem code. NFS sometimes has a small
658 * blocksize, but it can handle large reads itself.
660 } else if ((PAGE_SIZE / bsize) > 1 &&
661 (vp->v_mount->mnt_stat.f_type != nfs_mount_type)) {
663 for (i = 0; i < count; i++) {
670 return vnode_pager_input_smlfs(object, m[reqpage]);
675 * If we have a completely valid page available to us, we can
676 * clean up and return. Otherwise we have to re-read the
680 if (m[reqpage]->valid == VM_PAGE_BITS_ALL) {
681 for (i = 0; i < count; i++) {
687 m[reqpage]->valid = 0;
690 * here on direct device I/O
695 * calculate the run that includes the required page
697 for(first = 0, i = 0; i < count; i = runend) {
698 firstaddr = vnode_pager_addr(vp,
699 IDX_TO_OFF(m[i]->pindex), &runpg);
700 if (firstaddr == -1) {
701 if (i == reqpage && foff < object->un_pager.vnp.vnp_size) {
702 /* XXX no %qd in kernel. */
703 panic("vnode_pager_getpages: unexpected missing page: firstaddr: %d, foff: 0x%lx%08lx, vnp_size: 0x%lx%08lx",
704 firstaddr, (u_long)(foff >> 32),
705 (u_long)(u_int32_t)foff,
707 (object->un_pager.vnp.vnp_size >> 32),
709 object->un_pager.vnp.vnp_size);
717 if (runend <= reqpage) {
719 for (j = i; j < runend; j++) {
723 if (runpg < (count - first)) {
724 for (i = first + runpg; i < count; i++)
726 count = first + runpg;
734 * the first and last page have been calculated now, move input pages
735 * to be zero based...
738 for (i = first; i < count; i++) {
746 * calculate the file virtual address for the transfer
748 foff = IDX_TO_OFF(m[0]->pindex);
751 * calculate the size of the transfer
753 size = count * PAGE_SIZE;
754 if ((foff + size) > object->un_pager.vnp.vnp_size)
755 size = object->un_pager.vnp.vnp_size - foff;
758 * round up physical size for real devices.
760 if (dp->v_type == VBLK || dp->v_type == VCHR) {
761 int secmask = dp->v_rdev->si_bsize_phys - 1;
762 KASSERT(secmask < PAGE_SIZE, ("vnode_pager_generic_getpages: sector size %d too large\n", secmask + 1));
763 size = (size + secmask) & ~secmask;
766 bp = getpbuf(&vnode_pbuf_freecnt);
767 kva = (vm_offset_t) bp->b_data;
770 * and map the pages to be read into the kva
772 pmap_qenter(kva, m, count);
775 /* build a minimal buffer header */
776 bp->b_iocmd = BIO_READ;
777 bp->b_iodone = vnode_pager_iodone;
778 /* B_PHYS is not set, but it is nice to fill this in */
779 bp->b_rcred = bp->b_wcred = curproc->p_ucred;
780 if (bp->b_rcred != NOCRED)
782 if (bp->b_wcred != NOCRED)
784 bp->b_blkno = firstaddr;
787 bp->b_bufsize = size;
788 bp->b_runningbufspace = bp->b_bufsize;
789 runningbufspace += bp->b_runningbufspace;
792 cnt.v_vnodepgsin += count;
798 /* we definitely need to be at splvm here */
800 while ((bp->b_flags & B_DONE) == 0) {
801 tsleep(bp, PVM, "vnread", 0);
804 if ((bp->b_ioflags & BIO_ERROR) != 0)
808 if (size != count * PAGE_SIZE)
809 bzero((caddr_t) kva + size, PAGE_SIZE * count - size);
812 pmap_qremove(kva, count);
815 * free the buffer header back to the swap buffer pool
817 relpbuf(bp, &vnode_pbuf_freecnt);
819 for (i = 0, tfoff = foff; i < count; i++, tfoff = nextoff) {
822 nextoff = tfoff + PAGE_SIZE;
825 if (nextoff <= object->un_pager.vnp.vnp_size) {
827 * Read filled up entire page.
829 mt->valid = VM_PAGE_BITS_ALL;
830 vm_page_undirty(mt); /* should be an assert? XXX */
831 pmap_clear_modify(mt);
834 * Read did not fill up entire page. Since this
835 * is getpages, the page may be mapped, so we have
836 * to zero the invalid portions of the page even
837 * though we aren't setting them valid.
839 * Currently we do not set the entire page valid,
840 * we just try to clear the piece that we couldn't
843 vm_page_set_validclean(mt, 0,
844 object->un_pager.vnp.vnp_size - tfoff);
845 /* handled by vm_fault now */
846 /* vm_page_zero_invalid(mt, FALSE); */
849 vm_page_flag_clear(mt, PG_ZERO);
853 * whether or not to leave the page activated is up in
854 * the air, but we should put the page on a page queue
855 * somewhere. (it already is in the object). Result:
856 * It appears that empirical results show that
857 * deactivating pages is best.
861 * just in case someone was asking for this page we
862 * now tell them that it is ok to use
865 if (mt->flags & PG_WANTED)
866 vm_page_activate(mt);
868 vm_page_deactivate(mt);
876 printf("vnode_pager_getpages: I/O read error\n");
878 return (error ? VM_PAGER_ERROR : VM_PAGER_OK);
882 * EOPNOTSUPP is no longer legal. For local media VFS's that do not
883 * implement their own VOP_PUTPAGES, their VOP_PUTPAGES should call to
884 * vnode_pager_generic_putpages() to implement the previous behaviour.
886 * All other FS's should use the bypass to get to the local media
887 * backing vp's VOP_PUTPAGES.
890 vnode_pager_putpages(object, m, count, sync, rtvals)
900 int bytes = count * PAGE_SIZE;
902 mtx_assert(&Giant, MA_OWNED);
904 * Force synchronous operation if we are extremely low on memory
905 * to prevent a low-memory deadlock. VOP operations often need to
906 * allocate more memory to initiate the I/O ( i.e. do a BMAP
907 * operation ). The swapper handles the case by limiting the amount
908 * of asynchronous I/O, but that sort of solution doesn't scale well
909 * for the vnode pager without a lot of work.
911 * Also, the backing vnode's iodone routine may not wake the pageout
912 * daemon up. This should be probably be addressed XXX.
915 if ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_pageout_free_min)
919 * Call device-specific putpages function
924 if (vp->v_type != VREG)
926 (void)vn_start_write(vp, &mp, V_WAIT);
928 rtval = VOP_PUTPAGES(vp, m, bytes, sync, rtvals, 0);
929 KASSERT(rtval != EOPNOTSUPP,
930 ("vnode_pager: stale FS putpages\n"));
932 vn_finished_write(mp);
938 * This is now called from local media FS's to operate against their
939 * own vnodes if they fail to implement VOP_PUTPAGES.
941 * This is typically called indirectly via the pageout daemon and
942 * clustering has already typically occured, so in general we ask the
943 * underlying filesystem to write the data out asynchronously rather
947 vnode_pager_generic_putpages(vp, m, bytecount, flags, rtvals)
959 vm_ooffset_t poffset;
965 mtx_assert(&Giant, MA_OWNED);
966 object = vp->v_object;
967 count = bytecount / PAGE_SIZE;
969 for (i = 0; i < count; i++)
970 rtvals[i] = VM_PAGER_AGAIN;
972 if ((int) m[0]->pindex < 0) {
973 printf("vnode_pager_putpages: attempt to write meta-data!!! -- 0x%lx(%x)\n",
974 (long)m[0]->pindex, m[0]->dirty);
975 rtvals[0] = VM_PAGER_BAD;
979 maxsize = count * PAGE_SIZE;
982 poffset = IDX_TO_OFF(m[0]->pindex);
983 if (maxsize + poffset > object->un_pager.vnp.vnp_size) {
984 if (object->un_pager.vnp.vnp_size > poffset)
985 maxsize = object->un_pager.vnp.vnp_size - poffset;
988 ncount = btoc(maxsize);
989 if (ncount < count) {
990 for (i = ncount; i < count; i++) {
991 rtvals[i] = VM_PAGER_BAD;
998 * pageouts are already clustered, use IO_ASYNC t o force a bawrite()
999 * rather then a bdwrite() to prevent paging I/O from saturating
1003 ioflags |= (flags & (VM_PAGER_PUT_SYNC | VM_PAGER_PUT_INVAL)) ? IO_SYNC: IO_ASYNC;
1004 ioflags |= (flags & VM_PAGER_PUT_INVAL) ? IO_INVAL: 0;
1006 aiov.iov_base = (caddr_t) 0;
1007 aiov.iov_len = maxsize;
1008 auio.uio_iov = &aiov;
1009 auio.uio_iovcnt = 1;
1010 auio.uio_offset = poffset;
1011 auio.uio_segflg = UIO_NOCOPY;
1012 auio.uio_rw = UIO_WRITE;
1013 auio.uio_resid = maxsize;
1014 auio.uio_procp = (struct proc *) 0;
1015 error = VOP_WRITE(vp, &auio, ioflags, curproc->p_ucred);
1018 cnt.v_vnodepgsout += ncount;
1021 printf("vnode_pager_putpages: I/O error %d\n", error);
1023 if (auio.uio_resid) {
1024 printf("vnode_pager_putpages: residual I/O %d at %lu\n",
1025 auio.uio_resid, (u_long)m[0]->pindex);
1027 for (i = 0; i < ncount; i++) {
1028 rtvals[i] = VM_PAGER_OK;
1034 vnode_pager_lock(object)
1037 struct proc *p = curproc; /* XXX */
1039 mtx_assert(&vm_mtx, MA_NOTOWNED);
1040 mtx_assert(&Giant, MA_OWNED);
1042 for (; object != NULL; object = object->backing_object) {
1043 if (object->type != OBJT_VNODE)
1045 if (object->flags & OBJ_DEAD) {
1046 mtx_unlock(&vm_mtx);
1050 mtx_unlock(&vm_mtx);
1051 /* XXX; If object->handle can change, we need to cache it. */
1052 while (vget(object->handle,
1053 LK_NOPAUSE | LK_SHARED | LK_RETRY | LK_CANRECURSE, p)) {
1054 if ((object->flags & OBJ_DEAD) || (object->type != OBJT_VNODE))
1056 printf("vnode_pager_lock: retrying\n");
1058 return object->handle;
1060 mtx_unlock(&vm_mtx);