* Read data to a buf, including read-ahead if we find this to be beneficial. * cluster_read replaces bread. */
| 99 | * cluster_read replaces bread. |
| 100 | */ |
| 101 | int |
| 102 | cluster_read(struct vnode *vp, u_quad_t filesize, daddr_t lblkno, long size, |
| 103 | struct ucred *cred, long totread, int seqcount, int gbflags, |
| 104 | struct buf **bpp) |
| 105 | { |
| 106 | struct buf *bp, *rbp, *reqbp; |
| 107 | struct bufobj *bo; |
| 108 | struct thread *td; |
| 109 | daddr_t blkno, origblkno; |
| 110 | int maxra, racluster; |
| 111 | int error, ncontig; |
| 112 | int i; |
| 113 | |
| 114 | error = 0; |
| 115 | td = curthread; |
| 116 | bo = &vp->v_bufobj; |
| 117 | if (!unmapped_buf_allowed) |
| 118 | gbflags &= ~GB_UNMAPPED; |
| 119 | |
| 120 | /* |
| 121 | * Try to limit the amount of read-ahead by a few |
| 122 | * ad-hoc parameters. This needs work!!! |
| 123 | */ |
| 124 | racluster = vp->v_mount->mnt_iosize_max / size; |
| 125 | maxra = seqcount; |
| 126 | maxra = min(read_max, maxra); |
| 127 | maxra = min(nbuf/8, maxra); |
| 128 | if (((u_quad_t)(lblkno + maxra + 1) * size) > filesize) |
| 129 | maxra = (filesize / size) - lblkno; |
| 130 | |
| 131 | /* |
| 132 | * get the requested block |
| 133 | */ |
| 134 | error = getblkx(vp, lblkno, lblkno, size, 0, 0, gbflags, &bp); |
| 135 | if (error != 0) { |
| 136 | *bpp = NULL; |
| 137 | return (error); |
| 138 | } |
| 139 | gbflags &= ~GB_NOSPARSE; |
| 140 | origblkno = lblkno; |
| 141 | *bpp = reqbp = bp; |
| 142 | |
| 143 | /* |
| 144 | * if it is in the cache, then check to see if the reads have been |
| 145 | * sequential. If they have, then try some read-ahead, otherwise |
| 146 | * back-off on prospective read-aheads. |
| 147 | */ |
| 148 | if (bp->b_flags & B_CACHE) { |
| 149 | if (!seqcount) { |
| 150 | return 0; |
| 151 | } else if ((bp->b_flags & B_RAM) == 0) { |
| 152 | return 0; |
| 153 | } else { |
| 154 | bp->b_flags &= ~B_RAM; |
| 155 | BO_RLOCK(bo); |
| 156 | for (i = 1; i < maxra; i++) { |
| 157 | /* |
| 158 | * Stop if the buffer does not exist or it |
nothing calls this directly
no test coverage detected