qemu-e2k/include/block
Paolo Bonzini 5f50be9b58 async: the main AioContext is only "current" if under the BQL
If we want to wake up a coroutine from a worker thread, aio_co_wake()
currently does not work.  In that scenario, aio_co_wake() calls
aio_co_enter(), but there is no current AioContext and therefore
qemu_get_current_aio_context() returns the main thread.  aio_co_wake()
then attempts to call aio_context_acquire() instead of going through
aio_co_schedule().

The default case of qemu_get_current_aio_context() was added to cover
synchronous I/O started from the vCPU thread, but the main and vCPU
threads are quite different.  The main thread is an I/O thread itself,
only running a more complicated event loop; the vCPU thread instead
is essentially a worker thread that occasionally calls
qemu_mutex_lock_iothread().  It is only in those critical sections
that it acts as if it were the home thread of the main AioContext.

Therefore, this patch detaches qemu_get_current_aio_context() from
iothreads, which is a useless complication.  The AioContext pointer
is stored directly in the thread-local variable, including for the
main loop.  Worker threads (including vCPU threads) optionally behave
as temporary home threads if they have taken the big QEMU lock,
but if that is not the case they will always schedule coroutines
on remote threads via aio_co_schedule().

With this change, the stub qemu_mutex_iothread_locked() must be changed
from true to false.  The previous value of true was needed because the
main thread did not have an AioContext in the thread-local variable,
but now it does have one.

Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210609122234.544153-1-pbonzini@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Tested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[eblake: tweak commit message per Vladimir's review]
Signed-off-by: Eric Blake <eblake@redhat.com>
2021-06-18 10:59:52 -05:00
..
accounting.h
aio_task.h
aio-wait.h
aio.h async: the main AioContext is only "current" if under the BQL 2021-06-18 10:59:52 -05:00
block_backup.h
block_int.h block: drop BlockBackendRootState::read_only 2021-06-02 14:23:20 +02:00
block-copy.h block/block-copy: drop unused argument of block_copy() 2021-01-26 14:36:37 +01:00
block-hmp-cmds.h
block.h block/vvfat: child_vvfat_qcow: add .get_parent_aio_context, fix crash 2021-06-02 14:23:20 +02:00
blockjob_int.h blockjob: add set_speed to BlockJobDriver 2021-01-26 14:36:37 +01:00
blockjob.h blockjob: return status from block_job_set_speed() 2021-03-08 15:14:15 -06:00
dirty-bitmap.h block: remove dirty bitmaps 'status' field 2021-03-18 09:22:55 +00:00
export.h
fuse.h fuse: Allow exporting BDSs via FUSE 2020-12-11 17:52:39 +01:00
nbd.h nbd: make nbd_read* return -EIO on error 2021-02-03 08:17:12 -06:00
nvme.h hw/block/nvme: align with existing style 2021-05-17 09:15:13 +02:00
qapi.h
qdict.h vl: plumb keyval-based options into -readconfig 2021-06-04 13:50:04 +02:00
raw-aio.h
replication.h replication: move include out of root directory 2021-05-26 14:49:46 +02:00
snapshot.h block: rename and alter bdrv_all_find_snapshot semantics 2021-02-08 11:19:51 +00:00
thread-pool.h
throttle-groups.h block/throttle-groups: throttle_group_co_io_limits_intercept(): 64bit bytes 2021-02-03 08:14:00 -06:00
write-threshold.h write-threshold: deal with includes 2021-05-14 16:14:10 +02:00