block/blklogwrites: Protect mutable driver state with a mutex.
commita26d018c94ec367172d8376f00be4a31f74bf0d2
authorAri Sundholm <ari@tuxera.com>
Fri, 19 Jan 2024 16:29:13 +0000 (19 18:29 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 26 Jan 2024 10:16:58 +0000 (26 11:16 +0100)
treeef620fb72589f9e312bd73589e1759b9b17b67c2
parentd3f6f294aeadd5f88caf0155e4360808c95b3146
block/blklogwrites: Protect mutable driver state with a mutex.

During the review of a fix for a concurrency issue in blklogwrites,
it was found that the driver needs an additional fix when enabling
multiqueue, which is a new feature introduced in QEMU 9.0, as the
driver state may be read and written by multiple threads at the same
time, which was not the case when the driver was originally written.

Fix the multi-threaded scenario by introducing a mutex to protect the
mutable fields in the driver state, and always having the mutex locked
by the current thread when accessing them. Also use the mutex and a
CoQueue to ensure that the super block is not being written to by
multiple threads concurrently and updates are properly serialized.

Additionally, add the const qualifier to a few BDRVBlkLogWritesState
pointer targets in contexts where the driver state is not written to.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Message-ID: <20240119162913.2620245-1-ari@tuxera.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/blklogwrites.c