[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 10/17] mirror: Create mirror_co_alloc_qiov()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH 10/17] mirror: Create mirror_co_alloc_qiov() |
Date: |
Mon, 13 Aug 2018 04:19:59 +0200 |
By pulling this function out of mirror_co_read(), the latter becomes
simpler. This is important so the following patches can make it more
complicated again.
Signed-off-by: Max Reitz <address@hidden>
---
block/mirror.c | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index 6330269156..2a131d8b99 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -293,6 +293,29 @@ static inline void coroutine_fn
mirror_co_wait_for_any_operation(s, false);
}
+/* Allocate a QEMUIOVector from the mirror buffer pool (s->buf_free) */
+static void coroutine_fn mirror_co_alloc_qiov(MirrorBlockJob *s,
+ QEMUIOVector *qiov,
+ int64_t offset, uint64_t bytes)
+{
+ int nb_chunks = DIV_ROUND_UP(bytes, s->granularity);
+
+ while (s->buf_free_count < nb_chunks) {
+ trace_mirror_yield_in_flight(s, offset, s->in_flight);
+ mirror_co_wait_for_free_in_flight_slot(s);
+ }
+
+ qemu_iovec_init(qiov, nb_chunks);
+ while (nb_chunks-- > 0) {
+ MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
+ size_t remaining = bytes - qiov->size;
+
+ QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
+ s->buf_free_count--;
+ qemu_iovec_add(qiov, buf, MIN(s->granularity, remaining));
+ }
+}
+
/*
* Restrict *bytes to how much we can actually handle, and align the
* [*offset, *bytes] range to clusters if COW is needed.
@@ -327,28 +350,9 @@ static void coroutine_fn mirror_co_read(void *opaque)
{
MirrorOp *op = opaque;
MirrorBlockJob *s = op->s;
- int nb_chunks;
uint64_t ret;
- nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity);
-
- while (s->buf_free_count < nb_chunks) {
- trace_mirror_yield_in_flight(s, op->offset, s->in_flight);
- mirror_co_wait_for_free_in_flight_slot(s);
- }
-
- /* Now make a QEMUIOVector taking enough granularity-sized chunks
- * from s->buf_free.
- */
- qemu_iovec_init(&op->qiov, nb_chunks);
- while (nb_chunks-- > 0) {
- MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
- size_t remaining = op->bytes - op->qiov.size;
-
- QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
- s->buf_free_count--;
- qemu_iovec_add(&op->qiov, buf, MIN(s->granularity, remaining));
- }
+ mirror_co_alloc_qiov(s, &op->qiov, op->offset, op->bytes);
/* Copy the dirty cluster. */
s->in_flight++;
--
2.17.1
- [Qemu-block] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read(), (continued)
- [Qemu-block] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 04/17] mirror: Remove bytes_handled, part 1, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 05/17] mirror: Remove bytes_handled, part 2, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 06/17] mirror: Create mirror_co_perform(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 07/17] mirror: Make mirror_co_zero() nicer, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 08/17] mirror: Make mirror_co_discard() nicer, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 09/17] mirror: Lock AioContext in mirror_co_perform(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 10/17] mirror: Create mirror_co_alloc_qiov(),
Max Reitz <=
- [Qemu-block] [PATCH 11/17] mirror: Inline mirror_write_complete(), part 1, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 12/17] mirror: Put QIOV locally into mirror_co_read, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 13/17] mirror: Linearize mirror_co_read(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 14/17] mirror: Inline mirror_iteration_done(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 15/17] mirror: Release AioCtx before queue_restart_all(), Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 16/17] mirror: Support COR with write-blocking, Max Reitz, 2018/08/12
- [Qemu-block] [PATCH 17/17] iotests: Add test for active mirror with COR, Max Reitz, 2018/08/12