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

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

Comments

Benoît Canet - Jan. 18, 2013, 5:30 p.m.
Check that every bs file return the same length.
If not return -EIO to disable the quorum and
avoid length discrepancy.

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

Patch

diff --git a/block/quorum.c b/block/quorum.c
index e2b5208..a63a84f 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -651,12 +651,32 @@  static BlockDriverAIOCB *quorum_aio_writev(BlockDriverState *bs,
     return &acb->common;
 }
 
+static int64_t quorum_getlength(BlockDriverState *bs)
+{
+    BDRVQuorumState *s = bs->opaque;
+    int64_t result;
+    int i;
+
+    /* check that every file have the same length */
+    result = bdrv_getlength(s->bs[0]);
+    for (i = 1; i < s->total; i++) {
+        int64_t value = bdrv_getlength(s->bs[i]);
+        if (value != result) {
+            return -EIO;
+        }
+    }
+
+    return result;
+}
+
 static BlockDriver bdrv_quorum = {
     .format_name        = "quorum",
     .protocol_name      = "quorum",
 
     .instance_size      = sizeof(BDRVQuorumState),
 
+    .bdrv_getlength     = quorum_getlength,
+
     .bdrv_file_open     = quorum_open,
     .bdrv_close         = quorum_close,