Skip to content

Commit

Permalink
Add asserts to blk_enqueue/dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
erichchan999 committed Apr 24, 2024
1 parent 2cb2db7 commit 91e124a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/virtio/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)
/* get next available request to be handled */
uint16_t idx = vq->last_idx;

int err = 0;
LOG_BLOCK("------------- Driver notified device -------------\n");
for (; idx != virtq->avail->idx; idx++) {
uint16_t desc_head = virtq->avail->ring[idx % virtq->num];
Expand Down Expand Up @@ -258,7 +259,8 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)
ialloc_alloc(&ialloc, &req_id);
reqbk[req_id] = data;

blk_enqueue_req(queue_handle, READ_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
err = blk_enqueue_req(queue_handle, READ_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
assert(!err);
break;
}
case VIRTIO_BLK_T_OUT: {
Expand All @@ -277,7 +279,7 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)
bool not_aligned = ((virtio_req->sector % (BLK_TRANSFER_SIZE / VIRTIO_BLK_SECTOR_SIZE)) != 0);

/* If the write request is not aligned to the sddf block size, we need to first read the surrounding aligned memory, overwrite that
read memory on the unaligned areas we want write to, and then write the entire memory back to disk */
read memory on the unaligned areas we want write to, and then write the entire memory back to disk */
if (not_aligned) {
if (!sddf_make_req_check(queue_handle, sddf_count)) {
virtio_blk_set_req_fail(dev, desc_head);
Expand All @@ -299,7 +301,8 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)
ialloc_alloc(&ialloc, &req_id);
reqbk[req_id] = data;

blk_enqueue_req(queue_handle, READ_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
err = blk_enqueue_req(queue_handle, READ_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
assert(!err);
} else {
if (!sddf_make_req_check(queue_handle, sddf_count)) {
virtio_blk_set_req_fail(dev, desc_head);
Expand All @@ -323,7 +326,8 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)

/* Copy data from virtio buffer to data buffer, create sddf write request and initialise it with data buffer */
memcpy((void *)sddf_data, (void *)virtq->desc[curr_desc_head].addr, virtq->desc[curr_desc_head].len);
blk_enqueue_req(queue_handle, WRITE_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
err = blk_enqueue_req(queue_handle, WRITE_BLOCKS, sddf_data, sddf_block_number, sddf_count, req_id);
assert(!err);
}
break;
}
Expand All @@ -342,7 +346,7 @@ static int virtio_blk_mmio_queue_notify(struct virtio_device *dev)
ialloc_alloc(&ialloc, &req_id);
reqbk[req_id] = data;

blk_enqueue_req(queue_handle, FLUSH, 0, 0, 0, req_id);
err = blk_enqueue_req(queue_handle, FLUSH, 0, 0, 0, req_id);
break;
}
}
Expand Down Expand Up @@ -376,8 +380,10 @@ int virtio_blk_handle_resp(struct virtio_device *dev)
uint32_t sddf_ret_id;

bool handled = false;
int err = 0;
while (!blk_resp_queue_empty(queue_handle)) {
blk_dequeue_resp(queue_handle, &sddf_ret_status, &sddf_ret_success_count, &sddf_ret_id);
err = blk_dequeue_resp(queue_handle, &sddf_ret_status, &sddf_ret_success_count, &sddf_ret_id);
assert(!err);

/* Freeing and retrieving data store */
reqbk_t data = reqbk[sddf_ret_id];
Expand Down Expand Up @@ -405,7 +411,8 @@ int virtio_blk_handle_resp(struct virtio_device *dev)
ialloc_alloc(&ialloc, &new_sddf_id);
reqbk[new_sddf_id] = parsed_data;

blk_enqueue_req(queue_handle, WRITE_BLOCKS, data.sddf_data, data.sddf_block_number, data.sddf_count, new_sddf_id);
err = blk_enqueue_req(queue_handle, WRITE_BLOCKS, data.sddf_data, data.sddf_block_number, data.sddf_count, new_sddf_id);
assert(!err);
microkit_notify(dev->sddf_handlers[SDDF_BLK_DEFAULT_HANDLE].ch);
continue;
}
Expand Down

0 comments on commit 91e124a

Please sign in to comment.