migration (outgoing): add error propagation for all protocols

Error propagation is already there for socket backends, even though
it is (and remains) incomplete because no Error is passed to the
NonBlockingConnectHandler.  Add it to other protocols, simplifying
code that tests for errors that will never happen.

With all protocols understanding Error, the code can be simplified
further by removing the return value.

Before:

    (qemu) migrate fd:ffff
    migrate: An undefined error has occurred
    (qemu) info migrate
    (qemu)

After:

    (qemu) migrate fd:ffff
    migrate: File descriptor named 'ffff' has not been found
    (qemu) info migrate
    capabilities: xbzrle: off
    Migration status: failed
    total time: 0 milliseconds

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration (incoming): add error propagation to fd and exec protocols

And remove the superfluous integer return value.

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-char: ask and print error information from qemu-sockets

Before:

    $ qemu-system-x86_64 -monitor tcp:localhost:6000
    (starts despite error)

    $ qemu-system-x86_64 -monitor tcp:foo.bar:12345
    getaddrinfo(foo.bar,12345): Name or service not known
    chardev: opening backend "socket" failed

    $ qemu-system-x86_64 -monitor tcp:localhost:443,server=on
    inet_listen_opts: bind(ipv4,127.0.0.1,443): Permission denied
    inet_listen_opts: FAILED
    chardev: opening backend "socket" failed

After:

    $ x86_64-softmmu/qemu-system-x86_64 -monitor tcp:localhost:6000
    x86_64-softmmu/qemu-system-x86_64: -monitor tcp:localhost:6000: Failed to connect to socket: Connection refused
    chardev: opening backend "socket" failed

    $ x86_64-softmmu/qemu-system-x86_64 -monitor tcp:foo.bar:12345
    qemu-system-x86_64: -monitor tcp:foo.bar:12345: address resolution failed for foo.bar:12345: Name or service not known
    chardev: opening backend "socket" failed

    $ x86_64-softmmu/qemu-system-x86_64 -monitor tcp:localhost:443,server=on
    qemu-system-x86_64: -monitor tcp:localhost:443,server=on: Failed to bind socket: Permission denied
    chardev: opening backend "socket" failed

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nbd: ask and print error information from qemu-sockets

Before:

    $ qemu-system-x86_64 nbd:localhost:12345
    inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused
    qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused

After:

    $ x86_64-softmmu/qemu-system-x86_64 nbd:localhost:12345
    qemu-system-x86_64: Failed to connect to socket: Connection refused
    qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-ga: ask and print error information from qemu-sockets

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
vnc: add error propagation to vnc_display_open

Before:

    $ qemu-system-x86_64 -vnc foo.bar:12345
    getaddrinfo(foo.bar,18245): Name or service not known
    Failed to start VNC server on `foo.bar:12345'

    $ qemu-system-x86_64 -vnc localhost:12345,reverse=on
    inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused
    Failed to start VNC server on `localhost:12345,reverse=on'

After:

    $ x86_64-softmmu/qemu-system-x86_64 -vnc foo.bar:12345
    Failed to start VNC server on `foo.bar:12345': address resolution failed for foo.bar:18245: Name or service not known

    $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:12345,reverse=on
    Failed to start VNC server on `localhost:12345,reverse=on': Failed to connect to socket: Connection refused

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: include strerror or gai_strerror output in error messages

Among others, before:

    $ qemu-system-x86_64 -chardev socket,port=12345,id=char
    inet_connect: host and/or port not specified
    chardev: opening backend "socket" failed

After:

    $ x86_64-softmmu/qemu-system-x86_64 -chardev socket,port=12345,id=char
    qemu-system-x86_64: -chardev socket,port=12345,id=char: host and/or port not specified
    chardev: opening backend "socket" failed

perror and fprintf can be removed because all clients can now
consume Errors properly.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: add error propagation to inet_connect_addr

perror and fprintf can be removed because all clients can now consume
Errors properly.  However, we need to change the non-blocking connect
handlers to take an Error, in order to improve error handling for
migration with the TCP protocol.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: add error propagation to inet_dgram_opts

Before:

    $ qemu-system-x86_64 -monitor udp:localhost:631@localhost:631
    inet_dgram_opts: bind(ipv4,127.0.0.1,631): OK
    inet_dgram_opts failed
    chardev: opening backend "udp" failed

After:

    $ x86_64-softmmu/qemu-system-x86_64 -monitor udp:localhost:631@localhost:631
    qemu-system-x86_64: -monitor udp:localhost:631@localhost:631: Failed to bind socket: Address already in use
    chardev: opening backend "udp" failed

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: add error propagation to inet_parse

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: add error propagation to Unix socket functions

Before:

    $ qemu-system-x86_64 -monitor unix:/vvv,server=off
    connect(unix:/vvv): No such file or directory
    chardev: opening backend "socket" failed

After:

    $ x86_64-softmmu/qemu-system-x86_64 -monitor unix:/vvv,server=off
    qemu-system-x86_64: -monitor unix:/vvv,server=off: Failed to connect to socket: No such file or directory
    chardev: opening backend "socket" failed

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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>
virtfs-proxy-helper: check return code of setfsgid/setfsuid

Fixes the following error with glibc 2.16 on Fedora 18:

virtfs-proxy-helper.c: In function ‘setfsugid’:
virtfs-proxy-helper.c:293:13: error: ignoring return value of ‘setfsgid’, declared with attribute warn_unused_result [-Werror=unused-result]
virtfs-proxy-helper.c:294:13: error: ignoring return value of ‘setfsuid’, declared with attribute warn_unused_result [-Werror=unused-result]
cc1: all warnings being treated as errors

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