[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 07/28] qmp: Clean up how we enforce capabilit
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v4 07/28] qmp: Clean up how we enforce capability negotiation |
Date: |
Fri, 3 Mar 2017 12:40:57 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 03/03/2017 06:32 AM, Markus Armbruster wrote:
> To enforce capability negotiation before normal operation,
> handle_qmp_command() inspects every command before it's handed off to
> qmp_dispatch(). This is a bit of a layering violation, and results in
> duplicated code.
>
> Before capability negotiation (!cur_mon->in_command_mode), we fail
> commands other than "qmp_capabilities". This is what enforces
> capability negotiation.
>
> Afterwards, we fail command "qmp_capabilities".
>
> Clean this up as follows.
>
> The obvious place to fail a command is the command itself, so move the
> "afterwards" check to qmp_qmp_capabilities().
>
> We do the "before" check in every other command, but that would be
> bothersome. Instead, start with an alternate list of commant that
s/commant/commands/
> contains only "qmp_capabilities". Switch to the full list in
> qmp_qmp_capabilities().
>
> Additionally, replace the generic human-readable error message for
> CommandNotFound by one that reminds the user to run qmp_capabilities.
> Without that, we'd regress commit 2d5a834.
>
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
> monitor.c | 76
> +++++++++++++++++++++++++++++++++++----------------------------
> 1 file changed, 42 insertions(+), 34 deletions(-)
>
> @@ -3786,11 +3785,20 @@ static void handle_qmp_command(JSONMessageParser
> *parser, GQueue *tokens)
> cmd_name = qdict_get_str(qdict, "execute");
> trace_handle_qmp_command(mon, cmd_name);
>
> - if (invalid_qmp_mode(mon, cmd_name, &err)) {
> - goto err_out;
> - }
> + rsp = qmp_dispatch(cur_mon->qmp.commands, req);
>
> - rsp = qmp_dispatch(&qmp_commands, req);
> + qdict = qdict_get_qdict(qobject_to_qdict(rsp), "error");
> + if (qdict) {
> + if (mon->qmp.commands == &qmp_cap_negotiation_commands
> + && !g_strcmp0(qdict_get_try_str(qdict, "class"),
> + QapiErrorClass_lookup[ERROR_CLASS_COMMAND_NOT_FOUND])) {
Could join these two 'if' into one, for less {}, but that's cosmetic.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v4 24/28] test-qobject-input-visitor: Cover missing nested struct member, (continued)
- [Qemu-devel] [PATCH v4 24/28] test-qobject-input-visitor: Cover missing nested struct member, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 28/28] qapi: Improve qobject visitor documentation, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 21/28] test-string-input-visitor: Tear down existing test automatically, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 19/28] qapi: Drop unused non-strict qobject input visitor, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 02/28] libqtest: Work around a "QMP wants a newline" bug, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 22/28] test-string-input-visitor: Improve list coverage, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 14/28] qapi: Improve qobject input visitor error reporting, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 20/28] tests-qobject-input-strict: Merge into test-qobject-input-visitor, Markus Armbruster, 2017/03/03
- [Qemu-devel] [PATCH v4 07/28] qmp: Clean up how we enforce capability negotiation, Markus Armbruster, 2017/03/03
- Re: [Qemu-devel] [PATCH v4 07/28] qmp: Clean up how we enforce capability negotiation,
Eric Blake <=
- [Qemu-devel] [PATCH v4 16/28] qapi: Make string input and opts visitor require non-null input, Markus Armbruster, 2017/03/03
[Qemu-devel] [PATCH v4 05/28] qapi: Support multiple command registries per program, Markus Armbruster, 2017/03/03