Home | History | Annotate | Line # | Download | only in rumpvfs
      1  1.42  riastrad /*	$NetBSD: vm_vfs.c,v 1.42 2023/04/22 13:53:53 riastradh Exp $	*/
      2   1.1     pooka 
      3   1.1     pooka /*
      4  1.28     pooka  * Copyright (c) 2008-2011 Antti Kantee.  All Rights Reserved.
      5   1.1     pooka  *
      6   1.1     pooka  * Redistribution and use in source and binary forms, with or without
      7   1.1     pooka  * modification, are permitted provided that the following conditions
      8   1.1     pooka  * are met:
      9   1.1     pooka  * 1. Redistributions of source code must retain the above copyright
     10   1.1     pooka  *    notice, this list of conditions and the following disclaimer.
     11   1.1     pooka  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1     pooka  *    notice, this list of conditions and the following disclaimer in the
     13   1.1     pooka  *    documentation and/or other materials provided with the distribution.
     14   1.1     pooka  *
     15   1.1     pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16   1.1     pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17   1.1     pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18   1.1     pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19   1.1     pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20   1.1     pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21   1.1     pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22   1.1     pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23   1.1     pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24   1.1     pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25   1.1     pooka  * SUCH DAMAGE.
     26   1.1     pooka  */
     27   1.1     pooka 
     28   1.3     pooka #include <sys/cdefs.h>
     29  1.42  riastrad __KERNEL_RCSID(0, "$NetBSD: vm_vfs.c,v 1.42 2023/04/22 13:53:53 riastradh Exp $");
     30   1.3     pooka 
     31   1.1     pooka #include <sys/param.h>
     32   1.1     pooka 
     33   1.1     pooka #include <sys/buf.h>
     34   1.1     pooka #include <sys/vnode.h>
     35   1.1     pooka 
     36   1.1     pooka #include <uvm/uvm.h>
     37   1.1     pooka #include <uvm/uvm_readahead.h>
     38   1.1     pooka 
     39  1.39       chs void
     40  1.39       chs uvm_aio_aiodone_pages(struct vm_page **pgs, int npages, bool write, int error)
     41  1.39       chs {
     42  1.39       chs 	struct uvm_object *uobj = pgs[0]->uobject;
     43  1.39       chs 	struct vm_page *pg;
     44  1.39       chs 	int i;
     45  1.39       chs 
     46  1.39       chs 	rw_enter(uobj->vmobjlock, RW_WRITER);
     47  1.39       chs 	for (i = 0; i < npages; i++) {
     48  1.39       chs 		pg = pgs[i];
     49  1.40       chs 		KASSERT((pg->flags & PG_PAGEOUT) == 0 ||
     50  1.40       chs 			(pg->flags & PG_FAKE) == 0);
     51  1.41       chs 
     52  1.41       chs 		if (pg->flags & PG_FAKE) {
     53  1.41       chs 			KASSERT(!write);
     54  1.41       chs 			pg->flags &= ~PG_FAKE;
     55  1.41       chs 			KASSERT(uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN);
     56  1.41       chs 			uvm_pagelock(pg);
     57  1.41       chs 			uvm_pageenqueue(pg);
     58  1.41       chs 			uvm_pageunlock(pg);
     59  1.41       chs 		}
     60  1.41       chs 
     61  1.39       chs 	}
     62  1.39       chs 	uvm_page_unbusy(pgs, npages);
     63  1.39       chs 	rw_exit(uobj->vmobjlock);
     64  1.39       chs }
     65  1.39       chs 
     66   1.6     pooka /*
     67  1.39       chs  * Release resources held during async io.
     68   1.7     pooka  */
     69   1.1     pooka void
     70   1.1     pooka uvm_aio_aiodone(struct buf *bp)
     71   1.1     pooka {
     72  1.33     rmind 	struct uvm_object *uobj = NULL;
     73  1.39       chs 	int npages = bp->b_bufsize >> PAGE_SHIFT;
     74   1.6     pooka 	struct vm_page **pgs;
     75   1.6     pooka 	vaddr_t va;
     76  1.39       chs 	int i, error;
     77  1.39       chs 	bool write;
     78  1.39       chs 
     79  1.39       chs 	error = bp->b_error;
     80  1.39       chs 	write = BUF_ISWRITE(bp);
     81   1.6     pooka 
     82  1.21     pooka 	KASSERT(npages > 0);
     83   1.6     pooka 	pgs = kmem_alloc(npages * sizeof(*pgs), KM_SLEEP);
     84   1.6     pooka 	for (i = 0; i < npages; i++) {
     85   1.6     pooka 		va = (vaddr_t)bp->b_data + (i << PAGE_SHIFT);
     86   1.6     pooka 		pgs[i] = uvm_pageratop(va);
     87  1.33     rmind 
     88  1.33     rmind 		if (uobj == NULL) {
     89  1.33     rmind 			uobj = pgs[i]->uobject;
     90  1.33     rmind 			KASSERT(uobj != NULL);
     91  1.33     rmind 		} else {
     92  1.33     rmind 			KASSERT(uobj == pgs[i]->uobject);
     93  1.33     rmind 		}
     94   1.6     pooka 	}
     95  1.39       chs 	uvm_pagermapout((vaddr_t)bp->b_data, npages);
     96   1.6     pooka 
     97  1.39       chs 	uvm_aio_aiodone_pages(pgs, npages, write, error);
     98  1.25     pooka 
     99  1.39       chs 	if (write && (bp->b_cflags & BC_AGE) != 0) {
    100   1.6     pooka 		mutex_enter(bp->b_objlock);
    101   1.6     pooka 		vwakeup(bp);
    102   1.6     pooka 		mutex_exit(bp->b_objlock);
    103   1.6     pooka 	}
    104   1.6     pooka 
    105   1.6     pooka 	putiobuf(bp);
    106   1.6     pooka 
    107   1.6     pooka 	kmem_free(pgs, npages * sizeof(*pgs));
    108   1.1     pooka }
    109