summaryrefslogtreecommitdiff
path: root/kernel/bio.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2019-07-29 17:33:16 -0400
committerFrans Kaashoek <[email protected]>2019-07-29 17:33:16 -0400
commit530431045237d7ccbbc0bb65ed83309845c19893 (patch)
tree6617b13b8e63bb0fd19ff04ac21b8d5e5d9da6b0 /kernel/bio.c
parent34980381bd75ce28ffea2113559aefa1b02c64f0 (diff)
downloadxv6-labs-530431045237d7ccbbc0bb65ed83309845c19893.tar.gz
xv6-labs-530431045237d7ccbbc0bb65ed83309845c19893.tar.bz2
xv6-labs-530431045237d7ccbbc0bb65ed83309845c19893.zip
Remove B_DIRTY
Use refcnt to pin blocks into the cache Replace flags/B_VALID with a boolean field valid Use info[id].status to signal completion of disk interrupt Pass a read/write flag to virtio_disk_rw
Diffstat (limited to 'kernel/bio.c')
-rw-r--r--kernel/bio.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/kernel/bio.c b/kernel/bio.c
index a08884b..7455c06 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.