Patchwork [RFC,V7,11/11] quorum: Add quorum_co_flush().

login
register
mail settings
Submitter Benoît Canet
Date Jan. 18, 2013, 5:30 p.m.
Message ID <1358530244-9028-12-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/213694/
State New
Headers show

Comments

Benoît Canet - Jan. 18, 2013, 5:30 p.m.
Makes a vote to select error if any.

Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
 block/quorum.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Patch

diff --git a/block/quorum.c b/block/quorum.c
index 8cbf66f..0f4f634 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -731,6 +731,38 @@  static int coroutine_fn quorum_co_is_allocated(BlockDriverState *bs,
     return result;
 }
 
+static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
+{
+    BDRVQuorumState *s = bs->opaque;
+    QuorumVoteVersion *winner = NULL;
+    QuorumVotes error_votes;
+    QuorumVoteValue result_value;
+    int i;
+    int result = 0;
+    bool error = false;
+
+    QLIST_INIT(&error_votes.vote_list);
+    error_votes.compare = quorum_long_compare;
+
+    for (i = 0; i < s->total; i++) {
+        result = bdrv_co_flush(s->bs[i]);
+        if (result) {
+            error = true;
+            result_value.l = result;
+            quorum_count_vote(&error_votes, &result_value, i);
+        }
+    }
+
+    if (error) {
+        winner = quorum_get_vote_winner(&error_votes);
+        result = winner->value.l;
+    }
+
+    quorum_free_vote_list(&error_votes);
+
+    return result;
+}
+
 static BlockDriver bdrv_quorum = {
     .format_name        = "quorum",
     .protocol_name      = "quorum",
@@ -741,6 +773,7 @@  static BlockDriver bdrv_quorum = {
 
     .bdrv_file_open     = quorum_open,
     .bdrv_close         = quorum_close,
+    .bdrv_co_flush_to_disk = quorum_co_flush,
 
     .bdrv_aio_readv     = quorum_aio_readv,
     .bdrv_aio_writev    = quorum_aio_writev,