qapi: remove the 'middle' mode
cover qapi: remove the 'middle' mode
From: Marc-André Lureau <[email protected]>
Hi,
Although some QMP commands are still not fully qapi'fied, it is possible to use more qapi common and generated code by dropping the 'middle' mode.
This series of patches was sent last year as part of a larger series 'post-Eric's fixes, QAPI improvements'. It is still based on latest Eric qapi series that should land in upstream soon.
Marc-André Lureau (12):
qapi-schema: use generated marshaller for 'qmp_capabilities'
qapi-schema: add 'device_add'
monitor: register gen:false commands manually
monitor: remove usage of generated marshal functions
monitor: register the qapi generated commands
monitor: remove mhandler.cmd_new
monitor: implement 'qmp_query_commands' without qmp_cmds
build-sys: remove qmp-commands-old.h
qapi: remove the "middle" mode
monitor: use qmp_dispatch()
qmp: update qmp_query_spice fallback
Drop qmp-commands.hx
.gitignore | 1 - MAINTAINERS | 2 +- Makefile | 5 +- Makefile.target | 7 +- docs/qapi-code-gen.txt | 6 +- docs/writing-qmp-commands.txt | 46 +- hmp-commands-info.hx | 118 ++-- hmp-commands.hx | 206 +++--- monitor.c | 401 +++-------- qapi-schema.json | 45 ++ qmp-commands.hx => qmp-commands.txt | 1254 ----------------------------------- qmp.c | 16 - scripts/qapi-commands.py | 29 +- trace-events | 1 - vl.c | 1 + 15 files changed, 309 insertions(+), 1829 deletions(-) rename qmp-commands.hx => qmp-commands.txt (81%)
Signature · 1 line
2.9.0
PATCH 1/12 qapi-schema: use generated marshaller for 'qmp_capabilities'
From: Marc-André Lureau <[email protected]>
qapi'fy the 'qmp_capabilities' command.
--- monitor.c | 4 ++-- qapi-schema.json | 19 +++++++++++++++++++ qmp-commands.hx | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-)
monitor.c +2 -2
@@ -615,7 +615,7 @@ static void monitor_qapi_event_init(void)qmp_event_set_func_emit (monitor_qapi_event_queue); } -static void qmp_capabilities (QDict *params,QObject **ret_data,Error **errp) +void qmp_qmp_capabilities (Error **errp) { cur_mon->qmp.in_command_mode = true; }
@@ -3601,7 +3601,7 @@ static int monitor_can_read(void *opaque)static bool invalid_qmp_mode (const Monitor *mon,const mon_cmd_t *cmd,Error **errp) { -bool is_cap = cmd->mhandler.cmd_new == qmp_capabilities; +bool is_cap = cmd->mhandler.cmd_new == qmp_marshal_qmp_capabilities;if (is_cap && mon->qmp.in_command_mode) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
qapi-schema.json +19 -0
@@ -20,6 +20,25 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +## +# @qmp_capabilities: +# +# Enable QMP capabilities. +# +# Arguments: None. +# +# Example: +# +# -> { "execute": "qmp_capabilities" } +# <- { "return": {} } +# +# Notes: This command is valid exactly when first connecting: it must be +# issued before any other command will be accepted, and will fail once the +# monitor is accepting other commands. +# +## +{ 'command': 'qmp_capabilities' } + ## # @LostTickPolicy: #
qmp-commands.hx +1 -1
@@ -2197,7 +2197,7 @@ EQMP .args_type = "", .params = "", .help = "enable QMP capabilities", - .mhandler.cmd_new = qmp_capabilities, + .mhandler.cmd_new = qmp_marshal_qmp_capabilities, }, SQMP
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 01/12] qapi-schema: use generated marshaller for 'qmp_capabilities'
Quoted 23 lines · On 06/22/2016 06:07 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
qapi'fy the '
qmp_capabilities' command.Signed-off-by Marc-André Lureau <[email protected]>--- monitor.c | 4 ++-- qapi-schema.json | 19 +++++++++++++++++++ qmp-commands.hx | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-)+++
b/qapi-schema.jsonqapi-schema.json +6
-0@@ -20,6 +20,25 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +## +# @qmp_capabilities: +# +# Enable QMP capabilities. +# +# Arguments: None.
qapi-schema.json line 38
Quoted 10 lines
qapi-schema.json +10
-0+# +# Example: +# +# -> { "execute": "qmp_capabilities" } +# <- { "return": {} } +# +# Notes: This command is valid exactly when first connecting: it must be +# issued before any other command will be accepted, and will fail once the +# monitor is accepting other commands. +#
Missing a 'Since: x.y' designation. Part of me argues it would be 2.7, since that is when it shows up in introspection, part of me argues it would be 0.13, since it has always been part of QMP. Or maybe we just omit it? Anyone else with a favorite bikeshed color?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/12 qapi-schema: add 'device_add'
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Even though device_add is not fully qapi'fied, we may add it to the json schema with 'gen': false, so registration and documentation can be generated.
--- qapi-schema.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
qapi-schema.json +26 -0
@@ -2188,6 +2188,32 @@ ## { 'command': 'xen-set-global-dirty-log', 'data': { 'enable': 'bool' } } +## +# @device_add: +# +# @driver: the name of the new device's driver +# @bus: #optional the device's parent bus (device tree path) +# @id: the device's ID, must be unique +# @props: #optional a dictionary of properties to be passed to the backend +# +# Add a device. +# +# Notes: +# 1. For detailed information about this command, please refer to the +# 'docs/qdev-device-use.txt' file. +# +# 2. It's possible to list device properties by running QEMU with the +# "-device DEVICE,\?" command-line argument, where DEVICE is the device's name +# +# Example: +# +# -> { "execute": "device_add", "arguments": { "driver": "e1000", "id": "net1" } } +# <- { "return": {} } +# +## +{ 'command': 'device_add', + 'data': {'driver': 'str', 'id': 'str'}, 'gen': false } + ## # @device_del: #
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 02/12] qapi-schema: add 'device_add'
Quoted 25 lines · On 06/22/2016 06:07 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Even though
device_addis not fully qapi'fied, we may add it to the json schema with 'gen': false, so registration and documentation can be generated.Signed-off-by Marc-André Lureau <[email protected]>--- qapi-schema.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)qapi-schema.json +6
-0@@ -2188,6 +2188,32 @@ ## { 'command': 'xen-set-global-dirty-log', 'data': { 'enable': 'bool' } } +## +# @device_add: +# +# @driver: the name of the new device's driver +# @bus: #optional the device's parent bus (device tree path) +# @id: the device's ID, must be unique
qapi-schema.json line 2206
Quoted 10 lines
qapi-schema.json +10
-0+# @props: #optional a dictionary of properties to be passed to the backend +# +# Add a device. +# +# Notes: +# 1. For detailed information about this command, please refer to the +# 'docs/qdev-device-use.txt' file. +# +# 2. It's possible to list device properties by running QEMU with the +# "-device DEVICE,\?" command-line argument, where DEVICE is the device's name
I'd prefer mentioning -device DEVICE,help, rather than a shell metacharacter, so that the advice doesn't break in the presence of an oddly-named file in the current directory when the user forgets to quote things in the shell.
Long line; please keep under 80 columns.
qapi-schema.json line 2213
Quoted 7 lines
qapi-schema.json +7
-0+# +# Example: +# +# -> { "execute": "device_add", "arguments": { "driver": "e1000", "id": "net1" } } +# <- { "return": {} } +# +##
Missing a Since: designation; probably 0.13, since we've had it (and it has been non-introspectible) since that point.
Quoted 7 lines
qapi-schema.json +3
-0+{ 'command': 'device_add', + 'data': {'driver': 'str', 'id': 'str'}, 'gen': false } + ## # @device_del: #
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/12 monitor: register gen:false commands manually
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Since a few commands are using 'gen': false, they are not registered automatically by the generator. Register manually instead.
This is in preparation for removal of qapi 'middle' mode generation.
--- monitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
monitor.c +11 -0
@@ -79,6 +79,7 @@#include "sysemu/block-backend.h" #include "sysemu/qtest.h" #include "qemu/cutils.h" +#include "qapi/qmp/dispatch.h" /* for hmp_info_irq/pic */ #if defined(TARGET_SPARC )
@@ -987,6 +988,16 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, *ret_data =qobject_from_json (qmp_schema_json); } +static void qmp_init_marshal (void ) +{ +qmp_register_command ("query-qmp-schema" , qmp_query_qmp_schema, +QCO_NO_OPTIONS ); +qmp_register_command ("device_add" , qmp_device_add, +QCO_NO_OPTIONS ); +} + +qapi_init (qmp_init_marshal); +/* set the current CPU defined by the user */ int monitor_set_cpu (int cpu_index) {
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 03/12] monitor: register gen:false commands manually
Quoted 5 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Since a few commands are using 'gen': false, they are not registered automatically by the generator. Register manually instead.
Quoted 7 lines
This is in preparation for removal of qapi 'middle' mode generation.
Signed-off-by Marc-André Lureau <[email protected]>--- monitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 4/12 monitor: remove usage of generated marshal functions
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Once the middle mode is removed, the generated marshal functions will no longer be exported.
--- monitor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
monitor.c +5 -5
@@ -3609,21 +3609,21 @@ static int monitor_can_read(void *opaque)return (mon->suspend_cnt ==0 ) ?1 :0 ; } -static bool invalid_qmp_mode (const Monitor *mon,const mon_cmd_t *cmd, +static bool invalid_qmp_mode (const Monitor *mon,const gchar *cmd,Error **errp) { -bool is_cap = cmd->mhandler.cmd_new == qmp_marshal_qmp_capabilities; +bool is_cap = !g_strcmp0 (cmd,"qmp_capabilities" );if (is_cap && mon->qmp.in_command_mode) {error_set (errp,ERROR_CLASS_COMMAND_NOT_FOUND ,"Capabilities negotiation is already complete, command " -"'%s' ignored" , cmd->name); +"'%s' ignored" , cmd);return true; }if (!is_cap && !mon->qmp.in_command_mode) {error_set (errp,ERROR_CLASS_COMMAND_NOT_FOUND ,"Expecting capabilities negotiation with " -"'qmp_capabilities' before command '%s'" , cmd->name); +"'qmp_capabilities' before command '%s'" , cmd);return true; }return false;
@@ -3914,7 +3914,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) "The command %s has not been found", cmd_name); goto err_out; } -if (invalid_qmp_mode (mon, cmd, &local_err)) { +if (invalid_qmp_mode (mon, cmd_name, &local_err)) { goto err_out; }
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 04/12] monitor: remove usage of generated marshal functions
Quoted 15 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Once the middle mode is removed, the generated marshal functions will no longer be exported.
Signed-off-by Marc-André Lureau <[email protected]>--- monitor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)monitor.c +0
-0
monitor.c static int monitor_can_read(void *opaque) · line 3612
Quoted 5 lines
monitor.c +1
-1@@ -3609,21 +3609,21 @@ static int monitor_can_read(void *opaque)return (mon->suspend_cnt ==0 ) ?1 :0 ; } -static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd, +static bool invalid_qmp_mode(const Monitor *mon, const gchar *cmd,
Why 'gchar'? What's wrong with 'char'? (Some of glib's typedefs make sense, but gchar is not one of them)
monitor.c static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) · line 3918
Quoted 7 lines
monitor.c +1
-1@@ -3914,7 +3914,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) "The command %s has not been found", cmd_name); goto err_out; } -if (invalid_qmp_mode (mon, cmd, &local_err)) { +if (invalid_qmp_mode (mon, cmd_name, &local_err)) { goto err_out;
Particularly since cmd_name is const char * in the caller.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 04/12] monitor: remove usage of generated marshal functions
Hi
Quoted 6 lines · Eric Blake
monitor.c static int monitor_can_read(void *opaque) · line 3612
Quoted 3 lines
monitor.c +1
-1-static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd, +static bool invalid_qmp_mode(const Monitor *mon, const gchar *cmd,Why 'gchar'? What's wrong with 'char'? (Some of glib's typedefs make sense, but gchar is not one of them)
just some old habit, fixed.
ack otherwise?
Signature · 1 line
Marc-André Lureau
Eric Blake
Reviewed-byRe: [Qemu-devel] [PATCH 04/12] monitor: remove usage of generated marshal functions
Quoted 10 lines · Marc-André Lureau
Hi
Quoted 6 lines · Eric Blake
monitor.c static int monitor_can_read(void *opaque) · line 3612
Quoted 3 lines
monitor.c +1
-1-static bool invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd, +static bool invalid_qmp_mode(const Monitor *mon, const gchar *cmd,Why 'gchar'? What's wrong with 'char'? (Some of glib's typedefs make sense, but gchar is not one of them)
Quoted 3 lines
just some old habit, fixed.
ack otherwise?
Yes, you can add:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 5/12 monitor: register the qapi generated commands
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Stop using the so-called 'middle' mode. Instead, use qmp_find_command() from generated qapi commands registry.
Note: this commit requires a 'make clean' prior to make, since the generated files do not depend on Makefile (due to a cyclic rule introduced in 4115852bb0).
--- Makefile | 2 +- monitor.c | 12 +++-- qmp-commands.hx | 143 -------------------------------------------------------- vl.c | 1 + 4 files changed, 11 insertions(+), 147 deletions(-)
Makefile +1 -1
@@ -311,7 +311,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) qmp-commands.h qmp-marshal.c :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ - $(gen-out-type) -o "." -m $<, \ + $(gen-out-type) -o "." $<, \ " GEN $@") qmp-introspect.h qmp-introspect.c :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
monitor.c +9 -3
@@ -3884,6 +3884,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QObject *obj, *data;QDict *input, *args;const mon_cmd_t *cmd; +QmpCommand *qcmd;const char *cmd_name;Monitor *mon = cur_mon;
@@ -3909,7 +3910,8 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) cmd_name =qdict_get_str (input,"execute" );trace_handle_qmp_command (mon, cmd_name); cmd =qmp_find_cmd (cmd_name); -if (!cmd) { + qcmd =qmp_find_command (cmd_name); +if (!qcmd || !cmd) {error_set (&local_err,ERROR_CLASS_COMMAND_NOT_FOUND ,"The command %s has not been found" , cmd_name); goto err_out;
@@ -3931,7 +3933,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) goto err_out; } - cmd->mhandler.cmd_new (args, &data, &local_err); + qcmd->fn (args, &data, &local_err); err_out:monitor_protocol_emitter (mon, data, local_err);
@@ -4000,9 +4002,13 @@ void monitor_resume(Monitor *mon)static QObject *get_qmp_greeting (void ) { +QmpCommand *cmd;QObject *ver =NULL ; -qmp_marshal_query_version (NULL , &ver,NULL ); + cmd =qmp_find_command ("query-version" ); +assert (cmd && cmd->fn); + cmd->fn (NULL , &ver,NULL ); +return qobject_from_jsonf ("{'QMP':{'version': %p,'capabilities': []}}" ,ver); }
qmp-commands.hx +0 -143
967 lines not on this page · raw message
vl.c +1 -0
@@ -2971,6 +2971,7 @@ int main(int argc, char **argv, char **envp)qemu_init_exec_dir (argv[0 ]);module_call_init (MODULE_INIT_QOM ); +module_call_init (MODULE_INIT_QAPI );qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 05/12] monitor: register the qapi generated commands
Quoted 9 lines · On 23/06/2016 02:08, [email protected] wrote:
Stop using the so-called 'middle' mode. Instead, use
qmp_find_command()from generated qapi commands registry.Note: this commit requires a 'make clean' prior to make, since the generated files do not depend on
Makefile(due to a cyclic rule introduced in4115852bb0).Signed-off-by Marc-André Lureau <[email protected]>
What is the cyclic dependency?
Paolo
Re: [Qemu-devel] [PATCH 05/12] monitor: register the qapi generated commands
Hi
----- Original Message -----
Quoted 7 lines · On 23/06/2016 02:08, [email protected] wrote:
Quoted 4 lines
Stop using the so-called 'middle' mode. Instead, use
qmp_find_command()from generated qapi commands registry.
Quoted 7 lines
Quoted 5 lines
Note: this commit requires a 'make clean' prior to make, since the generated files do not depend on
Makefile(due to a cyclic rule introduced in4115852bb0).Signed-off-by Marc-André Lureau <[email protected]>What is the cyclic dependency?
We have in Makefile.target:
Makefile: $(GENERATED_HEADERS)
But we should also or rather have:
$(GENERATED_HEADERS) $(GENERATED_SOURCES): Makefile:
That would be cyclic.
I understand the first rule was added to simplify the dependencies and make sure the generated files are done prior to any building. But it sounds like it's not a conventional way to write your rules and prevent proper dependencies.
Do you know another trick we could use for the generated files?
regards
Re: [Qemu-devel] [PATCH 05/12] monitor: register the qapi generated commands
In reply to [email protected]Quoted 8 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Stop using the so-called 'middle' mode. Instead, use
qmp_find_command()from generated qapi commands registry.Note: this commit requires a 'make clean' prior to make, since the generated files do not depend on
Makefile(due to a cyclic rule introduced in4115852bb0).
I'm not as well-versed as Paolo on Makefile issues, so I won't comment on that part of the patch.
Quoted 20 lines
Signed-off-by Marc-André Lureau <[email protected]>--- Makefile | 2 +- monitor.c | 12 +++-- qmp-commands.hx | 143 -------------------------------------------------------- vl.c | 1 + 4 files changed, 11 insertions(+), 147 deletions(-)+++
b/monitor.cmonitor.c +1
-0@@ -3884,6 +3884,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)QObject *obj, *data;QDict *input, *args;const mon_cmd_t *cmd; +QmpCommand *qcmd;const char *cmd_name;Monitor *mon = cur_mon;
monitor.c static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) · line 3913
Quoted 5 lines
monitor.c +1
-1@@ -3909,7 +3910,8 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) cmd_name =qdict_get_str (input,"execute" );trace_handle_qmp_command (mon, cmd_name); cmd =qmp_find_cmd (cmd_name); -if (!cmd) { + qcmd =qmp_find_command (cmd_name);
Is it worth creating a single type that contains both mon_cmd_t and QmpCommand information, so that we don't need two similarly-named functions to look up two related pieces of information? Not necessarily in this patch.
Quoted 16 lines
monitor.c +2
-1+if (!qcmd || !cmd) {error_set (&local_err,ERROR_CLASS_COMMAND_NOT_FOUND ,"The command %s has not been found" , cmd_name); goto err_out;@@ -3931,7 +3933,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) goto err_out; } - cmd->mhandler.cmd_new (args, &data, &local_err); + qcmd->fn (args, &data, &local_err); err_out:monitor_protocol_emitter (mon, data, local_err);@@ -4000,9 +4002,13 @@ void monitor_resume(Monitor *mon)static QObject *get_qmp_greeting (void )
monitor.c void monitor_resume(Monitor *mon) · line 4012
Quoted 10 lines
monitor.c +5
-1{ +QmpCommand *cmd;QObject *ver =NULL ; -qmp_marshal_query_version (NULL , &ver,NULL ); + cmd =qmp_find_command ("query-version" ); +assert (cmd && cmd->fn); + cmd->fn (NULL , &ver,NULL ); +return qobject_from_jsonf ("{'QMP':{'version': %p,'capabilities': []}}" ,ver);
Worth fixing the missing space after ',' while touching near here?
qmp-commands.hx EQMP · line 66
Quoted 11 lines
(quoted diff) +0
-0}qmp-commands.hx +0
-1@@ -63,7 +63,6 @@ EQMP { .name = "quit", .args_type = "", - .mhandler.cmd_new = qmp_marshal_quit,
At one point, I posted an RFC patch for removing .args_type on most QMP command listings in this file. Maybe you still do that later in your series, but as my work definitely conflicts with yours, and your series is older, I don't mind getting through your series first.
Overall, I like the general idea of automating things rather than having to duplicate information in qmp-commands.hx.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 05/12] monitor: register the qapi generated commands
Quoted 6 lines · Eric Blake
Quoted 1 line
+ qcmd =
qmp_find_command(cmd_name);Is it worth creating a single type that contains both
mon_cmd_tand QmpCommand information, so that we don't need two similarly-named functions to look up two related pieces of information? Not necessarily in this patch.
Well, this is only temporary. Theuse 'qmp_dispatch()' get rid of all that.
Quoted 21 lines
Quoted 21 lines
monitor.c +3
-1+if (!qcmd || !cmd) {error_set (&local_err,ERROR_CLASS_COMMAND_NOT_FOUND ,"The command %s has not been found" , cmd_name); goto err_out;@@ -3931,7 +3933,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) goto err_out; } - cmd->mhandler.cmd_new (args, &data, &local_err); + qcmd->fn (args, &data, &local_err); err_out:monitor_protocol_emitter (mon, data, local_err);@@ -4000,9 +4002,13 @@ void monitor_resume(Monitor *mon)static QObject *get_qmp_greeting (void ) { +QmpCommand *cmd;QObject *ver =NULL ;
Quoted 8 lines
monitor.c void monitor_resume(Monitor *mon) · line 4012
Quoted 6 lines
monitor.c +4
-1-qmp_marshal_query_version (NULL , &ver,NULL ); + cmd =qmp_find_command ("query-version" ); +assert (cmd && cmd->fn); + cmd->fn (NULL , &ver,NULL ); +return qobject_from_jsonf ("{'QMP':{'version': %p,'capabilities': []}}" ,ver);Worth fixing the missing space after ',' while touching near here?
fine by me ;)
Quoted 18 lines
qmp-commands.hx EQMP · line 66
Quoted 12 lines
(quoted diff) +0
-0}qmp-commands.hx +0
-1@@ -63,7 +63,6 @@ EQMP { .name = "quit", .args_type = "", - .mhandler.cmd_new = qmp_marshal_quit,At one point, I posted an RFC patch for removing .args_type on most QMP command listings in this file. Maybe you still do that later in your series, but as my work definitely conflicts with yours, and your series is older, I don't mind getting through your series first.
Quoted 2 lines
Overall, I like the general idea of automating things rather than having to duplicate information in qmp-commands.hx.
Yeah, I basically get rid of qmp-commands.hx in my series (and the doc follow up in https://github.com/elmarco/qemu/commits/qapi-doc)
Signature · 1 line
Marc-André Lureau
PATCH 6/12 monitor: remove mhandler.cmd_new
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This is no longer necessary, now that middle mode has been removed.
--- docs/writing-qmp-commands.txt | 8 +- hmp-commands-info.hx | 118 ++++++++++++------------ hmp-commands.hx | 206 +++++++++++++++++++++--------------------- monitor.c | 11 +-- 4 files changed, 168 insertions(+), 175 deletions(-)
docs/writing-qmp-commands.txt +2 -6
@@ -127,7 +127,6 @@ following at the bottom: { .name = "hello-world", .args_type = "", - .mhandler.cmd_new = qmp_marshal_hello_world, }, You're done. Now build qemu, run it as suggested in the "Testing" section,
@@ -179,7 +178,6 @@ The last step is to update the qmp-commands.hx file: { .name = "hello-world", .args_type = "message:s?", - .mhandler.cmd_new = qmp_marshal_hello_world, }, Notice that the "args_type" member got our "message" argument. The character
@@ -337,7 +335,7 @@ we should add it to the hmp-commands.hx file: .args_type = "message:s?", .params = "hello-world [message]", .help = "Print message to the standard output", - .mhandler.cmd = hmp_hello_world, + .cmd = hmp_hello_world, }, STEXI
@@ -459,7 +457,6 @@ The last step is to add the correspoding entry in the qmp-commands.hx file: { .name = "query-alarm-clock", .args_type = "", - .mhandler.cmd_new = qmp_marshal_query_alarm_clock, }, Time to test the new command. Build qemu, run it as described in the "Testing"
@@ -518,7 +515,7 @@ in the monitor.c file. The entry for the "info alarmclock" follows: .args_type = "", .params = "", .help = "show information about the alarm clock", - .mhandler.info = hmp_info_alarm_clock, + .cmd = hmp_info_alarm_clock, }, To test this, run qemu and type "info alarmclock" in the user monitor.
@@ -605,7 +602,6 @@ To test this you have to add the corresponding qmp-commands.hx entry: { .name = "query-alarm-methods", .args_type = "", - .mhandler.cmd_new = qmp_marshal_query_alarm_methods, }, Now Build qemu, run it as explained in the "Testing" section and try our new
hmp-commands-info.hx +59 -59
452 lines not on this page · raw message
hmp-commands.hx +103 -103
824 lines not on this page · raw message
monitor.c +4 -7
@@ -130,13 +130,10 @@ typedef struct mon_cmd_t {const char *args_type;const char *params;const char *help; -union { -void (*cmd)(Monitor *mon,const QDict *qdict); -void (*cmd_new)(QDict *params,QObject **ret_data,Error **errp); - } mhandler; +void (*cmd)(Monitor *mon,const QDict *qdict);/* @sub_table is a list of 2nd level of commands. If it do not exist, -* mhandler should be used. If it exist, sub_table[?].mhandler should be -* used, and mhandler of 1st level plays the role of help function. +* cmd should be used. If it exist, sub_table[?].cmd should be +* used, and cmd of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table;void (*command_completion)(ReadLineState *rs,int nb_args,const char *str);
@@ -2927,7 +2924,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)return ; } - cmd->mhandler.cmd (mon, qdict); + cmd->cmd (mon, qdict);QDECREF (qdict); }
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 06/12] monitor: remove mhandler.cmd_new
Quoted 11 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
This is no longer necessary, now that middle mode has been removed.
Signed-off-by Marc-André Lureau <[email protected]>--- docs/writing-qmp-commands.txt | 8 +- hmp-commands-info.hx | 118 ++++++++++++------------ hmp-commands.hx | 206 +++++++++++++++++++++--------------------- monitor.c | 11 +-- 4 files changed, 168 insertions(+), 175 deletions(-)
The changes to hmp-commands*.hx are mechanical; you may want to set up git to order the diff so that more relevant files like monitor.c are listed first. Do that by 'git config diff.orderFile /path/to/file', then in that file, listing globs in the order that you want to prioritize.
monitor.c typedef struct mon_cmd_t { · line 134
Quoted 11 lines
+++
b/monitor.cmonitor.c +1
-4@@ -130,13 +130,10 @@ typedef struct mon_cmd_t {const char *args_type;const char *params;const char *help; -union { -void (*cmd)(Monitor *mon,const QDict *qdict); -void (*cmd_new)(QDict *params,QObject **ret_data,Error **errp); - } mhandler; +void (*cmd)(Monitor *mon,const QDict *qdict);/* @sub_table is a list of 2nd level of commands. If it do not exist,
As long as you are touching this, fix the grammar bug: s/do/does/
monitor.c typedef struct mon_cmd_t { · line 135
Quoted 3 lines
monitor.c +1
-2-* mhandler should be used. If it exist, sub_table[?].mhandler should be -* used, and mhandler of 1st level plays the role of help function. +* cmd should be used. If it exist, sub_table[?].cmd should be
s/exist/exists/
Quoted 14 lines
monitor.c +2
-1+* used, and cmd of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table;void (*command_completion)(ReadLineState *rs,int nb_args,const char *str);@@ -2927,7 +2924,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)return ; } - cmd->mhandler.cmd (mon, qdict); + cmd->cmd (mon, qdict);QDECREF (qdict); }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 06/12] monitor: remove mhandler.cmd_new
Hi
Quoted 13 lines · Eric Blake
Quoted 11 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
This is no longer necessary, now that middle mode has been removed.
Signed-off-by Marc-André Lureau <[email protected]>--- docs/writing-qmp-commands.txt | 8 +- hmp-commands-info.hx | 118 ++++++++++++------------ hmp-commands.hx | 206 +++++++++++++++++++++--------------------- monitor.c | 11 +-- 4 files changed, 168 insertions(+), 175 deletions(-)
Quoted 5 lines
The changes to hmp-commands*.hx are mechanical; you may want to set up git to order the diff so that more relevant files like
monitor.care listed first. Do that by 'git config diff.orderFile /path/to/file', then in that file, listing globs in the order that you want to prioritize.
Nice tip, didn't know about it. I wonder if it would be worth to have one in qemu source tree..
Quoted 14 lines
monitor.c typedef struct mon_cmd_t { · line 134
Quoted 11 lines
+++
b/monitor.cmonitor.c +1
-4@@ -130,13 +130,10 @@ typedef struct mon_cmd_t {const char *args_type;const char *params;const char *help; -union { -void (*cmd)(Monitor *mon,const QDict *qdict); -void (*cmd_new)(QDict *params,QObject **ret_data,Error **errp); - } mhandler; +void (*cmd)(Monitor *mon,const QDict *qdict);/* @sub_table is a list of 2nd level of commands. If it do not exist, As long as you are touching this, fix the grammar bug: s/do/does/
Quoted 6 lines
monitor.c typedef struct mon_cmd_t { · line 135
Quoted 3 lines
monitor.c +1
-2-* mhandler should be used. If it exist, sub_table[?].mhandler should be -* used, and mhandler of 1st level plays the role of help function. +* cmd should be used. If it exist, sub_table[?].cmd should be s/exist/exists/
fixed both
Quoted 19 lines
Quoted 6 lines
monitor.c +1
-0+* used, and cmd of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table;void (*command_completion)(ReadLineState *rs,int nb_args,const char *str);monitor.c static void handle_hmp_command(Monitor *mon, const char *cmdline) · line 2930
Quoted 8 lines
monitor.c +1
-1@@ -2927,7 +2924,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline)return ; } - cmd->mhandler.cmd (mon, qdict); + cmd->cmd (mon, qdict);QDECREF (qdict); }--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 06/12] monitor: remove mhandler.cmd_new
Quoted 16 lines · Marc-André Lureau
Hi
Quoted 13 lines · Eric Blake
Quoted 11 lines · On 06/22/2016 06:08 PM, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
This is no longer necessary, now that middle mode has been removed.
Signed-off-by Marc-André Lureau <[email protected]>--- docs/writing-qmp-commands.txt | 8 +- hmp-commands-info.hx | 118 ++++++++++++------------ hmp-commands.hx | 206 +++++++++++++++++++++--------------------- monitor.c | 11 +-- 4 files changed, 168 insertions(+), 175 deletions(-)
Quoted 8 lines
Quoted 5 lines
The changes to hmp-commands*.hx are mechanical; you may want to set up git to order the diff so that more relevant files like
monitor.care listed first. Do that by 'git config diff.orderFile /path/to/file', then in that file, listing globs in the order that you want to prioritize.Nice tip, didn't know about it. I wonder if it would be worth to have one in qemu source tree..
Maybe not: it still requires a local setting to be useful (the file existing in-tree doesn't mean that 'git diff' will automatically know to use it without users editing .git/config); having it version-controlled means that the diff you list now may depend on the version of the file in your tree now rather than the version at the time the patch was first generated for some confusing results; and there are still cases where I personally find that I don't necessarily want the same order as last time (so I'm frequently tweaking my own order file according to the series I'm currently posting).
Hmm - maybe it should get a mention on the SubmitAPatch wiki page, though.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 7/12 monitor: implement 'qmp_query_commands' without qmp_cmds
In reply to [email protected]From: Marc-André Lureau <[email protected]>
So we can get rid of the static qmp_cmds table.
--- monitor.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
monitor.c +14 -18
@@ -229,8 +229,6 @@ static int mon_refcount;static mon_cmd_t mon_cmds[];static mon_cmd_t info_cmds[]; -static const mon_cmd_t qmp_cmds[]; -Monitor *cur_mon;static QEMUClockType event_clock_type =QEMU_CLOCK_REALTIME ;
@@ -934,21 +932,24 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict)help_cmd (mon,"info" ); } -CommandInfoList *qmp_query_commands (Error **errp) +static void query_commands_cb (QmpCommand *cmd,void *opaque) { -CommandInfoList *info, *cmd_list =NULL ; -const mon_cmd_t *cmd; +CommandInfoList *info, **list = opaque; -for (cmd = qmp_cmds; cmd->name !=NULL ; cmd++) { - info =g_malloc0 (sizeof (*info)); - info->value =g_malloc0 (sizeof (*info->value)); - info->value->name =g_strdup (cmd->name); + info =g_malloc0 (sizeof (*info)); + info->value =g_malloc0 (sizeof (*info->value)); + info->value->name =g_strdup (cmd->name); + info->next = *list; + *list = info; +} - info->next = cmd_list; - cmd_list = info; - } +CommandInfoList *qmp_query_commands (Error **errp) +{ +CommandInfoList *list =NULL ; -return cmd_list; +qmp_for_each_command (query_commands_cb, &list); + +return list; }EventInfoList *qmp_query_events (Error **errp)
@@ -2133,11 +2134,6 @@ static mon_cmd_t mon_cmds[] = { { NULL, NULL, }, }; -static const mon_cmd_t qmp_cmds[] = { -#include "qmp-commands-old.h" - {/* NULL */ }, -}; -/*******************************************************************/ static const char *pch;
Signature · 1 line
2.9.0
PATCH 8/12 build-sys: remove qmp-commands-old.h
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- Makefile.target | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Makefile.target +2 -5
@@ -159,7 +159,7 @@ else obj-y += hw/$(TARGET_BASE_ARCH)/ endif -GENERATED_HEADERS += hmp-commands.h hmp-commands-info.h qmp-commands-old.h +GENERATED_HEADERS += hmp-commands.h hmp-commands-info.h endif # CONFIG_SOFTMMU
@@ -212,13 +212,10 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") -qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx $(SRC_PATH)/scripts/hxtool - $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") - clean: rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') - rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c + rm -f hmp-commands.h gdbstub-xml.c ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp endif
Signature · 1 line
2.9.0
PATCH 9/12 qapi: remove the "middle" mode
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Now that the register function is always generated, we can remove the so-called "middle" mode from the generator script.
--- scripts/qapi-commands.py | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-)
scripts/qapi-commands.py +5 -24
@@ -84,17 +84,8 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out, def gen_marshal_proto(name): - ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) - if not middle_mode: - ret = 'static ' + ret - return ret - - -def gen_marshal_decl(name): - return mcgen(''' -%(proto)s; -''', - proto=gen_marshal_proto(name)) + return 'static void qmp_marshal_%s' % c_name(name) + \ + '(QDict *args, QObject **ret, Error **errp)' def gen_marshal(name, arg_type, box, ret_type):
@@ -209,8 +200,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types = set() def visit_end(self): - if not middle_mode: - self.defn += gen_registry(self._regy) + self.defn += gen_registry(self._regy) self._regy = None self._visited_ret_types = None
@@ -222,21 +212,12 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): if ret_type and ret_type not in self._visited_ret_types: self._visited_ret_types.add(ret_type) self.defn += gen_marshal_output(ret_type) - if middle_mode: - self.decl += gen_marshal_decl(name) self.defn += gen_marshal(name, arg_type, box, ret_type) - if not middle_mode: - self._regy += gen_register_command(name, success_response) - + self._regy += gen_register_command(name, success_response) -middle_mode = False (input_file, output_dir, do_c, do_h, prefix, opts) = \ - parse_command_line("m", ["middle"]) - -for o, a in opts: - if o in ("-m", "--middle"): - middle_mode = True + parse_command_line() c_comment = ''' /*
Signature · 1 line
2.9.0
PATCH 10/12 monitor: use qmp_dispatch()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Replace the old manual dispatch and validation code by the generic one provided by qapi common code.
--- monitor.c | 319 +++++++---------------------------------------------------- trace-events | 1 - 2 files changed, 34 insertions(+), 286 deletions(-)
monitor.c +34 -285
@@ -166,7 +166,6 @@ struct MonFdset { }; typedef struct { - QObject *id; JSONMessageParser parser; /* * When a client connects, we're in capabilities negotiation mode.
@@ -397,49 +396,6 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data)QDECREF (json); } -static QDict *build_qmp_error_dict (Error *err) -{ -QObject *obj; - - obj =qobject_from_jsonf ("{ 'error': { 'class': %s, 'desc': %s } }" , - QapiErrorClass_lookup[error_get_class (err)], -error_get_pretty (err)); - -return qobject_to_qdict (obj); -} - -static void monitor_protocol_emitter (Monitor *mon,QObject *data, -Error *err) -{ -QDict *qmp; - -trace_monitor_protocol_emitter (mon); - -if (!err) { -/* success response */ - qmp =qdict_new (); -if (data) { -qobject_incref (data); -qdict_put_obj (qmp,"return" , data); - }else { -/* return an empty QDict by default */ -qdict_put (qmp,"return" ,qdict_new ()); - } - }else { -/* error response */ - qmp =build_qmp_error_dict (err); - } - -if (mon->qmp.id) { -qdict_put_obj (qmp,"id" , mon->qmp.id); - mon->qmp.id =NULL ; - } - -monitor_json_emitter (mon,QOBJECT (qmp)); -QDECREF (qmp); -} - -static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX ] = {/* Limit guest-triggerable events to 1 per second */ [QAPI_EVENT_RTC_CHANGE ] = {1000 *SCALE_MS },
@@ -2484,11 +2440,6 @@ static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table,return NULL ; } -static const mon_cmd_t *qmp_find_cmd (const char *cmdname) -{ -return search_dispatch_table (qmp_cmds, cmdname); -} -/* * Parse command name from @cmdp according to command table @table. * If blank, return NULL.
@@ -3622,199 +3573,6 @@ static bool invalid_qmp_mode(const Monitor *mon, const gchar *cmd,return false; } -/* -* Argument validation rules: -* -* 1. The argument must exist in cmd_args qdict -* 2. The argument type must be the expected one -* -* Special case: If the argument doesn't exist in cmd_args and -* the QMP_ACCEPT_UNKNOWNS flag is set, then the -* checking is skipped for it. -*/ -static void check_client_args_type (const QDict *client_args, -const QDict *cmd_args,int flags, -Error **errp) -{ -const QDictEntry *ent; - -for (ent =qdict_first (client_args); ent;ent =qdict_next (client_args,ent)){ -QObject *obj; -QString *arg_type; -const QObject *client_arg =qdict_entry_value (ent); -const char *client_arg_name =qdict_entry_key (ent); - - obj =qdict_get (cmd_args, client_arg_name); -if (!obj) { -if (flags &QMP_ACCEPT_UNKNOWNS ) { -/* handler accepts unknowns */ -continue ; - } -/* client arg doesn't exist */ -error_setg (errp,QERR_INVALID_PARAMETER , client_arg_name); -return ; - } - - arg_type =qobject_to_qstring (obj); -assert (arg_type !=NULL ); - -/* check if argument's type is correct */ -switch (qstring_get_str (arg_type)[0 ]) { -case 'F' : -case 'B' : -case 's' : -if (qobject_type (client_arg) !=QTYPE_QSTRING ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , - client_arg_name,"string" ); -return ; - } -break ; -case 'i' : -case 'l' : -case 'M' : -case 'o' : -if (qobject_type (client_arg) !=QTYPE_QINT ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , - client_arg_name,"int" ); -return ; - } -break ; -case 'T' : -if (qobject_type (client_arg) !=QTYPE_QINT && -qobject_type (client_arg) !=QTYPE_QFLOAT ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , - client_arg_name,"number" ); -return ; - } -break ; -case 'b' : -case '-' : -if (qobject_type (client_arg) !=QTYPE_QBOOL ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , - client_arg_name,"bool" ); -return ; - } -break ; -case 'O' : -assert (flags &QMP_ACCEPT_UNKNOWNS ); -break ; -case 'q' : -/* Any QObject can be passed. */ -break ; -case '/' : -case '.' : -/* -* These types are not supported by QMP and thus are not -* handled here. Fall through. -*/ -default : -abort (); - } - } -} - -/* -* - Check if the client has passed all mandatory args -* - Set special flags for argument validation -*/ -static void check_mandatory_args (const QDict *cmd_args, -const QDict *client_args,int *flags, -Error **errp) -{ -const QDictEntry *ent; - -for (ent =qdict_first (cmd_args); ent; ent =qdict_next (cmd_args, ent)) { -const char *cmd_arg_name =qdict_entry_key (ent); -QString *type =qobject_to_qstring (qdict_entry_value (ent)); -assert (type !=NULL ); - -if (qstring_get_str (type)[0 ] =='O' ) { -assert ((*flags &QMP_ACCEPT_UNKNOWNS ) ==0 ); - *flags |=QMP_ACCEPT_UNKNOWNS ; - }else if (qstring_get_str (type)[0 ] !='-' && -qstring_get_str (type)[1 ] !='?' && - !qdict_haskey (client_args, cmd_arg_name)) { -error_setg (errp,QERR_MISSING_PARAMETER , cmd_arg_name); -return ; - } - } -} - -static QDict *qdict_from_args_type (const char *args_type) -{ -int i; -QDict *qdict; -QString *key, *type, *cur_qs; - -assert (args_type !=NULL ); - - qdict =qdict_new (); - -if (args_type ==NULL || args_type[0 ] =='\0' ) { -/* no args, empty qdict */ - goto out; - } - - key =qstring_new (); - type =qstring_new (); - - cur_qs = key; - -for (i =0 ;; i++) { -switch (args_type[i]) { -case ',' : -case '\0' : -qdict_put (qdict,qstring_get_str (key), type); -QDECREF (key); -if (args_type[i] =='\0' ) { - goto out; - } - type =qstring_new ();/* qdict has ref */ - cur_qs = key =qstring_new (); -break ; -case ':' : - cur_qs = type; -break ; -default : -qstring_append_chr (cur_qs, args_type[i]); -break ; - } - } - -out: -return qdict; -} - -/* -* Client argument checking rules: -* -* 1. Client must provide all mandatory arguments -* 2. Each argument provided by the client must be expected -* 3. Each argument provided by the client must have the type expected -* by the command -*/ -static void qmp_check_client_args (const mon_cmd_t *cmd,QDict *client_args, -Error **errp) -{ -Error *err =NULL ; -int flags; -QDict *cmd_args; - - cmd_args =qdict_from_args_type (cmd->args_type); - - flags =0 ; -check_mandatory_args (cmd_args, client_args, &flags, &err); -if (err) { - goto out; - } - -check_client_args_type (client_args, cmd_args, flags, &err); - -out: -error_propagate (errp, err); -QDECREF (cmd_args); -} -/* * Input object checking rules *
@@ -3873,67 +3631,58 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp)static void handle_qmp_command (JSONMessageParser *parser,GQueue *tokens) { -Error *local_err =NULL ; -QObject *obj, *data; -QDict *input, *args; -const mon_cmd_t *cmd; -QmpCommand *qcmd; +QObject *req, *rsp =NULL , *id =NULL ; +QDict *qdict =NULL ;const char *cmd_name;Monitor *mon = cur_mon; +Error *err =NULL ; - args = input =NULL ; - data =NULL ; - - obj =json_parser_parse (tokens,NULL ); -if (!obj) { -// FIXME: should be triggered in json_parser_parse() -error_setg (&local_err,QERR_JSON_PARSING ); + req =json_parser_parse_err (tokens,NULL , &err); +if (err || !req ||qobject_type (req) !=QTYPE_QDICT ) { +if (!err) { +error_setg (&err,QERR_JSON_PARSING ); + } goto err_out; } - input =qmp_check_input_obj (obj, &local_err); -if (!input) { -qobject_decref (obj); + qdict =qmp_check_input_obj (req, &err); +if (!qdict) { goto err_out; } - mon->qmp.id =qdict_get (input,"id" ); -qobject_incref (mon->qmp.id); + id =qdict_get (qdict,"id" ); +qobject_incref (id); +qdict_del (qdict,"id" ); - cmd_name =qdict_get_str (input,"execute" ); + cmd_name =qdict_get_str (qdict,"execute" );trace_handle_qmp_command (mon, cmd_name); - cmd =qmp_find_cmd (cmd_name); - qcmd =qmp_find_command (cmd_name); -if (!qcmd || !cmd) { -error_set (&local_err,ERROR_CLASS_COMMAND_NOT_FOUND , -"The command %s has not been found" , cmd_name); - goto err_out; - } -if (invalid_qmp_mode (mon, cmd_name, &local_err)) { + +if (invalid_qmp_mode (mon, cmd_name, &err)) { goto err_out; } - obj =qdict_get (input,"arguments" ); -if (!obj) { - args =qdict_new (); - }else { - args =qobject_to_qdict (obj); -QINCREF (args); - } + rsp =qmp_dispatch (req); -qmp_check_client_args (cmd, args, &local_err); -if (local_err) { - goto err_out; +err_out: +if (err) { + qdict =qdict_new (); +qdict_put_obj (qdict,"error" ,qmp_build_error_object (err)); +error_free (err); + rsp =QOBJECT (qdict); } - qcmd->fn (args, &data, &local_err); +if (rsp) { +if (id) { +qdict_put_obj (qobject_to_qdict (rsp),"id" , id); + id =NULL ; + } -err_out: -monitor_protocol_emitter (mon, data, local_err); -qobject_decref (data); -error_free (local_err); -QDECREF (input); -QDECREF (args); +monitor_json_emitter (mon, rsp); + } + +qobject_decref (id); +qobject_decref (rsp); +qobject_decref (req); }static void monitor_qmp_read (void *opaque,const uint8_t *buf,int size)
trace-events +0 -1
@@ -97,7 +97,6 @@ qemu_co_mutex_unlock_return(void *mutex, void *self) "mutex %p self %p" # monitor.c handle_qmp_command(void *mon, const char *cmd_name) "mon %p cmd_name \"%s\"" -monitor_protocol_emitter(void *mon) "mon %p" monitor_protocol_event_handler(uint32_t event, void *qdict) "event=%d data=%p" monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p" monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "event=%d data=%p rate=%" PRId64
Signature · 1 line
2.9.0
PATCH 11/12 qmp: update qmp_query_spice fallback
In reply to [email protected]From: Marc-André Lureau <[email protected]>
There are a few commands that are undef #ifdef conditions in qmp-commands.hx. Move all the qmp_query_spice fallback in the same location, return an error and update the comment.
--- monitor.c | 14 ++++++++++++++ qmp.c | 16 ---------------- 2 files changed, 14 insertions(+), 16 deletions(-)
monitor.c +14 -0
@@ -4006,6 +4006,20 @@ QemuOptsList qemu_mon_opts = { }, }; +/* +* the QAPI schema is blissfully unaware #ifdef FOO commands, and the +* QAPI code generator happily generates a dead qmp_marshal_foo_cmd() +* that calls qmp_foo_cmd(). Provide it one, or else linking fails. +* FIXME Educate the QAPI schema on #ifdef commands. +*/ +#ifndef CONFIG_SPICE +SpiceInfo *qmp_query_spice (Error **errp) +{ +error_setg (errp,QERR_FEATURE_DISABLED ,"spice" ); +return NULL ; +}; +#endif +#ifndef TARGET_I386 void qmp_rtc_reset_reinjection (Error **errp) {
qmp.c +0 -16
@@ -161,22 +161,6 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) };#endif -#ifndef CONFIG_SPICE -/* -* qmp-commands.hx ensures that QMP command query-spice exists only -* #ifdef CONFIG_SPICE. Necessary for an accurate query-commands -* result. However, the QAPI schema is blissfully unaware of that, -* and the QAPI code generator happily generates a dead -* qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it -* one, or else linking fails. FIXME Educate the QAPI schema on -* CONFIG_SPICE. -*/ -SpiceInfo *qmp_query_spice (Error **errp) -{ -abort (); -}; -#endif -void qmp_cont (Error **errp) {Error *local_err =NULL ;
Signature · 1 line
2.9.0
PATCH 12/12 Drop qmp-commands.hx
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Only the documentation remains useful, so strip it. (a later update will move the documentation in the respective json files and generate the text file)
--- .gitignore | 1 - MAINTAINERS | 2 +- Makefile | 3 - docs/qapi-code-gen.txt | 6 +- docs/writing-qmp-commands.txt | 38 -- qmp-commands.hx => qmp-commands.txt | 1111 ----------------------------------- 6 files changed, 4 insertions(+), 1157 deletions(-) rename qmp-commands.hx => qmp-commands.txt (86%)
.gitignore +0 -1
@@ -55,7 +55,6 @@ /qemu-monitor-info.texi /qemu-version.h /qemu-version.h.tmp -/qmp-commands.txt /vscclient /fsdev/virtfs-proxy-helper *.[1-9]
MAINTAINERS +1 -1
@@ -1237,7 +1237,7 @@ M: Markus Armbruster <[email protected]> S: Supported F: qmp.c F: monitor.c -F: qmp-commands.hx +F: qmp-commands.txt F: docs/*qmp-* F: scripts/qmp/ T: git git://repo.or.cz/qemu/armbru.git qapi-next
Makefile +0 -3
@@ -553,9 +553,6 @@ qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool qemu-monitor-info.texi: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@") -qmp-commands.txt: $(SRC_PATH)/qmp-commands.hx $(SRC_PATH)/scripts/hxtool - $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -q < $< > $@," GEN $@") - qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@," GEN $@")
docs/qapi-code-gen.txt +3 -3
@@ -964,9 +964,9 @@ Example: Used to generate the marshaling/dispatch functions for the commands defined in the schema. The generated code implements -qmp_marshal_COMMAND() (mentioned in qmp-commands.hx, and registered -automatically), and declares qmp_COMMAND() that the user must -implement. The following files are generated: +qmp_marshal_COMMAND() (registered automatically), and declares +qmp_COMMAND() that the user must implement. The following files are +generated: $(prefix)qmp-marshal.c: command marshal/dispatch functions for each QMP command defined in the schema. Functions
docs/writing-qmp-commands.txt +0 -38
@@ -119,16 +119,6 @@ There are a few things to be noticed: 5. Printing to the terminal is discouraged for QMP commands, we do it here because it's the easiest way to demonstrate a QMP command -Now a little hack is needed. As we're still using the old QMP server we need -to add the new command to its internal dispatch table. This step won't be -required in the near future. Open the qmp-commands.hx file and add the -following at the bottom: - - { - .name = "hello-world", - .args_type = "", - }, - You're done. Now build qemu, run it as suggested in the "Testing" section, and then type the following QMP command:
@@ -173,20 +163,6 @@ There are two important details to be noticed: 2. The C implementation signature must follow the schema's argument ordering, which is defined by the "data" member -The last step is to update the qmp-commands.hx file: - - { - .name = "hello-world", - .args_type = "message:s?", - }, - -Notice that the "args_type" member got our "message" argument. The character -"s" stands for "string" and "?" means it's optional. This too must be ordered -according to the C implementation and schema file. You can look for more -examples in the qmp-commands.hx file if you need to define more arguments. - -Again, this step won't be required in the future. - Time to test our new version of the "hello-world" command. Build qemu, run it as described in the "Testing" section and then send two commands:
@@ -452,13 +428,6 @@ There are a number of things to be noticed: 6. You have to include the "qmp-commands.h" header file in qemu-timer.c, otherwise qemu won't build -The last step is to add the correspoding entry in the qmp-commands.hx file: - - { - .name = "query-alarm-clock", - .args_type = "", - }, - Time to test the new command. Build qemu, run it as described in the "Testing" section and try this:
@@ -597,13 +566,6 @@ iteration of the loop. That's because the alarm timer method in use is the first element of the alarm_timers array. Also notice that QAPI lists are handled by hand and we return the head of the list. -To test this you have to add the corresponding qmp-commands.hx entry: - - { - .name = "query-alarm-methods", - .args_type = "", - }, - Now Build qemu, run it as explained in the "Testing" section and try our new command:
qmp-commands.txt renamed from qmp-commands.hx +0 -1111
1,853 lines not on this page · raw message
Signature · 1 line
2.9.0