Am 30.05.2025 um 17:11 hat Fiona Ebner geschrieben: > Many write-locked sections are also drained sections. A new > bdrv_graph_wrunlock_drained() wrapper around bdrv_graph_wrunlock() is > introduced, which will begin a drained section first. A global > variable is used so bdrv_graph_wrunlock() knows if it also needs > to end such a drained section. Both the aio_poll call in > bdrv_graph_wrlock() and the aio_bh_poll() in bdrv_graph_wrunlock() > can re-enter a write-locked section. While for the latter, ending the > drain could be moved to before the call, the former requires that the > variable is a counter and not just a boolean. > > Since the wrapper calls bdrv_drain_all_begin(), which must be called > with the graph unlocked, mark the wrapper as GRAPH_UNLOCKED too. > > The switch to the new helpers was generated with the following > commands and then manually checked: > find . -name '*.c' -exec sed -i -z > 's/bdrv_drain_all_begin();\n\s*bdrv_graph_wrlock();/bdrv_graph_wrlock_drained();/g' > {} ';' > find . -name '*.c' -exec sed -i -z > 's/bdrv_graph_wrunlock();\n\s*bdrv_drain_all_end();/bdrv_graph_wrunlock();/g' > {} ';' > > Suggested-by: Kevin Wolf <kw...@redhat.com> > Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> > --- > > Changes in v4: > * Adapt to context changes from earlier patch. > * Mark the wrapper as GRAPH_UNLOCKED itself
> diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h > index 2c26c72108..b564cba2c0 100644 > --- a/include/block/graph-lock.h > +++ b/include/block/graph-lock.h > @@ -112,10 +112,21 @@ void unregister_aiocontext(AioContext *ctx); > void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA > bdrv_graph_wrlock(void); > > +/* > + * bdrv_graph_wrlock_drained: > + * Similar to bdrv_graph_wrlock, but will begin a drained section before > + * locking. > + */ > +void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA GRAPH_UNLOCKED > +bdrv_graph_wrlock_drained(void); GRAPH_UNLOCKED is redundant. TSA_ACQUIRE(graph_lock) already means that you can't call the function while holding the lock. Kevin