Print this page
5382 pvn_getpages handles lengths <= PAGESIZE just fine


  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
  25  *      All rights reserved.
  26  */
  27 
  28 /*
  29  * Copyright (c) 2013, Joyent, Inc. All rights reserved.

  30  */
  31 
  32 #include <sys/param.h>
  33 #include <sys/types.h>
  34 #include <sys/systm.h>
  35 #include <sys/cred.h>
  36 #include <sys/time.h>
  37 #include <sys/vnode.h>
  38 #include <sys/vfs.h>
  39 #include <sys/vfs_opreg.h>
  40 #include <sys/file.h>
  41 #include <sys/filio.h>
  42 #include <sys/uio.h>
  43 #include <sys/buf.h>
  44 #include <sys/mman.h>
  45 #include <sys/pathname.h>
  46 #include <sys/dirent.h>
  47 #include <sys/debug.h>
  48 #include <sys/vmsystm.h>
  49 #include <sys/fcntl.h>


3664          */
3665         if (rw == S_CREATE) {
3666                 while ((mi->mi_max_threads != 0 &&
3667                     rp->r_awcount > 2 * mi->mi_max_threads) ||
3668                     rp->r_gcount > 0)
3669                         cv_wait(&rp->r_cv, &rp->r_statelock);
3670         }
3671 
3672         /*
3673          * If we are getting called as a side effect of an nfs_write()
3674          * operation the local file size might not be extended yet.
3675          * In this case we want to be able to return pages of zeroes.
3676          */
3677         if (off + len > rp->r_size + PAGEOFFSET && seg != segkmap) {
3678                 mutex_exit(&rp->r_statelock);
3679                 return (EFAULT);                /* beyond EOF */
3680         }
3681 
3682         mutex_exit(&rp->r_statelock);
3683 
3684         if (len <= PAGESIZE) {
3685                 error = nfs_getapage(vp, off, len, protp, pl, plsz,
3686                     seg, addr, rw, cr);
3687         } else {
3688                 error = pvn_getpages(nfs_getapage, vp, off, len, protp,
3689                     pl, plsz, seg, addr, rw, cr);
3690         }
3691 
3692         switch (error) {
3693         case NFS_EOF:
3694                 nfs_purge_caches(vp, NFS_NOPURGE_DNLC, cr);
3695                 goto retry;
3696         case ESTALE:
3697                 PURGE_STALE_FH(error, vp, cr);
3698         }
3699 
3700         return (error);
3701 }
3702 
3703 /*
3704  * Called from pvn_getpages or nfs_getpage to get a particular page.
3705  */
3706 /* ARGSUSED */
3707 static int
3708 nfs_getapage(vnode_t *vp, u_offset_t off, size_t len, uint_t *protp,
3709         page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
3710         enum seg_rw rw, cred_t *cr)
3711 {
3712         rnode_t *rp;
3713         uint_t bsize;
3714         struct buf *bp;
3715         page_t *pp;
3716         u_offset_t lbn;
3717         u_offset_t io_off;
3718         u_offset_t blkoff;
3719         u_offset_t rablkoff;
3720         size_t io_len;
3721         uint_t blksize;
3722         int error;
3723         int readahead;
3724         int readahead_issued = 0;




  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
  25  *      All rights reserved.
  26  */
  27 
  28 /*
  29  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  30  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  31  */
  32 
  33 #include <sys/param.h>
  34 #include <sys/types.h>
  35 #include <sys/systm.h>
  36 #include <sys/cred.h>
  37 #include <sys/time.h>
  38 #include <sys/vnode.h>
  39 #include <sys/vfs.h>
  40 #include <sys/vfs_opreg.h>
  41 #include <sys/file.h>
  42 #include <sys/filio.h>
  43 #include <sys/uio.h>
  44 #include <sys/buf.h>
  45 #include <sys/mman.h>
  46 #include <sys/pathname.h>
  47 #include <sys/dirent.h>
  48 #include <sys/debug.h>
  49 #include <sys/vmsystm.h>
  50 #include <sys/fcntl.h>


3665          */
3666         if (rw == S_CREATE) {
3667                 while ((mi->mi_max_threads != 0 &&
3668                     rp->r_awcount > 2 * mi->mi_max_threads) ||
3669                     rp->r_gcount > 0)
3670                         cv_wait(&rp->r_cv, &rp->r_statelock);
3671         }
3672 
3673         /*
3674          * If we are getting called as a side effect of an nfs_write()
3675          * operation the local file size might not be extended yet.
3676          * In this case we want to be able to return pages of zeroes.
3677          */
3678         if (off + len > rp->r_size + PAGEOFFSET && seg != segkmap) {
3679                 mutex_exit(&rp->r_statelock);
3680                 return (EFAULT);                /* beyond EOF */
3681         }
3682 
3683         mutex_exit(&rp->r_statelock);
3684 
3685         error = pvn_getpages(nfs_getapage, vp, off, len, protp, pl, plsz,

3686             seg, addr, rw, cr);




3687 
3688         switch (error) {
3689         case NFS_EOF:
3690                 nfs_purge_caches(vp, NFS_NOPURGE_DNLC, cr);
3691                 goto retry;
3692         case ESTALE:
3693                 PURGE_STALE_FH(error, vp, cr);
3694         }
3695 
3696         return (error);
3697 }
3698 
3699 /*
3700  * Called from pvn_getpages to get a particular page.
3701  */
3702 /* ARGSUSED */
3703 static int
3704 nfs_getapage(vnode_t *vp, u_offset_t off, size_t len, uint_t *protp,
3705         page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
3706         enum seg_rw rw, cred_t *cr)
3707 {
3708         rnode_t *rp;
3709         uint_t bsize;
3710         struct buf *bp;
3711         page_t *pp;
3712         u_offset_t lbn;
3713         u_offset_t io_off;
3714         u_offset_t blkoff;
3715         u_offset_t rablkoff;
3716         size_t io_len;
3717         uint_t blksize;
3718         int error;
3719         int readahead;
3720         int readahead_issued = 0;