block/export: Fix vhost-user-blk shutdown with requests in flight
commit520d8b40e898158bc9a2b416d1cbdb44d2260bc7
authorKevin Wolf <kwolf@redhat.com>
Tue, 25 Jan 2022 15:14:35 +0000 (25 16:14 +0100)
committerKevin Wolf <kwolf@redhat.com>
Tue, 1 Feb 2022 12:49:15 +0000 (1 13:49 +0100)
tree64df91f7887219d09ac77454d20623faa9ff8693
parentc0829cb1fd5e0b35abfcf9fc3f04502c1ed5d7b6
block/export: Fix vhost-user-blk shutdown with requests in flight

The vhost-user-blk export runs requests asynchronously in their own
coroutine. When the vhost connection goes away and we want to stop the
vhost-user server, we need to wait for these coroutines to stop before
we can unmap the shared memory. Otherwise, they would still access the
unmapped memory and crash.

This introduces a refcount to VuServer which is increased when spawning
a new request coroutine and decreased before the coroutine exits. The
memory is only unmapped when the refcount reaches zero.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20220125151435.48792-1-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/export/vhost-user-blk-server.c
include/qemu/vhost-user-server.h
util/vhost-user-server.c