aio-wait: delegate polling of main AioContext if BQL not held
commit3c18a92dc4b55ca8cc37a755ed119f11c0f34099
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 Apr 2020 14:07:45 +0000 (7 10:07 -0400)
committerStefan Hajnoczi <stefanha@redhat.com>
Thu, 9 Apr 2020 15:16:28 +0000 (9 16:16 +0100)
tree1153ea1812c170bcc50e72820bae2d585827c0a0
parent636b836d5f4e36ceebb788e2e0d4724f7f9406e1
aio-wait: delegate polling of main AioContext if BQL not held

Any thread that is not a iothread returns NULL for qemu_get_current_aio_context().
As a result, it would also return true for
in_aio_context_home_thread(qemu_get_aio_context()), causing
AIO_WAIT_WHILE to invoke aio_poll() directly.  This is incorrect
if the BQL is not held, because aio_poll() does not expect to
run concurrently from multiple threads, and it can actually
happen when savevm writes to the vmstate file from the
migration thread.

Therefore, restrict in_aio_context_home_thread to return true
for the main AioContext only if the BQL is held.

The function is moved to aio-wait.h because it is mostly used
there and to avoid a circular reference between main-loop.h
and block/aio.h.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200407140746.8041-5-pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
include/block/aio-wait.h
include/block/aio.h