On Thu, Jun 10, 2021 at 01:07:41PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> We don't need all these states. The code refactored to use two boolean
> variables looks simpler.
>
> While moving the comment in nbd_co_establish_connection() rework it to
> give better information. Also, we are going to move the connection code
> to separate file and mentioning drained section would be confusing.
>
> Improve also the comment in NBDConnectThread, while dropping removed
> state names from it.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
> block/nbd.c | 139 +++++++++++++++++-----------------------------------
> 1 file changed, 44 insertions(+), 95 deletions(-)
>
> typedef struct NBDConnectThread {
> /* Initialization constants */
> SocketAddress *saddr; /* address to connect to */
>
> + QemuMutex mutex;
> +
> /*
> - * Result of last attempt. Valid in FAIL and SUCCESS states.
> - * If you want to steal error, don't forget to set pointer to NULL.
> + * @sioc and @err present a result of connection attempt.
> + * While running is true, they are used only by thread, mutex locking is
> not
> + * needed. When thread is finished nbd_co_establish_connection steal
> these
> + * pointers under mutex.
@sioc and @err represent a connection attempt. While running is true,
they are only used by the connection thread, and mutex locking is not
needed. Once the thread finishes, nbd_co_establish_connection then
steals these pointers under mutex.
> */
> QIOChannelSocket *sioc;
> Error *err;
>
> - QemuMutex mutex;
> - /* All further fields are protected by mutex */
> - NBDConnectThreadState state; /* current state of the thread */
> + /* All further fields are accessed only under mutex */
> + bool running; /* thread is running now */
> + bool detached; /* thread is detached and should cleanup the state */
>
Okay, I'm understanding this better than I did in v3.
Reviewed-by: Eric Blake <[email protected]>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org