Track in buf if disk "owns" buffer
This commit is contained in:
parent
87183da13d
commit
848d1906e8
|
@ -1,5 +1,6 @@
|
||||||
struct buf {
|
struct buf {
|
||||||
int valid; // has data been read from disk?
|
int valid; // has data been read from disk?
|
||||||
|
int disk; // does disk "own" buf?
|
||||||
uint dev;
|
uint dev;
|
||||||
uint blockno;
|
uint blockno;
|
||||||
struct sleeplock lock;
|
struct sleeplock lock;
|
||||||
|
|
|
@ -222,6 +222,7 @@ virtio_disk_rw(struct buf *b, int write)
|
||||||
desc[idx[2]].next = 0;
|
desc[idx[2]].next = 0;
|
||||||
|
|
||||||
// record struct buf for virtio_disk_intr().
|
// record struct buf for virtio_disk_intr().
|
||||||
|
b->disk = 1;
|
||||||
info[idx[0]].b = b;
|
info[idx[0]].b = b;
|
||||||
|
|
||||||
// avail[0] is flags
|
// 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
|
*R(VIRTIO_MMIO_QUEUE_NOTIFY) = 0; // value is queue number
|
||||||
|
|
||||||
// Wait for virtio_disk_intr() to say request has finished.
|
// Wait for virtio_disk_intr() to say request has finished.
|
||||||
while(info[idx[0]].status == 0) {
|
while(b->disk == 1) {
|
||||||
sleep(b, &vdisk_lock);
|
sleep(b, &vdisk_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ virtio_disk_intr()
|
||||||
if(info[id].status != 0)
|
if(info[id].status != 0)
|
||||||
panic("virtio_disk_intr status");
|
panic("virtio_disk_intr status");
|
||||||
|
|
||||||
info[id].status = 1;
|
info[id].b->disk = 0; // disk is done with buf
|
||||||
wakeup(info[id].b);
|
wakeup(info[id].b);
|
||||||
|
|
||||||
used_idx = (used_idx + 1) % NUM;
|
used_idx = (used_idx + 1) % NUM;
|
||||||
|
|
Loading…
Reference in a new issue