QAPI patches for 2016-09-19
The following changes since commit e3571ae30cd26d19efd4554c25e32ef64d6a36b3:
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20160916' into staging (2016-09-16 16:54:50 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2016-09-19
for you to fetch changes up to bd6092e407a5d682fbfddcbc510038b84bc1a1aa:
Replace qmp-commands.hx by docs/qmp-commands.txt (2016-09-19 18:27:37 +0200)
----------------------------------------------------------------
QAPI patches for 2016-09-19
----------------------------------------------------------------
Marc-André Lureau (17):
build-sys: define QEMU_VERSION_{MAJOR, MINOR, MICRO}
qapi-schema: use generated marshaller for 'qmp_capabilities'
qapi-schema: add 'device_add'
monitor: simplify invalid_qmp_mode()
monitor: register gen:false commands manually
qmp: Hack to keep commands configuration-specific
qapi: export the marshallers
monitor: use qmp_find_command() (using generated qapi code)
monitor: implement 'qmp_query_commands' without qmp_cmds
monitor: remove mhandler.cmd_new
qapi: remove the "middle" mode
qapi: check invalid arguments on no-args commands
tests: add a test to check invalid args
monitor: use qmp_dispatch()
build-sys: remove qmp-commands-old.h qmp-commands.hx: fix some styling
Replace qmp-commands.hx by docs/qmp-commands.txt
Markus Armbruster (1):
qapi: Support unregistering QMP commands
.gitignore | 1 - MAINTAINERS | 1 - Makefile | 8 +- Makefile.target | 7 +- docs/qapi-code-gen.txt | 6 +- qmp-commands.hx => docs/qmp-commands.txt | 1297 +----------------------------- docs/writing-qmp-commands.txt | 46 +- hmp-commands-info.hx | 118 +-- hmp-commands.hx | 208 ++--- include/qapi/qmp/dispatch.h | 1 + monitor.c | 426 +++------- qapi-schema.json | 61 ++ qapi/qmp-registry.c | 8 + qmp.c | 16 +- scripts/create_config | 6 + scripts/qapi-commands.py | 83 +- tests/test-qga.c | 21 + tests/test-qmp-commands.c | 15 + trace-events | 1 - vl.c | 1 + 20 files changed, 460 insertions(+), 1871 deletions(-) rename qmp-commands.hx => docs/qmp-commands.txt (81%)
[Qemu-devel] [PULL 14/18] tests: add a test to check invalid args
From: Marc-André Lureau <[email protected]>
Check that invalid args on commands without arguments returns an error.
Message-Id: <[email protected]>
--- tests/test-qga.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tests/test-qga.c +21 -0
@@ -198,6 +198,26 @@ static void test_qga_ping(gconstpointer fix)QDECREF (ret); } +static void test_qga_invalid_args (gconstpointer fix) +{ +const TestFixture *fixture = fix; +QDict *ret, *error; +const gchar *class, *desc; + + ret =qmp_fd (fixture->fd,"{'execute': 'guest-ping', " +"'arguments': {'foo': 42 }}" ); +g_assert_nonnull (ret); + + error =qdict_get_qdict (ret,"error" ); + class =qdict_get_try_str (error,"class" ); + desc =qdict_get_try_str (error,"desc" ); + + g_assert_cmpstr(class, ==, "GenericError"); + g_assert_cmpstr(desc, ==, "QMP input object member 'foo' is unexpected"); + +QDECREF (ret); +} +static void test_qga_invalid_cmd (gconstpointer fix) {const TestFixture *fixture = fix;
@@ -911,6 +931,7 @@ int main(int argc, char **argv)g_test_add_data_func ("/qga/file-write-read" , &fix, test_qga_file_write_read);g_test_add_data_func ("/qga/get-time" , &fix, test_qga_get_time);g_test_add_data_func ("/qga/invalid-cmd" , &fix, test_qga_invalid_cmd); +g_test_add_data_func ("/qga/invalid-args" , &fix, test_qga_invalid_args);g_test_add_data_func ("/qga/fsfreeze-status" , &fix, test_qga_fsfreeze_status);
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 02/18] qapi-schema: use generated marshaller for 'qmp_capabilities'
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
qapi'fy the 'qmp_capabilities' command, makes the command visible in query-qmp-schema.
Message-Id: <[email protected]>
--- monitor.c | 4 ++-- qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-)
monitor.c +2 -2
@@ -617,7 +617,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; }
@@ -3656,7 +3656,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 +21 -0
@@ -21,6 +21,27 @@ { '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. (see qemu docs/qmp-spec.txt) +# +# Since: 0.13 +# +## +{ 'command': 'qmp_capabilities' } + +## # @LostTickPolicy: # # Policy for handling lost ticks in timer devices.
qmp-commands.hx +1 -1
@@ -2219,7 +2219,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.5.5
[Qemu-devel] [PULL 03/18] qapi-schema: add 'device_add'
In reply to Markus ArmbrusterFrom: 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.
Message-Id: <[email protected]>
--- qapi-schema.json | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
qapi-schema.json +40 -0
@@ -2201,6 +2201,46 @@ { '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 +# +# Additional arguments depend on the type. +# +# 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,help" command-line argument, where DEVICE is the +# device's name +# +# Example: +# +# -> { "execute": "device_add", +# "arguments": { "driver": "e1000", "id": "net1", +# "bus": "pci.0", +# "mac": "52:54:00:12:34:56" } } +# <- { "return": {} } +# +# TODO This command effectively bypasses QAPI completely due to its +# "additional arguments" business. It shouldn't have been added to +# the schema in this form. It should be qapified properly, or +# replaced by a properly qapified command. +# +# Since: 0.13 +## +{ 'command': 'device_add', + 'data': {'driver': 'str', 'id': 'str'}, + 'gen': false } # so we can get the additional arguments + +## # @device_del: # # Remove a device from a guest
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 04/18] monitor: simplify invalid_qmp_mode()
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
handle_qmp_command() will switch to use qmp_dispatch(). It won't have a pointer to the marshaller function anymore, but only the name of the command to invoke. Simplify invalid_qmp_mode() so it can just be called with the command name.
Message-Id: <[email protected]>
--- monitor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
monitor.c +5 -5
@@ -3653,21 +3653,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 char *cmd,Error **errp) { -bool is_cap = cmd->mhandler.cmd_new == qmp_marshal_qmp_capabilities; +bool is_cap =g_str_equal (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;
@@ -3958,7 +3958,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.5.5
[Qemu-devel] [PULL 05/18] monitor: register gen:false commands manually
In reply to Markus ArmbrusterFrom: 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.
Note that qmp_init_marshal() function isn't run yet, so the commands aren't actually registered, until module_call_init(MODULE_INIT_QAPI) is added in a later patch.
Message-Id: <[email protected]>
--- monitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
monitor.c +13 -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 )
@@ -1007,6 +1008,18 @@ 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 ); +qmp_register_command ("netdev_add" , qmp_netdev_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.5.5
[Qemu-devel] [PULL 06/18] qapi: Support unregistering QMP commands
In reply to Markus ArmbrusterMessage-Id: <[email protected]>
--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-registry.c | 8 ++++++++ 2 files changed, 9 insertions(+)
include/qapi/qmp/dispatch.h +1 -0
@@ -36,6 +36,7 @@ typedef struct QmpCommandvoid qmp_register_command (const char *name,QmpCommandFunc *fn,QmpCommandOptions options); +void qmp_unregister_command (const char *name);QmpCommand *qmp_find_command (const char *name);QObject *qmp_dispatch (QObject *request);void qmp_disable_command (const char *name);
qapi/qmp-registry.c +8 -0
@@ -30,6 +30,14 @@ void qmp_register_command(const char *name, QmpCommandFunc *fn,QTAILQ_INSERT_TAIL (&qmp_commands, cmd, node); } +void qmp_unregister_command (const char *name) +{ +QmpCommand *cmd =qmp_find_command (name); + +QTAILQ_REMOVE (&qmp_commands, cmd, node); +g_free (cmd); +} +QmpCommand *qmp_find_command (const char *name) {QmpCommand *cmd;
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 12/18] qapi: remove the "middle" mode
In reply to Markus ArmbrusterFrom: 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.
Message-Id: <[email protected]>
--- scripts/qapi-commands.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
scripts/qapi-commands.py +3 -12
@@ -206,8 +206,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
@@ -221,18 +220,10 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.defn += gen_marshal_output(ret_type) self.decl += gen_marshal_decl(name) self.defn += gen_marshal(name, arg_type, boxed, 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 +(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() c_comment = ''' /*
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 01/18] build-sys: define QEMU_VERSION_{MAJOR, MINOR, MICRO}
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
There are better chances to find what went wrong at build time than a later assert in qmp_query_version
Message-Id: <[email protected]>
--- qmp.c | 16 +++------------- scripts/create_config | 6 ++++++ 2 files changed, 9 insertions(+), 13 deletions(-)
qmp.c +3 -13
@@ -51,21 +51,11 @@ NameInfo *qmp_query_name(Error **errp)VersionInfo *qmp_query_version (Error **errp) {VersionInfo *info =g_new0 (VersionInfo,1 ); -const char *version =QEMU_VERSION ; -const char *tmp; -int err; info->qemu =g_new0 (VersionTriple,1 ); - err =qemu_strtoll (version, &tmp,10 , &info->qemu->major); -assert (err ==0 ); - tmp++; - - err =qemu_strtoll (tmp, &tmp,10 , &info->qemu->minor); -assert (err ==0 ); - tmp++; - - err =qemu_strtoll (tmp, &tmp,10 , &info->qemu->micro); -assert (err ==0 ); + info->qemu->major =QEMU_VERSION_MAJOR ; + info->qemu->minor =QEMU_VERSION_MINOR ; + info->qemu->micro =QEMU_VERSION_MICRO ; info->package =g_strdup (QEMU_PKGVERSION );return info;
scripts/create_config +6 -0
@@ -7,7 +7,13 @@ while read line; do case $line in VERSION=*) # configuration version=${line#*=} + major=$(echo "$version" | cut -d. -f1) + minor=$(echo "$version" | cut -d. -f2) + micro=$(echo "$version" | cut -d. -f3) echo "#define QEMU_VERSION \"$version\"" + echo "#define QEMU_VERSION_MAJOR $major" + echo "#define QEMU_VERSION_MINOR $minor" + echo "#define QEMU_VERSION_MICRO $micro" ;; qemu_*dir=*) # qemu-specific directory configuration name=${line%=*}
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 10/18] monitor: implement 'qmp_query_commands' without qmp_cmds
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
One step towards getting rid of the static qmp_cmds table.
Message-Id: <[email protected]>
--- monitor.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
monitor.c +18 -11
@@ -957,21 +957,28 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict)help_cmd (mon,"info" ); } +static void query_commands_cb (QmpCommand *cmd,void *opaque) +{ +CommandInfoList *info, **list = opaque; + +if (!cmd->enabled) { +return ; + } + + info =g_malloc0 (sizeof (*info)); + info->value =g_malloc0 (sizeof (*info->value)); + info->value->name =g_strdup (cmd->name); + info->next = *list; + *list = info; +} +CommandInfoList *qmp_query_commands (Error **errp) { -CommandInfoList *info, *cmd_list =NULL ; -const mon_cmd_t *cmd; +CommandInfoList *list =NULL ; -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); +qmp_for_each_command (query_commands_cb, &list); - info->next = cmd_list; - cmd_list = info; - } - -return cmd_list; +return list; }EventInfoList *qmp_query_events (Error **errp)
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 13/18] qapi: check invalid arguments on no-args commands
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
The generated marshal functions do not visit arguments from commands that take no arguments. Thus they fail to catch invalid members. Visit the arguments, if provided, to throw an error in case of invalid members.
Currently, qmp_check_client_args() checks for invalid arguments and correctly catches this case. When switching to qmp_dispatch() we want to keep that behaviour. The commands using 'O' may have arbitrary arguments, and must have 'gen': false in the qapi schema to skip the generated checks.
Old/new diff:
void qmp_marshal_stop(QDict *args, QObject **ret, Error **errp)
{
Error *err = NULL;+ Visitor *v = NULL;
- (void)args;
+ if (args) {
+ v = qmp_input_visitor_new(QOBJECT(args), true);
+ visit_start_struct(v, NULL, NULL, 0, &err);
+ if (err) {+ goto out;
+ }
+
+ if (!err) {
+ visit_check_struct(v, &err);
+ }
+ visit_end_struct(v, NULL);
+ if (err) {+ goto out;
+ }
+ }
qmp_stop(&err);
+
+out:
error_propagate(errp, err);+ visit_free(v);
+ if (args) {
+ v = qapi_dealloc_visitor_new();
+ visit_start_struct(v, NULL, NULL, 0, NULL);
+
+ visit_end_struct(v, NULL);
+ visit_free(v);
+ }
}
The new code closely resembles code for a command with arguments. Differences:
- the visit of the argument and its cleanup struct don't visit any members (because there are none).
- the visit of the argument struct and its cleanup are conditional.
Message-Id: <[email protected]>
--- scripts/qapi-commands.py | 60 ++++++++++++++++++++++++++++++++++------------- tests/test-qmp-commands.c | 15 ++++++++++++ 2 files changed, 59 insertions(+), 16 deletions(-)
scripts/qapi-commands.py +44 -16
@@ -95,6 +95,8 @@ def gen_marshal_decl(name): def gen_marshal(name, arg_type, boxed, ret_type): + have_args = arg_type and not arg_type.is_empty() + ret = mcgen(''' %(proto)s
@@ -109,17 +111,31 @@ def gen_marshal(name, arg_type, boxed, ret_type): ''', c_type=ret_type.c_type()) - if arg_type and not arg_type.is_empty(): + if have_args: + visit_members = ('visit_type_%s_members(v, &arg, &err);' + % arg_type.c_name()) ret += mcgen(''' Visitor *v; %(c_name)s arg = {0}; +''', + c_name=arg_type.c_name()) + else: + visit_members = '' + ret += mcgen(''' + Visitor *v = NULL; + + if (args) { +''') + push_indent() + + ret += mcgen(''' v = qmp_input_visitor_new(QOBJECT(args), true); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; } - visit_type_%(c_name)s_members(v, &arg, &err); + %(visit_members)s if (!err) { visit_check_struct(v, &err); }
@@ -128,35 +144,47 @@ def gen_marshal(name, arg_type, boxed, ret_type): goto out; } ''', - c_name=arg_type.c_name()) + visit_members=visit_members) - else: + if not have_args: + pop_indent() ret += mcgen(''' - - (void)args; + } ''') ret += gen_call(name, arg_type, boxed, ret_type) - # 'goto out' produced above for arg_type, and by gen_call() for ret_type - if (arg_type and not arg_type.is_empty()) or ret_type: - ret += mcgen(''' + ret += mcgen(''' out: -''') - ret += mcgen(''' error_propagate(errp, err); -''') - if arg_type and not arg_type.is_empty(): - ret += mcgen(''' visit_free(v); +''') + + if have_args: + visit_members = ('visit_type_%s_members(v, &arg, NULL);' + % arg_type.c_name()) + else: + visit_members = '' + ret += mcgen(''' + if (args) { +''') + push_indent() + + ret += mcgen(''' v = qapi_dealloc_visitor_new(); visit_start_struct(v, NULL, NULL, 0, NULL); - visit_type_%(c_name)s_members(v, &arg, NULL); + %(visit_members)s visit_end_struct(v, NULL); visit_free(v); ''', - c_name=arg_type.c_name()) + visit_members=visit_members) + + if not have_args: + pop_indent() + ret += mcgen(''' + } +''') ret += mcgen(''' }
tests/test-qmp-commands.c +15 -0
@@ -106,6 +106,7 @@ static void test_dispatch_cmd(void)static void test_dispatch_cmd_failure (void ) {QDict *req =qdict_new (); +QDict *args =qdict_new ();QObject *resp;qdict_put_obj (req,"execute" ,QOBJECT (qstring_from_str ("user_def_cmd2" )));
@@ -116,6 +117,20 @@ static void test_dispatch_cmd_failure(void)qobject_decref (resp);QDECREF (req); + +/* check that with extra arguments it throws an error */ + req =qdict_new (); +qdict_put (args,"a" ,qint_from_int (66 )); +qdict_put (req,"arguments" , args); + +qdict_put_obj (req,"execute" ,QOBJECT (qstring_from_str ("user_def_cmd" ))); + + resp =qmp_dispatch (QOBJECT (req)); +assert (resp !=NULL ); +assert (qdict_haskey (qobject_to_qdict (resp),"error" )); + +qobject_decref (resp); +QDECREF (req); }static QObject *test_qmp_dispatch (QDict *req)
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 07/18] qmp: Hack to keep commands configuration-specific
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
We currently define QMP commands in two places: the QAPI schema and qmp-commands.hx. The latter is preprocessed, the former is not. We use the preprocessor to suppress configuration-specific commands. For instance, query-spice is only available #ifdef CONFIG_SPICE.
QMP command dispatch and query-commands use the qmp-commands.hx definition, and thus obey the #ifdeffery there. Good, because it lets QMP clients probe for available features more easily.
query-qmp-schema uses the QAPI schema, and thus lists the configuration-specific commands even when they're unavailable. Not so good.
We're about to flip command dispatch and query-commands to the non-middle-mode command registry, which uses the QAPI schema, so we can ditch qmp-commands.hx. To avoid regressing query-commands, arrange for commands that are suppressed with the preprocessor now to be unregistered with that registry. This will keep them unavailable and out of query-commands when we flip command dispatch and query-commands to that registry, exactly as before.
This is a hack. The proper solution is to support configuration-specific commands in the QAPI schema. Mark it FIXME.
Message-Id: <[email protected]>
--- monitor.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
monitor.c +35 -0
@@ -1008,6 +1008,38 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, *ret_data =qobject_from_json (qmp_schema_json); } +/* +* Note: right now, this function is never called. It will be called +* shortly when we stop using QAPI 'middle mode'. The rest of this +* comment is written as if that was the case already. +* +* We used to define commands in qmp-commands.hx in addition to the +* QAPI schema. This permitted defining some of them only in certain +* configurations. query-commands has always reflected that (good, +* because it lets QMP clients figure out what's actually available), +* while query-qmp-schema never did (not so good). This function is a +* hack to keep the configuration-specific commands defined exactly as +* before, even though qmp-commands.hx is gone. +* +* FIXME Educate the QAPI schema on configuration-specific commands, +* and drop this hack. +*/ +static void qmp_unregister_commands_hack (void ) +{ +#ifndef CONFIG_SPICE +qmp_unregister_command ("query-spice" ); +#endif +#ifndef TARGET_I386 +qmp_unregister_command ("rtc-reset-reinjection" ); +#endif +#ifndef TARGET_S390X +qmp_unregister_command ("dump-skeys" ); +#endif +#ifndef TARGET_ARM +qmp_unregister_command ("query-gic-capabilities" ); +#endif +} +static void qmp_init_marshal (void ) { qmp_register_command("query-qmp-schema", qmp_query_qmp_schema,
@@ -1016,6 +1048,9 @@ static void qmp_init_marshal(void) QCO_NO_OPTIONS);qmp_register_command ("netdev_add" , qmp_netdev_add,QCO_NO_OPTIONS ); + +/* call it after the rest of qapi_init() */ +register_module_init (qmp_unregister_commands_hack,MODULE_INIT_QAPI ); }qapi_init (qmp_init_marshal);
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 08/18] qapi: export the marshallers
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
Make it possible to call marshallers manually, without going through qmp_dispatch(). (this is currently only possible in middle-mode, but it's also useful in general)
Message-Id: <[email protected]>
--- scripts/qapi-commands.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
scripts/qapi-commands.py +2 -6
@@ -84,10 +84,7 @@ 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 + return 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) def gen_marshal_decl(name):
@@ -222,8 +219,7 @@ 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.decl += gen_marshal_decl(name) self.defn += gen_marshal(name, arg_type, boxed, ret_type) if not middle_mode: self._regy += gen_register_command(name, success_response)
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 17/18] qmp-commands.hx: fix some styling
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
Add some missing lines, remove superflous @ in command name, remove trailing spaces.
Message-Id: <[email protected]>
--- qmp-commands.hx | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
qmp-commands.hx +18 -16
@@ -91,7 +91,7 @@ eject Eject a removable medium. -Arguments: +Arguments: - force: force ejection (json-bool, optional) - device: device name (json-string)
@@ -1395,7 +1395,6 @@ EQMP }, SQMP - block-dirty-bitmap-add ---------------------- Since 2.4
@@ -1422,7 +1421,6 @@ EQMP }, SQMP - block-dirty-bitmap-remove ------------------------- Since 2.4
@@ -1449,7 +1447,6 @@ EQMP }, SQMP - block-dirty-bitmap-clear ------------------------ Since 2.4
@@ -2176,7 +2173,7 @@ human-monitor-command Execute a Human Monitor command. -Arguments: +Arguments: - command-line: the command name and its arguments, just like the Human Monitor's shell (json-string)
@@ -2988,7 +2985,7 @@ Example: }, "function":0, "regions":[ - + ] }, {
@@ -3005,7 +3002,7 @@ Example: }, "function":0, "regions":[ - + ] }, {
@@ -3467,8 +3464,8 @@ The main json-object contains the following: - "setup-time" amount of setup time in milliseconds _before_ the iterations begin but _after_ the QMP command is issued. This is designed to provide an accounting of any activities - (such as RDMA pinning) which may be expensive, but do not - actually occur during the iterative migration rounds + (such as RDMA pinning) which may be expensive, but do not + actually occur during the iterative migration rounds themselves. (json-int) - "downtime": only present when migration has finished correctly total amount in ms for downtime that happened (json-int)
@@ -4393,8 +4390,8 @@ EQMP }, SQMP -@query-named-block-nodes ------------------------- +query-named-block-nodes +----------------------- Return a list of BlockDeviceInfo for all the named block driver nodes
@@ -4543,7 +4540,7 @@ EQMP }, SQMP -@query-memory-devices +query-memory-devices -------------------- Return a list of memory devices.
@@ -4561,6 +4558,7 @@ Example: "slot": 0}, "type": "dimm" } ] } + EQMP {
@@ -4569,8 +4567,8 @@ EQMP }, SQMP -@query-acpi-ospm-status --------------------- +query-acpi-ospm-status +---------------------- Return list of ACPIOSTInfo for devices that support status reporting via ACPI _OST method.
@@ -4582,6 +4580,7 @@ Example: { "slot": "2", "slot-type": "DIMM", "source": 0, "status": 0}, { "slot": "3", "slot-type": "DIMM", "source": 0, "status": 0} ]} + EQMP #if defined TARGET_I386
@@ -4603,6 +4602,7 @@ Example: -> { "execute": "rtc-reset-reinjection" } <- { "return": {} } + EQMP {
@@ -4634,6 +4634,7 @@ Example: -> { "execute": "trace-event-get-state", "arguments": { "name": "qemu_memalign" } } <- { "return": [ { "name": "qemu_memalign", "state": "disabled" } ] } + EQMP {
@@ -4668,6 +4669,7 @@ Example: -> { "execute": "trace-event-set-state", "arguments": { "name": "qemu_memalign", "enable": "true" } } <- { "return": {} } + EQMP {
@@ -4676,8 +4678,8 @@ EQMP }, SQMP -@input-send-event ------------------ +input-send-event +---------------- Send input event to guest.
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 16/18] build-sys: remove qmp-commands-old.h
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
--- Makefile.target | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Makefile.target +2 -5
@@ -156,7 +156,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
@@ -209,13 +209,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: clean-target 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.5.5
[Qemu-devel] [PULL 09/18] monitor: use qmp_find_command() (using generated qapi code)
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
Stop using the so-called 'middle' mode. Instead, use qmp_find_command() from generated qapi commands registry. Update and fix the documentation too.
Message-Id: <[email protected]>
--- Makefile | 2 +- docs/writing-qmp-commands.txt | 8 +-- monitor.c | 14 ++-- qmp-commands.hx | 146 ------------------------------------------ vl.c | 1 + 5 files changed, 11 insertions(+), 160 deletions(-)
Makefile +1 -1
@@ -312,7 +312,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)
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
@@ -454,12 +452,11 @@ 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: +The last step is to add the corresponding 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, + .mhandler.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
monitor.c +7 -7
@@ -1009,10 +1009,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, }/* -* Note: right now, this function is never called. It will be called -* shortly when we stop using QAPI 'middle mode'. The rest of this -* comment is written as if that was the case already. -* * We used to define commands in qmp-commands.hx in addition to the * QAPI schema. This permitted defining some of them only in certain * configurations. query-commands has always reflected that (good,
@@ -3976,6 +3972,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;
@@ -4001,7 +3998,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;
@@ -4023,7 +4021,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);
@@ -4095,7 +4093,9 @@ static QObject *get_qmp_greeting(void)QObject *ver =NULL ;qmp_marshal_query_version (NULL , &ver,NULL ); -return qobject_from_jsonf ("{'QMP':{'version': %p,'capabilities': []}}" ,ver); + +return qobject_from_jsonf ("{'QMP': {'version': %p, 'capabilities': []}}" , + ver); }static void monitor_qmp_event (void *opaque,int event)
qmp-commands.hx +0 -146
985 lines not on this page · raw message
vl.c +1 -0
@@ -2987,6 +2987,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.5.5
[Qemu-devel] [PULL 15/18] monitor: use qmp_dispatch()
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
Replace the old manual dispatch and validation code by the generic one provided by qapi common code.
Note that it is now possible to call the following commands that used to be disabled by compile-time conditionals:
- dump-skeys
- query-spice
- rtc-reset-reinjection
- query-gic-capabilities
Their fallback functions return an appropriate "feature disabled" error.
Message-Id: <[email protected]>
--- monitor.c | 328 +++++++---------------------------------------------------- trace-events | 1 - 2 files changed, 35 insertions(+), 294 deletions(-)
monitor.c +35 -293
@@ -166,7 +166,6 @@ struct MonFdset { }; typedef struct { - QObject *id; JSONMessageParser parser; /* * When a client connects, we're in capabilities negotiation mode.
@@ -229,8 +228,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 ;
@@ -401,49 +398,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 },
@@ -2211,11 +2165,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;
@@ -2566,11 +2515,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.
@@ -3722,199 +3666,6 @@ static bool invalid_qmp_mode(const Monitor *mon, const char *cmd, }/* -* 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 * * 1. Input object must be a dict
@@ -3972,67 +3723,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)) { - goto err_out; - } - - obj =qdict_get (input,"arguments" ); -if (!obj) { - args =qdict_new (); - }else { - args =qobject_to_qdict (obj); -QINCREF (args); - } -qmp_check_client_args (cmd, args, &local_err); -if (local_err) { +if (invalid_qmp_mode (mon, cmd_name, &err)) { goto err_out; } - qcmd->fn (args, &data, &local_err); + rsp =qmp_dispatch (req); err_out: -monitor_protocol_emitter (mon, data, local_err); -qobject_decref (data); -error_free (local_err); -QDECREF (input); -QDECREF (args); +if (err) { + qdict =qdict_new (); +qdict_put_obj (qdict,"error" ,qmp_build_error_object (err)); +error_free (err); + rsp =QOBJECT (qdict); + } + +if (rsp) { +if (id) { +qdict_put_obj (qobject_to_qdict (rsp),"id" , id); + id =NULL ; + } + +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
@@ -98,7 +98,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.5.5
[Qemu-devel] [PULL 18/18] Replace qmp-commands.hx by docs/qmp-commands.txt
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
The only remaining function of qmp-commands.hx is to let us generate qmp-commands.txt from it. Replace qmp-commands.hx by qmp-commands.txt.
We intend to move the documentation into the QAPI schema and generate qapi-commands.txt from it, but not right now.
Message-Id: <[email protected]>
--- .gitignore | 1 - MAINTAINERS | 1 - Makefile | 6 +- docs/qapi-code-gen.txt | 6 +- qmp-commands.hx => docs/qmp-commands.txt | 1127 ------------------------------ docs/writing-qmp-commands.txt | 38 - 6 files changed, 4 insertions(+), 1175 deletions(-) rename qmp-commands.hx => docs/qmp-commands.txt (87%)
.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 +0 -1
@@ -1235,7 +1235,6 @@ M: Markus Armbruster <[email protected]> S: Supported F: qmp.c F: monitor.c -F: qmp-commands.hx F: docs/*qmp-* F: scripts/qmp/ T: git git://repo.or.cz/qemu/armbru.git qapi-next
Makefile +1 -5
@@ -92,7 +92,6 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF) ifdef BUILD_DOCS DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 -DOCS+=qmp-commands.txt ifdef CONFIG_VIRTFS DOCS+=fsdev/virtfs-proxy-helper.1 endif
@@ -432,7 +431,7 @@ endif install-doc: $(DOCS) $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)" $(INSTALL_DATA) qemu-doc.html qemu-tech.html "$(DESTDIR)$(qemu_docdir)" - $(INSTALL_DATA) qmp-commands.txt "$(DESTDIR)$(qemu_docdir)" + $(INSTALL_DATA) docs/qmp-commands.txt "$(DESTDIR)$(qemu_docdir)" ifdef CONFIG_POSIX $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" $(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
@@ -555,9 +554,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/qmp-commands.txt renamed from qmp-commands.hx +0 -1127
1,869 lines not on this page · raw message
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 corresponding 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:
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 11/18] monitor: remove mhandler.cmd_new
In reply to Markus ArmbrusterFrom: Marc-André Lureau <[email protected]>
This is no longer necessary now that we aren't using middle mode anymore.
Message-Id: <[email protected]>
--- docs/writing-qmp-commands.txt | 4 +- hmp-commands-info.hx | 118 ++++++++++++------------ hmp-commands.hx | 208 +++++++++++++++++++++--------------------- monitor.c | 13 +-- 4 files changed, 170 insertions(+), 173 deletions(-)
docs/writing-qmp-commands.txt +2 -2
@@ -335,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
@@ -515,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.cmd = hmp_info_alarm_clock, + .cmd = hmp_info_alarm_clock, }, To test this, run qemu and type "info alarmclock" in the user monitor.
hmp-commands-info.hx +59 -59
452 lines not on this page · raw message
hmp-commands.hx +104 -104
826 lines not on this page · raw message
monitor.c +5 -8
@@ -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; -/* @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. +void (*cmd)(Monitor *mon,const QDict *qdict); +/* @sub_table is a list of 2nd level of commands. If it does not exist, +* cmd should be used. If it exists, 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);
@@ -3005,7 +3002,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.5.5
Peter Maydell
AppliedQuoted 8 lines · Markus Armbruster
The following changes since commit
e3571ae30cd26d19efd4554c25e32ef64d6a36b3:Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20160916' into staging (2016-09-16 16:54:50 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/armbru.gittags/pull-qapi-2016-09-19
Quoted 8 lines
for you to fetch changes up to
bd6092e407a5d682fbfddcbc510038b84bc1a1aa:Replace qmp-commands.hx by
docs/qmp-commands.txt(2016-09-19 18:27:37 +0200)----------------------------------------------------------------
QAPI patches for 2016-09-19----------------------------------------------------------------
Applied, thanks.
-- PMM