diff options
author | Max Reitz <mreitz@redhat.com> | 2019-07-22 15:30:54 +0200 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2019-07-22 18:41:43 +0200 |
commit | 43eaaaef0e18817bf78d8f135993f8579cad2cc6 (patch) | |
tree | d177e7167cf62b61f3aa97d6d7fb7b72225eccf6 /block.c | |
parent | 65181d63817b33b10ecb1c418eb96c99e7cf8842 (diff) |
block: Only the main loop can change AioContexts
bdrv_set_aio_context_ignore() can only work in the main loop:
bdrv_drained_begin() only works in the main loop and the node's (old)
AioContext; and bdrv_drained_end() really only works in the main loop
and the node's (new) AioContext (contrary to its current comment, which
is just wrong).
Consequentially, bdrv_set_aio_context_ignore() must be called from the
main loop. Luckily, assuming that we can make block graph changes only
from the main loop as well, all its callers do that already.
Note that changing a node's context in a sense is an operation that
changes the block graph, so it actually makes sense to require this
function to be called from the main loop.
Also, fix bdrv_drained_end()'s description. You can only use it from
the main loop or the node's AioContext, and in the latter case, the
whole subtree must be in the same context.
Fixes: e037c09c78520cbdb6da7cfc6ad0256d5870b814
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190722133054.21781-3-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -5914,6 +5914,8 @@ static void bdrv_attach_aio_context(BlockDriverState *bs, * Changes the AioContext used for fd handlers, timers, and BHs by this * BlockDriverState and all its children and parents. * + * Must be called from the main AioContext. + * * The caller must own the AioContext lock for the old AioContext of bs, but it * must not own the AioContext lock for new_context (unless new_context is the * same as the current context of bs). @@ -5925,9 +5927,10 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, AioContext *new_context, GSList **ignore) { AioContext *old_context = bdrv_get_aio_context(bs); - AioContext *current_context = qemu_get_current_aio_context(); BdrvChild *child; + g_assert(qemu_get_current_aio_context() == qemu_get_aio_context()); + if (old_context == new_context) { return; } @@ -5953,7 +5956,7 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, bdrv_detach_aio_context(bs); /* Acquire the new context, if necessary */ - if (current_context != new_context) { + if (qemu_get_aio_context() != new_context) { aio_context_acquire(new_context); } @@ -5965,16 +5968,16 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, * subtree that have not yet been moved to the new AioContext. * Release the old one so bdrv_drained_end() can poll them. */ - if (current_context != old_context) { + if (qemu_get_aio_context() != old_context) { aio_context_release(old_context); } bdrv_drained_end(bs); - if (current_context != old_context) { + if (qemu_get_aio_context() != old_context) { aio_context_acquire(old_context); } - if (current_context != new_context) { + if (qemu_get_aio_context() != new_context) { aio_context_release(new_context); } } |