sockets: use weak aliases instead of qemu-tool.c

qemu-tool.c has its own (largeish) set of dependencies.  Weak aliases
can be placed directly where people use them, and do not contribute
to increasing the dependencies of generic utility files.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
fdsets: use weak aliases instead of qemu-tool.c/qemu-user.c

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
iohandler: add weak alias in qemu-sockets.c, for qemu-ga

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-timer: make initialization functions idempotent

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: unify qemu_init_main_loop between QEMU and tools

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-timer: use weak aliases instead of qemu-tool.c

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
main-loop: use weak aliases instead of qemu-tool.c

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
janitor: move iovector functions out of cutils.c

This removes the dependency of cutils.c on iov.c, and lets us remove
iov.o from several builds.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
build: move cutils.o and qemu-timer-common.o to oslib-obj-y

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
build: do not include main loop in qemu-ga and vscclient

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

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.

The return value of event_notifier_set changes to the cleaner 0/-errno.
No caller is actually checking the return value.

Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: change qemu_aio_set_fd_handler to return void

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
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 both POSIX and Win32.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: introduce AioContext, move bottom halves there

Start introducing AioContext, which will let us remove globals from
aio.c/async.c, and introduce multiple I/O threads.

The bottom half functions now take an additional AioContext argument.
A bottom half is created with a specific AioContext that remains the
same throughout the lifetime.  qemu_bh_new is just a wrapper that
uses a global context.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: add I/O handlers to the AioContext interface

With this patch, I/O handlers (including event notifier handlers) can be
attached to a single AioContext.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: test node->deleted before calling io_flush

Otherwise, there could be a case where io_flush accesses freed
memory because it should not have been called.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: add non-blocking variant of aio_wait

This will be used when polling the GSource attached to an AioContext.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: prepare for introducing GSource-based dispatch

This adds a GPollFD to each AioHandler.  It will then be possible to
attach these GPollFDs to a GSource, and from there to the main loop.
aio_wait examines the GPollFDs and avoids calling select() if any
is set (similar to what it does if bottom halves are available).

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

The Win32 implementation will only accept EventNotifiers, thus a few
drivers are disabled under Windows.  EventNotifiers are a good match
for the GSource implementation, too, because the Win32 port of glib
allows to place their HANDLEs in a GPollFD.

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