diff options
author | Christoph Hellwig <hch@lst.de> | 2010-06-08 18:26:07 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-06-14 15:46:28 -0500 |
commit | c20fd872257fb9abd2ce99741937c0f65aa162b7 (patch) | |
tree | 2c066d31397ea6fbd2c4024c9e30204903c5673d /hw | |
parent | 7e608e8903a39157c28ced12b2a061eafa43c905 (diff) | |
download | qemu-c20fd872257fb9abd2ce99741937c0f65aa162b7.zip qemu-c20fd872257fb9abd2ce99741937c0f65aa162b7.tar.gz qemu-c20fd872257fb9abd2ce99741937c0f65aa162b7.tar.bz2 |
virtio-blk: simplify multiwrite calling conventions
Pass the MultiReqBuffer structure down all the way to the I/O submission
instead of takin it apart. Also mark num_writes unsigned as it can't
go negative, and take the check for any pending I/O requests into the
submission function. Last but not least rename do_multiwrite to
virtio_submit_multiwrite to fit the general naming scheme and make clear
what it does.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/virtio-blk.c | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 4e67088..4cc94f6 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -223,33 +223,39 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req) } #endif /* __linux__ */ -static void do_multiwrite(BlockDriverState *bs, BlockRequest *blkreq, - int num_writes) +typedef struct MultiReqBuffer { + BlockRequest blkreq[32]; + unsigned int num_writes; +} MultiReqBuffer; + +static void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb) { int i, ret; - ret = bdrv_aio_multiwrite(bs, blkreq, num_writes); + if (!mrb->num_writes) { + return; + } + + ret = bdrv_aio_multiwrite(bs, mrb->blkreq, mrb->num_writes); if (ret != 0) { - for (i = 0; i < num_writes; i++) { - if (blkreq[i].error) { - virtio_blk_rw_complete(blkreq[i].opaque, -EIO); + for (i = 0; i < mrb->num_writes; i++) { + if (mrb->blkreq[i].error) { + virtio_blk_rw_complete(mrb->blkreq[i].opaque, -EIO); } } } + + mrb->num_writes = 0; } -static void virtio_blk_handle_flush(BlockRequest *blkreq, int *num_writes, - VirtIOBlockReq *req) +static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) { BlockDriverAIOCB *acb; /* * Make sure all outstanding writes are posted to the backing device. */ - if (*num_writes > 0) { - do_multiwrite(req->dev->bs, blkreq, *num_writes); - } - *num_writes = 0; + virtio_submit_multiwrite(req->dev->bs, mrb); acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); if (!acb) { @@ -257,27 +263,28 @@ static void virtio_blk_handle_flush(BlockRequest *blkreq, int *num_writes, } } -static void virtio_blk_handle_write(BlockRequest *blkreq, int *num_writes, - VirtIOBlockReq *req) +static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) { + BlockRequest *blkreq; + if (req->out->sector & req->dev->sector_mask) { virtio_blk_rw_complete(req, -EIO); return; } - if (*num_writes == 32) { - do_multiwrite(req->dev->bs, blkreq, *num_writes); - *num_writes = 0; + if (mrb->num_writes == 32) { + virtio_submit_multiwrite(req->dev->bs, mrb); } - blkreq[*num_writes].sector = req->out->sector; - blkreq[*num_writes].nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE; - blkreq[*num_writes].qiov = &req->qiov; - blkreq[*num_writes].cb = virtio_blk_rw_complete; - blkreq[*num_writes].opaque = req; - blkreq[*num_writes].error = 0; + blkreq = &mrb->blkreq[mrb->num_writes]; + blkreq->sector = req->out->sector; + blkreq->nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE; + blkreq->qiov = &req->qiov; + blkreq->cb = virtio_blk_rw_complete; + blkreq->opaque = req; + blkreq->error = 0; - (*num_writes)++; + mrb->num_writes++; } static void virtio_blk_handle_read(VirtIOBlockReq *req) @@ -297,11 +304,6 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req) } } -typedef struct MultiReqBuffer { - BlockRequest blkreq[32]; - int num_writes; -} MultiReqBuffer; - static void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) { @@ -320,13 +322,13 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req, req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base; if (req->out->type & VIRTIO_BLK_T_FLUSH) { - virtio_blk_handle_flush(mrb->blkreq, &mrb->num_writes, req); + virtio_blk_handle_flush(req, mrb); } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { virtio_blk_handle_scsi(req); } else if (req->out->type & VIRTIO_BLK_T_OUT) { qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1], req->elem.out_num - 1); - virtio_blk_handle_write(mrb->blkreq, &mrb->num_writes, req); + virtio_blk_handle_write(req, mrb); } else { qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0], req->elem.in_num - 1); @@ -346,9 +348,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) virtio_blk_handle_request(req, &mrb); } - if (mrb.num_writes > 0) { - do_multiwrite(s->bs, mrb.blkreq, mrb.num_writes); - } + virtio_submit_multiwrite(s->bs, &mrb); /* * FIXME: Want to check for completions before returning to guest mode, @@ -375,9 +375,7 @@ static void virtio_blk_dma_restart_bh(void *opaque) req = req->next; } - if (mrb.num_writes > 0) { - do_multiwrite(s->bs, mrb.blkreq, mrb.num_writes); - } + virtio_submit_multiwrite(s->bs, &mrb); } static void virtio_blk_dma_restart_cb(void *opaque, int running, int reason) |