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
This commit is contained in:
Frans Kaashoek 2019-07-29 17:33:16 -04:00
parent 34980381bd
commit 5304310452
5 changed files with 19 additions and 27 deletions

View file

@ -164,7 +164,7 @@ alloc3_desc(int *idx)
}
void
virtio_disk_rw(struct buf *b)
virtio_disk_rw(struct buf *b, int write)
{
uint64 sector = b->blockno * (BSIZE / 512);
@ -192,7 +192,7 @@ virtio_disk_rw(struct buf *b)
uint64 sector;
} buf0;
if(b->flags & B_DIRTY)
if(write)
buf0.type = VIRTIO_BLK_T_OUT; // write the disk
else
buf0.type = VIRTIO_BLK_T_IN; // read the disk
@ -208,7 +208,7 @@ virtio_disk_rw(struct buf *b)
desc[idx[1]].addr = (uint64) b->data;
desc[idx[1]].len = BSIZE;
if(b->flags & B_DIRTY)
if(write)
desc[idx[1]].flags = 0; // device reads b->data
else
desc[idx[1]].flags = VRING_DESC_F_WRITE; // device writes b->data
@ -235,7 +235,7 @@ virtio_disk_rw(struct buf *b)
*R(VIRTIO_MMIO_QUEUE_NOTIFY) = 0; // value is queue number
// Wait for virtio_disk_intr() to say request has finished.
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
while(info[idx[0]].status == 0) {
sleep(b, &vdisk_lock);
}
@ -253,9 +253,7 @@ virtio_disk_intr()
if(info[id].status != 0)
panic("virtio_disk_intr status");
info[id].b->flags |= B_VALID;
info[id].b->flags &= ~B_DIRTY;
info[id].status = 1;
wakeup(info[id].b);
info[id].b = 0;