From patchwork Mon Jan 28 13:22:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC,V7,07/13] quorum: Add quorum_getlength(). Date: Mon, 28 Jan 2013 03:22:53 -0000 From: =?utf-8?q?Beno=C3=AEt_Canet_=3Cbenoit=40irqsave=2Enet=3E?= X-Patchwork-Id: 216219 Message-Id: <1359379379-6017-8-git-send-email-benoit@irqsave.net> To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com 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 --- block/quorum.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index 307fab4..1f0954d 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -499,12 +499,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_aio_readv = quorum_aio_readv, .bdrv_aio_writev = quorum_aio_writev, };