- return (1);
- if (size < bp->b_bcount) {
- if (bp->b_flags & B_DELWRI) {
- bwrite(bp);
- return (0);
- }
- if (bp->b_flags & B_LOCKED)
- panic("brealloc");
- goto allocit;
- }
- bp->b_flags &= ~B_DONE;
- if (bp->b_dev == NODEV)
- goto allocit;
-
- /*
- * Search cache for any buffers that overlap the one that we
- * are trying to allocate. Overlapping buffers must be marked
- * invalid, after being written out if they are dirty. (indicated
- * by B_DELWRI) A disk block must be mapped by at most one buffer
- * at any point in time. Care must be taken to avoid deadlocking
- * when two buffer are trying to get the same set of disk blocks.
- */
- start = bp->b_blkno;
- last = start + (size / DEV_BSIZE) - 1;
- dp = BUFHASH(bp->b_dev, bp->b_blkno);
-loop:
- for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
- if (ep == bp || ep->b_dev != bp->b_dev || (ep->b_flags&B_INVAL))
- continue;
- /* look for overlap */
- if (ep->b_bcount == 0 || ep->b_blkno > last ||
- ep->b_blkno + (ep->b_bcount / DEV_BSIZE) <= start)
- continue;
-if (bioprintfs)
-if (ep->b_flags&B_BUSY)
-printf("sleeping on:dev 0x%x, blks %d-%d, flg 0%o allocing dev 0x%x, blks %d-%d, flg 0%o\n",
-ep->b_dev, ep->b_blkno, ep->b_blkno + (ep->b_bcount / DEV_BSIZE) - 1,
-ep->b_flags, bp->b_dev, start, last, bp->b_flags);
- 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);
- notavail(ep);
- if (ep->b_flags & B_DELWRI) {
-if (bioprintfs)
-printf("DELWRI:dev 0x%x, blks %d-%d, flg 0%o allocing dev 0x%x, blks %d-%d, flg 0%o\n",
-ep->b_dev, ep->b_blkno, ep->b_blkno + (ep->b_bcount / DEV_BSIZE) - 1,
-ep->b_flags, bp->b_dev, start, last, bp->b_flags);
- bwrite(ep);
- goto loop;
- }
- ep->b_flags |= B_INVAL;
- brelse(ep);
- }
-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;
- return (1);