From: Paolo Bonzini <pbonzini@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCHv3 2/9] consolidate qemu_iovec_memset{, _skip}() into single function and use existing iov_memset()
Date: Tue, 13 Mar 2012 18:46:09 +0100 [thread overview]
Message-ID: <4F5F87E1.2080101@redhat.com> (raw)
In-Reply-To: <1331579663-29950-3-git-send-email-mjt@msgid.tls.msk.ru>
Il 12/03/2012 20:14, Michael Tokarev ha scritto:
> This patch combines two functions into one, and replaces
> the implementation with already existing iov_memset() from
> iov.c.
>
> The new prototype of qemu_iovec_memset():
> size_t qemu_iovec_memset(qiov, size_t offset, int c, size_t bytes)
> It is different from former qemu_iovec_memset_skip(), and
> I want to make other functions to be consistent with it
> too: first how much to skip, second what, and 3rd how many
> of it. It also returns actual number of bytes filled in,
> which may be less than the requested `bytes' if qiov is
> smaller than offset+bytes, in the same way iov_memset()
> does.
>
> While at it, use utility function iov_memset() from
> iov.h in posix-aio-compat.c, where qiov was used.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> block/qcow2.c | 4 ++--
> block/qed.c | 4 ++--
> cutils.c | 44 ++++----------------------------------------
> linux-aio.c | 4 ++--
> posix-aio-compat.c | 8 +++-----
> qemu-common.h | 5 ++---
> 6 files changed, 15 insertions(+), 54 deletions(-)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index eb5ea48..d46ca70 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -406,7 +406,7 @@ int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
> else
> n1 = bs->total_sectors - sector_num;
>
> - qemu_iovec_memset_skip(qiov, 0, 512 * (nb_sectors - n1), 512 * n1);
> + qemu_iovec_memset(qiov, 512 * n1, 0, 512 * (nb_sectors - n1));
>
> return n1;
> }
> @@ -466,7 +466,7 @@ static coroutine_fn int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num,
> }
> } else {
> /* Note: in this case, no need to wait */
> - qemu_iovec_memset(&hd_qiov, 0, 512 * cur_nr_sectors);
> + qemu_iovec_memset(&hd_qiov, 0, 0, 512 * cur_nr_sectors);
> }
> } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
> /* add AIO support for compressed blocks ? */
> diff --git a/block/qed.c b/block/qed.c
> index a041d31..6f9325b 100644
> --- a/block/qed.c
> +++ b/block/qed.c
> @@ -738,7 +738,7 @@ static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
> /* Zero all sectors if reading beyond the end of the backing file */
> if (pos >= backing_length ||
> pos + qiov->size > backing_length) {
> - qemu_iovec_memset(qiov, 0, qiov->size);
> + qemu_iovec_memset(qiov, 0, 0, qiov->size);
> }
>
> /* Complete now if there are no backing file sectors to read */
> @@ -1253,7 +1253,7 @@ static void qed_aio_read_data(void *opaque, int ret,
>
> /* Handle zero cluster and backing file reads */
> if (ret == QED_CLUSTER_ZERO) {
> - qemu_iovec_memset(&acb->cur_qiov, 0, acb->cur_qiov.size);
> + qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size);
> qed_aio_next_io(acb, 0);
> return;
> } else if (ret != QED_CLUSTER_FOUND) {
> diff --git a/cutils.c b/cutils.c
> index af308cd..53ff825 100644
> --- a/cutils.c
> +++ b/cutils.c
> @@ -26,6 +26,7 @@
> #include <math.h>
>
> #include "qemu_socket.h"
> +#include "iov.h"
>
> void pstrcpy(char *buf, int buf_size, const char *str)
> {
> @@ -260,47 +261,10 @@ void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
> }
> }
>
> -void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count)
> +size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
> + int c, size_t bytes)
> {
> - size_t n;
> - int i;
> -
> - for (i = 0; i < qiov->niov && count; ++i) {
> - n = MIN(count, qiov->iov[i].iov_len);
> - memset(qiov->iov[i].iov_base, c, n);
> - count -= n;
> - }
> -}
> -
> -void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count,
> - size_t skip)
> -{
> - int i;
> - size_t done;
> - void *iov_base;
> - uint64_t iov_len;
> -
> - done = 0;
> - for (i = 0; (i < qiov->niov) && (done != count); i++) {
> - if (skip >= qiov->iov[i].iov_len) {
> - /* Skip the whole iov */
> - skip -= qiov->iov[i].iov_len;
> - continue;
> - } else {
> - /* Skip only part (or nothing) of the iov */
> - iov_base = (uint8_t*) qiov->iov[i].iov_base + skip;
> - iov_len = qiov->iov[i].iov_len - skip;
> - skip = 0;
> - }
> -
> - if (done + iov_len > count) {
> - memset(iov_base, c, count - done);
> - break;
> - } else {
> - memset(iov_base, c, iov_len);
> - }
> - done += iov_len;
> - }
> + return iov_memset(qiov->iov, qiov->niov, offset, c, bytes);
> }
>
> /*
> diff --git a/linux-aio.c b/linux-aio.c
> index d2fc2e7..5a46c13 100644
> --- a/linux-aio.c
> +++ b/linux-aio.c
> @@ -64,8 +64,8 @@ static void qemu_laio_process_completion(struct qemu_laio_state *s,
> } else if (ret >= 0) {
> /* Short reads mean EOF, pad with zeros. */
> if (laiocb->is_read) {
> - qemu_iovec_memset_skip(laiocb->qiov, 0,
> - laiocb->qiov->size - ret, ret);
> + qemu_iovec_memset(laiocb->qiov, ret, 0,
> + laiocb->qiov->size - ret);
> } else {
> ret = -EINVAL;
> }
> diff --git a/posix-aio-compat.c b/posix-aio-compat.c
> index d311d13..1ab4a18 100644
> --- a/posix-aio-compat.c
> +++ b/posix-aio-compat.c
> @@ -29,6 +29,7 @@
> #include "qemu-common.h"
> #include "trace.h"
> #include "block_int.h"
> +#include "iov.h"
>
> #include "block/raw-posix-aio.h"
>
> @@ -351,11 +352,8 @@ static void *aio_thread(void *unused)
> if (ret >= 0 && ret < aiocb->aio_nbytes && aiocb->common.bs->growable) {
> /* A short read means that we have reached EOF. Pad the buffer
> * with zeros for bytes after EOF. */
> - QEMUIOVector qiov;
> -
> - qemu_iovec_init_external(&qiov, aiocb->aio_iov,
> - aiocb->aio_niov);
> - qemu_iovec_memset_skip(&qiov, 0, aiocb->aio_nbytes - ret, ret);
> + iov_memset(aiocb->aio_iov, aiocb->aio_niov, ret,
> + 0, aiocb->aio_nbytes - ret);
>
> ret = aiocb->aio_nbytes;
> }
> diff --git a/qemu-common.h b/qemu-common.h
> index dbfce6f..90f17fe 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -340,9 +340,8 @@ 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);
> -void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count);
> -void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count,
> - size_t skip);
> +size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
> + int c, size_t bytes);
>
> bool buffer_is_zero(const void *buf, size_t len);
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo
next prev parent reply other threads:[~2012-03-13 17:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-12 19:14 [Qemu-devel] [PATCHv3 0/9] cleanup/consolidate some iovec functions Michael Tokarev
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 1/9] refresh iov_* functions Michael Tokarev
2012-03-13 17:44 ` Paolo Bonzini
2012-03-13 18:28 ` Michael Tokarev
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 2/9] consolidate qemu_iovec_memset{, _skip}() into single function and use existing iov_memset() Michael Tokarev
2012-03-13 17:46 ` Paolo Bonzini [this message]
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 3/9] allow qemu_iovec_from_buffer() to specify offset from which to start copying Michael Tokarev
2012-03-13 11:10 ` Kevin Wolf
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 4/9] consolidate qemu_iovec_copy() and qemu_iovec_concat() and make them consistent Michael Tokarev
2012-03-13 18:02 ` Paolo Bonzini
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 5/9] change qemu_iovec_to_buf() to match other to, from_buf functions Michael Tokarev
2012-03-13 18:02 ` Paolo Bonzini
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 6/9] change prototypes of qemu_sendv() and qemu_recvv() Michael Tokarev
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 7/9] export qemu_sendv_recvv() and use it in " Michael Tokarev
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 8/9] cleanup qemu_co_sendv(), qemu_co_recvv() and friends Michael Tokarev
2012-03-13 17:52 ` Paolo Bonzini
2012-03-13 18:01 ` Paolo Bonzini
2012-03-13 19:35 ` Michael Tokarev
2012-03-12 19:14 ` [Qemu-devel] [PATCHv3 9/9] rewrite and comment qemu_sendv_recvv() Michael Tokarev
2012-03-13 16:09 ` [Qemu-devel] [PATCHv3 0/9] cleanup/consolidate some iovec functions Michael Tokarev
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=4F5F87E1.2080101@redhat.com \
--to=pbonzini@redhat.com \
--cc=mjt@tls.msk.ru \
--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).