diff mbox

[V10,07/13] quorum: Add quorum_getlength().

Message ID 1390927974-31325-8-git-send-email-benoit.canet@irqsave.net
State New
Headers show

Commit Message

Benoît Canet Jan. 28, 2014, 4:52 p.m. UTC
From: Benoît Canet <benoit@irqsave.net>

Check that every bs file returns the same length.
Otherwize, return -EIO to disable the quorum and
avoid length discrepancy.

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

Comments

Max Reitz Feb. 2, 2014, 9:25 p.m. UTC | #1
On 28.01.2014 17:52, Benoît Canet wrote:
> From: Benoît Canet <benoit@irqsave.net>
>
> Check that every bs file returns the same length.
> Otherwize, return -EIO to disable the quorum and

*Otherwise

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

Aside from that:

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/block/quorum.c b/block/quorum.c
index c319719..a8a8492 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -553,12 +553,38 @@  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 all file have the same length */
+    result = bdrv_getlength(s->bs[0]);
+    if (result < 0) {
+        return result;
+    }
+    for (i = 1; i < s->total; i++) {
+        int64_t value = bdrv_getlength(s->bs[i]);
+        if (value < 0) {
+            return value;
+        }
+        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_aio_readv     = quorum_aio_readv,
     .bdrv_aio_writev    = quorum_aio_writev,
 };