graph-lock: Honour read locks even in the main thread
commit71438d8dac07f28c01cf6d90fce14efe04c77824
authorKevin Wolf <kwolf@redhat.com>
Wed, 10 May 2023 20:36:01 +0000 (10 22:36 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 19 May 2023 17:12:12 +0000 (19 19:12 +0200)
treed6603281d18a5f6c80f97f85f719ef63e22e0b9f
parent018e5987b57589e6e9089c2d2ef31db4e7519fd5
graph-lock: Honour read locks even in the main thread

There are some conditions under which we don't actually need to do
anything for taking a reader lock: Writing the graph is only possible
from the main context while holding the BQL. So if a reader is running
in the main context under the BQL and knows that it won't be interrupted
until the next writer runs, we don't actually need to do anything.

This is the case if the reader code neither has a nested event loop
(this is forbidden anyway while you hold the lock) nor is a coroutine
(because a writer could run when the coroutine has yielded).

These conditions are exactly what bdrv_graph_rdlock_main_loop() asserts.
They are not fulfilled in bdrv_graph_co_rdlock(), which always runs in a
coroutine.

This deletes the shortcuts in bdrv_graph_co_rdlock() that skip taking
the reader lock in the main thread.

Reported-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230510203601.418015-9-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/graph-lock.c