[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/20] block/nbd: refactor nbd_recv_coroutines_wake_all()
From: |
Eric Blake |
Subject: |
[PULL 17/20] block/nbd: refactor nbd_recv_coroutines_wake_all() |
Date: |
Mon, 27 Sep 2021 16:55:42 -0500 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Split out nbd_recv_coroutine_wake_one(), as it will be used
separately.
Rename the function and add a possibility to wake only first found
sleeping coroutine.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210902103805.25686-4-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: grammar tweak]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
block/nbd.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 2842e6263fe4..709c2499e33c 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -127,16 +127,24 @@ static bool nbd_client_connected(BDRVNBDState *s)
return qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED;
}
-static void nbd_recv_coroutines_wake_all(BDRVNBDState *s)
+static bool nbd_recv_coroutine_wake_one(NBDClientRequest *req)
+{
+ if (req->receiving) {
+ req->receiving = false;
+ aio_co_wake(req->coroutine);
+ return true;
+ }
+
+ return false;
+}
+
+static void nbd_recv_coroutines_wake(BDRVNBDState *s, bool all)
{
int i;
for (i = 0; i < MAX_NBD_REQUESTS; i++) {
- NBDClientRequest *req = &s->requests[i];
-
- if (req->coroutine && req->receiving) {
- req->receiving = false;
- aio_co_wake(req->coroutine);
+ if (nbd_recv_coroutine_wake_one(&s->requests[i]) && !all) {
+ return;
}
}
}
@@ -415,7 +423,7 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState
*s)
while (s->in_flight > 0) {
qemu_co_mutex_unlock(&s->send_mutex);
- nbd_recv_coroutines_wake_all(s);
+ nbd_recv_coroutines_wake(s, true);
s->wait_in_flight = true;
qemu_coroutine_yield();
s->wait_in_flight = false;
@@ -558,7 +566,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque)
}
qemu_co_queue_restart_all(&s->free_sema);
- nbd_recv_coroutines_wake_all(s);
+ nbd_recv_coroutines_wake(s, true);
bdrv_dec_in_flight(s->bs);
s->connection_co = NULL;
@@ -1035,7 +1043,7 @@ static coroutine_fn int nbd_co_receive_one_chunk(
if (s->connection_co && !s->wait_in_flight) {
/*
* We must check s->wait_in_flight, because we may entered by
- * nbd_recv_coroutines_wake_all(), in this case we should not
+ * nbd_recv_coroutines_wake(), in this case we should not
* wake connection_co here, it will woken by last request.
*/
aio_co_wake(s->connection_co);
--
2.31.1
- [PULL 06/20] block: use int64_t instead of uint64_t in copy_range driver handlers, (continued)
- [PULL 06/20] block: use int64_t instead of uint64_t in copy_range driver handlers, Eric Blake, 2021/09/27
- [PULL 10/20] block: make BlockLimits::max_pdiscard 64bit, Eric Blake, 2021/09/27
- [PULL 11/20] block: use int64_t instead of int in driver discard handlers, Eric Blake, 2021/09/27
- [PULL 04/20] block: use int64_t instead of uint64_t in driver read handlers, Eric Blake, 2021/09/27
- [PULL 07/20] block: make BlockLimits::max_pwrite_zeroes 64bit, Eric Blake, 2021/09/27
- [PULL 09/20] block/io: allow 64bit write-zeroes requests, Eric Blake, 2021/09/27
- [PULL 12/20] block/io: allow 64bit discard requests, Eric Blake, 2021/09/27
- [PULL 13/20] nbd/server: Allow LIST_META_CONTEXT without STRUCTURED_REPLY, Eric Blake, 2021/09/27
- [PULL 15/20] block/nbd: nbd_channel_error() shutdown channel unconditionally, Eric Blake, 2021/09/27
- [PULL 18/20] block/nbd: drop connection_co, Eric Blake, 2021/09/27
- [PULL 17/20] block/nbd: refactor nbd_recv_coroutines_wake_all(),
Eric Blake <=
- [PULL 08/20] block: use int64_t instead of int in driver write_zeroes handlers, Eric Blake, 2021/09/27
- [PULL 14/20] nbd/client-connection: nbd_co_establish_connection(): fix non set errp, Eric Blake, 2021/09/27
- [PULL 16/20] block/nbd: move nbd_recv_coroutines_wake_all() up, Eric Blake, 2021/09/27
- [PULL 19/20] block/nbd: check that received handle is valid, Eric Blake, 2021/09/27
- [PULL 20/20] nbd/server: Add --selinux-label option, Eric Blake, 2021/09/27
- Re: [PULL 00/20] NBD patches through 2021-09-27, Peter Maydell, 2021/09/29