All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	dkoch@cloudswitch.com, "Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
	Blue Swirl <blauwirbel@gmail.com>,
	khoa@us.ibm.com, Asias He <asias@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 09/12] iov: add iov_get_ptr() to reference vector data
Date: Thu, 22 Nov 2012 10:34:13 +0100	[thread overview]
Message-ID: <50ADF195.4030204@redhat.com> (raw)
In-Reply-To: <1353522781-12721-10-git-send-email-stefanha@redhat.com>

Il 21/11/2012 19:32, Stefan Hajnoczi ha scritto:
> The iov_get_ptr() data returns a pointer to contiguous data within a
> vector.  This allows the caller to manipulate data inside the vector
> without copying in/out using iov_from_buf()/iov_to_buf() when we know
> that data is contiguous within an iovec element.

This works for you because you have a single byte to write.  It would
not work for the SG_IO inhdr, which would need iov_to_buf().

What about the following alternative API:

void *iov_get_ptr(struct iovec *iov, unsigned int iov_cnt,
                  ssize_t offset, size_t *bytes);

which would place the number of valid bytes (i.e. the length of the
remainder of the iovec entry) in *bytes?

Also, I think that offset == iov_size(iov, iov_cnt) should be
acceptable, and it would be the only case in which *bytes == 0.

Otherwise looks good.

Paolo

> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  iov.c | 25 +++++++++++++++++++++++++
>  iov.h | 11 +++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/iov.c b/iov.c
> index 6eed089..bc78c34 100644
> --- a/iov.c
> +++ b/iov.c
> @@ -395,3 +395,28 @@ size_t iov_discard(struct iovec **iov, unsigned int *iov_cnt, ssize_t bytes)
>      }
>      return total;
>  }
> +
> +void *iov_get_ptr(struct iovec *iov, unsigned int iov_cnt,
> +                  ssize_t offset, size_t bytes)
> +{
> +    if (offset < 0) {
> +        offset += iov_size(iov, iov_cnt);
> +        if (offset < 0) {
> +            return NULL; /* offset before beginning of vector */
> +        }
> +    }
> +
> +    while (iov_cnt > 0) {
> +        if (offset < iov->iov_len) {
> +            if (bytes > iov->iov_len - offset) {
> +                return NULL; /* would span iovec elements */
> +            }
> +            return iov->iov_base + offset;
> +        }
> +
> +        offset -= iov->iov_len;
> +        iov_cnt--;
> +        iov++;
> +    }
> +    return NULL; /* offset beyond end of vector */
> +}
> diff --git a/iov.h b/iov.h
> index d6d1fa6..674dd51 100644
> --- a/iov.h
> +++ b/iov.h
> @@ -108,3 +108,14 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
>   * smaller than requested if the vector is too small.
>   */
>  size_t iov_discard(struct iovec **iov, unsigned int *iov_cnt, ssize_t bytes);
> +
> +/*
> + * Get a pointer into a vector at offset if the given number of bytes is
> + * contiguous and not split across iovec elements.  NULL is returned if
> + * memory would span iovec elements or exceed the length of the vector.
> + *
> + * The offset is ssize_t so that an offset from the end of the vector can
> + * be specified with a negative number.
> + */
> +void *iov_get_ptr(struct iovec *iov, unsigned int iov_cnt, ssize_t offset,
> +                  size_t bytes);
> 

  reply	other threads:[~2012-11-22  9:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21 18:32 [Qemu-devel] [PATCH v3 00/12] virtio: virtio-blk data plane Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 01/12] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 02/12] configure: add CONFIG_VIRTIO_BLK_DATA_PLANE Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 03/12] dataplane: add host memory mapping code Stefan Hajnoczi
2012-11-26 14:46   ` Don Koch
2012-11-26 15:36     ` Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 04/12] dataplane: add virtqueue vring code Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 05/12] dataplane: add event loop Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 06/12] dataplane: add Linux AIO request queue Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 07/12] iov: add iov_discard() to remove data Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 08/12] test-iov: add iov_discard() testcase Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 09/12] iov: add iov_get_ptr() to reference vector data Stefan Hajnoczi
2012-11-22  9:34   ` Paolo Bonzini [this message]
2012-11-22  9:45     ` Michael S. Tsirkin
2012-11-22  9:52       ` Paolo Bonzini
2012-11-22 10:38         ` Michael S. Tsirkin
2012-11-22 10:54           ` Paolo Bonzini
2012-11-22 11:14             ` Michael S. Tsirkin
2012-11-22 11:58     ` Stefan Hajnoczi
2012-11-22 12:15       ` Paolo Bonzini
2012-11-22 12:35       ` Michael S. Tsirkin
2012-11-22 15:18         ` Stefan Hajnoczi
2012-11-21 18:32 ` [Qemu-devel] [PATCH v3 10/12] test-iov: add iov_get_ptr() test case Stefan Hajnoczi
2012-11-21 18:33 ` [Qemu-devel] [PATCH v3 11/12] dataplane: add virtio-blk data plane code Stefan Hajnoczi
2012-11-21 18:33 ` [Qemu-devel] [PATCH v3 12/12] virtio-blk: add x-data-plane=on|off performance feature 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=50ADF195.4030204@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=asias@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=dkoch@cloudswitch.com \
    --cc=khoa@us.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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.