From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WA4nj-0004wM-Kx for qemu-devel@nongnu.org; Sun, 02 Feb 2014 16:42:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WA4ne-0005yj-In for qemu-devel@nongnu.org; Sun, 02 Feb 2014 16:42:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WA4ne-0005wz-9u for qemu-devel@nongnu.org; Sun, 02 Feb 2014 16:41:58 -0500 Message-ID: <52EEBC27.2000407@redhat.com> Date: Sun, 02 Feb 2014 22:44:07 +0100 From: Max Reitz MIME-Version: 1.0 References: <1390927974-31325-1-git-send-email-benoit.canet@irqsave.net> <1390927974-31325-10-git-send-email-benoit.canet@irqsave.net> In-Reply-To: <1390927974-31325-10-git-send-email-benoit.canet@irqsave.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V10 09/13] quorum: Add quorum_co_get_block_status. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?QmVub8OudCBDYW5ldA==?= , qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?B?QmVub8OudCBDYW5ldA==?= , stefanha@redhat.com On 28.01.2014 17:52, Beno=C3=AEt Canet wrote: > From: Beno=C3=AEt Canet > > Signed-off-by: Benoit Canet > --- > block/quorum.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++ > 1 file changed, 67 insertions(+) > > diff --git a/block/quorum.c b/block/quorum.c > index a47cd33..9b0718b 100644 > --- a/block/quorum.c > +++ b/block/quorum.c > @@ -171,6 +171,22 @@ static int quorum_sha256_compare(QuorumVoteValue *= a, QuorumVoteValue *b) > return memcmp(a->h, b->h, HASH_LENGTH); > } > =20 > +static int quorum_64bits_compare(QuorumVoteValue *a, QuorumVoteValue *= b) > +{ > + int64_t i =3D a->l; > + int64_t j =3D 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, > @@ -587,6 +603,56 @@ static void quorum_invalidate_cache(BlockDriverSta= te *bs) > } > } > =20 > +static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverStat= e *bs, > + int64_t sector_= num, > + int nb_sectors, > + int *pnum) > +{ > + BDRVQuorumState *s =3D bs->opaque; > + QuorumVoteVersion *winner =3D NULL; > + QuorumVotes result_votes, num_votes; > + QuorumVoteValue result_value, num_value; > + int i, num; > + int64_t result =3D 0; > + > + QLIST_INIT(&result_votes.vote_list); > + QLIST_INIT(&num_votes.vote_list); > + result_votes.compare =3D quorum_64bits_compare; > + num_votes.compare =3D quorum_64bits_compare; > + > + for (i =3D 0; i < s->total; i++) { > + result =3D bdrv_get_block_status(s->bs[i], sector_num, nb_sect= ors, &num); > + /* skip failed requests */ > + if (result < 0) { > + continue; > + } > + result_value.l =3D result & BDRV_BLOCK_DATA; > + num_value.l =3D num; > + quorum_count_vote(&result_votes, &result_value, i); > + quorum_count_vote(&num_votes, &num_value, i); > + } > + > + winner =3D quorum_get_vote_winner(&result_votes); > + result =3D winner->value.l; Below, you're reading the winning value after checking whether it's=20 corresponding votes exceeded the threshold. It doesn't matter in the=20 end, but for the sake of uniformity, I'd do it the same way here (i.e.,=20 move this statement below the if block). > + if (winner->vote_count < s->threshold) { > + result =3D -ERANGE; Is there any specific reason why you're returning -ERANGE here and -EIO=20 everywhere else (even in quorum_getlength())? Max > + goto free_exit; > + } > + > + winner =3D quorum_get_vote_winner(&num_votes); > + if (winner->vote_count < s->threshold) { > + result =3D -ERANGE; > + goto free_exit; > + } > + *pnum =3D winner->value.l; > + > +free_exit: > + quorum_free_vote_list(&result_votes); > + quorum_free_vote_list(&num_votes); > + > + return result; > +} > + > static BlockDriver bdrv_quorum =3D { > .format_name =3D "quorum", > .protocol_name =3D "quorum", > @@ -598,6 +664,7 @@ static BlockDriver bdrv_quorum =3D { > .bdrv_aio_readv =3D quorum_aio_readv, > .bdrv_aio_writev =3D quorum_aio_writev, > .bdrv_invalidate_cache =3D quorum_invalidate_cache, > + .bdrv_co_get_block_status =3D quorum_co_get_block_status, > }; > =20 > static void bdrv_quorum_init(void)