[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 43/54] quorum: Add quorum_aio_writev and its dependen
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 43/54] quorum: Add quorum_aio_writev and its dependencies. |
Date: |
Fri, 21 Feb 2014 23:12:40 +0100 |
From: BenoƮt Canet <address@hidden>
Writes are mirrored num_children times on num_children devices.
Signed-off-by: Benoit Canet <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/quorum.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/block/quorum.c b/block/quorum.c
index 375ffd5..99e0e03 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -69,11 +69,114 @@ struct QuorumAIOCB {
int vote_ret;
};
+static void quorum_aio_cancel(BlockDriverAIOCB *blockacb)
+{
+ QuorumAIOCB *acb = container_of(blockacb, QuorumAIOCB, common);
+ BDRVQuorumState *s = acb->common.bs->opaque;
+ int i;
+
+ /* cancel all callbacks */
+ for (i = 0; i < s->num_children; i++) {
+ bdrv_aio_cancel(acb->qcrs[i].aiocb);
+ }
+
+ g_free(acb->qcrs);
+ qemu_aio_release(acb);
+}
+
+static AIOCBInfo quorum_aiocb_info = {
+ .aiocb_size = sizeof(QuorumAIOCB),
+ .cancel = quorum_aio_cancel,
+};
+
+static void quorum_aio_finalize(QuorumAIOCB *acb)
+{
+ int ret = 0;
+
+ acb->common.cb(acb->common.opaque, ret);
+
+ g_free(acb->qcrs);
+ qemu_aio_release(acb);
+}
+
+static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
+ BlockDriverState *bs,
+ QEMUIOVector *qiov,
+ uint64_t sector_num,
+ int nb_sectors,
+ BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ QuorumAIOCB *acb = qemu_aio_get(&quorum_aiocb_info, bs, cb, opaque);
+ int i;
+
+ acb->common.bs->opaque = s;
+ acb->sector_num = sector_num;
+ acb->nb_sectors = nb_sectors;
+ acb->qiov = qiov;
+ acb->qcrs = g_new0(QuorumChildRequest, s->num_children);
+ acb->count = 0;
+ acb->success_count = 0;
+ acb->is_read = false;
+ acb->vote_ret = 0;
+
+ for (i = 0; i < s->num_children; i++) {
+ acb->qcrs[i].buf = NULL;
+ acb->qcrs[i].ret = 0;
+ acb->qcrs[i].parent = acb;
+ }
+
+ return acb;
+}
+
+static void quorum_aio_cb(void *opaque, int ret)
+{
+ QuorumChildRequest *sacb = opaque;
+ QuorumAIOCB *acb = sacb->parent;
+ BDRVQuorumState *s = acb->common.bs->opaque;
+
+ sacb->ret = ret;
+ acb->count++;
+ if (ret == 0) {
+ acb->success_count++;
+ }
+ assert(acb->count <= s->num_children);
+ assert(acb->success_count <= s->num_children);
+ if (acb->count < s->num_children) {
+ return;
+ }
+
+ quorum_aio_finalize(acb);
+}
+
+static BlockDriverAIOCB *quorum_aio_writev(BlockDriverState *bs,
+ int64_t sector_num,
+ QEMUIOVector *qiov,
+ int nb_sectors,
+ BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ BDRVQuorumState *s = bs->opaque;
+ QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num, nb_sectors,
+ cb, opaque);
+ int i;
+
+ for (i = 0; i < s->num_children; i++) {
+ acb->qcrs[i].aiocb = bdrv_aio_writev(s->bs[i], sector_num, qiov,
+ nb_sectors, &quorum_aio_cb,
+ &acb->qcrs[i]);
+ }
+
+ return &acb->common;
+}
+
static BlockDriver bdrv_quorum = {
.format_name = "quorum",
.protocol_name = "quorum",
.instance_size = sizeof(BDRVQuorumState),
+
+ .bdrv_aio_writev = quorum_aio_writev,
};
static void bdrv_quorum_init(void)
--
1.8.1.4
- [Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_option_list(), (continued)
- [Qemu-devel] [PULL 31/54] qemu-option: has_help_option() and is_valid_option_list(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 32/54] qemu-img create: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 33/54] qemu-img convert: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 34/54] qemu-img amend: Support multiple -o options, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 35/54] qemu-img: Allow -o help with incomplete argument list, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 36/54] qemu-iotests: Check qemu-img command line parsing, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 37/54] qemu-config: Sections must consist of keys, Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 38/54] qdict: Extract non-QDicts in qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 41/54] quorum: Create quorum.c, add QuorumChildRequest and QuorumAIOCB., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 42/54] quorum: Create BDRVQuorumState and BlkDriver and do init., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 43/54] quorum: Add quorum_aio_writev and its dependencies.,
Kevin Wolf <=
- [Qemu-devel] [PULL 40/54] check-qdict: Test termination of qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 39/54] check-qdict: Adjust test for qdict_array_split(), Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 44/54] blkverify: Extract qemu_iovec_clone() and qemu_iovec_compare() from blkverify., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 45/54] quorum: Add quorum_aio_readv., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 46/54] quorum: Add quorum mechanism., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 48/54] quorum: Add quorum_invalidate_cache()., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 47/54] quorum: Add quorum_getlength()., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 49/54] quorum: Add quorum_co_flush()., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 50/54] quorum: Implement recursive .bdrv_recurse_is_first_non_filter in quorum., Kevin Wolf, 2014/02/21
- [Qemu-devel] [PULL 51/54] quorum: Add quorum_open() and quorum_close()., Kevin Wolf, 2014/02/21