From 91e124aef106e9c39add4d028d2a1fa8464c73c5 Mon Sep 17 00:00:00 2001 From: Eric Chan Date: Wed, 24 Apr 2024 14:14:38 +1000 Subject: [PATCH] Add asserts to blk_enqueue/dequeue --- src/virtio/block.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/virtio/block.c b/src/virtio/block.c index 011290021..5e9568d89 100644 --- a/src/virtio/block.c +++ b/src/virtio/block.c @@ -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]; @@ -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: { @@ -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); @@ -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); @@ -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; } @@ -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; } } @@ -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]; @@ -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; }