Am 03.02.2014 um 22:51 hat Benoît Canet geschrieben:
> From: Benoît Canet <[email protected]>
>
> Signed-off-by: Benoit Canet <[email protected]>
> Reviewed-by: Max Reitz <[email protected]>
> ---
> block/blkverify.c | 108
> +-------------------------------------------------
> include/qemu-common.h | 2 +
> util/iov.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 107 insertions(+), 106 deletions(-)
> --- a/util/iov.c
> +++ b/util/iov.c
> @@ -378,6 +378,109 @@ 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
> + *
> + * @a: I/O vector
> + * @b: I/O vector
> + * @ret: Offset to first mismatching byte or -1 if match
> + */
Perhaps we should update the documentation to state explicitly that the
I/O vectors must have the same structure (i.e. same length of all parts)
and that you should therefore only use it on vectors previously created
with qemu_iovec_clone().
> +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;
> +}
Kevin