From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Markus Armbruster <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
qemu-devel@nongnu.org, Yanan Wang <wangyanan55@huawei.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eric Farman <farman@linux.ibm.com>,
Thomas Huth <thuth@redhat.com>, Eric Blake <eblake@redhat.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
qemu-s390x@nongnu.org, Eduardo Habkost <eduardo@habkost.net>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
David Hildenbrand <david@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [RFC PATCH 2/3] monitor: Allow passing HMP arguments to QMP HumanReadableText API
Date: Mon, 10 Jun 2024 19:26:33 +0100 [thread overview]
Message-ID: <ZmdFWdtTyhqoRREK@redhat.com> (raw)
In-Reply-To: <20240610175852.21215-3-philmd@linaro.org>
On Mon, Jun 10, 2024 at 07:58:51PM +0200, Philippe Mathieu-Daudé wrote:
> Allow HMP commands implemented using the HumanReadableText API
> (via the HMPCommand::cmd_info_hrt handler) to pass arguments
> to the QMP equivalent command. The arguments are serialized as
> a JSON dictionary.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> docs/devel/writing-monitor-commands.rst | 15 ++++++++++++++-
> qapi/machine.json | 24 ++++++++++++++++++++++++
> include/monitor/monitor.h | 3 ++-
> monitor/monitor-internal.h | 2 +-
> accel/tcg/monitor.c | 4 ++--
> hw/core/loader.c | 2 +-
> hw/core/machine-qmp-cmds.c | 9 +++++----
> hw/usb/bus.c | 2 +-
> monitor/hmp-target.c | 3 ++-
> monitor/hmp.c | 11 +++++++----
> 10 files changed, 59 insertions(+), 16 deletions(-)
>
> diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
> index 930da5cd06..843458e52c 100644
> --- a/docs/devel/writing-monitor-commands.rst
> +++ b/docs/devel/writing-monitor-commands.rst
> @@ -561,6 +561,7 @@ returns a ``HumanReadableText``::
> # Since: 6.2
> ##
> { 'command': 'x-query-roms',
> + 'data': { 'json-args': 'str'},
> 'returns': 'HumanReadableText',
> 'features': [ 'unstable' ] }
>
> @@ -578,7 +579,7 @@ Implementing the QMP command
> The QMP implementation will typically involve creating a ``GString``
> object and printing formatted data into it, like this::
>
> - HumanReadableText *qmp_x_query_roms(Error **errp)
> + HumanReadableText *qmp_x_query_roms(const char *json_args, Error **errp)
> {
> g_autoptr(GString) buf = g_string_new("");
> Rom *rom;
> @@ -596,6 +597,18 @@ object and printing formatted data into it, like this::
> The actual implementation emits more information. You can find it in
> hw/core/loader.c.
>
> +For QMP command taking (optional) parameters, these parameters are
> +serialized as a JSON dictionary, and can be retrieved using the QDict
> +API. If the previous ``x-query-roms`` command were taking a "index"
> +argument, it could be retrieved as::
> +
> + HumanReadableText *qmp_x_query_roms(const char *json_args, Error **errp)
> + {
> + g_autoptr(GString) buf = g_string_new("");
> + QDict *qdict = qobject_to(QDict, qobject_from_json(json_args, &error_abort));
> + uint64_t index = qdict_get_int(qdict, "index");
> + ...
> + }
Passing json inside json is pretty gross, and throwing away a key
benefit of QAPI - that it de-serializes the JSON into the actual
data types that you need, avoiding manual & error prone code for
unpacking args from a QDict.
IMHO if a commend requires arguments, they should be modelled
explicitly, and not use the cmd_info_hrt convenience handler
which was only ever intended simple for no-arg 'info' commands.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2024-06-10 18:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 17:58 [RFC PATCH 0/3] monitor: Pass HMP arguments to QMP HumanReadableText API as JSON Philippe Mathieu-Daudé
2024-06-10 17:58 ` [PATCH 1/3] hw/s390x: Declare target specific monitor commands in hmp-target.h Philippe Mathieu-Daudé
2024-06-10 21:02 ` Dr. David Alan Gilbert
2024-06-10 17:58 ` [RFC PATCH 2/3] monitor: Allow passing HMP arguments to QMP HumanReadableText API Philippe Mathieu-Daudé
2024-06-10 18:26 ` Daniel P. Berrangé [this message]
2024-06-10 17:58 ` [RFC PATCH 3/3] hw/s390x: Introduce x-query-s390x-cmma QMP command Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZmdFWdtTyhqoRREK@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=dave@treblig.org \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.