nbd: use a QemuMutex to synchronize yanking, reconnection and coroutines
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 14 Apr 2022 17:57:52 +0000 (19:57 +0200)
committerEric Blake <eblake@redhat.com>
Tue, 26 Apr 2022 18:16:37 +0000 (13:16 -0500)
commitee19d953ecff53908a645d38a1b913fdf15a72f4
treee85205cb70e809688b4c694a0c497a33891642a9
parent8610b4491f02312f3bf0de10826fad7aa99ddfcf
nbd: use a QemuMutex to synchronize yanking, reconnection and coroutines

The condition for waiting on the s->free_sema queue depends on
both s->in_flight and s->state.  The latter is currently using
atomics, but this is quite dubious and probably wrong.

Because s->state is written in the main thread too, for example by
the yank callback, it cannot be protected by a CoMutex.  Introduce a
separate lock that can be used by nbd_co_send_request(); later on this
lock will also be used for s->state.  There will not be any contention
on the lock unless there is a yank or reconnect, so this is not
performance sensitive.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20220414175756.671165-6-pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
Signed-off-by: Eric Blake <eblake@redhat.com>
block/nbd.c