All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCHv4 05/11] allow qemu_iovec_from_buffer() to specify offset from which to start copying
Date: Fri, 16 Mar 2012 11:19:49 -0500	[thread overview]
Message-ID: <4F636825.2090007@codemonkey.ws> (raw)
In-Reply-To: <1331845217-21705-6-git-send-email-mjt@msgid.tls.msk.ru>

On 03/15/2012 04:00 PM, Michael Tokarev wrote:
> Similar to
>   qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
>                     int c, size_t bytes);
> the new prototype is:
>   qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
>                       const void *buf, size_t bytes);
>
> The processing starts at offset bytes within qiov.
>
> This way, we may copy a bounce buffer directly to
> a middle of qiov.
>
> This is exactly the same function as iov_from_buf() from
> iov.c, so use the existing implementation and rename it
> to qemu_iovec_from_buf() to be shorter and to match the
> utility function.
>
> As with utility implementation, we now assert that the
> offset is inside actual iovec.  Nothing changed for
> current callers, because `offset' parameter is new.
>
> While at it, stop using "bounce-qiov" in block/qcow2.c
> and copy decrypted data directly from cluster_data
> instead of recreating a temp qiov for doing that
> (Cc'ing kwolf for this change).
>
> Signed-off-by: Michael Tokarev<mjt@tls.msk.ru>
> Cc: Kevin Wolf<kwolf@redhat.com>

Kevin, please Ack.

Regards,

Anthony Liguori

> ---
>   block.c       |    6 +++---
>   block/curl.c  |    6 +++---
>   block/qcow.c  |    2 +-
>   block/qcow2.c |    9 +++------
>   block/vdi.c   |    2 +-
>   cutils.c      |   16 +++-------------
>   qemu-common.h |    3 ++-
>   7 files changed, 16 insertions(+), 28 deletions(-)
>
> diff --git a/block.c b/block.c
> index b88ee90..b8db395 100644
> --- a/block.c
> +++ b/block.c
> @@ -1696,8 +1696,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs,
>       }
>
>       skip_bytes = (sector_num - cluster_sector_num) * BDRV_SECTOR_SIZE;
> -    qemu_iovec_from_buffer(qiov, bounce_buffer + skip_bytes,
> -                           nb_sectors * BDRV_SECTOR_SIZE);
> +    qemu_iovec_from_buf(qiov, 0, bounce_buffer + skip_bytes,
> +                        nb_sectors * BDRV_SECTOR_SIZE);
>
>   err:
>       qemu_vfree(bounce_buffer);
> @@ -3244,7 +3244,7 @@ static void bdrv_aio_bh_cb(void *opaque)
>       BlockDriverAIOCBSync *acb = opaque;
>
>       if (!acb->is_write)
> -        qemu_iovec_from_buffer(acb->qiov, acb->bounce, acb->qiov->size);
> +        qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size);
>       qemu_vfree(acb->bounce);
>       acb->common.cb(acb->common.opaque, acb->ret);
>       qemu_bh_delete(acb->bh);
> diff --git a/block/curl.c b/block/curl.c
> index e9102e3..cfc2ced 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -142,8 +142,8 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
>               continue;
>
>           if ((s->buf_off>= acb->end)) {
> -            qemu_iovec_from_buffer(acb->qiov, s->orig_buf + acb->start,
> -                                   acb->end - acb->start);
> +            qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start,
> +                                acb->end - acb->start);
>               acb->common.cb(acb->common.opaque, 0);
>               qemu_aio_release(acb);
>               s->acb[i] = NULL;
> @@ -178,7 +178,7 @@ static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
>           {
>               char *buf = state->orig_buf + (start - state->buf_start);
>
> -            qemu_iovec_from_buffer(acb->qiov, buf, len);
> +            qemu_iovec_from_buf(acb->qiov, 0, buf, len);
>               acb->common.cb(acb->common.opaque, 0);
>
>               return FIND_RET_OK;
> diff --git a/block/qcow.c b/block/qcow.c
> index b1cfe1f..562a19c 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -540,7 +540,7 @@ done:
>       qemu_co_mutex_unlock(&s->lock);
>
>       if (qiov->niov>  1) {
> -        qemu_iovec_from_buffer(qiov, orig_buf, qiov->size);
> +        qemu_iovec_from_buf(qiov, 0, orig_buf, qiov->size);
>           qemu_vfree(orig_buf);
>       }
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 941a6a9..a24c0dc 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -476,7 +476,7 @@ static coroutine_fn int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num,
>                   goto fail;
>               }
>
> -            qemu_iovec_from_buffer(&hd_qiov,
> +            qemu_iovec_from_buf(&hd_qiov, 0,
>                   s->cluster_cache + index_in_cluster * 512,
>                   512 * cur_nr_sectors);
>           } else {
> @@ -514,11 +514,8 @@ static coroutine_fn int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num,
>               if (s->crypt_method) {
>                   qcow2_encrypt_sectors(s, sector_num,  cluster_data,
>                       cluster_data, cur_nr_sectors, 0,&s->aes_decrypt_key);
> -                qemu_iovec_reset(&hd_qiov);
> -                qemu_iovec_copy(&hd_qiov, qiov, bytes_done,
> -                    cur_nr_sectors * 512);
> -                qemu_iovec_from_buffer(&hd_qiov, cluster_data,
> -                    512 * cur_nr_sectors);
> +                qemu_iovec_from_buf(qiov, bytes_done,
> +                    cluster_data, 512 * cur_nr_sectors);
>               }
>           }
>
> diff --git a/block/vdi.c b/block/vdi.c
> index 6a0011f..24f4027 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -635,7 +635,7 @@ static void vdi_aio_read_cb(void *opaque, int ret)
>       return;
>   done:
>       if (acb->qiov->niov>  1) {
> -        qemu_iovec_from_buffer(acb->qiov, acb->orig_buf, acb->qiov->size);
> +        qemu_iovec_from_buf(acb->qiov, 0, acb->orig_buf, acb->qiov->size);
>           qemu_vfree(acb->orig_buf);
>       }
>       acb->common.cb(acb->common.opaque, ret);
> diff --git a/cutils.c b/cutils.c
> index 0ddf4c7..b4dd844 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -245,20 +245,10 @@ void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
>       }
>   }
>
> -void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
> +size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
> +                           const void *buf, size_t bytes)
>   {
> -    const uint8_t *p = (const uint8_t *)buf;
> -    size_t copy;
> -    int i;
> -
> -    for (i = 0; i<  qiov->niov&&  count; ++i) {
> -        copy = count;
> -        if (copy>  qiov->iov[i].iov_len)
> -            copy = qiov->iov[i].iov_len;
> -        memcpy(qiov->iov[i].iov_base, p, copy);
> -        p     += copy;
> -        count -= copy;
> -    }
> +    return iov_from_buf(qiov->iov, qiov->niov, offset, buf, bytes);
>   }
>
>   size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
> diff --git a/qemu-common.h b/qemu-common.h
> index 3c556c8..a179afe 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -343,7 +343,8 @@ void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
>   void qemu_iovec_destroy(QEMUIOVector *qiov);
>   void qemu_iovec_reset(QEMUIOVector *qiov);
>   void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
> -void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
> +size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
> +                           const void *buf, size_t bytes);
>   size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
>                            int fillc, size_t bytes);
>

  reply	other threads:[~2012-03-16 16:20 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-15 21:00 [Qemu-devel] [PATCHv4 00/11] cleanup/consolidate iovec functions Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 01/11] virtio-serial-bus: use correct lengths in control_out() message Michael Tokarev
2012-03-16 16:12   ` Anthony Liguori
2012-03-16 16:34     ` Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 02/11] change iov_* function prototypes to be more appropriate Michael Tokarev
2012-03-16 16:14   ` Anthony Liguori
2012-03-16 16:28     ` Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 03/11] rewrite iov_* functions Michael Tokarev
2012-03-16 16:17   ` Anthony Liguori
2012-03-16 19:30     ` Michael Tokarev
2012-03-16 16:17   ` Anthony Liguori
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 04/11] consolidate qemu_iovec_memset{, _skip}() into single function and use existing iov_memset() Michael Tokarev
2012-03-16 16:19   ` Anthony Liguori
2012-03-19 14:36     ` Stefan Hajnoczi
2012-03-19 20:04       ` Michael Tokarev
2012-03-19 20:10         ` Anthony Liguori
2012-03-20  9:30         ` Stefan Hajnoczi
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 05/11] allow qemu_iovec_from_buffer() to specify offset from which to start copying Michael Tokarev
2012-03-16 16:19   ` Anthony Liguori [this message]
2012-03-16 19:35     ` Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 06/11] consolidate qemu_iovec_copy() and qemu_iovec_concat() and make them consistent Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 07/11] change qemu_iovec_to_buf() to match other to, from_buf functions Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 08/11] rename qemu_sendv to iov_send, change proto and move declarations to iov.h Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 09/11] export iov_send_recv() and use it in iov_send() and iov_recv() Michael Tokarev
2012-03-16 16:21   ` Anthony Liguori
2012-03-16 16:43     ` Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 10/11] cleanup qemu_co_sendv(), qemu_co_recvv() and friends Michael Tokarev
2012-03-16 16:22   ` Anthony Liguori
2012-03-16 19:37     ` Michael Tokarev
2012-03-15 21:00 ` [Qemu-devel] [PATCHv4 11/11] rewrite iov_send_recv() and move it to iov.c Michael Tokarev
2012-03-16 16:23   ` Anthony Liguori
2012-03-16 11:36 ` [Qemu-devel] [PATCHv4 00/11] cleanup/consolidate iovec functions Paolo Bonzini

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=4F636825.2090007@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kwolf@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@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 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.