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>
enable event_notifier to use pipes

This takes the eventfd emulation code from the main loop.
When the EventNotifier is used for the main loop too, we
need this compatibility code.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
add Win32 implementation of event notifiers

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
use event_notifier for linux-aio

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
let other threads interrupt qemu_aio_wait with a bottom half

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