[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/12] mirror: Add mirror_wait_for_io
From: |
Jeff Cody |
Subject: |
[Qemu-devel] [PULL 09/12] mirror: Add mirror_wait_for_io |
Date: |
Mon, 29 Feb 2016 15:08:49 -0500 |
From: Fam Zheng <address@hidden>
The three lines are duplicated a number of times now, refactor a
function.
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Jeff Cody <address@hidden>
---
block/mirror.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index 48cd0b3..9635fa8 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -196,6 +196,14 @@ static int mirror_cow_align(MirrorBlockJob *s,
return ret;
}
+static inline void mirror_wait_for_io(MirrorBlockJob *s)
+{
+ assert(!s->waiting_for_io);
+ s->waiting_for_io = true;
+ qemu_coroutine_yield();
+ s->waiting_for_io = false;
+}
+
/* Submit async read while handling COW.
* Returns: nb_sectors if no alignment is necessary, or
* (new_end - sector_num) if tail is rounded up or down due to
@@ -228,9 +236,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t
sector_num,
while (s->buf_free_count < nb_chunks) {
trace_mirror_yield_in_flight(s, sector_num, s->in_flight);
- s->waiting_for_io = true;
- qemu_coroutine_yield();
- s->waiting_for_io = false;
+ mirror_wait_for_io(s);
}
/* Allocate a MirrorOp that is used as an AIO callback. */
@@ -321,9 +327,7 @@ static uint64_t coroutine_fn
mirror_iteration(MirrorBlockJob *s)
break;
}
trace_mirror_yield_in_flight(s, next_sector, s->in_flight);
- s->waiting_for_io = true;
- qemu_coroutine_yield();
- s->waiting_for_io = false;
+ mirror_wait_for_io(s);
/* Now retry. */
} else {
hbitmap_next = hbitmap_iter_next(&s->hbi);
@@ -414,9 +418,7 @@ static void mirror_free_init(MirrorBlockJob *s)
static void mirror_drain(MirrorBlockJob *s)
{
while (s->in_flight > 0) {
- s->waiting_for_io = true;
- qemu_coroutine_yield();
- s->waiting_for_io = false;
+ mirror_wait_for_io(s);
}
}
@@ -604,9 +606,7 @@ static void coroutine_fn mirror_run(void *opaque)
if (s->in_flight == MAX_IN_FLIGHT || s->buf_free_count == 0 ||
(cnt == 0 && s->in_flight > 0)) {
trace_mirror_yield(s, s->in_flight, s->buf_free_count, cnt);
- s->waiting_for_io = true;
- qemu_coroutine_yield();
- s->waiting_for_io = false;
+ mirror_wait_for_io(s);
continue;
} else if (cnt != 0) {
delay_ns = mirror_iteration(s);
--
1.9.3
- [Qemu-devel] [PULL 00/12] Block patches, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 02/12] sheepdog: allow to delete snapshot, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 01/12] block/nfs: add support for setting debug level, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 04/12] curl: add support for HTTP authentication parameters, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 05/12] iscsi: add support for getting CHAP password via QCryptoSecret API, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 07/12] vhdx: Simplify vhdx_set_shift_bits(), Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 03/12] rbd: add support for getting password from QCryptoSecret object, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 09/12] mirror: Add mirror_wait_for_io,
Jeff Cody <=
- [Qemu-devel] [PULL 06/12] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries(), Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 12/12] iotests/124: Add cluster_size mismatch test, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 11/12] block/backup: avoid copying less than full target clusters, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 08/12] mirror: Rewrite mirror_iteration, Jeff Cody, 2016/02/29
- [Qemu-devel] [PULL 10/12] block/backup: make backup cluster size configurable, Jeff Cody, 2016/02/29