tools: split monitor-dummy.c, clean up qemu-tool.c

qemu-ga uses glib mostly, so it does not need a large part of the dummy
functions in qemu-tool.o (which are more related to the main loop and/or
the block layer).  Split the functions required by QAPI out into
monitor-dummy.c.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: move QEMUIOVector functions to iov.c

They do not really belong in cutils.c, and this way we can remove
iov.c from user-mode emulation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
build: move cutils.c/iov.c to oslib-obj-y and block-obj-y respectively

cutils.c and iov.c appeared in the Makefile in multiple spots.  Clean
this up by moving them respectively to oslib-obj-y and block-obj-y.
Notably, qemu-ga and user-mode emulation both need cutils.c but not iov.c.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-ga: do not include the QEMU main loop and dependencies

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
event_notifier: enable it 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.

Without CONFIG_EVENTFD, event_notifier_get_fd is only usable for the
"read" side of the notifier, for example to set a select() handler.

Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
event_notifier: add Win32 implementation

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: provide platform-independent API

This adds to aio.c a platform-independent API based on EventNotifiers, that
can be used by the portable thread pool.

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

The Win32 implementation only accepts EventNotifiers, thus a few
drivers are disabled under Windows.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: use event notifiers

Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
linux-aio: use event notifiers

Since linux-aio already uses an eventfd, converting it to use the
EventNotifier-based API simplifies the code even though it is not
meant to be portable.

Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-thread: add QemuSemaphore

The new thread pool will use semaphores instead of condition
variables, because QemuCond does not have qemu_cond_timedwait.
(I also like it more this way).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: add generic thread-pool facility

Add a generic thread-pool.  The code is roughly based on posix-aio-compat.c,
with some changes, especially the following:

- use QemuSemaphore instead of QemuCond;

- separate the state of the thread from the return code of the worker
function.  The return code is totally opaque for the thread pool;

- do not busy wait when doing cancellation.

A more generic threadpool (but still specific to I/O so that in the future
it can use special scheduling classes or PI mutexes) can have many uses:
it allows more flexibility in raw-posix.c and can more easily be extended
to Win32, and it will also be used to do an msync of the persistent bitmap.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: switch posix-aio-compat to threadpool

This is not meant for portability, but to remove code duplication.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw: merge posix-aio-compat.c into block/raw-posix.c

Making the qemu_paiocb specific to raw devices will let us access members
of the BDRVRawState arbitrarily.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-posix: rename raw-posix-aio.h, hide unavailable prototypes

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-win32: add emulated AIO support

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: support FALLOC_FL_PUNCH_HOLE trimming

Switch from the XFS-specific ioctl to the more generic
FALLOC_FL_PUNCH_HOLE.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
configure: do not look for xfsctl

We are not using it anymore.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw: support discard on block devices

Block devices use a ioctl instead of fallocate, so add a separate
implementation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: make discard asynchronous

This is possible now that we can use s->has_discard from the thread pool.

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