Patchwork [RFC,V5,11/11] quorum: Add quorum_co_is_allocated.

login
register
mail settings
Submitter Benoit Canet
Date Aug. 27, 2012, 7:30 a.m.
Message ID <1346052629-15686-12-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/180144/
State New
Headers show

Comments

Benoit Canet - Aug. 27, 2012, 7:30 a.m.
Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
 block/quorum.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Patch

diff --git a/block/quorum.c b/block/quorum.c
index c9dcd9c..5a9f598 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -581,6 +581,37 @@  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;
+    int i, result, num;
+
+    QLIST_INIT(&result_votes.vote_list);
+    QLIST_INIT(&num_votes.vote_list);
+
+    for (i = 0; i < s->total; i++) {
+        result = bdrv_co_is_allocated(s->bs[i], sector_num, nb_sectors, &num);
+        quorum_count_vote(&result_votes, result, i);
+        quorum_count_vote(&num_votes, num, i);
+    }
+
+    winner = quorum_get_vote_winner(&result_votes);
+    result = winner->value;
+
+    winner = quorum_get_vote_winner(&num_votes);
+    *pnum = winner->value;
+
+    quorum_free_vote_list(&result_votes);
+    quorum_free_vote_list(&num_votes);
+
+    return result;
+}
+
 static BlockDriver bdrv_quorum = {
     .format_name        = "quorum",
     .protocol_name      = "quorum",
@@ -596,6 +627,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)