On Tue, Aug 7, 2012 at 2:44 PM, Benoît Canet <[email protected]> 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.