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>
qapi: add socket address types

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: return IPSocketAddress from inet_parse

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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>
block: add close notifiers

The first user of close notifiers will be the embedded NBD server.
It is 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>
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>
hmp: add NBD server commands

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hmp: rename MigrationStatus to MigrationStatusData

The name MigrationStatus will be taken by an enum.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: use enum for MigrationInfo.status

libvirt is actually using it as an enum, make it clear that we cannot
change it to free-form.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: add Error information to query-migrate

Save the error from TCP migration.  Doesn't work yet for connection errors
however, because the connect handler doesn't get an Error *.

Before:

    (qemu) migrate tcp:foo.bar:12345
    getaddrinfo(foo.bar,12345): Name or service not known
    migrate: Failed to create socket
    (qemu) info migrate
    capabilities: xbzrle: off
    Migration status: failed
    total time: 0 milliseconds

After:

    (qemu) migrate tcp:foo.bar:12345
    migrate: address resolution failed for foo.bar:12345: Name or service not known
    (qemu) info migrate
    capabilities: xbzrle: off
    Migration status: failed (address resolution failed for foo.bar:12345: Name or service not known)
    total time: 0 milliseconds

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: preserve errno value in qemu_fopen and qemu_fdopen

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qapi: use error_set_errno for QERR_OPEN_FILE_FAILED

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
opts-visitor: move QemuOpts processing to opts_visitor_new

Right now, QemuOpts are not processed until the first start_struct
call.  This patch lets clients extract information from the visitor
even outside a struct.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-char: add QAPI types

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-char: get socket options via the OptsVisitor

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: convert inet_listen_opts and inet_connect_opts to QAPI types

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: convert unix_listen_opts and unix_connect_opts to QAPI types

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: convert inet_dgram_opts to QAPI types

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: remove dummy_opts

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9p-synth: fix read-side critical sections

The read-side critical sections in 9p-synth currently only include the
navigation of the list.  This is incorrect; it works for two reasons,
first obviously because rcu_read_lock/unlock are still no-ops; second,
because elements of the list are never deleted from the list (only added).
In fact, only adding items is the reason why rcu_read_lock/unlock can
be left as no-ops.

If items were deleted, they could be reclaimed as soon as the read-side
critical section ends.  So, the read-side critical section must include
all _usage_ of the node we got from the list too.

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