[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 21/32] nbd/client-connection: shutdown connection on release
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v4 21/32] nbd/client-connection: shutdown connection on release |
Date: |
Thu, 10 Jun 2021 13:07:51 +0300 |
Now, when a thread can do negotiation and retry, it may run relatively
long. We need a mechanism to stop it, when the user is not interested
in a result any more. So, on nbd_client_connection_release() let's
shutdown the socket, and do not retry connection if thread is detached.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
nbd/client-connection.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/nbd/client-connection.c b/nbd/client-connection.c
index 76346481ba..80c19f4eff 100644
--- a/nbd/client-connection.c
+++ b/nbd/client-connection.c
@@ -167,9 +167,13 @@ static void *connect_thread_func(void *opaque)
uint64_t timeout = 1;
uint64_t max_timeout = 16;
- while (true) {
+ qemu_mutex_lock(&conn->mutex);
+ while (!conn->detached) {
+ assert(!conn->sioc);
conn->sioc = qio_channel_socket_new();
+ qemu_mutex_unlock(&conn->mutex);
+
error_free(conn->err);
conn->err = NULL;
conn->updated_info = conn->initial_info;
@@ -187,14 +191,20 @@ static void *connect_thread_func(void *opaque)
conn->updated_info.x_dirty_bitmap = NULL;
conn->updated_info.name = NULL;
+ qemu_mutex_lock(&conn->mutex);
+
if (ret < 0) {
object_unref(OBJECT(conn->sioc));
conn->sioc = NULL;
- if (conn->do_retry) {
+ if (conn->do_retry && !conn->detached) {
+ qemu_mutex_unlock(&conn->mutex);
+
sleep(timeout);
if (timeout < max_timeout) {
timeout *= 2;
}
+
+ qemu_mutex_lock(&conn->mutex);
continue;
}
}
@@ -202,7 +212,7 @@ static void *connect_thread_func(void *opaque)
break;
}
- qemu_mutex_lock(&conn->mutex);
+ /* mutex is locked */
assert(conn->running);
conn->running = false;
@@ -236,6 +246,10 @@ void nbd_client_connection_release(NBDClientConnection
*conn)
} else {
do_free = true;
}
+ if (conn->sioc) {
+ qio_channel_shutdown(QIO_CHANNEL(conn->sioc),
+ QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
+ }
}
if (do_free) {
--
2.29.2
- [PATCH v4 05/32] qemu-sockets: introduce socket_address_parse_named_fd(), (continued)
- [PATCH v4 05/32] qemu-sockets: introduce socket_address_parse_named_fd(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 15/32] block/nbd: introduce nbd_client_connection_new(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 20/32] nbd/client-connection: implement connection retry, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 12/32] block/nbd: bs-independent interface for nbd_co_establish_connection(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 13/32] block/nbd: make nbd_co_establish_connection_cancel() bs-independent, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 19/32] nbd/client-connection: add possibility of negotiation, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 21/32] nbd/client-connection: shutdown connection on release,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v4 14/32] block/nbd: rename NBDConnectThread to NBDClientConnection, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 27/32] block-coroutine-wrapper: allow non bdrv_ prefix, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 26/32] nbd/client-connection: return only one io channel, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 25/32] block/nbd: drop BDRVNBDState::sioc, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 16/32] block/nbd: introduce nbd_client_connection_release(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 23/32] block/nbd: use negotiation of NBDClientConnection, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 22/32] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 30/32] block/nbd: reuse nbd_co_do_establish_connection() in nbd_open(), Vladimir Sementsov-Ogievskiy, 2021/06/10