Commit graph

22610 commits

Author SHA1 Message Date
Paolo Bonzini 10fb6e0682 raw-posix: move linux-aio.c to block/
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-31 10:38:13 +01:00
Paolo Bonzini fc4edb84bf raw-win32: add emulated AIO support
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-31 10:38:13 +01:00
Paolo Bonzini 9f8540ecef raw-posix: rename raw-posix-aio.h, hide unavailable prototypes
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-31 10:38:12 +01:00
Paolo Bonzini de81a16936 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>
2012-10-31 10:38:12 +01:00
Paolo Bonzini 47e6b251a5 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>
2012-10-31 10:38:12 +01:00
Paolo Bonzini 19d092cf9b threadpool: do not take lock in event_notifier_ready
The ordering is:

    worker thread                         consumer thread
    -------------------------------------------------------------------
    write ret                             event_notifier_test_and_clear
    wmb()                                 read state
    write state                           rmb()
    event_notifier_set                    read ret

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-31 10:38:01 +01:00
Paolo Bonzini d354c7eccf 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>
2012-10-31 10:37:48 +01:00
Paolo Bonzini 38b14db34e 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>
2012-10-31 09:45:47 +01:00
Paolo Bonzini c90caf25e2 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>
2012-10-30 09:30:54 +01:00
Paolo Bonzini 22bfa75eaf aio: clean up now-unused functions
Some cleanups can now be made, now that the main loop does not anymore need
hooks into the bottom half code.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:54 +01:00
Paolo Bonzini 4c8d0d2767 main-loop: use aio_notify for qemu_notify_event
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:54 +01:00
Paolo Bonzini 82cbbdc6a0 main-loop: use GSource to poll AIO file descriptors
This lets us remove the hooks for the main loop in async.c.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:53 +01:00
Paolo Bonzini 7ed2b24ce1 aio: call aio_notify after setting I/O handlers
In the current code, this is done by qemu_set_fd_handler2, which is
called by qemu_aio_set_fd_handler.  We need to keep the same behavior
even after removing the call to qemu_set_fd_handler2.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:53 +01:00
Paolo Bonzini 2f4dc3c1b2 aio: add aio_notify
With this change async.c does not rely anymore on any service from
main-loop.c, i.e. it is completely self-contained.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:53 +01:00
Paolo Bonzini e3713e001f aio: make AioContexts GSources
This lets AioContexts be used (optionally) with a glib main loop.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:53 +01:00
Paolo Bonzini f42b22077b 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini cd9ba1ebcf 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini 7c0628b20e 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini 4231c88d27 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini a915f4bc97 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini f627aab1cc 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>
2012-10-30 09:30:53 +01:00
Paolo Bonzini 9958c351ee 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>
2012-10-30 09:30:52 +01:00
Paolo Bonzini b078dc3cfe 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>
2012-10-30 09:30:52 +01:00
Paolo Bonzini 1c53786fbd vl: init main loop earlier
Otherwise, chardevs will not be able to create a bottom half as soon
as that will require an AioContext.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:52 +01:00
Paolo Bonzini d0cc2fbfa6 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>
2012-10-30 09:30:52 +01:00
Paolo Bonzini fc97a652de event_notifier: add Win32 implementation
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:52 +01:00
Paolo Bonzini 136594f19a build: do not include main loop where it is not actually used
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:52 +01:00
Paolo Bonzini 63186e56c8 build: opts-visitor is not really part of QAPI
It is only used by QEMU itself, do not build it into the tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:30:52 +01:00
Paolo Bonzini 3f4cdf1511 qemu-tool: do not depend on qemu-timer.c
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini 172061a0a0 main-loop: unify qemu_init_main_loop between QEMU and tools
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini 744ca8e375 qemu-timer: make initialization functions idempotent
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini dbb5f3802e win32: add weak version of qemu_fd_register
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini 462016d2da iohandler: add weak alias in qemu-sockets.c, for qemu-ga
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini 0100fbbe73 fdsets: use weak aliases instead of qemu-tool.c/qemu-user.c
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:44 +01:00
Paolo Bonzini d249e1fc4f 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>
2012-10-30 09:18:43 +01:00
Paolo Bonzini 67d223be90 compiler: use weak aliases to provide default definitions
This is simpler and more portable.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:43 +01:00
Paolo Bonzini f3192e8fb2 build: move cutils.o and qemu-timer-common.o to oslib-obj-y
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-30 09:18:43 +01:00
Paolo Bonzini 0191253cea 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>
2012-10-30 09:18:42 +01:00
Luiz Capitulino 8473f37739 win32: fix broken build due to missing QEMU_MADV_HUGEPAGE
Commit ad0b5321f1 forgot to add
QEMU_MADV_HUGEPAGE macros for when CONFIG_MADVISE is not defined.
This broke the build for Windows. Fix it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-10-24 15:01:45 -05:00
Anthony Liguori c6b8141b84 Merge remote-tracking branch 'bonzini/nbd-next' into staging
* bonzini/nbd-next: (30 commits)
  qmp: add NBD server commands
  block: add close notifiers
  block: prepare code for adding block notifiers
  qemu-sockets: add socket_listen, socket_connect, socket_parse
  tests: do not include tools-obj-y Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  qemu-sockets: return InetSocketAddress from inet_parse
  qapi: add socket address types
  build: add QAPI files to the tools
  vnc: drop QERR_VNC_SERVER_FAILED
  qemu-sockets: add error propagation to Unix socket functions
  qemu-sockets: add error propagation to inet_parse
  qemu-sockets: add error propagation to inet_dgram_opts
  qemu-sockets: add error propagation to inet_connect_addr
  qemu-sockets: include strerror or gai_strerror output in error messages
  vnc: add error propagation to vnc_display_open
  vnc: reorganize code for reverse mode
  vnc: introduce a single label for error returns
  vnc: avoid Yoda conditionals
  qemu-ga: ask and print error information from qemu-sockets
  nbd: ask and print error information from qemu-sockets
  ...
2012-10-24 09:39:49 -05:00
Paolo Bonzini 6dd844db4a qmp: add NBD server commands
Adding an NBD server inside QEMU is trivial, since all the logic is
in nbd.c and can be shared easily between qemu-nbd and QEMU itself.
The main difference is that qemu-nbd serves a single unnamed export,
while QEMU serves named exports.

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 22:39:33 +02:00
Paolo Bonzini d7d512f609 block: add close notifiers
The first user of close notifiers will be the embedded NBD server.
It would be possible to use them to do some of the ad hoc processing
(e.g. for block jobs and I/O limits) that is currently done by
bdrv_close.

Acked-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 22:39:32 +02:00
Paolo Bonzini 3cbc002c34 block: prepare code for adding block notifiers
There is no reason in principle to skip job cancellation and draining
of pending I/O when there is no medium in the disk.  Do these unconditionally,
which also prepares the code for the next patch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 22:39:32 +02:00
Paolo Bonzini 101f9cbc2b qemu-sockets: add socket_listen, socket_connect, socket_parse
These are QAPI-friendly versions of the qemu-sockets functions.  They
support IP sockets, Unix sockets, and named file descriptors, using a
QAPI union to dispatch to the correct function.

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 22:39:16 +02:00
Paolo Bonzini 0ef3dd6c2d tests: do not include tools-obj-y
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 22:38:41 +02:00
Paolo Bonzini 879e45c72d qemu-sockets: return InetSocketAddress from inet_parse
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 19:05:41 +02:00
Paolo Bonzini 5be8c759f0 qapi: add socket address types
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 19:05:41 +02:00
Paolo Bonzini 69758c22e0 build: add QAPI files to the tools
We need them because qemu-sockets will soon be using SocketAddress.

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 19:05:39 +02:00
Avi Kivity a8170e5e97 Rename target_phys_addr_t to hwaddr
target_phys_addr_t is unwieldly, violates the C standard (_t suffixes are
reserved) and its purpose doesn't match the name (most target_phys_addr_t
addresses are not target specific).  Replace it with a finger-friendly,
standards conformant hwaddr.

Outstanding patchsets can be fixed up with the command

  git rebase -i --exec 'find -name "*.[ch]"
                        | xargs s/target_phys_addr_t/hwaddr/g' origin

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-10-23 08:58:25 -05:00
Paolo Bonzini 3f8b11bc7d vnc: drop QERR_VNC_SERVER_FAILED
We now always return "nice" error messages in errp when we goto fail.
Drop the default error message.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-10-23 13:54:57 +02:00