Skip to content

Commit

Permalink
quorum: Add quorum_getlength().
Browse files Browse the repository at this point in the history
Check that every bs file returns the same length.
Otherwise, return -EIO to disable the quorum and
avoid length discrepancy.

Signed-off-by: Benoit Canet <benoit@irqsave.net>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
benoit-canet authored and kevmw committed Feb 21, 2014
1 parent 95c6bff commit d55dee2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions block/quorum.c
Expand Up @@ -595,12 +595,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->num_children; 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,
};
Expand Down

0 comments on commit d55dee2

Please sign in to comment.