* bufdone: * * Finish I/O on a buffer, optionally calling a completion function. * This is usually called from an interrupt so process blocking is * not allowed. * * biodone is also responsible for setting B_CACHE in a B_VMIO bp. * In a non-VMIO bp, B_CACHE will be set on the next getblk() * assuming B_INVAL is clear. * * For the VMIO case, we set B_CACHE if the op was a read and no *
| 4453 | * in the biodone routine. |
| 4454 | */ |
| 4455 | void |
| 4456 | bufdone(struct buf *bp) |
| 4457 | { |
| 4458 | struct bufobj *dropobj; |
| 4459 | void (*biodone)(struct buf *); |
| 4460 | |
| 4461 | buf_track(bp, __func__); |
| 4462 | CTR3(KTR_BUF, "bufdone(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); |
| 4463 | dropobj = NULL; |
| 4464 | |
| 4465 | KASSERT(!(bp->b_flags & B_DONE), ("biodone: bp %p already done", bp)); |
| 4466 | |
| 4467 | runningbufwakeup(bp); |
| 4468 | if (bp->b_iocmd == BIO_WRITE) |
| 4469 | dropobj = bp->b_bufobj; |
| 4470 | /* call optional completion function if requested */ |
| 4471 | if (bp->b_iodone != NULL) { |
| 4472 | biodone = bp->b_iodone; |
| 4473 | bp->b_iodone = NULL; |
| 4474 | (*biodone) (bp); |
| 4475 | if (dropobj) |
| 4476 | bufobj_wdrop(dropobj); |
| 4477 | return; |
| 4478 | } |
| 4479 | if (bp->b_flags & B_VMIO) { |
| 4480 | /* |
| 4481 | * Set B_CACHE if the op was a normal read and no error |
| 4482 | * occurred. B_CACHE is set for writes in the b*write() |
| 4483 | * routines. |
| 4484 | */ |
| 4485 | if (bp->b_iocmd == BIO_READ && |
| 4486 | !(bp->b_flags & (B_INVAL|B_NOCACHE)) && |
| 4487 | !(bp->b_ioflags & BIO_ERROR)) |
| 4488 | bp->b_flags |= B_CACHE; |
| 4489 | vfs_vmio_iodone(bp); |
| 4490 | } |
| 4491 | if (!LIST_EMPTY(&bp->b_dep)) |
| 4492 | buf_complete(bp); |
| 4493 | if ((bp->b_flags & B_CKHASH) != 0) { |
| 4494 | KASSERT(bp->b_iocmd == BIO_READ, |
| 4495 | ("bufdone: b_iocmd %d not BIO_READ", bp->b_iocmd)); |
| 4496 | KASSERT(buf_mapped(bp), ("bufdone: bp %p not mapped", bp)); |
| 4497 | (*bp->b_ckhashcalc)(bp); |
| 4498 | } |
| 4499 | /* |
| 4500 | * For asynchronous completions, release the buffer now. The brelse |
| 4501 | * will do a wakeup there if necessary - so no need to do a wakeup |
| 4502 | * here in the async case. The sync case always needs to do a wakeup. |
| 4503 | */ |
| 4504 | if (bp->b_flags & B_ASYNC) { |
| 4505 | if ((bp->b_flags & (B_NOCACHE | B_INVAL | B_RELBUF)) || |
| 4506 | (bp->b_ioflags & BIO_ERROR)) |
| 4507 | brelse(bp); |
| 4508 | else |
| 4509 | bqrelse(bp); |
| 4510 | } else |
| 4511 | bdone(bp); |
| 4512 | if (dropobj) |
no test coverage detected