qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated.


From: Kevin Wolf
Subject: Re: [Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated.
Date: Fri, 08 Feb 2013 13:20:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0

Am 28.01.2013 18:07, schrieb BenoƮt Canet:
> Signed-off-by: Benoit Canet <address@hidden>
> ---
>  block/quorum.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/block/quorum.c b/block/quorum.c
> index 1c50ed5..459434f 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -134,6 +134,22 @@ static int quorum_sha256_compare(QuorumVoteValue *a, 
> QuorumVoteValue *b)
>      return memcmp(a, b, HASH_LENGTH);
>  }
>  
> +static int quorum_long_compare(QuorumVoteValue *a, QuorumVoteValue *b)
> +{
> +    unsigned long i = a->l;
> +    unsigned long j = b->l;
> +
> +    if (i < j) {
> +        return -1;
> +    }
> +
> +    if (i > j) {
> +        return 1;
> +    }
> +
> +    return 0;
> +}
> +
>  static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
>                                     BlockDriverState *bs,
>                                     QEMUIOVector *qiov,
> @@ -525,6 +541,42 @@ static void quorum_invalidate_cache(BlockDriverState *bs)
>      }
>  }
>  
> +static int coroutine_fn quorum_co_is_allocated(BlockDriverState *bs,
> +                                               int64_t sector_num,
> +                                               int nb_sectors,
> +                                               int *pnum)
> +{
> +    BDRVQuorumState *s = bs->opaque;
> +    QuorumVoteVersion *winner = NULL;
> +    QuorumVotes result_votes, num_votes;
> +    QuorumVoteValue result_value, num_value;
> +    int i, result = 0, num;
> +
> +    QLIST_INIT(&result_votes.vote_list);
> +    QLIST_INIT(&num_votes.vote_list);
> +    result_votes.compare = quorum_long_compare;
> +    num_votes.compare = quorum_long_compare;
> +
> +    for (i = 0; i < s->total; i++) {
> +        result = bdrv_co_is_allocated(s->bs[i], sector_num, nb_sectors, 
> &num);
> +        result_value.l = result;
> +        num_value.l = num;
> +        quorum_count_vote(&result_votes, &result_value, i);
> +        quorum_count_vote(&num_votes, &num_value, i);

Maybe it would be better to not include the num_value of failed requests.

> +    }
> +
> +    winner = quorum_get_vote_winner(&result_votes);
> +    result = winner->value.l;
> +
> +    winner = quorum_get_vote_winner(&num_votes);
> +    *pnum = winner->value.l;

No comparison against the threshold?

> +
> +    quorum_free_vote_list(&result_votes);
> +    quorum_free_vote_list(&num_votes);
> +
> +    return result;
> +}
> +
>  static BlockDriver bdrv_quorum = {
>      .format_name        = "quorum",
>      .protocol_name      = "quorum",
> @@ -536,6 +588,7 @@ static BlockDriver bdrv_quorum = {
>      .bdrv_aio_readv     = quorum_aio_readv,
>      .bdrv_aio_writev    = quorum_aio_writev,
>      .bdrv_invalidate_cache = quorum_invalidate_cache,
> +    .bdrv_co_is_allocated  = quorum_co_is_allocated,
>  };
>  
>  static void bdrv_quorum_init(void)
> 

Kevin



reply via email to

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