提交 bc6694d4 编写于 作者: K Kevin Wolf 提交者: Anthony Liguori

virtio_blk: Factor virtio_blk_handle_request out

We need a function that handles a single request. Create one by splitting out
code from virtio_blk_handle_output.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 4516e45f
......@@ -317,15 +317,15 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
}
}
static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOBlock *s = to_virtio_blk(vdev);
VirtIOBlockReq *req;
typedef struct MultiReqBuffer {
BlockRequest blkreq[32];
int num_writes = 0;
BlockDriverState *old_bs = NULL;
int num_writes;
BlockDriverState *old_bs;
} MultiReqBuffer;
while ((req = virtio_blk_get_request(s))) {
static void virtio_blk_handle_request(VirtIOBlockReq *req,
MultiReqBuffer *mrb)
{
if (req->elem.out_num < 1 || req->elem.in_num < 1) {
fprintf(stderr, "virtio-blk missing headers\n");
exit(1);
......@@ -347,16 +347,30 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
} 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(blkreq, &num_writes, req, &old_bs);
virtio_blk_handle_write(mrb->blkreq, &mrb->num_writes,
req, &mrb->old_bs);
} else {
qemu_iovec_init_external(&req->qiov, &req->elem.in_sg[0],
req->elem.in_num - 1);
virtio_blk_handle_read(req);
}
}
static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOBlock *s = to_virtio_blk(vdev);
VirtIOBlockReq *req;
MultiReqBuffer mrb = {
.num_writes = 0,
.old_bs = NULL,
};
while ((req = virtio_blk_get_request(s))) {
virtio_blk_handle_request(req, &mrb);
}
if (num_writes > 0) {
do_multiwrite(old_bs, blkreq, num_writes);
if (mrb.num_writes > 0) {
do_multiwrite(mrb.old_bs, mrb.blkreq, mrb.num_writes);
}
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册