qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: "Benoît Canet" <benoit.canet@irqsave.net>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com,
	"Benoît Canet" <benoit@irqsave.net>,
	stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH V17 04/12] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify.
Date: Sat, 15 Feb 2014 02:36:42 +0100	[thread overview]
Message-ID: <52FEC4AA.8060400@redhat.com> (raw)
In-Reply-To: <1392242799-16364-5-git-send-email-benoit.canet@irqsave.net>

On 12.02.2014 23:06, Benoît Canet wrote:
> From: Benoît Canet <benoit@irqsave.net>
>
> qemu_iovec_compare() will be used to compare IOs vectors in quorum blkverify
> mode. The patch extract these functions in order to factorize the code.

"extracts" (just a sidenode: If I'm correcting (or thinking I'm 
correcting) spelling mistakes, I'm just saying "Try to fix it if you're 
doing a new version anyway", but I won't force you to; but if you don't 
correct it, prepare for me pointing it out again ;-))

Reviewed-by: Max Reitz <mreitz@redhat.com>

> Signed-off-by: Benoit Canet <benoit@irqsave.net>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
>   block/blkverify.c     | 108 +-------------------------------------------------
>   include/qemu-common.h |   2 +
>   util/iov.c            | 106 +++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 110 insertions(+), 106 deletions(-)
>
> diff --git a/block/blkverify.c b/block/blkverify.c
> index b57da59..c86ad7a 100644
> --- a/block/blkverify.c
> +++ b/block/blkverify.c
> @@ -173,110 +173,6 @@ static int64_t blkverify_getlength(BlockDriverState *bs)
>       return bdrv_getlength(s->test_file);
>   }
>   
> -/**
> - * Check that I/O vector contents are identical
> - *
> - * @a:          I/O vector
> - * @b:          I/O vector
> - * @ret:        Offset to first mismatching byte or -1 if match
> - */
> -static ssize_t blkverify_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
> -{
> -    int i;
> -    ssize_t offset = 0;
> -
> -    assert(a->niov == b->niov);
> -    for (i = 0; i < a->niov; i++) {
> -        size_t len = 0;
> -        uint8_t *p = (uint8_t *)a->iov[i].iov_base;
> -        uint8_t *q = (uint8_t *)b->iov[i].iov_base;
> -
> -        assert(a->iov[i].iov_len == b->iov[i].iov_len);
> -        while (len < a->iov[i].iov_len && *p++ == *q++) {
> -            len++;
> -        }
> -
> -        offset += len;
> -
> -        if (len != a->iov[i].iov_len) {
> -            return offset;
> -        }
> -    }
> -    return -1;
> -}
> -
> -typedef struct {
> -    int src_index;
> -    struct iovec *src_iov;
> -    void *dest_base;
> -} IOVectorSortElem;
> -
> -static int sortelem_cmp_src_base(const void *a, const void *b)
> -{
> -    const IOVectorSortElem *elem_a = a;
> -    const IOVectorSortElem *elem_b = b;
> -
> -    /* Don't overflow */
> -    if (elem_a->src_iov->iov_base < elem_b->src_iov->iov_base) {
> -        return -1;
> -    } else if (elem_a->src_iov->iov_base > elem_b->src_iov->iov_base) {
> -        return 1;
> -    } else {
> -        return 0;
> -    }
> -}
> -
> -static int sortelem_cmp_src_index(const void *a, const void *b)
> -{
> -    const IOVectorSortElem *elem_a = a;
> -    const IOVectorSortElem *elem_b = b;
> -
> -    return elem_a->src_index - elem_b->src_index;
> -}
> -
> -/**
> - * Copy contents of I/O vector
> - *
> - * The relative relationships of overlapping iovecs are preserved.  This is
> - * necessary to ensure identical semantics in the cloned I/O vector.
> - */
> -static void blkverify_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src,
> -                                  void *buf)
> -{
> -    IOVectorSortElem sortelems[src->niov];
> -    void *last_end;
> -    int i;
> -
> -    /* Sort by source iovecs by base address */
> -    for (i = 0; i < src->niov; i++) {
> -        sortelems[i].src_index = i;
> -        sortelems[i].src_iov = &src->iov[i];
> -    }
> -    qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_base);
> -
> -    /* Allocate buffer space taking into account overlapping iovecs */
> -    last_end = NULL;
> -    for (i = 0; i < src->niov; i++) {
> -        struct iovec *cur = sortelems[i].src_iov;
> -        ptrdiff_t rewind = 0;
> -
> -        /* Detect overlap */
> -        if (last_end && last_end > cur->iov_base) {
> -            rewind = last_end - cur->iov_base;
> -        }
> -
> -        sortelems[i].dest_base = buf - rewind;
> -        buf += cur->iov_len - MIN(rewind, cur->iov_len);
> -        last_end = MAX(cur->iov_base + cur->iov_len, last_end);
> -    }
> -
> -    /* Sort by source iovec index and build destination iovec */
> -    qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_index);
> -    for (i = 0; i < src->niov; i++) {
> -        qemu_iovec_add(dest, sortelems[i].dest_base, src->iov[i].iov_len);
> -    }
> -}
> -
>   static BlkverifyAIOCB *blkverify_aio_get(BlockDriverState *bs, bool is_write,
>                                            int64_t sector_num, QEMUIOVector *qiov,
>                                            int nb_sectors,
> @@ -340,7 +236,7 @@ static void blkverify_aio_cb(void *opaque, int ret)
>   
>   static void blkverify_verify_readv(BlkverifyAIOCB *acb)
>   {
> -    ssize_t offset = blkverify_iovec_compare(acb->qiov, &acb->raw_qiov);
> +    ssize_t offset = qemu_iovec_compare(acb->qiov, &acb->raw_qiov);
>       if (offset != -1) {
>           blkverify_err(acb, "contents mismatch in sector %" PRId64,
>                         acb->sector_num + (int64_t)(offset / BDRV_SECTOR_SIZE));
> @@ -358,7 +254,7 @@ static BlockDriverAIOCB *blkverify_aio_readv(BlockDriverState *bs,
>       acb->verify = blkverify_verify_readv;
>       acb->buf = qemu_blockalign(bs->file, qiov->size);
>       qemu_iovec_init(&acb->raw_qiov, acb->qiov->niov);
> -    blkverify_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
> +    qemu_iovec_clone(&acb->raw_qiov, qiov, acb->buf);
>   
>       bdrv_aio_readv(s->test_file, sector_num, qiov, nb_sectors,
>                      blkverify_aio_cb, acb);
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 5054836..d70783e 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -346,6 +346,8 @@ 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);
> +ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b);
> +void qemu_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src, void *buf);
>   
>   bool buffer_is_zero(const void *buf, size_t len);
>   
> diff --git a/util/iov.c b/util/iov.c
> index bb46c04..03934da 100644
> --- a/util/iov.c
> +++ b/util/iov.c
> @@ -378,6 +378,112 @@ size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
>       return iov_memset(qiov->iov, qiov->niov, offset, fillc, bytes);
>   }
>   
> +/**
> + * Check that I/O vector contents are identical
> + *
> + * The IO vectors must have the same structure (same length of all parts).
> + * A typical usage is to compare vectors created with qemu_iovec_clone().
> + *
> + * @a:          I/O vector
> + * @b:          I/O vector
> + * @ret:        Offset to first mismatching byte or -1 if match
> + */
> +ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
> +{
> +    int i;
> +    ssize_t offset = 0;
> +
> +    assert(a->niov == b->niov);
> +    for (i = 0; i < a->niov; i++) {
> +        size_t len = 0;
> +        uint8_t *p = (uint8_t *)a->iov[i].iov_base;
> +        uint8_t *q = (uint8_t *)b->iov[i].iov_base;
> +
> +        assert(a->iov[i].iov_len == b->iov[i].iov_len);
> +        while (len < a->iov[i].iov_len && *p++ == *q++) {
> +            len++;
> +        }
> +
> +        offset += len;
> +
> +        if (len != a->iov[i].iov_len) {
> +            return offset;
> +        }
> +    }
> +    return -1;
> +}
> +
> +typedef struct {
> +    int src_index;
> +    struct iovec *src_iov;
> +    void *dest_base;
> +} IOVectorSortElem;
> +
> +static int sortelem_cmp_src_base(const void *a, const void *b)
> +{
> +    const IOVectorSortElem *elem_a = a;
> +    const IOVectorSortElem *elem_b = b;
> +
> +    /* Don't overflow */
> +    if (elem_a->src_iov->iov_base < elem_b->src_iov->iov_base) {
> +        return -1;
> +    } else if (elem_a->src_iov->iov_base > elem_b->src_iov->iov_base) {
> +        return 1;
> +    } else {
> +        return 0;
> +    }
> +}
> +
> +static int sortelem_cmp_src_index(const void *a, const void *b)
> +{
> +    const IOVectorSortElem *elem_a = a;
> +    const IOVectorSortElem *elem_b = b;
> +
> +    return elem_a->src_index - elem_b->src_index;
> +}
> +
> +/**
> + * Copy contents of I/O vector
> + *
> + * The relative relationships of overlapping iovecs are preserved.  This is
> + * necessary to ensure identical semantics in the cloned I/O vector.
> + */
> +void qemu_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src, void *buf)
> +{
> +    IOVectorSortElem sortelems[src->niov];
> +    void *last_end;
> +    int i;
> +
> +    /* Sort by source iovecs by base address */
> +    for (i = 0; i < src->niov; i++) {
> +        sortelems[i].src_index = i;
> +        sortelems[i].src_iov = &src->iov[i];
> +    }
> +    qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_base);
> +
> +    /* Allocate buffer space taking into account overlapping iovecs */
> +    last_end = NULL;
> +    for (i = 0; i < src->niov; i++) {
> +        struct iovec *cur = sortelems[i].src_iov;
> +        ptrdiff_t rewind = 0;
> +
> +        /* Detect overlap */
> +        if (last_end && last_end > cur->iov_base) {
> +            rewind = last_end - cur->iov_base;
> +        }
> +
> +        sortelems[i].dest_base = buf - rewind;
> +        buf += cur->iov_len - MIN(rewind, cur->iov_len);
> +        last_end = MAX(cur->iov_base + cur->iov_len, last_end);
> +    }
> +
> +    /* Sort by source iovec index and build destination iovec */
> +    qsort(sortelems, src->niov, sizeof(sortelems[0]), sortelem_cmp_src_index);
> +    for (i = 0; i < src->niov; i++) {
> +        qemu_iovec_add(dest, sortelems[i].dest_base, src->iov[i].iov_len);
> +    }
> +}
> +
>   size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
>                            size_t bytes)
>   {

  reply	other threads:[~2014-02-15  1:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12 22:06 [Qemu-devel] [PATCH V17 00/12] quorum block filter Benoît Canet
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 01/12] quorum: Create quorum.c, add QuorumChildRequest and QuorumAIOCB Benoît Canet
2014-02-15  1:17   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 02/12] quorum: Create BDRVQuorumState and BlkDriver and do init Benoît Canet
2014-02-15  1:22   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 03/12] quorum: Add quorum_aio_writev and its dependencies Benoît Canet
2014-02-15  1:31   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 04/12] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify Benoît Canet
2014-02-15  1:36   ` Max Reitz [this message]
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 05/12] quorum: Add quorum_aio_readv Benoît Canet
2014-02-15  1:40   ` Max Reitz
2014-02-17 10:57     ` Kevin Wolf
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 06/12] quorum: Add quorum mechanism Benoît Canet
2014-02-15  1:53   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 07/12] quorum: Add quorum_getlength() Benoît Canet
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 08/12] quorum: Add quorum_invalidate_cache() Benoît Canet
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 09/12] quorum: Add quorum_co_flush() Benoît Canet
2014-02-15  1:54   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 10/12] quorum: Implement recursive .bdrv_recurse_is_first_non_filter in quorum Benoît Canet
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 11/12] quorum: Add quorum_open() and quorum_close() Benoît Canet
2014-02-13  9:09   ` Benoît Canet
2014-02-18  4:06     ` Fam Zheng
2014-02-18 12:31       ` Benoît Canet
2014-02-15  2:02   ` Max Reitz
2014-02-12 22:06 ` [Qemu-devel] [PATCH V17 12/12] quorum: Add unit test Benoît Canet
2014-02-15  1:15 ` [Qemu-devel] [PATCH V17 00/12] quorum block filter Max Reitz
2014-02-15  2:04   ` Max Reitz

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=52FEC4AA.8060400@redhat.com \
    --to=mreitz@redhat.com \
    --cc=benoit.canet@irqsave.net \
    --cc=benoit@irqsave.net \
    --cc=famz@redhat.com \
    --cc=kwolf@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 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).