: Monitor: First step on an internal QMP API
cover : Monitor: First step on an internal QMP API
Today, when writing an info command that is used by QMP and HMP, the programmer has to implement:
1. The handler itself, that's the function that gathers data and returns it as QObjects
2. A pretty printing function, which is called by the human monitor to print the returned QObjects in human readable form
However, we want to have a clean separation between QMP and the human monitor. Actually, we want to turn QMP into an internal API and the human monitor should be written on top of that.
So, this series does:
1. Move all QMP calling code to the info handler using it, that's we change the pretty printing function to call QMP and turn it into an info handler
2. Drop all QMP calling code from do_info()
Please, note that this is only done for info handlers. Command handlers will take a bit more time to be converted.
balloon.c | 26 +----- balloon.h | 2 +- block.c | 16 ++- block.h | 8 +- console.h | 8 +- hw/pci.c | 9 ++- hw/pci.h | 4 +- input.c | 11 ++- migration.c | 13 ++- migration.h | 4 +- monitor.c | 341 +++++++++++++++++++++++++++-------------------------------- qemu-char.c | 10 ++- qemu-char.h | 4 +- ui/vnc.c | 11 ++- 14 files changed, 227 insertions(+), 240 deletions(-)
PATCH 1/25 QMP: Rename query handlers
Query handlers still carry their human monitor name. This commit renames all of them to a more QMP-like name.
For example, do_info_version() is renamed to qmp_query_version().
--- balloon.c | 4 +- balloon.h | 2 +- block.c | 4 +- block.h | 4 +- console.h | 4 +- hw/pci.c | 2 +- hw/pci.h | 2 +- input.c | 2 +- migration.c | 2 +- migration.h | 2 +- monitor.c | 74 +++++++++++++++++++++++++++++----------------------------- qemu-char.c | 2 +- qemu-char.h | 2 +- ui/vnc.c | 2 +- 14 files changed, 54 insertions(+), 54 deletions(-)
balloon.c +2 -2
@@ -86,7 +86,7 @@ void monitor_print_balloon(Monitor *mon, const QObject *data) }/** -* do_info_balloon(): Balloon information +* qmp_query_balloon(): Balloon information * * Make an asynchronous request for balloon info. When the request completes * a QDict will be returned according to the following specification:
@@ -106,7 +106,7 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)* "major_page_faults": 142, "minor_page_faults": 239245, * "free_mem": 1014185984, "total_mem": 1044668416 } */ -int do_info_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) +int qmp_query_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) {int ret;
balloon.h +1 -1
@@ -26,7 +26,7 @@ int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque);int qemu_balloon_status (MonitorCompletion cb,void *opaque);void monitor_print_balloon (Monitor *mon,const QObject *data); -int do_info_balloon (Monitor *mon,MonitorCompletion cb,void *opaque); +int qmp_query_balloon (Monitor *mon,MonitorCompletion cb,void *opaque);int do_balloon (Monitor *mon,const QDict *params,MonitorCompletion cb,void *opaque);
block.c +2 -2
@@ -1596,7 +1596,7 @@ void bdrv_info_print(Monitor *mon, const QObject *data)qlist_iter (qobject_to_qlist (data), bdrv_print_dict, mon); } -void bdrv_info (Monitor *mon,QObject **ret_data) +void qmp_query_block (Monitor *mon,QObject **ret_data) {QList *bs_list;BlockDriverState *bs;
@@ -1702,7 +1702,7 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs)return res; } -void bdrv_info_stats (Monitor *mon,QObject **ret_data) +void qmp_query_blockstats (Monitor *mon,QObject **ret_data) {QObject *obj;QList *devices;
block.h +2 -2
@@ -53,9 +53,9 @@ typedef enum {void bdrv_mon_event (const BlockDriverState *bdrv,BlockMonEventAction action,int is_read);void bdrv_info_print (Monitor *mon,const QObject *data); -void bdrv_info (Monitor *mon,QObject **ret_data); +void qmp_query_block (Monitor *mon,QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data); -void bdrv_info_stats (Monitor *mon,QObject **ret_data); +void qmp_query_blockstats (Monitor *mon,QObject **ret_data);void bdrv_init (void );void bdrv_init_with_whitelist (void );
console.h +2 -2
@@ -73,7 +73,7 @@ struct MouseTransformInfo { };void do_info_mice_print (Monitor *mon,const QObject *data); -void do_info_mice (Monitor *mon,QObject **ret_data); +void qmp_query_mice (Monitor *mon,QObject **ret_data);void do_mouse_set (Monitor *mon,const QDict *qdict);/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
@@ -370,7 +370,7 @@ void vnc_display_close(DisplayState *ds);int vnc_display_open (DisplayState *ds,const char *display);int vnc_display_password (DisplayState *ds,const char *password);void do_info_vnc_print (Monitor *mon,const QObject *data); -void do_info_vnc (Monitor *mon,QObject **ret_data); +void qmp_query_vnc (Monitor *mon,QObject **ret_data);char *vnc_display_local_addr (DisplayState *ds);/* curses.c */
hw/pci.c +1 -1
@@ -1438,7 +1438,7 @@ static QObject *pci_get_bus_dict(PCIBus *bus, int bus_num)return NULL ; } -void do_pci_info (Monitor *mon,QObject **ret_data) +void qmp_query_pci (Monitor *mon,QObject **ret_data) {QList *bus_list;struct PCIHostBus *host;
hw/pci.h +1 -1
@@ -254,7 +254,7 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp, unsigned *slotp);void do_pci_info_print (Monitor *mon,const QObject *data); -void do_pci_info (Monitor *mon,QObject **ret_data); +void qmp_query_pci (Monitor *mon,QObject **ret_data);void pci_bridge_update_mappings (PCIBus *b);bool pci_msi_enabled (PCIDevice *dev);
input.c +1 -1
@@ -220,7 +220,7 @@ void do_info_mice_print(Monitor *mon, const QObject *data)qlist_iter (mice_list, info_mice_iter, mon); } -void do_info_mice (Monitor *mon,QObject **ret_data) +void qmp_query_mice (Monitor *mon,QObject **ret_data) {QEMUPutMouseEntry *cursor;QList *mice_list;
migration.c +1 -1
@@ -216,7 +216,7 @@ static void migrate_put_status(QDict *qdict, const char *name,qdict_put_obj (qdict, name, obj); } -void do_info_migrate (Monitor *mon,QObject **ret_data) +void qmp_query_migrate (Monitor *mon,QObject **ret_data) {QDict *qdict;MigrationState *s = current_migration;
migration.h +1 -1
@@ -67,7 +67,7 @@ int do_migrate_set_downtime(Monitor *mon, const QDict *qdict,void do_info_migrate_print (Monitor *mon,const QObject *data); -void do_info_migrate (Monitor *mon,QObject **ret_data); +void qmp_query_migrate (Monitor *mon,QObject **ret_data);int exec_start_incoming_migration (const char *host_port);
monitor.c +37 -37
296 lines not on this page · raw message
qemu-char.c +1 -1
@@ -2589,7 +2589,7 @@ void qemu_chr_info_print(Monitor *mon, const QObject *ret_data)qlist_iter (qobject_to_qlist (ret_data), qemu_chr_qlist_iter, mon); } -void qemu_chr_info (Monitor *mon,QObject **ret_data) +void qmp_query_chardev (Monitor *mon,QObject **ret_data) {QList *chr_list;CharDriverState *chr;
qemu-char.h +1 -1
@@ -93,7 +93,7 @@ void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);int qemu_chr_get_msgfd (CharDriverState *s);void qemu_chr_accept_input (CharDriverState *s);void qemu_chr_info_print (Monitor *mon,const QObject *ret_data); -void qemu_chr_info (Monitor *mon,QObject **ret_data); +void qmp_query_chardev (Monitor *mon,QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);/* add an eventfd to the qemu devices that are polled */
ui/vnc.c +1 -1
@@ -327,7 +327,7 @@ void do_info_vnc_print(Monitor *mon, const QObject *data) } } -void do_info_vnc (Monitor *mon,QObject **ret_data) +void qmp_query_vnc (Monitor *mon,QObject **ret_data) {if (vnc_display ==NULL || vnc_display->display ==NULL ) { *ret_data =qobject_from_jsonf ("{ 'enabled': false }" );
Signature · 1 line
1.7.3.3.398.g0b0cd
Re: [Qemu-devel] [PATCH 01/25] QMP: Rename query handlers
Quoted 10 lines · Luiz Capitulino
Query handlers still carry their human monitor name. This commit renames all of them to a more QMP-like name.
For example,
do_info_version()is renamed toqmp_query_version().
- *do_info_balloon(): Balloon information
+ *qmp_query_balloon(): Balloon information
*
* Make an asynchronous request for balloon info. When the request completes
* a QDict will be returned according to the following specification:
balloon.c void monitor_print_balloon(Monitor *mon, const QObject *data) · line 110
Quoted 6 lines
balloon.c +1
-1@@ -106,7 +106,7 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)* "major_page_faults": 142, "minor_page_faults": 239245, * "free_mem": 1014185984, "total_mem": 1044668416 } */ -int do_info_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) +int qmp_query_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) {
If the idea is to detach the human monitor from the QMP API, is there any reason to keep passing Monitor *mon to qmp_* functions? In some parts of the code NULL is being passed.
Regards,
Miguel
Re: [Qemu-devel] [PATCH 01/25] QMP: Rename query handlers
Quoted 4 lines · On Tue, 7 Dec 2010 10:28:25 -0200 Miguel Di Ciurcio Filho…
Quoted 3 lines · Luiz Capitulino
Query handlers still carry their human monitor name. This commit renames all of them to a more QMP-like name.
Quoted 16 lines
balloon.c void monitor_print_balloon(Monitor *mon, const QObject *data) · line 110
Quoted 13 lines
For example,
do_info_version()is renamed toqmp_query_version().
- *do_info_balloon(): Balloon information
+ *qmp_query_balloon(): Balloon information
*
* Make an asynchronous request for balloon info. When the request completes
* a QDict will be returned according to the following specification:balloon.c +1
-1@@ -106,7 +106,7 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)* "major_page_faults": 142, "minor_page_faults": 239245, * "free_mem": 1014185984, "total_mem": 1044668416 } */ -int do_info_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) +int qmp_query_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) {If the idea is to detach the human monitor from the QMP API, is there any reason to keep passing
Monitor *monto qmp_* functions?
No, I should drop it soon.
Quoted 1 line
In some parts of the code NULL is being passed.
Yes, this series is just a first step. We have lots of work to do and sometimes I don't know what to do next, but the plan looks more or less like this:
1. Change info handlers to make directly QMP calls
This series.
2. Move all qmp_query_* functions from the qmp_query_cmds[] table to the qmp-commands.hx one
I have this almost ready, but I'm wondering if I should take the opportunity to drop the monitor object in this series...
3. Split all monitor commands into a human monitor part and a QMP part, the QMP part becomes the QMP API and the human monitor just calls it
I have started doing this (maybe it's in an RFC state), but trust me, it's very difficult to split some handlers.
One example is the do_change() one. Yes, a clearly human targeted command. So the question is: should we split such a handler or should we just add a good replacement?
If we choose to add a replacement, then it's going to take a lot of time to have the QMP vs. HMP separation done. If we split the handler, then we'll have to live with complex, ugly code for a while.
4. Make handlers return an error object
This is the new error infrastructure work, Markus will work on this.
5. Drop all Monitor object usage by QMP by introducing a QMP object
We won't pass the QMP object to handlers, it's just our interface with the chardev layer that will change.
6. Add async command infrastructure
Not necessary step 6, we'll probably be able to do it sooner.
7. Split the monitor code inti different files
Possibly moving it to its own directory:
- monitor/monitor.c: common code
- monitor/hmp.c: human monitor
- monitor/qmp.c: (guess what)
8. Make the QMP C API a real API
Ie. do all cleanup needed to make it consumable, maybe even outside of QEMU
9. Conquer the world
PATCH 2/25 QMP: Drop user_print usage from the qmp_query_cmds[] table
In reply to Luiz CapitulinoQMP doesn't use this field, it's only useful in the human monitor.
NOTE: Other unused fields are going to be dropped by future
commits.
--- monitor.c | 15 --------------- 1 files changed, 0 insertions(+), 15 deletions(-)
monitor.c +0 -15
@@ -2673,7 +2673,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the version of QEMU", - .user_print = do_info_version_print, .mhandler.info_new = qmp_query_version, }, {
@@ -2681,7 +2680,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "list QMP available commands", - .user_print = monitor_user_noop, .mhandler.info_new = qmp_query_commands, }, {
@@ -2689,7 +2687,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .user_print = qemu_chr_info_print, .mhandler.info_new = qmp_query_chardev, }, {
@@ -2697,7 +2694,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the block devices", - .user_print = bdrv_info_print, .mhandler.info_new = qmp_query_block, }, {
@@ -2705,7 +2701,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show block device statistics", - .user_print = bdrv_stats_print, .mhandler.info_new = qmp_query_blockstats, }, {
@@ -2713,7 +2708,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show infos for each CPU", - .user_print = monitor_print_cpus, .mhandler.info_new = qmp_query_cpus, }, {
@@ -2721,7 +2715,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show PCI info", - .user_print = do_pci_info_print, .mhandler.info_new = qmp_query_pci, }, {
@@ -2729,7 +2722,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show KVM information", - .user_print = do_info_kvm_print, .mhandler.info_new = qmp_query_kvm, }, {
@@ -2737,7 +2729,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the current VM status (running|paused)", - .user_print = do_info_status_print, .mhandler.info_new = qmp_query_status, }, {
@@ -2745,7 +2736,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show which guest mouse is receiving events", - .user_print = do_info_mice_print, .mhandler.info_new = qmp_query_mice, }, {
@@ -2753,7 +2743,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the vnc server status", - .user_print = do_info_vnc_print, .mhandler.info_new = qmp_query_vnc, }, {
@@ -2761,7 +2750,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, .mhandler.info_new = qmp_query_name, }, {
@@ -2769,7 +2757,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the current VM UUID", - .user_print = do_info_uuid_print, .mhandler.info_new = qmp_query_uuid, }, {
@@ -2777,7 +2764,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show migration status", - .user_print = do_info_migrate_print, .mhandler.info_new = qmp_query_migrate, }, {
@@ -2785,7 +2771,6 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show balloon information", - .user_print = monitor_print_balloon, .mhandler.info_async = qmp_query_balloon, .flags = MONITOR_CMD_ASYNC, },
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 3/25 Monitor: Drop balloon handlers comments
In reply to Luiz CapitulinoCommit 637503d122eb7656d91a8489e254d9e880be7504 dropped (duplicated) documentation from code, but it missed the balloon handlers.
--- balloon.c | 24 ------------------------ 1 files changed, 0 insertions(+), 24 deletions(-)
balloon.c +0 -24
@@ -85,27 +85,6 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)monitor_printf (mon,"\n" ); } -/** -* qmp_query_balloon(): Balloon information -* -* Make an asynchronous request for balloon info. When the request completes -* a QDict will be returned according to the following specification: -* -* - "actual": current balloon value in bytes -* The following fields may or may not be present: -* - "mem_swapped_in": Amount of memory swapped in (bytes) -* - "mem_swapped_out": Amount of memory swapped out (bytes) -* - "major_page_faults": Number of major faults -* - "minor_page_faults": Number of minor faults -* - "free_mem": Total amount of free and unused memory (bytes) -* - "total_mem": Total amount of available memory (bytes) -* -* Example: -* -* { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, -* "major_page_faults": 142, "minor_page_faults": 239245, -* "free_mem": 1014185984, "total_mem": 1044668416 } -*/ int qmp_query_balloon (Monitor *mon,MonitorCompletion cb,void *opaque) {int ret;
@@ -124,9 +103,6 @@ int qmp_query_balloon(Monitor *mon, MonitorCompletion cb, void *opaque)return 0 ; } -/** -* do_balloon(): Request VM to change its memory allocation -*/ int do_balloon (Monitor *mon,const QDict *params,MonitorCompletion cb,void *opaque) {
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 4/25 Monitor: Move qmp_query_version() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change do_info_version_print() to call it.
--- monitor.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-)
monitor.c +15 -15
@@ -714,21 +714,6 @@ help:help_cmd (mon,"info" ); } -static void do_info_version_print (Monitor *mon,const QObject *data) -{ -QDict *qdict; -QDict *qemu; - - qdict =qobject_to_qdict (data); - qemu =qdict_get_qdict (qdict,"qemu" ); - -monitor_printf (mon,"%" PRId64".%" PRId64".%" PRId64"%s\n" , -qdict_get_int (qemu,"major" ), -qdict_get_int (qemu,"minor" ), -qdict_get_int (qemu,"micro" ), -qdict_get_str (qdict,"package" )); -} -static void qmp_query_version (Monitor *mon,QObject **ret_data) {const char *version =QEMU_VERSION ;
@@ -745,6 +730,21 @@ static void qmp_query_version(Monitor *mon, QObject **ret_data) 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); } +static void do_info_version_print (Monitor *mon,const QObject *data) +{ +QDict *qdict; +QDict *qemu; + + qdict =qobject_to_qdict (data); + qemu =qdict_get_qdict (qdict,"qemu" ); + +monitor_printf (mon,"%" PRId64".%" PRId64".%" PRId64"%s\n" , +qdict_get_int (qemu,"major" ), +qdict_get_int (qemu,"minor" ), +qdict_get_int (qemu,"micro" ), +qdict_get_str (qdict,"package" )); +} +static void do_info_name_print (Monitor *mon,const QObject *data) {QDict *qdict;
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 5/25 Monitor: Convert do_info_version_print() into do_info_version()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_version() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
monitor.c +7 -5
@@ -730,11 +730,12 @@ static void qmp_query_version(Monitor *mon, QObject **ret_data) 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); } -static void do_info_version_print (Monitor *mon,const QObject *data) +static void do_info_version (Monitor *mon) { -QDict *qdict; -QDict *qemu; +QDict *qdict, *qemu; +QObject *data; +qmp_query_version (NULL , &data); qdict =qobject_to_qdict (data); qemu =qdict_get_qdict (qdict,"qemu" );
@@ -743,6 +744,8 @@ static void do_info_version_print(Monitor *mon, const QObject *data)qdict_get_int (qemu,"minor" ),qdict_get_int (qemu,"micro" ), qdict_get_str(qdict, "package")); + +qobject_decref (data); }static void do_info_name_print (Monitor *mon,const QObject *data)
@@ -2385,8 +2388,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the version of QEMU", - .user_print = do_info_version_print, - .mhandler.info_new = qmp_query_version, + .mhandler.info = do_info_version, }, { .name = "network",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 6/25 Monitor: Convert qemu_chr_info_print() into qemu_chr_info()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_chardev() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 3 +-- qemu-char.c | 8 ++++++-- qemu-char.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-)
monitor.c +1 -2
@@ -2402,8 +2402,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .user_print = qemu_chr_info_print, - .mhandler.info_new = qmp_query_chardev, + .mhandler.info = qemu_chr_info, }, { .name = "block",
qemu-char.c +6 -2
@@ -2584,9 +2584,13 @@ static void qemu_chr_qlist_iter(QObject *obj, void *opaque) qdict_get_str(chr_dict, "filename")); } -void qemu_chr_info_print (Monitor *mon,const QObject *ret_data) +void qemu_chr_info (Monitor *mon) { -qlist_iter (qobject_to_qlist (ret_data), qemu_chr_qlist_iter, mon); +QObject *data; + +qmp_query_chardev (NULL , &data); +qlist_iter (qobject_to_qlist (data), qemu_chr_qlist_iter, mon); +qobject_decref (data); }void qmp_query_chardev (Monitor *mon,QObject **ret_data)
qemu-char.h +1 -1
@@ -92,7 +92,7 @@ int qemu_chr_can_read(CharDriverState *s);void qemu_chr_read (CharDriverState *s,uint8_t *buf,int len);int qemu_chr_get_msgfd (CharDriverState *s);void qemu_chr_accept_input (CharDriverState *s); -void qemu_chr_info_print (Monitor *mon,const QObject *ret_data); +void qemu_chr_info (Monitor *mon);void qmp_query_chardev (Monitor *mon,QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 7/25 Monitor: Convert bdrv_info_print() into bdrv_info()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_block() to gather data and then prints it. This change allows us to drop the user_print callback.
--- block.c | 6 +++++- block.h | 2 +- monitor.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-)
block.c +5 -1
@@ -1591,9 +1591,13 @@ static void bdrv_print_dict(QObject *obj, void *opaque)monitor_printf (mon,"\n" ); } -void bdrv_info_print (Monitor *mon,const QObject *data) +void bdrv_info (Monitor *mon) { +QObject *data; + +qmp_query_block (NULL , &data);qlist_iter (qobject_to_qlist (data), bdrv_print_dict, mon); +qobject_decref (data); }void qmp_query_block (Monitor *mon,QObject **ret_data)
block.h +1 -1
@@ -52,8 +52,8 @@ typedef enum {void bdrv_mon_event (const BlockDriverState *bdrv,BlockMonEventAction action,int is_read); -void bdrv_info_print (Monitor *mon,const QObject *data);void qmp_query_block (Monitor *mon,QObject **ret_data); +void bdrv_info (Monitor *mon);void bdrv_stats_print (Monitor *mon,const QObject *data);void qmp_query_blockstats (Monitor *mon,QObject **ret_data);
monitor.c +1 -2
@@ -2409,8 +2409,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the block devices", - .user_print = bdrv_info_print, - .mhandler.info_new = qmp_query_block, + .mhandler.info = bdrv_info, }, { .name = "blockstats",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 8/25 Monitor: Convert bdrv_stats_print() into bdrv_stats()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_blockstats() to gather data and then prints it. This change allows us to drop the user_print callback.
--- block.c | 6 +++++- block.h | 2 +- monitor.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-)
block.c +5 -1
@@ -1671,9 +1671,13 @@ static void bdrv_stats_iter(QObject *data, void *opaque) qdict_get_int(qdict, "wr_operations")); } -void bdrv_stats_print (Monitor *mon,const QObject *data) +void bdrv_stats (Monitor *mon) { +QObject *data; + +qmp_query_blockstats (NULL , &data);qlist_iter (qobject_to_qlist (data), bdrv_stats_iter, mon); +qobject_decref (data); }static QObject *bdrv_info_stats_bs (BlockDriverState *bs)
block.h +1 -1
@@ -54,7 +54,7 @@ void bdrv_mon_event(const BlockDriverState *bdrv, BlockMonEventAction action, int is_read);void qmp_query_block (Monitor *mon,QObject **ret_data);void bdrv_info (Monitor *mon); -void bdrv_stats_print (Monitor *mon,const QObject *data); +void bdrv_stats (Monitor *mon);void qmp_query_blockstats (Monitor *mon,QObject **ret_data);void bdrv_init (void );
monitor.c +1 -2
@@ -2416,8 +2416,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show block device statistics", - .user_print = bdrv_stats_print, - .mhandler.info_new = qmp_query_blockstats, + .mhandler.info = bdrv_stats, }, { .name = "registers",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 9/25 Monitor: Move qmp_query_cpus() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change monitor_print_cpus() to call it.
--- monitor.c | 78 ++++++++++++++++++++++++++++++------------------------------ 1 files changed, 39 insertions(+), 39 deletions(-)
monitor.c +39 -39
@@ -854,6 +854,45 @@ static void do_info_registers(Monitor *mon)#endif } +static void qmp_query_cpus (Monitor *mon,QObject **ret_data) +{ +CPUState *env; +QList *cpu_list; + + cpu_list =qlist_new (); + +/* just to set the default cpu if not already done */ +mon_get_cpu (); + +for (env = first_cpu; env !=NULL ; env = env->next_cpu) { +QDict *cpu; +QObject *obj; + +cpu_synchronize_state (env); + + obj =qobject_from_jsonf ("{ 'CPU': %d, 'current': %i, 'halted': %i }" , + env->cpu_index, env == mon->mon_cpu, + env->halted); + + cpu =qobject_to_qdict (obj); + +#if defined(TARGET_I386 ) +qdict_put (cpu,"pc" ,qint_from_int (env->eip + env->segs[R_CS ].base)); +#elif defined(TARGET_PPC ) +qdict_put (cpu,"nip" ,qint_from_int (env->nip)); +#elif defined(TARGET_SPARC ) +qdict_put (cpu,"pc" ,qint_from_int (env->pc)); +qdict_put (cpu,"npc" ,qint_from_int (env->npc)); +#elif defined(TARGET_MIPS ) +qdict_put (cpu,"PC" ,qint_from_int (env->active_tc.PC)); +#endif + +qlist_append (cpu_list, cpu); + } + + *ret_data =QOBJECT (cpu_list); +} +static void print_cpu_iter (QObject *obj,void *opaque) {QDict *cpu;
@@ -901,45 +940,6 @@ static void monitor_print_cpus(Monitor *mon, const QObject *data)qlist_iter (cpu_list, print_cpu_iter, mon); } -static void qmp_query_cpus (Monitor *mon,QObject **ret_data) -{ -CPUState *env; -QList *cpu_list; - - cpu_list =qlist_new (); - -/* just to set the default cpu if not already done */ -mon_get_cpu (); - -for (env = first_cpu; env !=NULL ; env = env->next_cpu) { -QDict *cpu; -QObject *obj; - -cpu_synchronize_state (env); - - obj =qobject_from_jsonf ("{ 'CPU': %d, 'current': %i, 'halted': %i }" , - env->cpu_index, env == mon->mon_cpu, - env->halted); - - cpu =qobject_to_qdict (obj); - -#if defined(TARGET_I386 ) -qdict_put (cpu,"pc" ,qint_from_int (env->eip + env->segs[R_CS ].base)); -#elif defined(TARGET_PPC ) -qdict_put (cpu,"nip" ,qint_from_int (env->nip)); -#elif defined(TARGET_SPARC ) -qdict_put (cpu,"pc" ,qint_from_int (env->pc)); -qdict_put (cpu,"npc" ,qint_from_int (env->npc)); -#elif defined(TARGET_MIPS ) -qdict_put (cpu,"PC" ,qint_from_int (env->active_tc.PC)); -#endif - -qlist_append (cpu_list, cpu); - } - - *ret_data =QOBJECT (cpu_list); -} -static int do_cpu_set (Monitor *mon,const QDict *qdict,QObject **ret_data) {int index =qdict_get_int (qdict,"index" );
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 10/25 Monitor: Convert monitor_print_cpus() into do_info_cpus()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_cpus() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
monitor.c +6 -7
@@ -931,13 +931,13 @@ static void print_cpu_iter(QObject *obj, void *opaque)monitor_printf (mon,"\n" ); } -static void monitor_print_cpus (Monitor *mon,const QObject *data) +static void do_info_cpus (Monitor *mon) { -QList *cpu_list; +QObject *data; -assert (qobject_type (data) ==QTYPE_QLIST ); - cpu_list =qobject_to_qlist (data); -qlist_iter (cpu_list, print_cpu_iter, mon); +qmp_query_cpus (mon, &data); +qlist_iter (qobject_to_qlist (data), print_cpu_iter, mon); +qobject_decref (data); }static int do_cpu_set (Monitor *mon,const QDict *qdict,QObject **ret_data)
@@ -2430,8 +2430,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show infos for each CPU", - .user_print = monitor_print_cpus, - .mhandler.info_new = qmp_query_cpus, + .mhandler.info = do_info_cpus, }, { .name = "history",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 11/25 Monitor: Convert do_pci_info_print() into do_pci_info()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_pci() to gather data and then prints it. This change allows us to drop the user_print callback.
--- hw/pci.c | 7 ++++++- hw/pci.h | 2 +- monitor.c | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-)
hw/pci.c +6 -1
@@ -1276,9 +1276,12 @@ static void pci_device_print(Monitor *mon, QDict *device) } } -void do_pci_info_print (Monitor *mon,const QObject *data) +void do_pci_info (Monitor *mon) {QListEntry *bus, *dev; +QObject *data; + +qmp_query_pci (NULL , &data); QLIST_FOREACH_ENTRY(qobject_to_qlist(data), bus) {QDict *qdict =qobject_to_qdict (qlist_entry_obj (bus));
@@ -1286,6 +1289,8 @@ void do_pci_info_print(Monitor *mon, const QObject *data)pci_device_print (mon,qobject_to_qdict (qlist_entry_obj (dev))); } } + +qobject_decref (data); }static QObject *pci_get_dev_class (const PCIDevice *dev)
hw/pci.h +1 -1
@@ -253,7 +253,7 @@ int pci_parse_devaddr(const char *addr, int *domp, int *busp,int pci_read_devaddr (Monitor *mon,const char *addr,int *domp,int *busp,unsigned *slotp); -void do_pci_info_print (Monitor *mon,const QObject *data); +void do_pci_info (Monitor *mon);void qmp_query_pci (Monitor *mon,QObject **ret_data);void pci_bridge_update_mappings (PCIBus *b);
monitor.c +1 -2
@@ -2458,8 +2458,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show PCI info", - .user_print = do_pci_info_print, - .mhandler.info_new = qmp_query_pci, + .mhandler.info = do_pci_info, },#if defined(TARGET_I386 ) || defined(TARGET_SH4 ) {
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 12/25 Monitor: Move qmp_query_kvm() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change do_info_kvm_print() to call it.
--- monitor.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
monitor.c +10 -10
@@ -1994,6 +1994,16 @@ static void tlb_info(Monitor *mon)#endif +static void qmp_query_kvm (Monitor *mon,QObject **ret_data) +{ +#ifdef CONFIG_KVM + *ret_data =qobject_from_jsonf ("{ 'enabled': %i, 'present': true }" , +kvm_enabled ()); +#else + *ret_data =qobject_from_jsonf ("{ 'enabled': false, 'present': false }" ); +#endif +} +static void do_info_kvm_print (Monitor *mon,const QObject *data) {QDict *qdict;
@@ -2009,16 +2019,6 @@ static void do_info_kvm_print(Monitor *mon, const QObject *data) } } -static void qmp_query_kvm (Monitor *mon,QObject **ret_data) -{ -#ifdef CONFIG_KVM - *ret_data =qobject_from_jsonf ("{ 'enabled': %i, 'present': true }" , -kvm_enabled ()); -#else - *ret_data =qobject_from_jsonf ("{ 'enabled': false, 'present': false }" ); -#endif -} -static void do_info_numa (Monitor *mon) {int i;
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 13/25 Monitor: Convert do_info_kvm_print() into do_info_kvm()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_kvm() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
monitor.c +6 -3
@@ -2004,10 +2004,12 @@ static void qmp_query_kvm(Monitor *mon, QObject **ret_data)#endif } -static void do_info_kvm_print (Monitor *mon,const QObject *data) +static void do_info_kvm (Monitor *mon) { +QObject *data;QDict *qdict; +qmp_query_kvm (NULL , &data); qdict =qobject_to_qdict (data);monitor_printf (mon,"kvm support: " );
@@ -2017,6 +2019,8 @@ static void do_info_kvm_print(Monitor *mon, const QObject *data) }else {monitor_printf (mon,"not compiled\n" ); } + +qobject_decref (data); }static void do_info_numa (Monitor *mon)
@@ -2490,8 +2494,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show KVM information", - .user_print = do_info_kvm_print, - .mhandler.info_new = qmp_query_kvm, + .mhandler.info = do_info_kvm, }, { .name = "numa",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 14/25 Monitor: Move qmp_query_status() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change do_info_status_print() to use it.
--- monitor.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
monitor.c +6 -6
@@ -2137,6 +2137,12 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) }#endif +static void qmp_query_status (Monitor *mon,QObject **ret_data) +{ + *ret_data =qobject_from_jsonf ("{ 'running': %i, 'singlestep': %i }" , + vm_running, singlestep); +} +static void do_info_status_print (Monitor *mon,const QObject *data) {QDict *qdict;
@@ -2156,12 +2162,6 @@ static void do_info_status_print(Monitor *mon, const QObject *data)monitor_printf (mon,"\n" ); } -static void qmp_query_status (Monitor *mon,QObject **ret_data) -{ - *ret_data =qobject_from_jsonf ("{ 'running': %i, 'singlestep': %i }" , - vm_running, singlestep); -} -static qemu_acl *find_acl (Monitor *mon,const char *name) {qemu_acl *acl =qemu_acl_find (name);
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 15/25 Monitor: Convert do_info_status_print() into do_info_status()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_status() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
monitor.c +5 -3
@@ -2143,10 +2143,12 @@ static void qmp_query_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } -static void do_info_status_print (Monitor *mon,const QObject *data) +static void do_info_status (Monitor *mon) {QDict *qdict; +QObject *data; +qmp_query_status (NULL , &data); qdict =qobject_to_qdict (data);monitor_printf (mon,"VM status: " );
@@ -2160,6 +2162,7 @@ static void do_info_status_print(Monitor *mon, const QObject *data) }monitor_printf (mon,"\n" ); +qobject_decref (data); }static qemu_acl *find_acl (Monitor *mon,const char *name)
@@ -2543,8 +2546,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM status (running|paused)", - .user_print = do_info_status_print, - .mhandler.info_new = qmp_query_status, + .mhandler.info = do_info_status, }, { .name = "pcmcia",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 16/25 Monitor: Convert do_info_mice_print() into do_info_mice()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_mice() to gather data and then prints it. This change allows us to drop the user_print callback.
--- console.h | 2 +- input.c | 9 +++++++-- monitor.c | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-)
console.h +1 -1
@@ -72,7 +72,7 @@ struct MouseTransformInfo {int a[7 ]; }; -void do_info_mice_print (Monitor *mon,const QObject *data); +void do_info_mice (Monitor *mon);void qmp_query_mice (Monitor *mon,QObject **ret_data);void do_mouse_set (Monitor *mon,const QDict *qdict);
input.c +7 -2
@@ -207,17 +207,22 @@ static void info_mice_iter(QObject *data, void *opaque) qdict_get_bool(mouse, "absolute") ? " (absolute)" : ""); } -void do_info_mice_print (Monitor *mon,const QObject *data) +void do_info_mice (Monitor *mon) {QList *mice_list; +QObject *data; +qmp_query_mice (NULL , &data); mice_list =qobject_to_qlist (data);if (qlist_empty (mice_list)) {monitor_printf (mon,"No mouse devices connected\n" ); -return ; + goto out; }qlist_iter (mice_list, info_mice_iter, mon); + +out: +qobject_decref (data); }void qmp_query_mice (Monitor *mon,QObject **ret_data)
monitor.c +1 -2
@@ -2560,8 +2560,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show which guest mouse is receiving events", - .user_print = do_info_mice_print, - .mhandler.info_new = qmp_query_mice, + .mhandler.info = do_info_mice, }, { .name = "vnc",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 17/25 Monitor: Convert do_info_vnc_print() into do_info_vnc()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_vnc() to gather data and then prints it. This change allows us to drop the user_print callback.
--- console.h | 2 +- monitor.c | 3 +-- ui/vnc.c | 9 +++++++-- 3 files changed, 9 insertions(+), 5 deletions(-)
console.h +1 -1
@@ -369,7 +369,7 @@ void vnc_display_init(DisplayState *ds);void vnc_display_close (DisplayState *ds);int vnc_display_open (DisplayState *ds,const char *display);int vnc_display_password (DisplayState *ds,const char *password); -void do_info_vnc_print (Monitor *mon,const QObject *data); +void do_info_vnc (Monitor *mon);void qmp_query_vnc (Monitor *mon,QObject **ret_data);char *vnc_display_local_addr (DisplayState *ds);
monitor.c +1 -2
@@ -2567,8 +2567,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the vnc server status", - .user_print = do_info_vnc_print, - .mhandler.info_new = qmp_query_vnc, + .mhandler.info = do_info_vnc, }, { .name = "name",
ui/vnc.c +7 -2
@@ -302,15 +302,17 @@ static void info_vnc_iter(QObject *obj, void *opaque)#endif } -void do_info_vnc_print (Monitor *mon,const QObject *data) +void do_info_vnc (Monitor *mon) {QDict *server;QList *clients; +QObject *data; +qmp_query_vnc (NULL , &data); server =qobject_to_qdict (data);if (qdict_get_bool (server,"enabled" ) ==0 ) {monitor_printf (mon,"Server: disabled\n" ); -return ; + goto out; }monitor_printf (mon,"Server:\n" );
@@ -325,6 +327,9 @@ void do_info_vnc_print(Monitor *mon, const QObject *data) }else {qlist_iter (clients, info_vnc_iter, mon); } + +out: +qobject_decref (data); }void qmp_query_vnc (Monitor *mon,QObject **ret_data)
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 18/25 Monitor: Move qmp_query_name() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change do_info_name_print() to call it.
--- monitor.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
monitor.c +6 -6
@@ -748,6 +748,12 @@ static void do_info_version(Monitor *mon)qobject_decref (data); } +static void qmp_query_name (Monitor *mon,QObject **ret_data) +{ + *ret_data = qemu_name ?qobject_from_jsonf ("{'name': %s }" , qemu_name) : +qobject_from_jsonf ("{}" ); +} +static void do_info_name_print (Monitor *mon,const QObject *data) {QDict *qdict;
@@ -760,12 +766,6 @@ static void do_info_name_print(Monitor *mon, const QObject *data)monitor_printf (mon,"%s\n" ,qdict_get_str (qdict,"name" )); } -static void qmp_query_name (Monitor *mon,QObject **ret_data) -{ - *ret_data = qemu_name ?qobject_from_jsonf ("{'name': %s }" , qemu_name) : -qobject_from_jsonf ("{}" ); -} -static QObject *get_cmd_dict (const char *name) {const char *p;
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 19/25 Monitor: Convert do_info_name_print() into do_info_name()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_name() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
monitor.c +8 -4
@@ -754,16 +754,21 @@ static void qmp_query_name(Monitor *mon, QObject **ret_data)qobject_from_jsonf ("{}" ); } -static void do_info_name_print (Monitor *mon,const QObject *data) +static void do_info_name (Monitor *mon) {QDict *qdict; +QObject *data; +qmp_query_name (NULL , &data); qdict =qobject_to_qdict (data);if (qdict_size (qdict) ==0 ) { -return ; + goto out; }monitor_printf (mon,"%s\n" ,qdict_get_str (qdict,"name" )); + +out: +qobject_decref (data); }static QObject *get_cmd_dict (const char *name)
@@ -2574,8 +2579,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = qmp_query_name, + .mhandler.info = do_info_name, }, { .name = "uuid",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 20/25 Monitor: Move qmp_query_uuid() up in monitor.c
In reply to Luiz CapitulinoSo that next commit can change do_info_uuid_print() to call it.
--- monitor.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
monitor.c +5 -5
@@ -806,11 +806,6 @@ static void qmp_query_commands(Monitor *mon, QObject **ret_data) *ret_data =QOBJECT (cmd_list); } -static void do_info_uuid_print (Monitor *mon,const QObject *data) -{ -monitor_printf (mon,"%s\n" ,qdict_get_str (qobject_to_qdict (data),"UUID" )); -} -static void qmp_query_uuid (Monitor *mon,QObject **ret_data) {char uuid[64 ];
@@ -823,6 +818,11 @@ static void qmp_query_uuid(Monitor *mon, QObject **ret_data) *ret_data =qobject_from_jsonf ("{ 'UUID': %s }" , uuid); } +static void do_info_uuid_print (Monitor *mon,const QObject *data) +{ +monitor_printf (mon,"%s\n" ,qdict_get_str (qobject_to_qdict (data),"UUID" )); +} +/* get the current CPU defined by the user */ static int mon_set_cpu (int cpu_index) {
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 21/25 Monitor: Convert do_info_uuid_print() into do_info_uuid()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_uuid() to gather data and then prints it. This change allows us to drop the user_print callback.
--- monitor.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
monitor.c +6 -3
@@ -818,9 +818,13 @@ static void qmp_query_uuid(Monitor *mon, QObject **ret_data) *ret_data =qobject_from_jsonf ("{ 'UUID': %s }" , uuid); } -static void do_info_uuid_print (Monitor *mon,const QObject *data) +static void do_info_uuid (Monitor *mon) { +QObject *data; + +qmp_query_uuid (NULL , &data);monitor_printf (mon,"%s\n" ,qdict_get_str (qobject_to_qdict (data),"UUID" )); +qobject_decref (data); }/* get the current CPU defined by the user */
@@ -2586,8 +2590,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM UUID", - .user_print = do_info_uuid_print, - .mhandler.info_new = qmp_query_uuid, + .mhandler.info = do_info_uuid, },#if defined(TARGET_PPC ) {
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 22/25 Monitor: qmp_query_migrate(): Return {} for empty MigrationState
In reply to Luiz CapitulinoWhen no migration has been performed (ie. empty MigrationState), qmp_query_migrate() returns nothing.
Let's do what other query handlers do: return an empty json-object.
--- migration.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
migration.c +5 -0
@@ -192,6 +192,9 @@ void do_info_migrate_print(Monitor *mon, const QObject *data)QDict *qdict; qdict =qobject_to_qdict (data); +if (qdict_size (qdict) ==0 ) { +return ; + }monitor_printf (mon,"Migration status: %s\n" ,qdict_get_str (qdict,"status" ));
@@ -248,6 +251,8 @@ void qmp_query_migrate(Monitor *mon, QObject **ret_data) *ret_data =qobject_from_jsonf ("{ 'status': 'cancelled' }" );break ; } + }else { + *ret_data =qobject_from_jsonf ("{}" ); } }
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 23/25 Monitor: Convert do_info_migrate_print() into do_info_migrate()
In reply to Luiz CapitulinoThe new handler directly calls qmp_query_migrate() to gather data and then prints it. This change allows us to drop the user_print callback.
--- migration.c | 8 ++++++-- migration.h | 2 +- monitor.c | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-)
migration.c +6 -2
@@ -187,13 +187,15 @@ static void migrate_print_status(Monitor *mon, const char *name, qdict_get_int(qdict, "total") >> 10); } -void do_info_migrate_print (Monitor *mon,const QObject *data) +void do_info_migrate (Monitor *mon) {QDict *qdict; +QObject *data; +qmp_query_migrate (NULL , &data); qdict =qobject_to_qdict (data);if (qdict_size (qdict) ==0 ) { -return ; + goto out; } monitor_printf(mon, "Migration status: %s\n",
@@ -206,6 +208,8 @@ void do_info_migrate_print(Monitor *mon, const QObject *data)if (qdict_haskey (qdict,"disk" )) {migrate_print_status (mon,"disk" , qdict); } +out: +qobject_decref (data); } static void migrate_put_status(QDict *qdict, const char *name,
migration.h +1 -1
@@ -65,7 +65,7 @@ uint64_t migrate_max_downtime(void);int do_migrate_set_downtime (Monitor *mon,const QDict *qdict,QObject **ret_data); -void do_info_migrate_print (Monitor *mon,const QObject *data); +void do_info_migrate (Monitor *mon);void qmp_query_migrate (Monitor *mon,QObject **ret_data);
monitor.c +1 -2
@@ -2615,8 +2615,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show migration status", - .user_print = do_info_migrate_print, - .mhandler.info_new = qmp_query_migrate, + .mhandler.info = do_info_migrate, }, { .name = "balloon",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 24/25 Monitor: Introduce do_info_balloon()
In reply to Luiz CapitulinoToday, the do_info() function takes care of handling asynchronous calls. But what we really want is to move all the asynchronous stuff behind the (future) QMP API.
The QMP API will be directly used by handlers, and won't be tied to the human monitor common code (like do_info()) in any way.
This commit takes the first step towards this goal: it introduces do_info_ballon(), which is a regular info handler, except that it knows how to directly call an asynchronous QMP handler.
--- monitor.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
monitor.c +17 -3
@@ -714,6 +714,22 @@ help:help_cmd (mon,"info" ); } +static void do_info_balloon (Monitor *mon) +{ +int err; +MonitorCompletionData *cb_data; + + cb_data =qemu_malloc (sizeof (*cb_data)); + cb_data->mon = mon; + cb_data->user_print = monitor_print_balloon; +monitor_suspend (mon); + err =qmp_query_balloon (NULL , user_monitor_complete, cb_data); +if (err <0 ) { +monitor_resume (mon); +qemu_free (cb_data); + } +} +static void qmp_query_version (Monitor *mon,QObject **ret_data) {const char *version =QEMU_VERSION ;
@@ -2622,9 +2638,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show balloon information", - .user_print = monitor_print_balloon, - .mhandler.info_async = qmp_query_balloon, - .flags = MONITOR_CMD_ASYNC, + .mhandler.info = do_info_balloon, }, { .name = "qtree",
Signature · 1 line
1.7.3.3.398.g0b0cd
PATCH 25/25 Monitor: do_info(): Drop unused code
In reply to Luiz CapitulinoLast commits moved QMP calling code to the info handlers themselves, now do_info() does nothing with QMP anymore, just drop all QMP handling code from it.
--- monitor.c | 42 ++++++------------------------------------ 1 files changed, 6 insertions(+), 36 deletions(-)
monitor.c +6 -36
@@ -661,28 +661,14 @@ static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd, } } -static void user_async_info_handler (Monitor *mon,const mon_cmd_t *cmd) -{ -int ret; - -MonitorCompletionData *cb_data =qemu_malloc (sizeof (*cb_data)); - cb_data->mon = mon; - cb_data->user_print = cmd->user_print; -monitor_suspend (mon); - ret = cmd->mhandler.info_async (mon, user_monitor_complete, cb_data); -if (ret <0 ) { -monitor_resume (mon); -qemu_free (cb_data); - } -} -static void do_info (Monitor *mon,const QDict *qdict) {const mon_cmd_t *cmd;const char *item =qdict_get_try_str (qdict,"item" );if (!item) { - goto help; +help_cmd (mon,"info" ); +return ; }for (cmd = info_cmds; cmd->name !=NULL ; cmd++) {
@@ -690,28 +676,12 @@ static void do_info(Monitor *mon, const QDict *qdict)break ; } -if (cmd->name ==NULL ) { - goto help; - } - -if (handler_is_async (cmd)) { -user_async_info_handler (mon, cmd); - }else if (handler_is_qobject (cmd)) { -QObject *info_data =NULL ; - - cmd->mhandler.info_new (mon, &info_data); -if (info_data) { - cmd->user_print (mon, info_data); -qobject_decref (info_data); - } - }else { - cmd->mhandler.info (mon); +if (!cmd->name) { +help_cmd (mon,"info" ); +return ; } -return ; - -help: -help_cmd (mon,"info" ); + cmd->mhandler.info (mon); }static void do_info_balloon (Monitor *mon)
Signature · 1 line
1.7.3.3.398.g0b0cd