* Delayed write. (Buffer is marked dirty). Do not bother writing * anything if the buffer is marked invalid. * * Note that since the buffer must be completely valid, we can safely * set B_CACHE. In fact, we have to set B_CACHE here rather then in * biodone() in order to prevent getblk from writing the buffer * out synchronously. */
| 2372 | * out synchronously. |
| 2373 | */ |
| 2374 | void |
| 2375 | bdwrite(struct buf *bp) |
| 2376 | { |
| 2377 | struct thread *td = curthread; |
| 2378 | struct vnode *vp; |
| 2379 | struct bufobj *bo; |
| 2380 | |
| 2381 | CTR3(KTR_BUF, "bdwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); |
| 2382 | KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); |
| 2383 | KASSERT((bp->b_flags & B_BARRIER) == 0, |
| 2384 | ("Barrier request in delayed write %p", bp)); |
| 2385 | |
| 2386 | if (bp->b_flags & B_INVAL) { |
| 2387 | brelse(bp); |
| 2388 | return; |
| 2389 | } |
| 2390 | |
| 2391 | /* |
| 2392 | * If we have too many dirty buffers, don't create any more. |
| 2393 | * If we are wildly over our limit, then force a complete |
| 2394 | * cleanup. Otherwise, just keep the situation from getting |
| 2395 | * out of control. Note that we have to avoid a recursive |
| 2396 | * disaster and not try to clean up after our own cleanup! |
| 2397 | */ |
| 2398 | vp = bp->b_vp; |
| 2399 | bo = bp->b_bufobj; |
| 2400 | if ((td->td_pflags & (TDP_COWINPROGRESS|TDP_INBDFLUSH)) == 0) { |
| 2401 | td->td_pflags |= TDP_INBDFLUSH; |
| 2402 | BO_BDFLUSH(bo, bp); |
| 2403 | td->td_pflags &= ~TDP_INBDFLUSH; |
| 2404 | } else |
| 2405 | recursiveflushes++; |
| 2406 | |
| 2407 | bdirty(bp); |
| 2408 | /* |
| 2409 | * Set B_CACHE, indicating that the buffer is fully valid. This is |
| 2410 | * true even of NFS now. |
| 2411 | */ |
| 2412 | bp->b_flags |= B_CACHE; |
| 2413 | |
| 2414 | /* |
| 2415 | * This bmap keeps the system from needing to do the bmap later, |
| 2416 | * perhaps when the system is attempting to do a sync. Since it |
| 2417 | * is likely that the indirect block -- or whatever other datastructure |
| 2418 | * that the filesystem needs is still in memory now, it is a good |
| 2419 | * thing to do this. Note also, that if the pageout daemon is |
| 2420 | * requesting a sync -- there might not be enough memory to do |
| 2421 | * the bmap then... So, this is important to do. |
| 2422 | */ |
| 2423 | if (vp->v_type != VCHR && bp->b_lblkno == bp->b_blkno) { |
| 2424 | VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL); |
| 2425 | } |
| 2426 | |
| 2427 | buf_track(bp, __func__); |
| 2428 | |
| 2429 | /* |
| 2430 | * Set the *dirty* buffer range based upon the VM system dirty |
| 2431 | * pages. |
no test coverage detected