aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
AgeCommit message (Collapse)Author
2010-01-20QMP: Fix asynchronous events deliveryLuiz Capitulino
Commit f039a563f200beee80cc10fd70b21ea396979dab 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> (cherry picked from commit 23fabed13645fdf66473e458f318baa63be56b22)
2010-01-19QMP: Emit asynchronous events on all QMP monitorsAdam Litke
When using a control/QMP monitor in tandem with a regular monitor, asynchronous messages can get lost depending on the order of the QEMU program arguments. QEMU events issued by monitor_protocol_event() always go to cur_mon. If the user monitor was specified on the command line first (or it has ,default), the message will be directed to the user monitor (not the QMP monitor). Additionally, only one QMP session is currently able to receive async messages. To avoid this confusion, scan through the list of monitors and emit the message on each QMP monitor. Signed-off-by: Adam Litke <agl@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit f039a563f200beee80cc10fd70b21ea396979dab)
2010-01-12QMP: Don't free async event's 'data'Luiz Capitulino
The monitor_protocol_event() function will free the event's data, this is wrong as 'data' management is up to the caller. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 3d72f9a2be640f368229d579e80ce4ef2a823e49)
2010-01-08QMP: Drop wrong assert()Luiz Capitulino
Some commands return a QList of QDicts, which is valid, but will trig the assert(). Just drop it. Reported-by: Nathan Baum <nathan@parenthephobia.org.uk> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 810f49b56a5d0cd6848856af51d3093ae9adc7b1)
2009-12-19monitor: do_balloon(): Use 'M' argument typeLuiz Capitulino
This makes do_balloon() accept megabyte values from the user Monitor while accepting byte values for QMP. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 056001ab30b1e596b992e70f9cb2adacef9c0ad0)
2009-12-19monitor: Introduce 'M' argument typeLuiz Capitulino
This is a target long value in megabytes which should be converted to bytes. It will be used by handlers which accept a megabyte value when in "user mode". Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 7cfe34fe4e3b518485c15aa9a78b4cf9cbd11a4d)
2009-12-19QMP: Assure that returned data is a QDictLuiz Capitulino
This is for debug purposes only. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 19863875a2e18fc868a7b830f16fa76d32518bd1)
2009-12-19QMP: Return an empty dict by defaultLuiz Capitulino
Currently, when a regular command doesn't have any data to output, QMP will emit: { "return": "OK" } Returning an empty dict is better though, because dicts can support some protocol changes in a compatible way. So, with this commit we will return: { "return": {} } Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit e38fb11b5099db8de8d60d536d4a01610ee4c08b)
2009-12-19QMP: Only handle converted commandsLuiz Capitulino
Looks like I dropped this check when addressing the 'query-' commands request. QMP should only handle converted commands, obviously. Reported-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 89f5461fc9a3c437e632f6895dc605e8f03b925e)
2009-12-19monitor: Accept input only byte-wiseJan Kiszka
This allows to suspend command interpretation and execution synchronously, e.g. during migration. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit c62313bbdc48f72e93fa8196f2fff96ba35e4e9d)
2009-12-19monitor: Catch printing to non-existent monitorLuiz Capitulino
The monitor_vprintf() function now touches the 'mon' pointer before calling monitor_puts(), this causes block migration to segfault as its functions call monitor_printf() with a NULL 'mon'. To fix the problem this commit moves the 'mon' NULL check from monitor_puts() to monitor_vprintf(). This can potentially hide bugs, but for some reason this has been the behavior for a long time. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 2daa11912699d9412fb4404d646031a74b166aa5)
2009-12-19monitor: Avoid readline functions in QMPLuiz Capitulino
The monitor_read_command() function is readline specific and should only be used when readline is available. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 183e6e525764d5c4978e37b42dc2cde0b0ffcfec)
2009-12-19monitor: do_balloon(): Check for errorsLuiz Capitulino
do_balloon() should check for ballooning availability as do_info_balloon() does. Noted by Daniel P. Berrange <berrange@redhat.com>. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit cfdf2c40577ed99bb19cdc05d0537e2808d77a78)
2009-12-19monitor: Use 'device' in ejectLuiz Capitulino
Monitor's eject command uses 'filename' for the device name argument, but 'device' is a better name. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 78d714e08f15171adf48e32ba86709f9c64f37cf)
2009-12-12VNC: Convert do_info_vnc() to QObjectLuiz Capitulino
Return a QDict with server information. Connected clients are returned as a QList of QDicts. The new functions (vnc_qdict_remote_addr(), vnc_qdict_local_addr() and put_addr_qdict()) are used to insert 'host' and 'service' information in the returned QDict. This patch is big, but I don't see how to split it. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit d96fd29cca420d1ff3d34cde233cf41a3818c550)
2009-12-12char: Convert qemu_chr_info() to QObjectLuiz Capitulino
Each device is represented by a QDict. The returned QObject is a QList of all devices. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 588b38320134edee4a569f60ed88c9848961d6ee)
2009-12-12block: Convert bdrv_info_stats() to QObjectLuiz Capitulino
Each device statistic information is stored in a QDict and the returned QObject is a QList of all devices. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 218a536a7a7c6d3679d5eca0103f32fd11fbfaf0)
2009-12-12block: Convert bdrv_info() to QObjectLuiz Capitulino
Each block device information is stored in a QDict and the returned QObject is a QList of all devices. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit d15e546567d75fca36d852c39e30adaab02121a7)
2009-12-12migration: Convert do_info_migrate() to QObjectLuiz Capitulino
Return a QDict, which may contain up to more two QDicts, depending on the type of migration we're performing. IMPORTANT: as a QInt stores a int64_t integer, RAM values are going to be stored as int64_t and not as uint64_t as they are today. If this is a problem QInt will have to be changed. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit c86a668390d16d6b3249acd50bfa61ad825c7a80)
2009-12-12monitor: Convert do_info_mice() to QObjectLuiz Capitulino
Each mouse is represented by a QDict, the returned QObject is a QList of all mice. This commit should not change user output. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit e78c48ec4e192ef1b1a210bdf5a8d253d7826c25)
2009-12-12monitor: Convert do_info_uuid() to QObjectLuiz Capitulino
snprintf() is used because the UUID_FMT is too complex for qobject_from_jsonf(). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 9603ceba2edd1dc7e3823da76d84706d3d1c3d78)
2009-12-12monitor: Convert do_info_hpet() to QObjectLuiz Capitulino
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 14f0720df929181eed5424b3f436d84ce05541c3)
2009-12-12monitor: Convert do_info_name() to QObjectLuiz Capitulino
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit e05486cba662ccceef6be4b3ce38961876aa8f6e)
2009-12-12monitor: Convert do_info_kvm() to QObjectLuiz Capitulino
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 2af5ba712b3e03cf644320f7386bf1dfd2c2b6a8)
2009-12-12monitor: Convert do_info_status() to QObjectLuiz Capitulino
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit c0e8520ed5efef2891e2e930a1bb21c1b040410f)
2009-12-12monitor: do_info_version(): Use QDictLuiz Capitulino
All 'info' commands should use QDict, this commit also kills monitor_print_qobject() as do_info_version() doesn't use it anymore (and no handler will). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 45e914cfe03f9fcf946bdc124f752d8f288eff05)
2009-12-12monitor: do_info_cpus(): Use QBoolLuiz Capitulino
While there update the documentation as well. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 55483ad657dcb62cde09bce3b38a5fc28d08f999)
2009-12-12monitor: Fix do_info_commands() outputLuiz Capitulino
Should return a QDict and should not print the user protocol bits (eg. "c|cont"). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 1a728677d4e2f0434caf352c0e88100652fd6711)
2009-12-12monitor: Fix do_info_balloon() outputLuiz Capitulino
Monitor commands should always return values in bytes and info commands should always return a QDict. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 7f1796713ed2f338bd9abc094aacf10f67aed1e5)
2009-12-12Revert "monitor: Command-line flag to enable control mode"Gerd Hoffmann
This reverts commit adcb181afe5a951c521411c7a8e9d9b791aa6742. Conflicts: monitor.h Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 4e307fc883b39c89ffc093c79eb9c9735724d227)
2009-12-07QMP: add human-readable description to error responseMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 77e595e7c613c495714d04ce63fb9bce263c29ae)
2009-12-07monitor: convert do_getfd() to QErrorMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 7cdfcfe18f0a9e8603e4a14770a84eb5649521c5)
2009-12-07monitor: convert do_closefd() to QErrorMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 063c1a0918d5a08f7ba89300d022b3421174fbf7)
2009-12-07monitor: convert do_change() to QObject, QErrorMarkus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit ec3b82afaa0c4c06689d6a6381d351eefc4ee171)
2009-12-07monitor: convert do_eject() to QErrorMarkus Armbruster
Also affects do_change(), because the two share eject_device(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 2c2a6bb860c09a80f519cd6297f1c0585a1436ec)
2009-12-07monitor: Fix double-prompt after "change vnc passwd BLA"Markus Armbruster
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 2895e075c6dba0e66c72af781b1eed2bff0c3777)
2009-12-07monitor: do_cont(): Don't ask for passwordsLuiz Capitulino
The do_cont() function will ask the user to enter a password if a device is encrypted. This is invalid under QMP, so we raise a QERR_DEVICE_ENCRYPTED error. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 94171e119cb6f7bab2578896643b0daff1d9b184)
2009-12-07monitor: Introduce 'block_passwd' commandLuiz Capitulino
When using encrypted disk images, QEMU will prompt the user for passwords when started. This makes sense for the user protocol, but doesn't for QMP. The solution is to have Monitor command which allows the user or a Client to set passwords in advance, so that we avoid the prompt completely. This is what block_passwd does, for example: (QEMU) block_passwd ide0-hd0 foobar Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit a3a55a2edb7c0fd72bc62a8a4c719a1e1983e6ac)
2009-12-04monitor: fix use of plain integer as NULL pointer, spotted by SparseBlue Swirl
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-12-04monitor: use qemu_gettimeofday(), not gettimeofday()Blue Swirl
Fix mingw32 build. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-12-04monitor: rename EVENT_* to QEVENT_* to avoid conflict on mingw32Blue Swirl
Partially fixes mingw32 build. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-12-03net: move slirp code from net.c to net/slirp.cMark McLoughlin
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03QMP: Disable monitor print functionsLuiz Capitulino
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>
2009-12-03QMP: Introduce basic asynchronous eventsLuiz Capitulino
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>
2009-12-03QMP: Asynchronous events infrastructureLuiz Capitulino
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>
2009-12-03QMP: Allow 'query-' commandsLuiz Capitulino
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>
2009-12-03QMP: Input supportLuiz Capitulino
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>
2009-12-03QMP: do_info() checksLuiz Capitulino
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>
2009-12-03QMP: Output supportLuiz Capitulino
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>
2009-12-03QMP: Initial supportLuiz Capitulino
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>