qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC V2 10/10] quorum: Add quorum mechanism.


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [RFC V2 10/10] quorum: Add quorum mechanism.
Date: Wed, 8 Aug 2012 16:54:21 +0100

On Tue, Aug 7, 2012 at 2:44 PM, Benoît Canet <address@hidden> wrote:
> +static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
> +{
> +    int i;
> +    for (i = 0; i < source->niov; i++) {
> +        memcpy(dest->iov[i].iov_base,
> +               source->iov[i].iov_base,
> +               source->iov[i].iov_len);
> +        dest->iov[i].iov_len = source->iov[i].iov_len;
> +    }
> +    dest->niov = source->niov;
> +    dest->nalloc = source->nalloc;
> +    dest->size = source->size;

dest and source must be compatible.  Their element lengths must be identical.

Therefore I suggest dropping the assignments and replacing them with
assert(3) calls that remind us that we know they are compatible.

> +}
> +
> +static void quorum_vote(QuorumAIOCB *acb)
> +{
> +    ssize_t a_b, b_c, a_c;
> +    a_b = blkverify_iovec_compare(&acb->qiovs[0], &acb->qiovs[1]);
> +    b_c = blkverify_iovec_compare(&acb->qiovs[1], &acb->qiovs[2]);
> +
> +    /* Three vector identical -> quorum */
> +    if (a_b == b_c && a_b == -1) {
> +        quorum_copy_qiov(acb->qiov, &acb->qiovs[0]); /*clone a */
> +        return;
> +    }
> +    if (a_b == -1) {
> +        quorum_print_bad(acb, "C");
> +        quorum_copy_qiov(acb->qiov, &acb->qiovs[0]); /*clone a */
> +        return;
> +    }
> +    if (b_c == -1) {
> +        quorum_print_bad(acb, "A");
> +        quorum_copy_qiov(acb->qiov, &acb->qiovs[1]); /*clone b */
> +        return;
> +    }
> +    a_c = blkverify_iovec_compare(&acb->qiovs[0], &acb->qiovs[2]);
> +    if (a_c == -1) {
> +        quorum_print_bad(acb, "B");
> +        quorum_copy_qiov(acb->qiov, &acb->qiovs[0]); /*clone a */
> +        return;
> +    }
> +    quorum_print_failure(acb);
> +    acb->vote_ret = -EIO;
>  }

In the common case comparison will succeed so we could use acb->qiov
as acb->qiovs[0] (a's qiov).  In that case we wouldn't need to copy
the data.  If you feel this will complicate things you could leave a
comment so someone can add it in the future, if necessary.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]