We still have handlers which will call monitor print functions
in several places. Usually to report errors.
If they do this when we are in control mode, we will be emitting
garbage to our clients.
To avoid this problem, this commit adds a way to disable those
functions. If any of them is called when in control mode, we will
emit a generic error.
Although this is far from the perfect solution, it guarantees
that only JSON is sent to Clients.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Debug, shutdown, reset, powerdown and stop are all basic events,
as they are very simple they can be added in the same commit.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Asynchronous events are generated with a call to
monitor_protocol_event().
This function builds the right data-type and emit the event
right away. The emitted data is always a JSON object and its
format is as follows:
{ "event": json-string,
"timestamp": { "seconds": json-number, "microseconds": json-number },
"data": json-value }
This design is based on ideas by Amit Shah <amit.shah@redhat.com>.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The 'info' command makes sense for the user protocol, but for QMP
it doesn't, as its return data is not well defined. That is, it
can return anything.
To fix this Avi proposes having 'query-' commands when in protocol
mode. For example, 'info balloon' would become 'query-balloon'.
The right way of supporting this would probably be to move all
info handlers to qemu-monitor.hx, add a flags field to mon_cmd_t
to identify them and then modify do_info() to do its search based
on that flag.
Unfortunately, this would require a big change in the Monitor.
To make things simpler for now, this commit takes a different
approach: a check for commands starting with "query-" is added to
toplevel QMP code, if it's true we setup things so that do_info()
is called with the appropriate arguments.
This is a hack, but is a temporary one and guarantees that query-
commands will work from the first day.
Also note that 'info' is not allowed in protocol mode.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The JSON stream parser is used to do QMP input. When there
are enough characters to be parsed it calls Monitor's
handle_qmp_command() function to handle the input.
This function's job is to check if the input is correct and
call the appropriate handler. In other words, it does for QMP
what handle_user_command() does for the user protocol.
This means that handle_qmp_command() also has to parse the
(ugly) "args_type" format to able to get the arguments names
and types expected by the handler.
The format to input commands in QMP is as follows:
{ "execute": json-string,
"id": json-value, "arguments": json-object }
Please, note that this commit also adds "id" support.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit adds specific QMP checks to do_info(), so that
it behaves as expected in QMP mode.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
In the new Monitor output is always performed by only two
functions: do_info() and monitor_call_handler().
To support QMP output, we modify those functions to check if we
are in control mode. If so, we call monitor_protocol_emitter()
to emit QMP output, otherwise we do regular output.
QMP has two types of responses to issued commands: success and
error. The outputed data is always a JSON object.
Success responses have the following format:
{ "return": json-value, "id": json-value }
Error responses have the following format:
{ "error": { "class": json-string,
"desc": json-string,
"data": json-value } "id": json-value }
Please, note that the "id" key is part of the input code, and
thus is not added in this commit.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit adds initial QMP support in QEMU. It's important
to notice that most QMP code will be part of the Monitor.
Input will be read by monitor_control_read(). Currently it
does nothing but next patches will add proper input support.
The function monitor_json_emitter(), as its name implies, is
used by the Monitor to emit JSON output. In this commit it's
used by monitor_control_event() to print our greeting message.
Finally, control mode support is also added to monitor_init(),
allowing QMP to be really enabled.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
List QMP available commands. Only valid in control mode, where
has to be used as 'query-commands.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
As this series will add a new kind of Monitor command, it's better
to rename monitor_handle_command() to what it really is:
handle_user_command().
This will avoid confusion.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit moves the loop which searches for the command
entry corresponding to a command name to its own function.
It will be used by QMP code as well.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit moves the code which calls Monitor handlers to
its own function, as it will be used by QMP code as well.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit adds a flag called 'control' to the '-monitor'
command-line option. This flag enables control mode.
The syntax is:
qemu [...] -monitor control,<device>
Where <device> is a chardev (excluding 'vc', for obvious reasons).
For example:
$ qemu [...] -monitor control,tcp:localhost:4444,server
Will run QEMU in control mode, waiting for a client TCP connection
on localhost port 4444.
NOTE: I've tried using QemuOpts for this, but turns out that it
will try to parse the device part, which should be untouched.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This flag will be set when Monitor enters "control mode", in
which the output will be defined by the QEMU Monitor Protocol.
This also introduces a macro to check if the flag is set.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit adds QError support in the Monitor.
A QError member is added to the Monitor struct. This new member
stores error information and is also used to check if an error
has occurred when the called handler returns.
Additionally, a new macro called qemu_error_new() is introduced.
It builds on top of the QemuErrorSink API and should be used in
place of qemu_error().
When all conversion to qemu_error_new() is done, qemu_error() can
be turned private.
Basically, Monitor's error flow is something like this:
1. An error occurs in the handler, it calls qemu_error_new()
2. qemu_error_new() builds a new QError object and stores it in
the Monitor struct
3. The handler returns
4. Top level Monitor code checks the Monitor struct and calls
qerror_print() to print the error
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This patch adds the option to activate non-shared storage migration from the
monitor.
The migration command is as follows:
(qemu) migrate -d tcp:0:4444 # for ordinary live migration
(qemu) migrate -d -b tcp:0:4444 # for live migration with complete storage copy
(qemu) migrate -d -i tcp:0:4444 # for live migration with incremental storage copy, storage is cow based.
Changes from v4:
- Minor coding style issues.
Signed-off-by: Liran Schour <lirans@il.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
We have code for a quite a few block formats. While I trust that all
of these formats are useful at least for some people in some
circumstances, some of them are of a kind that friends don't let
friends use in production.
This patch provides an optional block format whitelist, default off.
If a whitelist is configured with --block-drv-whitelist, QEMU proper
can use only whitelisted formats. Other programs, like qemu-img, are
not affected.
Drivers for formats off the whitelist still participate in format
probing, to ensure all programs probe exactly the same. Without that,
QEMU proper would be prone to treat images with a format off the
whitelist as raw when the image's format is probed.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Note that errors are not being converted yet.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Note that errors are not being converted yet.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Note that errors are not being converted yet.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Note that errors are not being converted yet.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Note that errors are not being converted yet.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The char event RESET is emitted when a char device is opened.
Give it a better name.
Patchworks-ID: 35287
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Each CPU information is stored in a QDict and the returned
QObject is a QList of all CPUs.
The QDict contains the following information:
- "CPU": cpu index
- "current": "yes" or "no"
- "pc": current PC
- "halted": "yes" or "no"
The user output in the Monitor should not change and the
future monitor protocol is expected to emit something like:
[ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" },
{ "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ]
which corresponds to the following user output:
* CPU #0: pc=0x00000000fffffff0
CPU #1: pc=0x00000000fffffff0 (halted)
Patchworks-ID: 35352
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
On success return a QInt with the balloon's value.
This also introduces monitor_print_balloon() to print the
balloon information in the user protocol.
Please, note that errors are not being converted yet.
Patchworks-ID: 35351
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The returned data is always a QString.
Also introduces monitor_print_qobject(), which can be used as
a standard way to print QObjects in the user protocol format.
Patchworks-ID: 35350
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
It is important to note that it never fails, as big refactoring
of the virtio code would be needed to get the proper error code.
Patchworks-ID: 35349
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Appropriate error handling support will be needed to have
encrypted images working under the future machine protocol,
but this initial conversion will work with the current
user protocol.
Patchworks-ID: 35348
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
do_info() is special, its job is to call 'info handlers'.
This is similar to what monitor_handle_command() does,
therefore do_info() also has to distinguish among new and
old style info handlers.
This commit converts do_info() to the new QObject style and
makes the appropriate changes so that it can handle both
info handlers styles.
In the future, when all handlers are converted to QObject's
style, it will be possible to share more code with
monitor_handle_command().
This commit also introduces a new function called
monitor_user_noop(), it should be used by handlers which do
not have data to print.
This is the case of do_info().
Patchworks-ID: 35341
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit changes monitor_handle_command() to support old style
_and_ new style handlers.
New style handlers are protocol independent, they return their
data to the Monitor, which in turn decides how to print them
(ie. user protocol vs. machine protocol).
Converted handlers will use the 'user_print' member of 'mon_cmd_t'
to define its user protocol function, which will be called to print
data in the user protocol format.
Handlers which don't have 'user_print' defined are not converted
and are handled as usual.
Patchworks-ID: 35340
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This new struct member will store a pointer to a function that
should be used to output data in the user protocol format.
It will also serve as a flag to say if a given handler has already
been converted to the new QObject style.
Patchworks-ID: 35339
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commits adds a new union member to mon_cmd_t for command
handlers and convert monitor_handle_command() and qemu-monitor.hx
to use it.
This improves type safety.
Patchworks-ID: 35337
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit adds a union to mon_cmd_t for info handlers and
converts do_info() and info_cmds[] array to use it.
This improves type safety.
Next commit will convert command handlers.
Patchworks-ID: 35336
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This patch adds infrastructure to maintain memory regions which must be
restored on reset. That includes roms (vga bios and option roms on pc),
but is also used when loading linux kernels directly. Features:
- loading files is supported.
- passing blobs is supported.
- target address range is supported (for optionrom area).
- fixed target memory address is supported (linux kernel).
New in v2:
- writes to ROM are done only at initial boot.
- also handle aout and uimage loaders.
- drop unused fread_targphys() function.
The final memory layout is created once all memory regions are
registered. The option roms get addresses assigned and the
registered regions are checked against overlaps. Finally all data
is copyed to the guest memory.
Advantages:
(1) Filling memory on initial boot and on reset takes the same
code path, making reset more robust.
(2) The need to keep track of the option rom load address is gone.
(3) Due to (2) option roms can be loaded outside pc_init(). This
allows to move the pxe rom loading into the nic drivers for
example.
Additional bonus: There is a 'info roms' monitor command now.
The patch also switches over pc.c and removes the
option_rom_setup_reset() and load_option_rom() functions.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
In the very least, a change like this requires discussion on the list.
The naming convention is goofy and it causes a massive merge problem. Something
like this _must_ be presented on the list first so people can provide input
and cope with it.
This reverts commit 99a0949b72.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The CPU state parameter is not used, remove it and adjust callers. Now we
can compile ioport.c once for all targets.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Problem: Our file sys-queue.h is a copy of the BSD file, but there are
some additions and it's not entirely compatible. Because of that, there have
been conflicts with system headers on BSD systems. Some hacks have been
introduced in the commits 15cc923584,
f40d753718,
96555a96d7 and
3990d09adf but the fixes were fragile.
Solution: Avoid the conflict entirely by renaming the functions and the
file. Revert the previous hacks.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
make the mux driver send mux_in and mux_out events when switching
focus while hooking up more handlers.
stop using CharDriverState->focus in monitor.c, track state using
the mux events instead. This also removes the implicit assumtion
that a muxed monitor allways has mux channel 0.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
The 'i' argument type is for 32-bit only and most handlers
will use an 'int' to store its value.
It's better to fail gracefully when the user enters a value
greater than 32-bit than to get subtle casting bugs.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>