pass bottom halves to aio.c

The next patches remove the process queue callback and replace it
with a bottom half.  However, in order to do this bottom halves must
be able to interrupt the select() loop in qemu_aio_wait.

In addition, we must not sleep until we first check the io_flush
callbacks, otherwise qemu_aio_wait() will find that nothing is ready
and sleep forever in select().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
posix-aio: merge posix_aio_process_queue and posix_aio_read

qemu_aio_process_queue is always followed by a select loop that calls
posix_aio_read.  There is no need for a separate process_queue callback.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: remove process_queue callback and qemu_aio_process_queue

Both unused after the previous patch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-io: use main_loop_wait

This will let timers run during aio_read and aio_write commands,
though not during synchronous commands.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
introduce qemu_iovec_init_copy

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
change is_write to a request type enum in BdrvTrackedRequest

We would like to use BdrvTrackedRequest for all kinds of request.  Even
though most code paths would not care about is_write, for debugging it
is useful to know the request type.  So, add values for all five types
and start replacing uses of is_write.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
add more fields to BdrvTrackedRequest

In order to pass a complete request to a different thread we will
need to store all information in a single struct.  We can reuse
BdrvTrackedRequest for this end.  Add missing fields, and move it
close to the declaration for the flags.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
replace more uses of is_write with type

Use type more pervasively.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pass BdrvTrackedRequest to bdrv_co_do_{read,write}v

Split initialization of a BdrvTrackedRequest from tracked_request_begin,
and push initialization up to the callers.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
move return code to BdrvTrackedRequest

This is needed to unify BdrvTrackedRequest with RwCo.  It will not really
be needed anymore after switching to threads.  We can revisit it later.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
push BdrvTrackedRequest to bdrv_aio_*

Replace BlockRequest with BdrvTrackedRequest.  This avoids repeated
unmarshaling/marshaling of arguments.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
unify RwCo and BdrvTrackedRequest

Similarly avoid adjacent unmarshaling/marshaling.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tweak BdrvCoIsAllocatedData

Make the struct more similar to BdrvTrackedRequest, and use
NOT_DONE to detect termination of the coroutine.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
change bdrv_is_allocated to use BdrvTrackedRequest

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pass BdrvTrackedRequest to bdrv_iolimits_intercept

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
change tracked_requests to TAILQ

We'll need to share the list entry between tracked_requests and
throttled_reqs.  Since throttled_reqs requires queue semantics,
use a TAILQ for tracked_requests too.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
change throttled_reqs to a QTAILQ

Remove the CoQueue, instead manage the queue manually.  There is a
small change in that bdrv_io_limits_disable will start only the
first pending request, since this one will in turn restart the
others at the end of bdrv_io_limits_intercept.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
add event_notifier_set

EventNotifier right now cannot be used as an inter-thread communication
primitive.  It only works if something else (the kernel) sets the eventfd.
Add a primitive to signal an EventNotifier that another thread is waiting
on.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
remove event_notifier_test

This is broken; since the eventfd is used in nonblocking mode there
is a race between reading and writing.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
add event_notifier_set_handler

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>