qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, hch@lst.de
Subject: Re: [Qemu-devel] [PATCH 1/3] virtio_blk: Factor virtio_blk_handle_request out
Date: Fri, 29 Jan 2010 14:43:20 -0600	[thread overview]
Message-ID: <4B634868.9070507@codemonkey.ws> (raw)
In-Reply-To: <1264594356-10375-2-git-send-email-kwolf@redhat.com>

On 01/27/2010 06:12 AM, Kevin Wolf wrote:
> We need a function that handles a single request. Create one by splitting out
> code from virtio_blk_handle_output.
>
> Signed-off-by: Kevin Wolf<kwolf@redhat.com>
>    

Applied all.  Thanks.

Regards,

Anthony Liguori

> ---
>   hw/virtio-blk.c |   78 ++++++++++++++++++++++++++++++++----------------------
>   1 files changed, 46 insertions(+), 32 deletions(-)
>
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index 865352a..82f96e5 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -317,46 +317,60 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
>       }
>   }
>
> +typedef struct MultiReqBuffer {
> +    BlockRequest        blkreq[32];
> +    int                 num_writes;
> +    BlockDriverState    *old_bs;
> +} MultiReqBuffer;
> +
> +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);
> +    }
> +
> +    if (req->elem.out_sg[0].iov_len<  sizeof(*req->out) ||
> +        req->elem.in_sg[req->elem.in_num - 1].iov_len<  sizeof(*req->in)) {
> +        fprintf(stderr, "virtio-blk header not in correct element\n");
> +        exit(1);
> +    }
> +
> +    req->out = (void *)req->elem.out_sg[0].iov_base;
> +    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(req);
> +    } 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,&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;
> -    BlockRequest blkreq[32];
> -    int num_writes = 0;
> -    BlockDriverState *old_bs = NULL;
> +    MultiReqBuffer mrb = {
> +        .num_writes = 0,
> +        .old_bs = NULL,
> +    };
>
>       while ((req = virtio_blk_get_request(s))) {
> -        if (req->elem.out_num<  1 || req->elem.in_num<  1) {
> -            fprintf(stderr, "virtio-blk missing headers\n");
> -            exit(1);
> -        }
> -
> -        if (req->elem.out_sg[0].iov_len<  sizeof(*req->out) ||
> -            req->elem.in_sg[req->elem.in_num - 1].iov_len<  sizeof(*req->in)) {
> -            fprintf(stderr, "virtio-blk header not in correct element\n");
> -            exit(1);
> -        }
> -
> -        req->out = (void *)req->elem.out_sg[0].iov_base;
> -        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(req);
> -        } 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(blkreq,&num_writes, req,&old_bs);
> -        } else {
> -            qemu_iovec_init_external(&req->qiov,&req->elem.in_sg[0],
> -                                     req->elem.in_num - 1);
> -            virtio_blk_handle_read(req);
> -        }
> +        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);
>       }
>
>       /*
>    

  parent reply	other threads:[~2010-01-29 20:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 12:12 [Qemu-devel] [PATCH 0/3] virtio-blk: rerror/werror fixes (including corruption fix) Kevin Wolf
2010-01-27 12:12 ` [Qemu-devel] [PATCH 1/3] virtio_blk: Factor virtio_blk_handle_request out Kevin Wolf
2010-01-27 18:20   ` [Qemu-devel] " Christoph Hellwig
2010-01-29 20:43   ` Anthony Liguori [this message]
2010-01-27 12:12 ` [Qemu-devel] [PATCH 2/3] virtio-blk: Fix restart after read error Kevin Wolf
2010-01-27 18:20   ` [Qemu-devel] " Christoph Hellwig
2010-01-27 12:12 ` [Qemu-devel] [PATCH 3/3] virtio-blk: Fix error cases which ignored rerror/werror Kevin Wolf
2010-01-27 18:21   ` [Qemu-devel] " Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B634868.9070507@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=hch@lst.de \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).