Index: vfs_cluster.c =================================================================== RCS file: /cvs/src/sys/kern/vfs_cluster.c,v retrieving revision 1.17 diff -u -r1.17 vfs_cluster.c --- vfs_cluster.c 5 Mar 2006 18:38:34 -0000 1.17 +++ vfs_cluster.c 7 Mar 2006 20:00:01 -0000 @@ -179,7 +179,7 @@ nblks = racluster; error = VOP_BMAP(vp, lblkno, NULL, - &blkno, &ncontigafter, NULL); + &blkno, &ncontigafter, NULL); if (error) goto single_block_read; if (blkno == -1) @@ -190,7 +190,7 @@ nblks = ncontigafter + 1; bp = cluster_rbuild(vp, filesize, lblkno, - blkno, size, nblks, bp); + blkno, size, nblks, bp); lblkno += (bp->b_bufsize / size); } else { single_block_read: @@ -204,36 +204,46 @@ } /* - * if we have been doing sequential I/O, then do some read-ahead + * If we have been doing sequential I/O, then do some read-ahead. */ rbp = NULL; - if (seqcount && (lblkno < (origblkno + seqcount))) { - /* - * we now build the read-ahead buffer if it is desirable. - */ - if (((u_quad_t)(lblkno + 1) * size) <= filesize && - !(error = VOP_BMAP(vp, lblkno, NULL, &blkno, &num_ra, NULL)) && - blkno != -1) { + if (seqcount && + lblkno < origblkno + seqcount && + (u_quad_t)(lblkno + 1) * size <= filesize + ) { + rbp = getblk(vp, lblkno, size, 0, 0); + if ((rbp->b_flags & B_CACHE) == 0) { int nblksread; - int ntoread = num_ra + 1; + int ntoread; + + error = VOP_BMAP(vp, lblkno, NULL, + &blkno, &num_ra, NULL); + if (error || blkno == (daddr_t)-1) { + rbp->b_flags &= ~(B_ASYNC | B_READ); + brelse(rbp); + rbp = NULL; + goto no_read_ahead; + } + ntoread = num_ra + 1; nblksread = (origtotread + size - 1) / size; if (seqcount < nblksread) seqcount = nblksread; if (seqcount < ntoread) ntoread = seqcount; + + rbp->b_flags |= B_READ | B_ASYNC | B_RAM; if (num_ra) { rbp = cluster_rbuild(vp, filesize, lblkno, - blkno, size, ntoread, NULL); + blkno, size, ntoread, rbp); } else { - rbp = getblk(vp, lblkno, size, 0, 0); - rbp->b_flags |= B_READ | B_ASYNC | B_RAM; rbp->b_bio2.bio_blkno = blkno; } } } +no_read_ahead: /* - * handle the synchronous read + * Handle the synchronous read */ if (bp) { #if defined(CLUSTERDEBUG) @@ -252,7 +262,7 @@ } /* - * and if we have read-aheads, do them too + * And if we have read-aheads, do them too */ if (rbp) { if (error) { @@ -316,16 +326,8 @@ --run; } - if (fbp) { - tbp = fbp; - tbp->b_flags |= B_READ; - } else { - tbp = getblk(vp, lbn, size, 0, 0); - if (tbp->b_flags & B_CACHE) - return tbp; - tbp->b_flags |= B_ASYNC | B_READ | B_RAM; - } - + tbp = fbp; + tbp->b_flags |= B_READ; tbp->b_bio2.bio_blkno = blkno; if( (tbp->b_flags & B_MALLOC) || ((tbp->b_flags & B_VMIO) == 0) || (run <= 1) ) @@ -420,7 +422,7 @@ /* * Set a read-ahead mark as appropriate */ - if ((fbp && (i == 1)) || (i == (run - 1))) + if (i == 1 || i == (run - 1)) tbp->b_flags |= B_RAM; /*