[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated.
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated. |
Date: |
Mon, 28 Jan 2013 18:07:21 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block/quorum.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/block/quorum.c b/block/quorum.c
index 1c50ed5..459434f 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -134,6 +134,22 @@ static int quorum_sha256_compare(QuorumVoteValue *a,
QuorumVoteValue *b)
return memcmp(a, b, HASH_LENGTH);
}
+static int quorum_long_compare(QuorumVoteValue *a, QuorumVoteValue *b)
+{
+ unsigned long i = a->l;
+ unsigned long j = b->l;
+
+ if (i < j) {
+ return -1;
+ }
+
+ if (i > j) {
+ return 1;
+ }
+
+ return 0;
+}
+
static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
BlockDriverState *bs,
QEMUIOVector *qiov,
@@ -525,6 +541,42 @@ static void quorum_invalidate_cache(BlockDriverState *bs)
}
}
+static int coroutine_fn quorum_co_is_allocated(BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors,
+ int *pnum)
+{
+ BDRVQuorumState *s = bs->opaque;
+ QuorumVoteVersion *winner = NULL;
+ QuorumVotes result_votes, num_votes;
+ QuorumVoteValue result_value, num_value;
+ int i, result = 0, num;
+
+ QLIST_INIT(&result_votes.vote_list);
+ QLIST_INIT(&num_votes.vote_list);
+ result_votes.compare = quorum_long_compare;
+ num_votes.compare = quorum_long_compare;
+
+ for (i = 0; i < s->total; i++) {
+ result = bdrv_co_is_allocated(s->bs[i], sector_num, nb_sectors, &num);
+ result_value.l = result;
+ num_value.l = num;
+ quorum_count_vote(&result_votes, &result_value, i);
+ quorum_count_vote(&num_votes, &num_value, i);
+ }
+
+ winner = quorum_get_vote_winner(&result_votes);
+ result = winner->value.l;
+
+ winner = quorum_get_vote_winner(&num_votes);
+ *pnum = winner->value.l;
+
+ quorum_free_vote_list(&result_votes);
+ quorum_free_vote_list(&num_votes);
+
+ return result;
+}
+
static BlockDriver bdrv_quorum = {
.format_name = "quorum",
.protocol_name = "quorum",
@@ -536,6 +588,7 @@ static BlockDriver bdrv_quorum = {
.bdrv_aio_readv = quorum_aio_readv,
.bdrv_aio_writev = quorum_aio_writev,
.bdrv_invalidate_cache = quorum_invalidate_cache,
+ .bdrv_co_is_allocated = quorum_co_is_allocated,
};
static void bdrv_quorum_init(void)
--
1.7.10.4
- [Qemu-devel] [RFC V8 00/13] Quorum block filter., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 02/13] quorum: Create BDRVQuorumState and BlkDriver and do init., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 01/13] quorum: Create quorum .c, add QuorumSingleAIOCB and QuorumAIOCB., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 03/13] quorum: Add quorum_aio_writev and its dependencies., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 05/13] quorum: Add quorum_aio_readv., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 04/13] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 06/13] quorum: Add quorum mechanism., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 09/13] quorum: Add quorum_co_is_allocated.,
Benoît Canet <=
- [Qemu-devel] [RFC V8 08/13] quorum: Add quorum_invalidate_cache()., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 10/13] quorum: Add quorum_co_flush()., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 11/13] quorum: Add quorum_snapshot_img_create., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 07/13] quorum: Add quorum_getlength()., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 12/13] quorum: Add quorum_snapshot_reopen., Benoît Canet, 2013/01/28
- [Qemu-devel] [RFC V8 13/13] quorum: Add quorum_open() and quorum_close()., Benoît Canet, 2013/01/28