All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Nick Thomas <nick@bytemark.co.uk>
Cc: stefanha@gmail.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 2/3] NBD library: add aio-compatible read/write function
Date: Mon, 21 Feb 2011 13:37:40 +0100	[thread overview]
Message-ID: <4D625C94.404@redhat.com> (raw)
In-Reply-To: <1298033729-17945-2-git-send-email-nick@bytemark.co.uk>

Am 18.02.2011 13:55, schrieb Nick Thomas:
> Signed-off-by: Nicholas Thomas <nick@bytemark.co.uk>
> ---
>  nbd.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  nbd.h |    2 ++
>  2 files changed, 53 insertions(+), 0 deletions(-)
> 
> diff --git a/nbd.c b/nbd.c
> index abe0ecb..83d3342 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -107,6 +107,57 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
>      return offset;
>  }
>  
> +int nbd_wr_aio(int sockfd, struct iovec *iov, size_t len,  off_t offset,
> +               bool do_read)
> +{
> +    struct msghdr msg;
> +    int ret, diff;
> +
> +    memset(&msg, 0, sizeof(msg));
> +    msg.msg_iov = iov;
> +    msg.msg_iovlen = 1;
> +
> +    len += offset;
> +
> +    while (iov->iov_len < len) {
> +        len -= iov->iov_len;
> +
> +        iov++;
> +        msg.msg_iovlen++;
> +    }

Is there a reason why you don't use a QEMUIOVector here? It already has
alls the information like the number of entries. Throwing this
information away only to recalculate it here seems a bit pointless.

> +
> +    diff = iov->iov_len - len;
> +    iov->iov_len -= diff;
> +
> +    while (msg.msg_iov->iov_len <= offset) {
> +        offset -= msg.msg_iov->iov_len;
> +
> +        msg.msg_iov++;
> +        msg.msg_iovlen--;
> +    }
> +
> +    msg.msg_iov->iov_base = (char *) msg.msg_iov->iov_base + offset;
> +    msg.msg_iov->iov_len -= offset;

You could use qemu_iovec_copy to create a qiov that covers exactly the
part that you want to use.

> +
> +retry:
> +    if (do_read) {
> +        ret = recvmsg(sockfd, &msg, 0);
> +    } else {
> +        ret = sendmsg(sockfd, &msg, 0);
> +    }
> +
> +    /* recoverable error */
> +    if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
> +        goto retry;
> +    }

Make this a do...while loop, no reason for goto here.

> +
> +    msg.msg_iov->iov_base = (char *) msg.msg_iov->iov_base - offset;
> +    msg.msg_iov->iov_len += offset;
> +
> +    iov->iov_len += diff;
> +    return ret;

This wouldn't be necessary with a copied qiov either (but you'd need to
destroy the copy)

Kevin

       reply	other threads:[~2011-02-21 12:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1298033729-17945-1-git-send-email-nick@bytemark.co.uk>
     [not found] ` <1298033729-17945-2-git-send-email-nick@bytemark.co.uk>
2011-02-21 12:37   ` Kevin Wolf [this message]
2011-02-21 20:10     ` [Qemu-devel] Re: [PATCH 2/3] NBD library: add aio-compatible read/write function Stefan Hajnoczi
2011-02-22 15:26       ` Nicholas Thomas
2011-02-22 20:14         ` Stefan Hajnoczi
2011-02-21 12:37 ` [Qemu-devel] Re: [PATCH 1/3] NBD library: whitespace changes Kevin Wolf
     [not found] ` <1298033729-17945-3-git-send-email-nick@bytemark.co.uk>
2011-02-21 12:59   ` [Qemu-devel] Re: [PATCH 3/3] block/nbd: Make the NBD block device use the AIO interface Kevin Wolf
2011-02-21 16:31     ` Nicholas Thomas
2011-02-21 16:48       ` Kevin Wolf
2011-02-22 16:06         ` MORITA Kazutaka
2011-02-21 20:07   ` Stefan Hajnoczi
2011-02-22 11:48     ` Nicholas Thomas
2011-02-22 13:31       ` Stefan Hajnoczi

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=4D625C94.404@redhat.com \
    --to=kwolf@redhat.com \
    --cc=nick@bytemark.co.uk \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.