summaryrefslogtreecommitdiff
path: root/kernel/bio.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2019-08-01 15:46:50 -0400
committerFrans Kaashoek <[email protected]>2019-08-01 15:46:50 -0400
commit62ece4b09e6a568ede0e3b524af959194e0cb792 (patch)
tree72553e7a6c57a3298193b288db07eb1a4eab17d0 /kernel/bio.c
parentfb8a0099d48643775d0bca626af1a73a3ab618a4 (diff)
parent9c4f62e8e3e7f114c6f82a75579a815e6329d767 (diff)
downloadxv6-labs-62ece4b09e6a568ede0e3b524af959194e0cb792.tar.gz
xv6-labs-62ece4b09e6a568ede0e3b524af959194e0cb792.tar.bz2
xv6-labs-62ece4b09e6a568ede0e3b524af959194e0cb792.zip
Merge branch 'riscv-bcache' into riscv
Diffstat (limited to 'kernel/bio.c')
-rw-r--r--kernel/bio.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/kernel/bio.c b/kernel/bio.c
index a08884b..a1074f2 100644
--- a/kernel/bio.c
+++ b/kernel/bio.c
@@ -12,11 +12,7 @@
// * Do not use the buffer after calling brelse.
// * Only one process at a time can use a buffer,
// so do not keep them longer than necessary.
-//
-// The implementation uses two state flags internally:
-// * B_VALID: the buffer data has been read from the disk.
-// * B_DIRTY: the buffer data has been modified
-// and needs to be written to disk.
+
#include "types.h"
#include "param.h"
@@ -76,13 +72,11 @@ bget(uint dev, uint blockno)
}
// Not cached; recycle an unused buffer.
- // Even if refcnt==0, B_DIRTY indicates a buffer is in use
- // because log.c has modified it but not yet committed it.
for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
- if(b->refcnt == 0 && (b->flags & B_DIRTY) == 0) {
+ if(b->refcnt == 0) {
b->dev = dev;
b->blockno = blockno;
- b->flags = 0;
+ b->valid = 0;
b->refcnt = 1;
release(&bcache.lock);
acquiresleep(&b->lock);
@@ -99,8 +93,9 @@ bread(uint dev, uint blockno)
struct buf *b;
b = bget(dev, blockno);
- if((b->flags & B_VALID) == 0) {
- virtio_disk_rw(b);
+ if(!b->valid) {
+ virtio_disk_rw(b, 0);
+ b->valid = 1;
}
return b;
}
@@ -111,8 +106,7 @@ bwrite(struct buf *b)
{
if(!holdingsleep(&b->lock))
panic("bwrite");
- b->flags |= B_DIRTY;
- virtio_disk_rw(b);
+ virtio_disk_rw(b, 1);
}
// Release a locked buffer.
@@ -139,3 +133,19 @@ brelse(struct buf *b)
release(&bcache.lock);
}
+
+void
+bpin(struct buf *b) {
+ acquire(&bcache.lock);
+ b->refcnt++;
+ release(&bcache.lock);
+}
+
+void
+bunpin(struct buf *b) {
+ acquire(&bcache.lock);
+ b->refcnt--;
+ release(&bcache.lock);
+}
+
+