Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/vfs_bio.c
Show First 20 Lines • Show All 1,473 Lines • ▼ Show 20 Lines | buf_alloc(void) | ||||
bp->b_offset = NOOFFSET; | bp->b_offset = NOOFFSET; | ||||
bp->b_iodone = 0; | bp->b_iodone = 0; | ||||
bp->b_error = 0; | bp->b_error = 0; | ||||
bp->b_resid = 0; | bp->b_resid = 0; | ||||
bp->b_bcount = 0; | bp->b_bcount = 0; | ||||
bp->b_npages = 0; | bp->b_npages = 0; | ||||
bp->b_dirtyoff = bp->b_dirtyend = 0; | bp->b_dirtyoff = bp->b_dirtyend = 0; | ||||
bp->b_bufobj = NULL; | bp->b_bufobj = NULL; | ||||
bp->b_pin_count = 0; | |||||
bp->b_data = bp->b_kvabase = unmapped_buf; | bp->b_data = bp->b_kvabase = unmapped_buf; | ||||
bp->b_fsprivate1 = NULL; | bp->b_fsprivate1 = NULL; | ||||
bp->b_fsprivate2 = NULL; | bp->b_fsprivate2 = NULL; | ||||
bp->b_fsprivate3 = NULL; | bp->b_fsprivate3 = NULL; | ||||
LIST_INIT(&bp->b_dep); | LIST_INIT(&bp->b_dep); | ||||
return (bp); | return (bp); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | bufwrite(struct buf *bp) | ||||
if (bp->b_flags & B_BARRIER) | if (bp->b_flags & B_BARRIER) | ||||
barrierwrites++; | barrierwrites++; | ||||
oldflags = bp->b_flags; | oldflags = bp->b_flags; | ||||
BUF_ASSERT_HELD(bp); | BUF_ASSERT_HELD(bp); | ||||
if (bp->b_pin_count > 0) | |||||
bunpin_wait(bp); | |||||
KASSERT(!(bp->b_vflags & BV_BKGRDINPROG), | KASSERT(!(bp->b_vflags & BV_BKGRDINPROG), | ||||
("FFS background buffer should not get here %p", bp)); | ("FFS background buffer should not get here %p", bp)); | ||||
vp = bp->b_vp; | vp = bp->b_vp; | ||||
if (vp) | if (vp) | ||||
vp_md = vp->v_vflag & VV_MD; | vp_md = vp->v_vflag & VV_MD; | ||||
else | else | ||||
vp_md = 0; | vp_md = 0; | ||||
▲ Show 20 Lines • Show All 1,196 Lines • ▼ Show 20 Lines | if (bp->b_qindex == QUEUE_SENTINEL || (lvp != NULL && | ||||
bp->b_vp != lvp)) { | bp->b_vp != lvp)) { | ||||
mtx_unlock(&bqlocks[queue]); | mtx_unlock(&bqlocks[queue]); | ||||
continue; | continue; | ||||
} | } | ||||
error = BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL); | error = BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL); | ||||
mtx_unlock(&bqlocks[queue]); | mtx_unlock(&bqlocks[queue]); | ||||
if (error != 0) | if (error != 0) | ||||
continue; | continue; | ||||
if (bp->b_pin_count > 0) { | |||||
BUF_UNLOCK(bp); | |||||
continue; | |||||
} | |||||
/* | /* | ||||
* BKGRDINPROG can only be set with the buf and bufobj | * BKGRDINPROG can only be set with the buf and bufobj | ||||
* locks both held. We tolerate a race to clear it here. | * locks both held. We tolerate a race to clear it here. | ||||
*/ | */ | ||||
if ((bp->b_vflags & BV_BKGRDINPROG) != 0 || | if ((bp->b_vflags & BV_BKGRDINPROG) != 0 || | ||||
(bp->b_flags & B_DELWRI) == 0) { | (bp->b_flags & B_DELWRI) == 0) { | ||||
BUF_UNLOCK(bp); | BUF_UNLOCK(bp); | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 403 Lines • ▼ Show 20 Lines | if (bp != NULL) { | ||||
/* | /* | ||||
* check for size inconsistencies for non-VMIO case. | * check for size inconsistencies for non-VMIO case. | ||||
*/ | */ | ||||
if (bp->b_bcount != size) { | if (bp->b_bcount != size) { | ||||
if ((bp->b_flags & B_VMIO) == 0 || | if ((bp->b_flags & B_VMIO) == 0 || | ||||
(size > bp->b_kvasize)) { | (size > bp->b_kvasize)) { | ||||
if (bp->b_flags & B_DELWRI) { | if (bp->b_flags & B_DELWRI) { | ||||
/* | |||||
* If buffer is pinned and caller does | |||||
* not want sleep waiting for it to be | |||||
* unpinned, bail out | |||||
* */ | |||||
if (bp->b_pin_count > 0) { | |||||
if (flags & GB_LOCK_NOWAIT) { | |||||
bqrelse(bp); | |||||
return (NULL); | |||||
} else { | |||||
bunpin_wait(bp); | |||||
} | |||||
} | |||||
bp->b_flags |= B_NOCACHE; | bp->b_flags |= B_NOCACHE; | ||||
bwrite(bp); | bwrite(bp); | ||||
} else { | } else { | ||||
if (LIST_EMPTY(&bp->b_dep)) { | if (LIST_EMPTY(&bp->b_dep)) { | ||||
bp->b_flags |= B_RELBUF; | bp->b_flags |= B_RELBUF; | ||||
brelse(bp); | brelse(bp); | ||||
} else { | } else { | ||||
bp->b_flags |= B_NOCACHE; | bp->b_flags |= B_NOCACHE; | ||||
▲ Show 20 Lines • Show All 1,055 Lines • ▼ Show 20 Lines | bufobj_wwait(struct bufobj *bo, int slpflag, int timeo) | ||||
while (bo->bo_numoutput) { | while (bo->bo_numoutput) { | ||||
bo->bo_flag |= BO_WWAIT; | bo->bo_flag |= BO_WWAIT; | ||||
error = msleep(&bo->bo_numoutput, BO_LOCKPTR(bo), | error = msleep(&bo->bo_numoutput, BO_LOCKPTR(bo), | ||||
slpflag | (PRIBIO + 1), "bo_wwait", timeo); | slpflag | (PRIBIO + 1), "bo_wwait", timeo); | ||||
if (error) | if (error) | ||||
break; | break; | ||||
} | } | ||||
return (error); | return (error); | ||||
} | |||||
void | |||||
bpin(struct buf *bp) | |||||
{ | |||||
struct mtx *mtxp; | |||||
mtxp = mtx_pool_find(mtxpool_sleep, bp); | |||||
mtx_lock(mtxp); | |||||
bp->b_pin_count++; | |||||
mtx_unlock(mtxp); | |||||
} | |||||
void | |||||
bunpin(struct buf *bp) | |||||
{ | |||||
struct mtx *mtxp; | |||||
mtxp = mtx_pool_find(mtxpool_sleep, bp); | |||||
mtx_lock(mtxp); | |||||
if (--bp->b_pin_count == 0) | |||||
wakeup(bp); | |||||
mtx_unlock(mtxp); | |||||
} | |||||
void | |||||
bunpin_wait(struct buf *bp) | |||||
{ | |||||
struct mtx *mtxp; | |||||
mtxp = mtx_pool_find(mtxpool_sleep, bp); | |||||
mtx_lock(mtxp); | |||||
while (bp->b_pin_count > 0) | |||||
msleep(bp, mtxp, PRIBIO, "bwunpin", 0); | |||||
mtx_unlock(mtxp); | |||||
} | } | ||||
/* | /* | ||||
* Set bio_data or bio_ma for struct bio from the struct buf. | * Set bio_data or bio_ma for struct bio from the struct buf. | ||||
*/ | */ | ||||
void | void | ||||
bdata2bio(struct buf *bp, struct bio *bip) | bdata2bio(struct buf *bp, struct bio *bip) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |