vfs_bio.c (175294) | vfs_bio.c (175486) |
---|---|
1/*- 2 * Copyright (c) 2004 Poul-Henning Kamp 3 * Copyright (c) 1994,1997 John S. Dyson 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 25 unchanged lines hidden (view full) --- 34 * Author: John S. Dyson 35 * Significant help during the development and debugging phases 36 * had been provided by David Greenman, also of the FreeBSD core team. 37 * 38 * see man buf(9) for more info. 39 */ 40 41#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004 Poul-Henning Kamp 3 * Copyright (c) 1994,1997 John S. Dyson 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 25 unchanged lines hidden (view full) --- 34 * Author: John S. Dyson 35 * Significant help during the development and debugging phases 36 * had been provided by David Greenman, also of the FreeBSD core team. 37 * 38 * see man buf(9) for more info. 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 175294 2008-01-13 14:44:15Z attilio $"); | 42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 175486 2008-01-19 17:36:23Z attilio $"); |
43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/bio.h> 47#include <sys/conf.h> 48#include <sys/buf.h> 49#include <sys/devicestat.h> 50#include <sys/eventhandler.h> --- 602 unchanged lines hidden (view full) --- 653 * Mark the buffer for removal from the appropriate free list in brelse. 654 * 655 */ 656void 657bremfree(struct buf *bp) 658{ 659 660 CTR3(KTR_BUF, "bremfree(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); | 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/bio.h> 47#include <sys/conf.h> 48#include <sys/buf.h> 49#include <sys/devicestat.h> 50#include <sys/eventhandler.h> --- 602 unchanged lines hidden (view full) --- 653 * Mark the buffer for removal from the appropriate free list in brelse. 654 * 655 */ 656void 657bremfree(struct buf *bp) 658{ 659 660 CTR3(KTR_BUF, "bremfree(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); |
661 KASSERT(BUF_REFCNT(bp), ("bremfree: buf must be locked.")); | 661 KASSERT(BUF_ISLOCKED(bp), ("bremfree: buf must be locked.")); |
662 KASSERT((bp->b_flags & B_REMFREE) == 0, 663 ("bremfree: buffer %p already marked for delayed removal.", bp)); 664 KASSERT(bp->b_qindex != QUEUE_NONE, 665 ("bremfree: buffer %p not on a queue.", bp)); 666 667 bp->b_flags |= B_REMFREE; 668 /* Fixup numfreebuffers count. */ 669 if ((bp->b_flags & B_INVAL) || (bp->b_flags & B_DELWRI) == 0) --- 20 unchanged lines hidden (view full) --- 690 * Removes a buffer from the free list, must be called with the 691 * bqlock held. 692 */ 693static void 694bremfreel(struct buf *bp) 695{ 696 CTR3(KTR_BUF, "bremfreel(%p) vp %p flags %X", 697 bp, bp->b_vp, bp->b_flags); | 662 KASSERT((bp->b_flags & B_REMFREE) == 0, 663 ("bremfree: buffer %p already marked for delayed removal.", bp)); 664 KASSERT(bp->b_qindex != QUEUE_NONE, 665 ("bremfree: buffer %p not on a queue.", bp)); 666 667 bp->b_flags |= B_REMFREE; 668 /* Fixup numfreebuffers count. */ 669 if ((bp->b_flags & B_INVAL) || (bp->b_flags & B_DELWRI) == 0) --- 20 unchanged lines hidden (view full) --- 690 * Removes a buffer from the free list, must be called with the 691 * bqlock held. 692 */ 693static void 694bremfreel(struct buf *bp) 695{ 696 CTR3(KTR_BUF, "bremfreel(%p) vp %p flags %X", 697 bp, bp->b_vp, bp->b_flags); |
698 KASSERT(BUF_REFCNT(bp), ("bremfreel: buffer %p not locked.", bp)); | 698 KASSERT(BUF_ISLOCKED(bp), ("bremfreel: buffer %p not locked.", bp)); |
699 KASSERT(bp->b_qindex != QUEUE_NONE, 700 ("bremfreel: buffer %p not on a queue.", bp)); 701 mtx_assert(&bqlock, MA_OWNED); 702 703 TAILQ_REMOVE(&bufqueues[bp->b_qindex], bp, b_freelist); 704 bp->b_qindex = QUEUE_NONE; 705 /* 706 * If this was a delayed bremfree() we only need to remove the buffer --- 122 unchanged lines hidden (view full) --- 829 CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 830 if (bp->b_flags & B_INVAL) { 831 brelse(bp); 832 return (0); 833 } 834 835 oldflags = bp->b_flags; 836 | 699 KASSERT(bp->b_qindex != QUEUE_NONE, 700 ("bremfreel: buffer %p not on a queue.", bp)); 701 mtx_assert(&bqlock, MA_OWNED); 702 703 TAILQ_REMOVE(&bufqueues[bp->b_qindex], bp, b_freelist); 704 bp->b_qindex = QUEUE_NONE; 705 /* 706 * If this was a delayed bremfree() we only need to remove the buffer --- 122 unchanged lines hidden (view full) --- 829 CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 830 if (bp->b_flags & B_INVAL) { 831 brelse(bp); 832 return (0); 833 } 834 835 oldflags = bp->b_flags; 836 |
837 if (BUF_REFCNT(bp) == 0) | 837 if (!BUF_ISLOCKED(bp)) |
838 panic("bufwrite: buffer is not busy???"); 839 840 if (bp->b_pin_count > 0) 841 bunpin_wait(bp); 842 843 KASSERT(!(bp->b_vflags & BV_BKGRDINPROG), 844 ("FFS background buffer should not get here %p", bp)); 845 --- 101 unchanged lines hidden (view full) --- 947bdwrite(struct buf *bp) 948{ 949 struct thread *td = curthread; 950 struct vnode *vp; 951 struct bufobj *bo; 952 953 CTR3(KTR_BUF, "bdwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 954 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); | 838 panic("bufwrite: buffer is not busy???"); 839 840 if (bp->b_pin_count > 0) 841 bunpin_wait(bp); 842 843 KASSERT(!(bp->b_vflags & BV_BKGRDINPROG), 844 ("FFS background buffer should not get here %p", bp)); 845 --- 101 unchanged lines hidden (view full) --- 947bdwrite(struct buf *bp) 948{ 949 struct thread *td = curthread; 950 struct vnode *vp; 951 struct bufobj *bo; 952 953 CTR3(KTR_BUF, "bdwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 954 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); |
955 KASSERT(BUF_REFCNT(bp) != 0, ("bdwrite: buffer is not busy")); | 955 KASSERT(BUF_ISLOCKED(bp), ("bdwrite: buffer is not busy")); |
956 957 if (bp->b_flags & B_INVAL) { 958 brelse(bp); 959 return; 960 } 961 962 /* 963 * If we have too many dirty buffers, don't create any more. --- 78 unchanged lines hidden (view full) --- 1042 * The buffer must be on QUEUE_NONE. 1043 */ 1044void 1045bdirty(struct buf *bp) 1046{ 1047 1048 CTR3(KTR_BUF, "bdirty(%p) vp %p flags %X", 1049 bp, bp->b_vp, bp->b_flags); | 956 957 if (bp->b_flags & B_INVAL) { 958 brelse(bp); 959 return; 960 } 961 962 /* 963 * If we have too many dirty buffers, don't create any more. --- 78 unchanged lines hidden (view full) --- 1042 * The buffer must be on QUEUE_NONE. 1043 */ 1044void 1045bdirty(struct buf *bp) 1046{ 1047 1048 CTR3(KTR_BUF, "bdirty(%p) vp %p flags %X", 1049 bp, bp->b_vp, bp->b_flags); |
1050 KASSERT(BUF_REFCNT(bp) == 1, ("bdirty: bp %p not locked",bp)); | 1050 KASSERT(BUF_ISLOCKED(bp), ("bdirty: bp %p not locked",bp)); |
1051 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); 1052 KASSERT(bp->b_flags & B_REMFREE || bp->b_qindex == QUEUE_NONE, 1053 ("bdirty: buffer %p still on queue %d", bp, bp->b_qindex)); 1054 bp->b_flags &= ~(B_RELBUF); 1055 bp->b_iocmd = BIO_WRITE; 1056 1057 if ((bp->b_flags & B_DELWRI) == 0) { 1058 bp->b_flags |= /* XXX B_DONE | */ B_DELWRI; --- 17 unchanged lines hidden (view full) --- 1076void 1077bundirty(struct buf *bp) 1078{ 1079 1080 CTR3(KTR_BUF, "bundirty(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 1081 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); 1082 KASSERT(bp->b_flags & B_REMFREE || bp->b_qindex == QUEUE_NONE, 1083 ("bundirty: buffer %p still on queue %d", bp, bp->b_qindex)); | 1051 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); 1052 KASSERT(bp->b_flags & B_REMFREE || bp->b_qindex == QUEUE_NONE, 1053 ("bdirty: buffer %p still on queue %d", bp, bp->b_qindex)); 1054 bp->b_flags &= ~(B_RELBUF); 1055 bp->b_iocmd = BIO_WRITE; 1056 1057 if ((bp->b_flags & B_DELWRI) == 0) { 1058 bp->b_flags |= /* XXX B_DONE | */ B_DELWRI; --- 17 unchanged lines hidden (view full) --- 1076void 1077bundirty(struct buf *bp) 1078{ 1079 1080 CTR3(KTR_BUF, "bundirty(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 1081 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp)); 1082 KASSERT(bp->b_flags & B_REMFREE || bp->b_qindex == QUEUE_NONE, 1083 ("bundirty: buffer %p still on queue %d", bp, bp->b_qindex)); |
1084 KASSERT(BUF_REFCNT(bp) == 1, ("bundirty: bp %p not locked",bp)); | 1084 KASSERT(BUF_ISLOCKED(bp), ("bundirty: bp %p not locked",bp)); |
1085 1086 if (bp->b_flags & B_DELWRI) { 1087 bp->b_flags &= ~B_DELWRI; 1088 reassignbuf(bp); 1089 atomic_subtract_int(&numdirtybuffers, 1); 1090 numdirtywakeup(lodirtybuffers); 1091 } 1092 /* --- 243 unchanged lines hidden (view full) --- 1336 1337 } else if ((bp->b_flags & (B_INVAL | B_RELBUF)) != 0) { 1338 if (bp->b_bufsize != 0) 1339 allocbuf(bp, 0); 1340 if (bp->b_vp != NULL) 1341 brelvp(bp); 1342 } 1343 | 1085 1086 if (bp->b_flags & B_DELWRI) { 1087 bp->b_flags &= ~B_DELWRI; 1088 reassignbuf(bp); 1089 atomic_subtract_int(&numdirtybuffers, 1); 1090 numdirtywakeup(lodirtybuffers); 1091 } 1092 /* --- 243 unchanged lines hidden (view full) --- 1336 1337 } else if ((bp->b_flags & (B_INVAL | B_RELBUF)) != 0) { 1338 if (bp->b_bufsize != 0) 1339 allocbuf(bp, 0); 1340 if (bp->b_vp != NULL) 1341 brelvp(bp); 1342 } 1343 |
1344 if (BUF_REFCNT(bp) > 1) { | 1344 if (BUF_LOCKRECURSED(bp)) { |
1345 /* do not release to free list */ 1346 BUF_UNLOCK(bp); 1347 return; 1348 } 1349 1350 /* enqueue */ 1351 mtx_lock(&bqlock); 1352 /* Handle delayed bremfree() processing. */ --- 88 unchanged lines hidden (view full) --- 1441 */ 1442void 1443bqrelse(struct buf *bp) 1444{ 1445 CTR3(KTR_BUF, "bqrelse(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 1446 KASSERT(!(bp->b_flags & (B_CLUSTER|B_PAGING)), 1447 ("bqrelse: inappropriate B_PAGING or B_CLUSTER bp %p", bp)); 1448 | 1345 /* do not release to free list */ 1346 BUF_UNLOCK(bp); 1347 return; 1348 } 1349 1350 /* enqueue */ 1351 mtx_lock(&bqlock); 1352 /* Handle delayed bremfree() processing. */ --- 88 unchanged lines hidden (view full) --- 1441 */ 1442void 1443bqrelse(struct buf *bp) 1444{ 1445 CTR3(KTR_BUF, "bqrelse(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 1446 KASSERT(!(bp->b_flags & (B_CLUSTER|B_PAGING)), 1447 ("bqrelse: inappropriate B_PAGING or B_CLUSTER bp %p", bp)); 1448 |
1449 if (BUF_REFCNT(bp) > 1) { | 1449 if (BUF_LOCKRECURSED(bp)) { |
1450 /* do not release to free list */ 1451 BUF_UNLOCK(bp); 1452 return; 1453 } 1454 1455 if (bp->b_flags & B_MANAGED) { 1456 if (bp->b_flags & B_REMFREE) { 1457 mtx_lock(&bqlock); --- 1197 unchanged lines hidden (view full) --- 2655 ("ARGH! has b_bufobj->bo_object %p %p\n", 2656 bp, bp->b_bufobj->bo_object)); 2657 } 2658 2659 allocbuf(bp, size); 2660 bp->b_flags &= ~B_DONE; 2661 } 2662 CTR4(KTR_BUF, "getblk(%p, %ld, %d) = %p", vp, (long)blkno, size, bp); | 1450 /* do not release to free list */ 1451 BUF_UNLOCK(bp); 1452 return; 1453 } 1454 1455 if (bp->b_flags & B_MANAGED) { 1456 if (bp->b_flags & B_REMFREE) { 1457 mtx_lock(&bqlock); --- 1197 unchanged lines hidden (view full) --- 2655 ("ARGH! has b_bufobj->bo_object %p %p\n", 2656 bp, bp->b_bufobj->bo_object)); 2657 } 2658 2659 allocbuf(bp, size); 2660 bp->b_flags &= ~B_DONE; 2661 } 2662 CTR4(KTR_BUF, "getblk(%p, %ld, %d) = %p", vp, (long)blkno, size, bp); |
2663 KASSERT(BUF_REFCNT(bp) == 1, ("getblk: bp %p not locked",bp)); | 2663 KASSERT(BUF_ISLOCKED(bp), ("getblk: bp %p not locked",bp)); |
2664 KASSERT(bp->b_bufobj == bo, 2665 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo)); 2666 return (bp); 2667} 2668 2669/* 2670 * Get an empty, disassociated buffer of given size. The buffer is initially 2671 * set to B_INVAL. --- 4 unchanged lines hidden (view full) --- 2676 struct buf *bp; 2677 int maxsize; 2678 2679 maxsize = (size + BKVAMASK) & ~BKVAMASK; 2680 while ((bp = getnewbuf(0, 0, size, maxsize)) == 0) 2681 continue; 2682 allocbuf(bp, size); 2683 bp->b_flags |= B_INVAL; /* b_dep cleared by getnewbuf() */ | 2664 KASSERT(bp->b_bufobj == bo, 2665 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo)); 2666 return (bp); 2667} 2668 2669/* 2670 * Get an empty, disassociated buffer of given size. The buffer is initially 2671 * set to B_INVAL. --- 4 unchanged lines hidden (view full) --- 2676 struct buf *bp; 2677 int maxsize; 2678 2679 maxsize = (size + BKVAMASK) & ~BKVAMASK; 2680 while ((bp = getnewbuf(0, 0, size, maxsize)) == 0) 2681 continue; 2682 allocbuf(bp, size); 2683 bp->b_flags |= B_INVAL; /* b_dep cleared by getnewbuf() */ |
2684 KASSERT(BUF_REFCNT(bp) == 1, ("geteblk: bp %p not locked",bp)); | 2684 KASSERT(BUF_ISLOCKED(bp), ("geteblk: bp %p not locked",bp)); |
2685 return (bp); 2686} 2687 2688 2689/* 2690 * This code constitutes the buffer memory from either anonymous system 2691 * memory (in the case of non-VMIO operations) or from an associated 2692 * VM object (in the case of VMIO operations). This code is able to --- 9 unchanged lines hidden (view full) --- 2702 */ 2703 2704int 2705allocbuf(struct buf *bp, int size) 2706{ 2707 int newbsize, mbsize; 2708 int i; 2709 | 2685 return (bp); 2686} 2687 2688 2689/* 2690 * This code constitutes the buffer memory from either anonymous system 2691 * memory (in the case of non-VMIO operations) or from an associated 2692 * VM object (in the case of VMIO operations). This code is able to --- 9 unchanged lines hidden (view full) --- 2702 */ 2703 2704int 2705allocbuf(struct buf *bp, int size) 2706{ 2707 int newbsize, mbsize; 2708 int i; 2709 |
2710 if (BUF_REFCNT(bp) == 0) | 2710 if (!BUF_ISLOCKED(bp)) |
2711 panic("allocbuf: buffer not busy"); 2712 2713 if (bp->b_kvasize < size) 2714 panic("allocbuf: buffer too small"); 2715 2716 if ((bp->b_flags & B_VMIO) == 0) { 2717 caddr_t origbuf; 2718 int origbufsize; --- 426 unchanged lines hidden (view full) --- 3145bufdone(struct buf *bp) 3146{ 3147 struct bufobj *dropobj; 3148 void (*biodone)(struct buf *); 3149 3150 CTR3(KTR_BUF, "bufdone(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 3151 dropobj = NULL; 3152 | 2711 panic("allocbuf: buffer not busy"); 2712 2713 if (bp->b_kvasize < size) 2714 panic("allocbuf: buffer too small"); 2715 2716 if ((bp->b_flags & B_VMIO) == 0) { 2717 caddr_t origbuf; 2718 int origbufsize; --- 426 unchanged lines hidden (view full) --- 3145bufdone(struct buf *bp) 3146{ 3147 struct bufobj *dropobj; 3148 void (*biodone)(struct buf *); 3149 3150 CTR3(KTR_BUF, "bufdone(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 3151 dropobj = NULL; 3152 |
3153 KASSERT(BUF_REFCNT(bp) > 0, ("biodone: bp %p not busy %d", bp, 3154 BUF_REFCNT(bp))); | 3153 KASSERT(BUF_ISLOCKED(bp), ("biodone: bp %p not busy", bp)); |
3155 KASSERT(!(bp->b_flags & B_DONE), ("biodone: bp %p already done", bp)); 3156 3157 runningbufwakeup(bp); 3158 if (bp->b_iocmd == BIO_WRITE) 3159 dropobj = bp->b_bufobj; 3160 /* call optional completion function if requested */ 3161 if (bp->b_iodone != NULL) { 3162 biodone = bp->b_iodone; --- 8 unchanged lines hidden (view full) --- 3171 3172 if (dropobj) 3173 bufobj_wdrop(dropobj); 3174} 3175 3176void 3177bufdone_finish(struct buf *bp) 3178{ | 3154 KASSERT(!(bp->b_flags & B_DONE), ("biodone: bp %p already done", bp)); 3155 3156 runningbufwakeup(bp); 3157 if (bp->b_iocmd == BIO_WRITE) 3158 dropobj = bp->b_bufobj; 3159 /* call optional completion function if requested */ 3160 if (bp->b_iodone != NULL) { 3161 biodone = bp->b_iodone; --- 8 unchanged lines hidden (view full) --- 3170 3171 if (dropobj) 3172 bufobj_wdrop(dropobj); 3173} 3174 3175void 3176bufdone_finish(struct buf *bp) 3177{ |
3179 KASSERT(BUF_REFCNT(bp) > 0, ("biodone: bp %p not busy %d", bp, 3180 BUF_REFCNT(bp))); | 3178 KASSERT(BUF_ISLOCKED(bp), ("biodone: bp %p not busy", bp)); |
3181 3182 if (!LIST_EMPTY(&bp->b_dep)) 3183 buf_complete(bp); 3184 3185 if (bp->b_flags & B_VMIO) { 3186 int i; 3187 vm_ooffset_t foff; 3188 vm_page_t m; --- 749 unchanged lines hidden (view full) --- 3938 3939DB_SHOW_COMMAND(lockedbufs, lockedbufs) 3940{ 3941 struct buf *bp; 3942 int i; 3943 3944 for (i = 0; i < nbuf; i++) { 3945 bp = &buf[i]; | 3179 3180 if (!LIST_EMPTY(&bp->b_dep)) 3181 buf_complete(bp); 3182 3183 if (bp->b_flags & B_VMIO) { 3184 int i; 3185 vm_ooffset_t foff; 3186 vm_page_t m; --- 749 unchanged lines hidden (view full) --- 3936 3937DB_SHOW_COMMAND(lockedbufs, lockedbufs) 3938{ 3939 struct buf *bp; 3940 int i; 3941 3942 for (i = 0; i < nbuf; i++) { 3943 bp = &buf[i]; |
3946 if (lockcount(&bp->b_lock)) { | 3944 if (BUF_ISLOCKED(bp)) { |
3947 db_show_buffer((uintptr_t)bp, 1, 0, NULL); 3948 db_printf("\n"); 3949 } 3950 } 3951} 3952#endif /* DDB */ | 3945 db_show_buffer((uintptr_t)bp, 1, 0, NULL); 3946 db_printf("\n"); 3947 } 3948 } 3949} 3950#endif /* DDB */ |