[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/34] nbd/client-connection: shutdown connection on release
From: |
Eric Blake |
Subject: |
[PULL 23/34] nbd/client-connection: shutdown connection on release |
Date: |
Tue, 15 Jun 2021 15:47:45 -0500 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
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>
Message-Id: <20210610100802.5888-22-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.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 032b38ed3e9b..883f9cf158cb 100644
--- a/nbd/client-connection.c
+++ b/nbd/client-connection.c
@@ -168,9 +168,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;
@@ -188,14 +192,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;
}
}
@@ -203,7 +213,7 @@ static void *connect_thread_func(void *opaque)
break;
}
- qemu_mutex_lock(&conn->mutex);
+ /* mutex is locked */
assert(conn->running);
conn->running = false;
@@ -237,6 +247,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.31.1
- [PULL 13/34] block/nbd: drop thr->state, (continued)
- [PULL 13/34] block/nbd: drop thr->state, Eric Blake, 2021/06/15
- [PULL 14/34] block/nbd: bs-independent interface for nbd_co_establish_connection(), Eric Blake, 2021/06/15
- [PULL 15/34] block/nbd: make nbd_co_establish_connection_cancel() bs-independent, Eric Blake, 2021/06/15
- [PULL 17/34] block/nbd: introduce nbd_client_connection_new(), Eric Blake, 2021/06/15
- [PULL 18/34] block/nbd: introduce nbd_client_connection_release(), Eric Blake, 2021/06/15
- [PULL 16/34] block/nbd: rename NBDConnectThread to NBDClientConnection, Eric Blake, 2021/06/15
- [PULL 22/34] nbd/client-connection: implement connection retry, Eric Blake, 2021/06/15
- [PULL 20/34] nbd/client-connection: use QEMU_LOCK_GUARD, Eric Blake, 2021/06/15
- [PULL 21/34] nbd/client-connection: add possibility of negotiation, Eric Blake, 2021/06/15
- [PULL 19/34] nbd: move connection code from block/nbd to nbd/client-connection, Eric Blake, 2021/06/15
- [PULL 23/34] nbd/client-connection: shutdown connection on release,
Eric Blake <=
- [PULL 25/34] block/nbd: use negotiation of NBDClientConnection, Eric Blake, 2021/06/15
- [PULL 26/34] block/nbd: don't touch s->sioc in nbd_teardown_connection(), Eric Blake, 2021/06/15
- [PULL 24/34] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake(), Eric Blake, 2021/06/15
- [PULL 27/34] block/nbd: drop BDRVNBDState::sioc, Eric Blake, 2021/06/15
- [PULL 30/34] block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt, Eric Blake, 2021/06/15
- [PULL 28/34] nbd/client-connection: return only one io channel, Eric Blake, 2021/06/15
- [PULL 31/34] nbd/client-connection: add option for non-blocking connection attempt, Eric Blake, 2021/06/15
- [PULL 29/34] block-coroutine-wrapper: allow non bdrv_ prefix, Eric Blake, 2021/06/15