Make negotiation optional in QEMUMonitorProtocol

This is a preparation for qemu-ga-client which uses
QEMUMonitorProtocol class. The class tries to
negotiate capabilities on connect, however, qemu-ga
doesn't suppose it and fails.

This change makes the negotiation optional, though
it's still performed by default for compatibility.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Support settimeout in QEMUMonitorProtocol

This method is used in the following qemu-ga-client script
to implement non-blocking operations.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Add qemu-ga-client script

This is an easy-to-use QEMU guest agent client written in
Python. It simply provides commands to call guest agent
functions like ping, fsfreeze and shutdown. Additionally,
it provides extra useful commands, e.g, cat, ifconfig and
reboot, by using guet agent functions.

Examples:
  $ export QGA_CLIENT_ADDRESS=/tmp/qga.sock
  $ qemu-ga-client ping

  $ qemu-ga-client cat /etc/resolv.conf
  # Generated by NetworkManager
  nameserver 10.0.2.3

  $ qemu-ga-client fsfreeze status
  thawed
  $ qemu-ga-client fsfreeze freeze
  2 filesystems frozen

The script communicates with a guest agent by means of
qmp.QEMUMonitorProtocol. Every commands are called with
timeout (3 sec.) to avoid blocking. The script always
calls sync command prior to issuing an actual command
(except for ping which doesn't need sync).

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
qapi: do not protect enum values from namespace pollution

Enum values are always preceded by the uppercase name of the enum, so
they do not conflict with reserved words.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
qapi: add "unix" to the set of reserved words

It is #defined to 1.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
pci-assign: use monitor_handle_fd_param

There is no need to open-code the choice between a file descriptor
number or a named one.  Just use monitor_handle_fd_param, which
also takes care of printing the error message.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
monitor: add Error * argument to monitor_get_fd

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
qapi: convert add_client

Also fixes a few issues while there:

 1. The fd returned by monitor_get_fd() leaks in most error conditions
 2. monitor_get_fd() return value is not checked. Best case we get
    an error that is not correctly reported, worse case one of the
    functions using the fd (with value of -1) will explode
 3. A few error conditions aren't reported
 4. We now "use up" @fdname always.  Before, it was left alone for
    invalid @protocol

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Merge remote-tracking branches 'luiz/queue/qmp' and 'luiz/qmp/qapi-commands-conv/add-client/v4' into HEAD

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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qapi: add socket address types

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

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

This patch starts harmonizing unix_* and inet_* functions.

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

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.

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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hmp: add NBD server commands

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>