From: Markus Armbruster <armbru@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: berrange@redhat.com, qemu-devel@nongnu.org, clg@kaod.org,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
afaerber@suse.de
Subject: Re: [PATCH 2/2] hmp: Simplify qom_set
Date: Fri, 29 May 2020 08:20:00 +0200 [thread overview]
Message-ID: <871rn3p8j3.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20200528140644.GG3069@work-vm> (David Alan Gilbert's message of "Thu, 28 May 2020 15:06:44 +0100")
"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:
> * Markus Armbruster (armbru@redhat.com) wrote:
>> "Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:
>>
>> > * Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
>> >> On 5/20/20 5:11 PM, Dr. David Alan Gilbert (git) wrote:
>> >> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>> >> >
>> >> > Simplify qom_set by making it use qmp_qom_set and the JSON parser.
>> >> >
>> >> > Note that qom-set likes JSON strings quoted with ' not ", e.g.:
>> >> >
>> >> > (qemu) qom-get /machine smm
>> >> > "auto"
>> >> > (qemu) qom-set /machine smm 'auto'
>> >>
>> >> Will I get this output using "?
>> >>
>> >> (qemu) qom-set /machine smm "auto"
>> >> Error: Expecting a JSON value
>> >
>> > The error you get is:
>> >
>> > (qemu) qom-set /machine smm "auto"
>> > Error: JSON parse error, invalid keyword 'auto'
>> >
>> > I think, having seen alphanumerics, it's expecting a keyword;
>> > i.e. a true/false making a bool, or a null.
>>
>> The command parses its argument as JSON.
>>
>> Before we get there, the HMP core extracts the argument from the line of
>> input. The extraction is guided by the command's .args_type, in this
>> case the 's' in "value:s" in
>>
>> {
>> .name = "qom-set",
>> .args_type = "path:s,property:s,value:s",
>> [...]
>> },
>>
>> monitor/monitor-internal.h documents type code 's' as
>>
>> * 's' string (accept optional quote)
>>
>> The implementation boils down to:
>>
>> 1. Skip whitespace.
>>
>> 2. If looking at '"', get the string enclosed in '"', with C-like escape
>> sequences \n, \r, \\, \', \".
>>
>> 3. Else, get the string up to the next whitespace.
>>
>> See get_str().
>>
>> Therefore, argument "auto" is the same as auto. Parsing auto as JSON
>> duly fails.
>>
>> Argument 'auto' works, but only because qobject_from_json() recognizes
>> single-quoted strings. This is as extension over RFC 8259.
>>
>> Using single quotes falls apart when you want to pass something
>> containing whitespace. Then you'd have to use
>>
>> "\"ugly and unintuitive\""
>>
>> or, again relying on the extension
>>
>> "'ugly and unintuitive'"
>>
>> There's a better way, and Paolo pointed it out in
>>
>> Subject: Re: [RFC PATCH] qom: Implement qom-get HMP command
>> Date: Thu, 21 May 2020 16:24:12 +0200
>> Message-ID: <2c148331-78ae-31f7-8702-d65c37a090b0@redhat.com>
>>
>> Use argument type 'S'. Documented as
>>
>> * 'S' it just appends the rest of the string (accept optional quote)
>>
>> but the parenthesis is confusing. It really just skips whitespace, then
>> extracts the remainder of the line. Can't do string with leading
>> whitespace, but that's just fine for us.
>
> Yep, thanks - I spotted Paolo's response but thanks for the deeper
> explanation.
> With that would you give me a Review-by?
Also fix the typo in the title "hmp: Simplify qom_set": it's qom-set.
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2020-05-29 6:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 15:11 [PATCH 0/2] HMP: qom-get and set Dr. David Alan Gilbert (git)
2020-05-20 15:11 ` [PATCH 1/2] hmp: Implement qom-get HMP command Dr. David Alan Gilbert (git)
2020-05-20 16:44 ` Philippe Mathieu-Daudé
2020-05-25 9:02 ` Markus Armbruster
2020-05-29 6:59 ` Markus Armbruster
2020-05-20 15:11 ` [PATCH 2/2] hmp: Simplify qom_set Dr. David Alan Gilbert (git)
2020-05-20 16:47 ` Philippe Mathieu-Daudé
2020-05-20 19:03 ` Dr. David Alan Gilbert
2020-05-25 8:54 ` Markus Armbruster
2020-05-28 14:06 ` Dr. David Alan Gilbert
2020-05-28 15:12 ` Philippe Mathieu-Daudé
2020-05-29 6:20 ` Markus Armbruster [this message]
2020-05-29 9:07 ` Dr. David Alan Gilbert
2020-05-29 18:48 ` [PATCH 0/2] HMP: qom-get and set Dr. David Alan Gilbert
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=871rn3p8j3.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.