Track in buf if disk "owns" buffer

This commit is contained in:
Frans Kaashoek 2019-07-30 12:53:19 -04:00
parent 87183da13d
commit 848d1906e8
2 changed files with 5 additions and 3 deletions

View file

@ -1,5 +1,6 @@
struct buf {
int valid; // has data been read from disk?
int disk; // does disk "own" buf?
uint dev;
uint blockno;
struct sleeplock lock;

View file

@ -222,6 +222,7 @@ virtio_disk_rw(struct buf *b, int write)
desc[idx[2]].next = 0;
// record struct buf for virtio_disk_intr().
b->disk = 1;
info[idx[0]].b = b;
// avail[0] is flags
@ -235,7 +236,7 @@ virtio_disk_rw(struct buf *b, int write)
*R(VIRTIO_MMIO_QUEUE_NOTIFY) = 0; // value is queue number
// Wait for virtio_disk_intr() to say request has finished.
while(info[idx[0]].status == 0) {
while(b->disk == 1) {
sleep(b, &vdisk_lock);
}
@ -256,7 +257,7 @@ virtio_disk_intr()
if(info[id].status != 0)
panic("virtio_disk_intr status");
info[id].status = 1;
info[id].b->disk = 0; // disk is done with buf
wakeup(info[id].b);
used_idx = (used_idx + 1) % NUM;