[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release(
From: |
Roman Kagan |
Subject: |
Re: [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release() |
Date: |
Wed, 28 Apr 2021 01:35:20 +0300 |
On Fri, Apr 16, 2021 at 11:08:51AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> block/nbd.c | 43 ++++++++++++++++++++++++++-----------------
> 1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/block/nbd.c b/block/nbd.c
> index 21a4039359..8531d019b2 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -118,7 +118,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 *
> @@ -130,20 +130,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;
> -
> - qemu_mutex_lock(&conn->mutex);
> - if (conn->running) {
> - conn->detached = true;
> - }
> - do_free = !conn->running && !conn->detached;
> - qemu_mutex_unlock(&conn->mutex);
>
> - /* the runaway thread will clean it 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));
>
> @@ -365,7 +354,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);
> @@ -379,8 +368,8 @@ static void nbd_free_connect_thread(NBDClientConnection
> *conn)
> static void *connect_thread_func(void *opaque)
> {
> NBDClientConnection *conn = opaque;
> + bool do_free;
> int ret;
> - bool do_free = false;
>
This hunk belongs in patch 8.
Roman.
> conn->sioc = qio_channel_socket_new();
>
> @@ -405,12 +394,32 @@ 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;
> +
> + if (!conn) {
> + return;
> + }
> +
> + qemu_mutex_lock(&conn->mutex);
> + if (conn->running) {
> + conn->detached = true;
> + }
> + do_free = !conn->running && !conn->detached;
> + qemu_mutex_unlock(&conn->mutex);
> +
> + if (do_free) {
> + nbd_client_connection_do_free(conn);
> + }
> +}
> +
> /*
> * Get a new connection in context of @conn:
> * if thread is running, wait for completion
> --
> 2.29.2
>
- Re: [PATCH v3 14/33] nbd: move connection code from block/nbd to nbd/client-connection, (continued)
- [PATCH v3 23/33] block/nbd: nbd_teardown_connection() don't touch s->sioc, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 16/33] nbd/client-connection: add possibility of negotiation, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 12/33] block/nbd: introduce nbd_client_connection_new(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 15/33] nbd/client-connection: use QEMU_LOCK_GUARD, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 17/33] nbd/client-connection: implement connection retry, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 24/33] block/nbd: drop BDRVNBDState::sioc, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- Re: [PATCH v3 13/33] block/nbd: introduce nbd_client_connection_release(),
Roman Kagan <=
- [PATCH v3 27/33] block/nbd: split nbd_co_do_establish_connection out of nbd_reconnect_attempt, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 18/33] nbd/client-connection: shutdown connection on release, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 28/33] nbd/client-connection: do qio_channel_set_delay(false), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 25/33] nbd/client-connection: return only one io channel, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 22/33] block/nbd: pass monitor directly to connection thread, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 20/33] block/nbd: use negotiation of NBDClientConnection, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 29/33] nbd/client-connection: add option for non-blocking connection attempt, Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 19/33] block/nbd: split nbd_handle_updated_info out of nbd_client_handshake(), Vladimir Sementsov-Ogievskiy, 2021/04/16
- [PATCH v3 26/33] block-coroutine-wrapper: allow non bdrv_ prefix, Vladimir Sementsov-Ogievskiy, 2021/04/16