[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 01/10] block/nbd: introduce NBDConnectThread reference cou
From: |
Roman Kagan |
Subject: |
Re: [PATCH v2 01/10] block/nbd: introduce NBDConnectThread reference counter |
Date: |
Thu, 8 Apr 2021 18:31:23 +0300 |
On Thu, Apr 08, 2021 at 05:08:18PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> The structure is shared between NBD BDS and connection thread. And it
> is possible the connect thread will finish after closing and releasing
> for the bs. To handle this we have a concept of
> CONNECT_THREAD_RUNNING_DETACHED state and when thread is running and
> BDS is going to be closed we don't free the structure, but instead move
> it to CONNECT_THREAD_RUNNING_DETACHED state, so that thread will free
> it.
>
> Still more native way to solve the problem is using reference counter
> for shared structure. Let's use it. It makes code smaller and more
> readable.
>
> New approach also makes checks in nbd_co_establish_connection()
> redundant: now we are sure that s->connect_thread is valid during the
> whole life of NBD BDS.
>
> This also fixes possible use-after-free of s->connect_thread if
> nbd_co_establish_connection_cancel() clears it during
> nbd_co_establish_connection(), and nbd_co_establish_connection() uses
> local copy of s->connect_thread after yield point.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> block/nbd.c | 62 +++++++++++++++++------------------------------------
> 1 file changed, 20 insertions(+), 42 deletions(-)
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
- [PATCH v2 00/10] block/nbd: move connection code to separate file, Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 04/10] block/nbd: simplify waking of nbd_co_establish_connection(), Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 01/10] block/nbd: introduce NBDConnectThread reference counter, Vladimir Sementsov-Ogievskiy, 2021/04/08
- Re: [PATCH v2 01/10] block/nbd: introduce NBDConnectThread reference counter,
Roman Kagan <=
- [PATCH v2 08/10] block/nbd: rename NBDConnectThread to NBDClientConnection, Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 05/10] block/nbd: drop thr->state, Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 02/10] block/nbd: BDRVNBDState: drop unused connect_err and connect_status, Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 07/10] block/nbd: make nbd_co_establish_connection_cancel() bs-independent, Vladimir Sementsov-Ogievskiy, 2021/04/08
- [PATCH v2 09/10] block/nbd: introduce nbd_client_connection_new(), Vladimir Sementsov-Ogievskiy, 2021/04/08