-
-/*
- * Ensure that no part of a specified block is in an incore buffer.
-#ifdef SECSIZE
- * "size" is given in device blocks (the units of b_blkno).
-#endif SECSIZE
-#ifdef SECSIZE
- * "size" is given in device blocks (the units of b_blkno).
-#endif SECSIZE
- */
-blkflush(vp, blkno, size)
- struct vnode *vp;
- daddr_t blkno;
-#ifdef SECSIZE
- int size;
-#else SECSIZE
- long size;
-#endif SECSIZE
-{
- register struct buf *ep;
- struct buf *dp;
- daddr_t curblk, nextblk, ecurblk, lastblk;
- int s, error, allerrors = 0;
-
- /*
- * Iterate through each possible hash chain.
- */
- lastblk = blkno + btodb(size) - 1;
- for (curblk = blkno; curblk <= lastblk; curblk = nextblk) {
-#if RND & (RND-1)
- nextblk = ((curblk / RND) + 1) * RND;
-#else
- nextblk = ((curblk & ~(RND-1)) + RND);
-#endif
- ecurblk = nextblk > lastblk ? lastblk : nextblk - 1;
- dp = BUFHASH(vp, curblk);
-loop:
- for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
- if (ep->b_vp != vp || (ep->b_flags & B_INVAL))
- continue;
- /* look for overlap */
- if (ep->b_bcount == 0 || ep->b_blkno > ecurblk ||
- ep->b_blkno + btodb(ep->b_bcount) <= curblk)
- continue;
- s = splbio();
- if (ep->b_flags&B_BUSY) {
- ep->b_flags |= B_WANTED;
- sleep((caddr_t)ep, PRIBIO+1);
- splx(s);
- goto loop;
- }
- if (ep->b_flags & B_DELWRI) {
- splx(s);
- notavail(ep);
- if (error = bwrite(ep))
- allerrors = error;
- goto loop;
- }
- splx(s);
- }
- }
- return (allerrors);
-}
-
-/*
- * Make sure all write-behind blocks associated
- * with mount point are flushed out (from sync).
- */
-bflush(mountp)
- struct mount *mountp;
-{
- register struct buf *bp;
- register struct buf *flist;
- int s;
-
-loop:
- s = splbio();
- for (flist = bfreelist; flist < &bfreelist[BQ_EMPTY]; flist++) {
- for (bp = flist->av_forw; bp != flist; bp = bp->av_forw) {
- if ((bp->b_flags & B_BUSY))
- continue;
- if ((bp->b_flags & B_DELWRI) == 0)
- continue;
- if (bp->b_vp && bp->b_vp->v_mount == mountp) {
- splx(s);
- notavail(bp);
- (void) bawrite(bp);
- goto loop;
- }
- }
- }
- splx(s);
-}
-
-/*
- * Invalidate in core blocks belonging to closed or umounted filesystem
- *
- * We walk through the buffer pool and invalidate any buffers for the
- * indicated mount point. Normally this routine is preceeded by a bflush
- * call, so that on a quiescent filesystem there will be no dirty
- * buffers when we are done. We return the count of dirty buffers when
- * we are finished.
- */
-binval(mountp)
- struct mount *mountp;
-{
- register struct buf *bp;
- register struct bufhd *hp;
- int s, dirty = 0;
-#define dp ((struct buf *)hp)
-
-loop:
- for (hp = bufhash; hp < &bufhash[BUFHSZ]; hp++) {
- for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) {
- if (bp->b_vp == NULL || bp->b_vp->v_mount != mountp)
- continue;
- s = splbio();
- if (bp->b_flags & B_BUSY) {
- bp->b_flags |= B_WANTED;
- sleep((caddr_t)bp, PRIBIO+1);
- splx(s);
- goto loop;
- }
- splx(s);
- notavail(bp);
- if (bp->b_flags & B_DELWRI) {
- (void) bawrite(bp);
- dirty++;
- continue;
- }
- bp->b_flags |= B_INVAL;
- brelvp(bp);
- brelse(bp);
- }
- }
- return (dirty);
-}
-
-brelvp(bp)
- struct buf *bp;
-{
- struct vnode *vp;
-
- if (bp->b_vp == (struct vnode *) 0)
- return;
- vp = bp->b_vp;
- bp->b_vp = (struct vnode *) 0;
- vrele(vp);
-}