- if (size < bp->b_bcount || bp->b_dev == NODEV)
- goto allocit;
-
- start = bp->b_blkno + (bp->b_bcount / DEV_BSIZE);
- last = bp->b_blkno + (size / DEV_BSIZE) - 1;
- if (bp->b_bcount == 0) {
- start++;
- if (start == last)
- goto allocit;
- }
- dp = BUFHASH(bp->b_dev, bp->b_blkno);
-loop:
- for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
- if (ep->b_blkno < start || ep->b_blkno > last ||
- ep->b_dev != bp->b_dev || ep->b_flags&B_INVAL)
- continue;
- s = spl6();
- if (ep->b_flags&B_BUSY) {
- ep->b_flags |= B_WANTED;
- sleep((caddr_t)ep, PRIBIO+1);
- (void) splx(s);
- goto loop;
- }
- (void) splx(s);
- /*
- * What we would really like to do is kill this
- * I/O since it is now useless. We cannot do that
- * so we force it to complete, so that it cannot
- * over-write our useful data later.
- */
- if (ep->b_flags & B_DELWRI) {
- notavail(ep);
- ep->b_flags |= B_ASYNC;
- bwrite(ep);
- goto loop;
- }
- }
-allocit:
- /*
- * Here the buffer is already available, so all we
- * need to do is set the size. Someday a better memory
- * management scheme will be implemented.
- */
- bp->b_bcount = size;