sim-card
/
qemu
Archived
10
0
Fork 0
Commit Graph

366 Commits

Author SHA1 Message Date
Markus Armbruster 6e4f984cb9 error: Simplify error sink setup
qemu_error_sink can either point to a monitor or a file.  In practice,
it always points to the current monitor if we have one, else to
stderr.  Simply route errors to the current monitor or else to stderr,
and remove qemu_error_sink along with the functions to control it.

Actually, the old code switches the sink slightly later, in
handle_user_command() and handle_qmp_command(), than it gets switched
now, implicitly, by setting the current monitor in monitor_read() and
monitor_control_read().  Likewise, it switches back slightly earlier
(same places).  Doesn't make a difference, because there are no calls
of qemu_error() in between.
2010-03-16 16:55:05 +01:00
Markus Armbruster b4a51f7f5d error: Move qemu_error() & friends from monitor.c to own file
They're about reporting errors, not about the monitor.
2010-03-16 16:55:05 +01:00
Markus Armbruster d6f468337a monitor: Factor monitor_set_error() out of qemu_error_internal()
This separates the monitor part from the QError part.
2010-03-16 16:55:05 +01:00
Markus Armbruster 8631b6084a monitor: Separate "default monitor" and "current monitor" cleanly
Commits 376253ec..731b0364 introduced global variable cur_mon, which
points to the "default monitor" (if any), except during execution of
monitor_read() or monitor_control_read() it points to the monitor from
which we're reading instead (the "current monitor").  Monitor command
handlers run within monitor_read() or monitor_control_read().

Default monitor and current monitor are really separate things, and
squashing them together is confusing and error-prone.

For instance, usb_host_scan() can run both in "info usbhost" and
periodically via usb_host_auto_check().  It prints to cur_mon, which
is what we want in the former case: the monitor executing "info
usbhost".  But since that's the default monitor in the latter case, it
periodically spams the default monitor there.

A few places use cur_mon to log stuff to the default monitor.  If we
ever log something while cur_mon points to current monitor instead of
default monitor, the log temporarily "jumps" to another monitor.
Whether that can or cannot happen isn't always obvious.

Maybe logging to the default monitor (which may not even exist) is a
bad idea, and we should log to stderr or a logfile instead.  But
that's outside the scope of this commit.

Change cur_mon to point to the current monitor.  Create new
default_mon to point to the default monitor.  Update users of cur_mon
accordingly.

This fixes the periodical spamming of the default monitor by
usb_host_scan().  It also stops "log jumping", should that problem
exist.
2010-03-16 16:55:05 +01:00
Markus Armbruster 03cd4655cb savevm: Fix -loadvm to report errors to stderr, not the monitor
A monitor may not even exist.

Change load_vmstate() to use qemu_error() instead of monitor_printf().
Parameter mon is now unused, remove it.
2010-03-16 16:55:05 +01:00
Luiz Capitulino 9eedeb3b88 QMP: Introduce WATCHDOG event
It's emitted whenever the watchdog device's timer expires. The action
taken is provided in the 'data' member.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-09 08:47:27 -06:00
Luiz Capitulino 80cd34787f QMP: Introduce RTC_CHANGE event
Emitted whenever the RTC time changes.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-08 11:30:09 -06:00
Luiz Capitulino 51a3bd71b3 QMP: Drop DEBUG event
This event has been introduced in the first round of QMP commits,
turns out that it's based on the usage of the EXCP_DEBUG macro,
which has discussable semantics when exposed through QMP.

As libvirt doesn't use this, let's just drop it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-08 11:30:08 -06:00
Adam Litke 93d67ee69d Fix hanging user monitor when using balloon command
This patch application failed.  My patch adds a cb() call in
do_balloon(), but the change in git has added the cb() call to
do_info_balloon().  That is causing qemu segfaults.  Applying the
following should correct the damage.  Thanks.

Fix for commit: 5c366a8a3d

The cb() call is needed in do_balloon(), not do_info_balloon().

Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-08 11:29:17 -06:00
Gleb Natapov c64484a543 fix 'i' format handling in memory dump
It was broken by 09b9418c6d. (!env && !is_physical) != (!is_physical)
when env is true.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-23 13:23:29 -06:00
Adam Litke 5c366a8a3d Fix hanging user monitor when using balloon command
Arghh... Adding missing S-O-B

Hi Anthony.  I wonder if there was a problem when importing my async
command handler patchset.  Since the 'balloon' command completes
immediately, it must call the completion callback before returning.
That call was missing but is added by the patch below.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:32:15 -06:00
Luiz Capitulino 068b332a65 Monitor: Report more than one error in handlers
Handlers can generate only one error in a call, we let the
programmer know if they brake this rule and clients will only
get the first generated error.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:18 -06:00
Luiz Capitulino 10e4f606ec Monitor: Debug stray prints the right way
QObject Monitor handlers should not call any Monitor print
function: they should only build objects, printing is done
by common code.

Current QMP code will ignore such calls, as we can't send
garbage to clients, additionally it will also emit an
undefined error on the assumption that print calls usually
report errors.

However, the right way to deal with this is to rely on a
return code. This has been fixed by other commit already.

Now, this commit drops the error from monitor_vprintf() and
adds a better debugging mechanism for those 'stray' prints:
we count them if debug is enabled and let the developer know
if a QObject handler is trying to print anything.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:18 -06:00
Luiz Capitulino bb89c2e901 Monitor: Audit handler return
This commit verifies the following two rules specified by
Markus Armbruster:

1. If the handler returns failure, it must have passed an error.

   If it didn't, it's broken. Report an internal error to the client,
   and report the bug to the programmer.

2. If the handler returns success, it must not have passed an error.

   If it did, it's broken. Report the error to the client, and report
   the bug to the programmer.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:18 -06:00
Luiz Capitulino b8b08266bd Monitor: Drop the print disabling mechanism
We can ignore calls to monitor_vprintf() in QMP mode and use
monitor_puts() directly in monitor_json_emitter().

This allows us to drop this ugly hack.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:18 -06:00
Luiz Capitulino b4475aa2b3 Monitor: Debugging support
Add configure options (--enable-debug-mon and --disable-debug-mon)
plus the MON_DEBUG() macro.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:18 -06:00
Luiz Capitulino 261394dbff Monitor: Rename cmd_new_ret()
Now that all handlers are converted to cmd_new_ret(), we can rename
it back to cmd_new(). But now it returns a value.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino 0bbc47bb21 Monitor: Convert do_change() to cmd_new_ret()
Not that trivial as the call chain also has to be modified.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino 4fdc94b406 Monitor: Convert do_info() to cmd_new_ret()
Note that this function only fails in QMP, in the user Monitor
it prints the help text instead.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino fe38a32acc Monitor: Convert do_physical_memory_save() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino 9869622ee8 Monitor: Convert do_memory_save() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino aeb91c1e13 Monitor: Convert do_closefd() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino 6ad3ebd28e Monitor: Convert do_getfd() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:17 -06:00
Luiz Capitulino ba85d35191 Monitor: Convert do_block_set_passwd() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino 584cbdb596 Monitor: Convert do_cpu_set() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino 9b9d4d9c79 Monitor: Convert do_eject() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino d5a7b38f5c Monitor: Convert do_cont() to cmd_new_ret()
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino ef4b7eeec1 Monitor: Convert simple handlers to cmd_new_ret()
The following handlers always succeed and hence can be converted
to cmd_new_ret() in the same commit.

- do_stop()
- do_quit()
- do_system_reset()
- do_system_powerdown()
- do_migrate_cancel()
- do_qmp_capabilities()
- do_migrate_set_speed()
- do_migrate_set_downtime()

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino 97536cffbf Monitor: Introduce cmd_new_ret()
In order to implement the new error handling and debugging
mechanism for command handlers, we need to change the cmd_new()
callback to return a value.

This commit introduces cmd_new_ret(), which returns a value and
will be used only temporarily to handle the transition from
cmd_new().

That is, as soon as all command handlers are ported to cmd_new_ret(),
it will be renamed back to cmd_new() and the new error handling
and debugging mechanism will be added on top of it.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19 15:18:16 -06:00
Luiz Capitulino 47116d1c90 QMP: Don't leak on connection close
QMP's chardev event callback doesn't call
json_message_parser_destroy() on CHR_EVENT_CLOSED. As the call
to json_message_parser_init() on CHR_EVENT_OPENED allocates memory,
we'are leaking on close.

Fix that by just calling json_message_parser_destroy() on
CHR_EVENT_CLOSED.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 13:46:17 -06:00
Luiz Capitulino 27a749fb73 QError: Don't abort on multiple faults
Ideally, Monitor code should report an error only once and
return the error information up the call chain.

To assure that this happens as expected and that no error is
lost, we have an assert() in qemu_error_internal().

However, we still have not fully converted handlers using
monitor_printf() to report errors. As there can be multiple
monitor_printf() calls on an error, the assertion is easily
triggered when debugging is enabled; and we will get a memory
leak if it's not.

The solution to this problem is to allow multiple faults by only
reporting the first one, and to release the additional error objects.

A better mechanism to report multiple errors to programmers is
underway.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 13:46:17 -06:00
Luiz Capitulino ba14414174 Monitor: remove unneeded checks
It's not needed to check the return of qobject_from_jsonf()
anymore, as an assert() has been added there.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 13:46:17 -06:00
Luiz Capitulino 09069b19f4 QMP: Enforce capability negotiation rules
With this commit QMP will be started in Capabilities Negotiation
mode, where the only command allowed to run is 'qmp_capabilities'.

All other commands will return CommandNotFound error. Asynchronous
messages are not delivered either.

When 'qmp_capabilities' is successfully executed QMP enters in
Command mode, where all commands (except 'qmp_capabilities') are
allowed to run and asynchronous messages are delivered.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 12:46:05 -06:00
Luiz Capitulino 4a7e1190df QMP: Introduce the qmp_capabilities command
This command will be used to enable QMP capabilities advertised
by the capabilities array.

Note that it will be mandatory to issue this command in order
to make QMP functional (although this behavior is not being
enforced by this commit).

Also, as we don't have any capabilities yet, the new command
doesn't accept any arguments. I will postpone the decision for
a format for this until we get our first capability.

Finally, this command is visible from the user Monitor too, in
the meaning that you can execute it but it won't do anything.
Making it only visible in QMP is beyond this series' goal, as
it requires changes in unrelated places.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 12:46:05 -06:00
Luiz Capitulino ca9567e234 QMP: Add QEMU's version to the greeting message
With capability negotiation support clients will only have a chance
to check QEMU's version (ie. issue 'query-version') after the
negotiation procedure is done.

It might be useful to clients to check QEMU's version before
negotiating features, though.

To allow that, this commit adds the QEMU's version object to the
greeting message.

Not really sure this is needed, but doesn't hurt anyway.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 12:46:05 -06:00
Luiz Capitulino aa1db6edaf QMP: BLOCK_IO_ERROR event handling
This commit adds the basic definitions for the BLOCK_IO_ERROR
event, but actual event emission will be introduced by the
next commits.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 11:57:02 -06:00
Markus Armbruster cc0c4185e5 monitor: Use QERR_INVALID_PARAMETER instead of QERR_INVALID_CPU_INDEX
This changes the error message from "Invalid CPU index" to "Invalid
parameter index" in the human monitor.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-03 12:39:01 -06:00
Markus Armbruster fccfb11e0d monitor: New argument type 'T'
This is a double value with optional suffixes ms, us, ns.  We'll need
this to get migrate_set_downtime() QMP-ready.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-03 12:36:26 -06:00
Markus Armbruster 3350a4dd07 monitor: New argument type 'b'
This is a double value with optional suffixes G, g, M, m, K, k.  We'll
need this to get migrate_set_speed() QMP-ready.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-03 12:36:26 -06:00
Markus Armbruster 9fec543fa6 monitor: Document argument type 'M'
Was forgotten in commit b6e098d7.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-03 12:36:25 -06:00
Luiz Capitulino 82617d7ce3 Monitor: Fix command execution regression
Function is_async_return() added by commit 940cc30d0d assumes
that 'data', which is returned by handlers, is always a QDict.

This is not true, as QLists can also be returned, in this case
we'll get a segfault.

Fix that by checking if 'data' is a QDict.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-01-28 19:09:44 +00:00
Adam Litke 625a5befc2 virtio: Add memory statistics reporting to the balloon driver
When using ballooning to manage overcommitted memory on a host, a system for
guests to communicate their memory usage to the host can provide information
that will minimize the impact of ballooning on the guests.  The current method
employs a daemon running in each guest that communicates memory statistics to a
host daemon at a specified time interval.  The host daemon aggregates this
information and inflates and/or deflates balloons according to the level of
host memory pressure.  This approach is effective but overly complex since a
daemon must be installed inside each guest and coordinated to communicate with
the host.  A simpler approach is to collect memory statistics in the virtio
balloon driver and communicate them directly to the hypervisor.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 17:08:03 -06:00
Adam Litke 940cc30d0d New API for asynchronous monitor commands
Qemu has a number of commands that can operate asynchronously (savevm, migrate,
etc) and it will be getting more.  For these commands, the user monitor needs
to be suspended, but QMP monitors could continue to to accept other commands.
This patch introduces a new command API that isolates the details of handling
different monitor types from the actual command execution.

A monitor command can use this API by implementing the mhandler.cmd_async
handler (or info_async if appropriate).  This function is responsible for
submitting the command and does not return any data although it may raise
errors.  When the command completes, the QMPCompletion callback should be
invoked with its opaque data and the command result.

The process for submitting and completing an asynchronous command is different
for QMP and user monitors.  A user monitor must be suspended at submit time and
resumed at completion time.  The user_print() function must be passed to the
QMPCompletion callback so the result can be displayed properly.  QMP monitors
are simpler.  No submit time setup is required.  When the command completes,
monitor_protocol_emitter() writes the result in JSON format.

This API can also be used to implement synchronous commands.  In this case, the
cmd_async handler should immediately call the QMPCompletion callback.  It is my
hope that this new interface will work for all commands, leading to a
drastically simplified monitor.c once all commands are ported.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 17:08:03 -06:00
Luiz Capitulino 163c8a59f6 PCI: Convert pci_info() to QObject
The returned QObject is a QList of all buses. Each bus is
represented by a QDict, which has a key with a QList of all
PCI devices attached to it. Each device is represented by
a QDict.

As has happended to other complex conversions, it's hard to
split this commit as part of it are new functions which are
called by each other.

IMPORTANT: support for printing PCI bridge attached devices
is NOT part of this commit, it's going to be added by the
next commit, as it's untested.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 15:42:02 -06:00
Kirill A. Shutemov 27e3ddd3e0 monitor.c: fix warnings with _FORTIFY_SOURCE
CC    i386-softmmu/monitor.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_memory_save':
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1318: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_physical_memory_save':
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1345: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result
make[1]: *** [monitor.o] Error 1

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:59:20 -06:00
Markus Armbruster 81a1b45ac7 monitor: convert do_cpu_set() to QObject, QError
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:55:11 -06:00
Markus Armbruster 95fada8c2c monitor: convert do_physical_memory_save() to QError
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:55:11 -06:00
Markus Armbruster c34ed28b6b monitor: convert do_memory_save() to QError
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:55:10 -06:00
Markus Armbruster 09b9418c6d monitor: Don't check for mon_get_cpu() failure
mon_get_cpu() can't return null pointer, because it passes its return
value to cpu_synchronize_state() first, which crashes if its argument
is null.

Remove the (pretty cheesy) handling of this non-existing error.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26 14:55:10 -06:00
Luiz Capitulino 23fabed136 QMP: Fix asynchronous events delivery
Commit f039a563f2 introduces
a regression as monitor_protocol_event() will return in
the first user Monitor it finds in the QLIST_FOREACH()
loop.

The right thing to do is to only delivery an asynchronous
event if the 'mon' is a QMP Monitor.

The aforementioned commit was an early version, if it was
applied to stable (it should) this one has to be applied
there too.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-20 08:25:23 -06:00