[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 16/32] block/nbd: introduce nbd_client_connection_release()
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v4 16/32] block/nbd: introduce nbd_client_connection_release() |
Date: |
Thu, 10 Jun 2021 13:07:46 +0300 |
This is a last step of creating bs-independent nbd connection
interface. With next commit we can finally move it to separate file.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/nbd.c | 45 +++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 1acac1953e..b34957e464 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -126,7 +126,7 @@ typedef struct BDRVNBDState {
NBDClientConnection *conn;
} BDRVNBDState;
-static void nbd_free_connect_thread(NBDClientConnection *conn);
+static void nbd_client_connection_release(NBDClientConnection *conn);
static int nbd_establish_connection(BlockDriverState *bs, SocketAddress *saddr,
Error **errp);
static coroutine_fn QIOChannelSocket *
@@ -138,22 +138,9 @@ static void nbd_yank(void *opaque);
static void nbd_clear_bdrvstate(BlockDriverState *bs)
{
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
- NBDClientConnection *conn = s->conn;
- bool do_free = false;
-
- qemu_mutex_lock(&conn->mutex);
- assert(!conn->detached);
- if (conn->running) {
- conn->detached = true;
- } else {
- do_free = true;
- }
- qemu_mutex_unlock(&conn->mutex);
- /* the runaway thread will clean up itself */
- if (do_free) {
- nbd_free_connect_thread(conn);
- }
+ nbd_client_connection_release(s->conn);
+ s->conn = NULL;
yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name));
@@ -371,7 +358,7 @@ nbd_client_connection_new(const SocketAddress *saddr)
return conn;
}
-static void nbd_free_connect_thread(NBDClientConnection *conn)
+static void nbd_client_connection_do_free(NBDClientConnection *conn)
{
if (conn->sioc) {
qio_channel_close(QIO_CHANNEL(conn->sioc), NULL);
@@ -413,12 +400,34 @@ static void *connect_thread_func(void *opaque)
qemu_mutex_unlock(&conn->mutex);
if (do_free) {
- nbd_free_connect_thread(conn);
+ nbd_client_connection_do_free(conn);
}
return NULL;
}
+static void nbd_client_connection_release(NBDClientConnection *conn)
+{
+ bool do_free = false;
+
+ if (!conn) {
+ return;
+ }
+
+ qemu_mutex_lock(&conn->mutex);
+ assert(!conn->detached);
+ if (conn->running) {
+ conn->detached = true;
+ } else {
+ do_free = true;
+ }
+ qemu_mutex_unlock(&conn->mutex);
+
+ if (do_free) {
+ nbd_client_connection_do_free(conn);
+ }
+}
+
/*
* Get a new connection in context of @conn:
* if the thread is running, wait for completion
--
2.29.2
- [PATCH v4 12/32] block/nbd: bs-independent interface for nbd_co_establish_connection(), (continued)
- [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, 2021/06/10
- [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 <=
- [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
- [PATCH v4 24/32] block/nbd: don't touch s->sioc in nbd_teardown_connection(), Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 29/32] nbd/client-connection: add option for non-blocking connection attempt, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 28/32] block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 31/32] block/nbd: add nbd_client_connected() helper, Vladimir Sementsov-Ogievskiy, 2021/06/10
- [PATCH v4 32/32] block/nbd: safer transition to receiving request, Vladimir Sementsov-Ogievskiy, 2021/06/10