chardev: Add -qmp-pretty
v4 cover chardev: Add -qmp-pretty
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=on
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Patch 3 makes uses of the new option in qemu-iotest 067 to greatly increase maintainability of its reference output. Patch 2 extends the QMP filter for qemu-iotests so it is able to filter out the QMP version object in pretty mode.
v4:
- Patch 2: Add newline in sed script after c\ [Eric]
v3:
- Patch 2: Cull useless "discard=0"
v2:
- Patch 2: Replaced the multi-line QMP_VERSION replacement written in bash by a nice sed script [Eric]
git-backport-diff against v3:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/3:[----] [--] 'chardev: Add -qmp-pretty' 002/3:[0003] [FC] 'iotests: _filter_qmp for pretty JSON output' 003/3:[----] [--] 'iotests: Use -qmp-pretty in 067'
Max Reitz (3):
chardev: Add -qmp-pretty
iotests: _filter_qmp for pretty JSON output
iotests: Use -qmp-pretty in 067
qemu-options.hx | 8 + tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 ++++++++++++++++++++++++++++++++++++--- tests/qemu-iotests/common.filter | 4 +- vl.c | 15 +- 5 files changed, 744 insertions(+), 64 deletions(-)
Signature · 1 line
1.9.3
PATCH v4 1/3 chardev: Add -qmp-pretty
Add a command line option for adding a QMP monitor using pretty JSON formatting.
--- qemu-options.hx | 8 ++++++++ vl.c | 15 ++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
qemu-options.hx +8 -0
@@ -2788,6 +2788,14 @@ STEXI @findex -qmp Like -monitor but opens in 'control' mode. ETEXI +DEF("qmp-pretty", HAS_ARG, QEMU_OPTION_qmp_pretty, \ + "-qmp-pretty dev like -qmp but uses pretty JSON formatting\n", + QEMU_ARCH_ALL) +STEXI +@item -qmp-pretty @var{dev} +@findex -qmp-pretty +Like -qmp but uses pretty JSON formatting. +ETEXI DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ "-mon [chardev=]name[,mode=readline|control][,default]\n", QEMU_ARCH_ALL)
vl.c +10 -5
@@ -2284,7 +2284,7 @@ static int mon_init_func(QemuOpts *opts, void *opaque)return 0 ; } -static void monitor_parse (const char *optarg,const char *mode) +static void monitor_parse (const char *optarg,const char *mode,bool pretty) {static int monitor_device_index =0 ;QemuOpts *opts;
@@ -2314,6 +2314,7 @@ static void monitor_parse(const char *optarg, const char *mode) }qemu_opt_set (opts,"mode" , mode);qemu_opt_set (opts,"chardev" , label); +qemu_opt_set_bool (opts,"pretty" , pretty);if (def)qemu_opt_set (opts,"default" ,"on" ); monitor_device_index++;
@@ -3292,11 +3293,15 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_monitor: default_monitor =0 ;if (strncmp (optarg,"none" ,4 )) { -monitor_parse (optarg,"readline" ); +monitor_parse (optarg,"readline" , false); }break ;case QEMU_OPTION_qmp: -monitor_parse (optarg,"control" ); +monitor_parse (optarg,"control" , false); + default_monitor =0 ; +break ; +case QEMU_OPTION_qmp_pretty: +monitor_parse (optarg,"control" , true); default_monitor =0 ;break ;case QEMU_OPTION_mon:
@@ -3994,7 +3999,7 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_SCLP ,"stdio" ); }if (default_monitor) -monitor_parse ("stdio" ,"readline" ); +monitor_parse ("stdio" ,"readline" , false); } }else {if (default_serial)
@@ -4002,7 +4007,7 @@ int main(int argc, char **argv, char **envp)if (default_parallel)add_device_config (DEV_PARALLEL ,"vc:80Cx24C" );if (default_monitor) -monitor_parse ("vc:80Cx24C" ,"readline" ); +monitor_parse ("vc:80Cx24C" ,"readline" , false);if (default_virtcon)add_device_config (DEV_VIRTCON ,"vc:80Cx24C" );if (default_sclp) {
Signature · 1 line
1.9.3
PATCH v4 2/3 iotests: _filter_qmp for pretty JSON output
In reply to Max Reitz_filter_qmp should be able to correctly filter out the QMP version object for pretty JSON output.
--- tests/qemu-iotests/common.filter | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.filter +3 -1
@@ -167,7 +167,9 @@ _filter_qmp() { _filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\' \ + -e ' QMP_VERSION' } # replace driver-specific options in the "Formatting..." line
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 13 lines · Max Reitz
_filter_qmpshould be able to correctly filter out the QMP version object for pretty JSON output.Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/common.filter | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +0
-0
tests/qemu-iotests/common.filter _filter_qmp() · line 171
Quoted 6 lines
tests/qemu-iotests/common.filter +2
-1@@ -167,7 +167,9 @@ _filter_qmp() { _filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\' \
\s is a GNU sed extension. But we don't really need to care about whitespace to the end of the line; I think that it is sufficient to just match the following regex:
-e '/^ "QMP": {/, /^ }/ c\' \
tests/qemu-iotests/common.filter _filter_qmp() · line 172
Quoted 1 line
tests/qemu-iotests/common.filter +1
-0+ -e ' QMP_VERSION'
Either way, it's not the first time we've used a GNU sed extension, and since other series are now depending on this one, I can live with:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 24 lines · Eric Blake
Quoted 13 lines · Max Reitz
_filter_qmpshould be able to correctly filter out the QMP version object for pretty JSON output.Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/common.filter | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/qemu-iotests/common.filter +0
-0tests/qemu-iotests/common.filter _filter_qmp() · line 171
Quoted 6 lines
tests/qemu-iotests/common.filter +2
-1@@ -167,7 +167,9 @@ _filter_qmp() { _filter_win32 | \ sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ - -e 's#^{"QMP":.*}$#QMP_VERSION#' + -e 's#^{"QMP":.*}$#QMP_VERSION#' \ + -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\' \\s is a GNU sed extension. But we don't really need to care about whitespace to the end of the line; I think that it is sufficient to just match the following regex:
Quoted 1 line
-e '/^ "QMP": {/, /^ }/ c\' \
That doesn't match, however. QEMU's JSON formatter sometimes outputs whitespace at the end of line.
Quoted 3 lines
tests/qemu-iotests/common.filter _filter_qmp() · line 172
Quoted 1 line
tests/qemu-iotests/common.filter +1
-0+ -e ' QMP_VERSION'Either way, it's not the first time we've used a GNU sed extension, and since other series are now depending on this one, I can live with:
Ooooh, you mean version 3 was actually fine? (which used 'c\' without a line break) ;-)
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thank you!
Max
Re: [Qemu-devel] [PATCH v4 2/3] iotests: _filter_qmp for pretty JSON output
Quoted 9 lines · Max Reitz
Quoted 6 lines
Quoted 1 line
+ -e '/^ "QMP": {\s*$/, /^ }\s*$/ c\' \
\s is a GNU sed extension. But we don't really need to care about whitespace to the end of the line; I think that it is sufficient to just match the following regex:
-e '/^ "QMP": {/, /^ }/ c\' \
That doesn't match, however. QEMU's JSON formatter sometimes outputs whitespace at the end of line.
No, I explicitly omitted the $. The lines match because they are anchored to the beginning, regardless of trailing whitespace at the end.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
+ -e '
QMP_VERSION'Either way, it's not the first time we've used a GNU sed extension, and since other series are now depending on this one, I can live with:
Ooooh, you mean version 3 was actually fine? (which used 'c\' without a line break) ;-)
I'm more comfortable with v4 than v3 (\s is well-known, and can be easily converted into an alternative if someone proves their system doesn't support it. But c\ is not well-known; and reading 'info sed' to learn about c\ only documents its use with a newline; so using c\
without a newline is relying on undocumented GNU behavior, which is very risky). Of course, a v5 that avoids \s would avoid any confusion, but now we're bikeshedding, and I'm not sure it's worth the time.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v4 3/3 iotests: Use -qmp-pretty in 067
In reply to Max Reitz067 invokes query-block, resulting in a reference output with really long lines (which may pose a problem in email patches and always poses a problem when the output changes, because it is hard to see what has actually changed). Use -qmp-pretty to mitigate this issue.
--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)
tests/qemu-iotests/067 +1 -1
@@ -39,7 +39,7 @@ _supported_os Linux function do_run_qemu() { echo Testing: "$@" - $QEMU -nographic -qmp stdio -serial none "$@" + $QEMU -nographic -qmp-pretty stdio -serial none "$@" echo }
tests/qemu-iotests/067.out +722 -57
799 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 3/3] iotests: Use -qmp-pretty in 067
Am 17.11.2014 um 13:31 hat Max Reitz geschrieben:
Quoted 11 lines
067 invokes query-block, resulting in a reference output with really long lines (which may pose a problem in email patches and always poses a problem when the output changes, because it is hard to see what has actually changed). Use -qmp-pretty to mitigate this issue.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)
Hm, when I tried to rebase my query-block patch that adds cache information, I noticed that I get a trailing space on every line of the JSON dump, which isn't there in this patch. So 'cp 067.out.bad 067.out' ended up changing every single line. :-/
Did you postprocess the reference output or do really get it without trailing whitespace?
Kevin
Re: [Qemu-devel] [PATCH v4 3/3] iotests: Use -qmp-pretty in 067
Quoted 12 lines · Kevin Wolf
Am 17.11.2014 um 13:31 hat Max Reitz geschrieben:
Quoted 11 lines
067 invokes query-block, resulting in a reference output with really long lines (which may pose a problem in email patches and always poses a problem when the output changes, because it is hard to see what has actually changed). Use -qmp-pretty to mitigate this issue.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)
Quoted 7 lines
Hm, when I tried to rebase my query-block patch that adds cache information, I noticed that I get a trailing space on every line of the JSON dump, which isn't there in this patch. So 'cp 067.out.bad 067.out' ended up changing every single line. :-/
Did you postprocess the reference output or do really get it without trailing whitespace?
Yes, I post-processed it, because you once complained about me sending patches with trailing whitespace. :-P
As I wrote in some reply to some reply from Eric on some version of this patch, QEMU's pretty JSON formatter emits whitespace at the end of some lines.
Max
Re: [Qemu-devel] [PATCH v4 3/3] iotests: Use -qmp-pretty in 067
Quoted 22 lines · Max Reitz
Quoted 13 lines · Kevin Wolf
Am 17.11.2014 um 13:31 hat Max Reitz geschrieben:
Quoted 5 lines
067 invokes query-block, resulting in a reference output with really long lines (which may pose a problem in email patches and always poses a problem when the output changes, because it is hard to see what has actually changed). Use -qmp-pretty to mitigate this issue.
Quoted 7 lines
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>--- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 779 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 723 insertions(+), 58 deletions(-)Quoted 7 lines
Hm, when I tried to rebase my query-block patch that adds cache information, I noticed that I get a trailing space on every line of the JSON dump, which isn't there in this patch. So 'cp 067.out.bad 067.out' ended up changing every single line. :-/
Did you postprocess the reference output or do really get it without trailing whitespace?
Quoted 6 lines
Yes, I post-processed it, because you once complained about me sending patches with trailing whitespace. :-P
As I wrote in some reply to some reply from Eric on some version of this patch, QEMU's pretty JSON formatter emits whitespace at the end of some lines.
Trailing whitespace in canonical sources is annoying and should be avoided. But this file is about trailing whitespace in generated files (such as reference output) and which is therefore worth keeping, unless we fix the cause of the reference material having trailing whitespace in the first place. That way, we can regenerate the file from the same reference source, and won't have needless differences in trailing whitespace. Sounds like a bug in the JSON pretty formatter, but fixing it should be a separate series.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Kevin Wolf
AppliedAm 17.11.2014 um 13:31 hat Max Reitz geschrieben:
Quoted 14 lines
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=onHowever, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Quoted 4 lines
Patch 3 makes uses of the new option in qemu-iotest 067 to greatly increase maintainability of its reference output. Patch 2 extends the QMP filter for qemu-iotests so it is able to filter out the QMP version object in pretty mode.
Thanks, applied to block-next.
Kevin
Copying Luiz.
Quoted 5 lines · Max Reitz
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=on
Quoted 7 lines
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Yet another "convenience" option *groan*
Why can't we simply make -qmp set pretty=on and be done with it? It's a convenience option, i.e. meant for humans, and why would humans *not* want pretty=on?
Quoted 17 lines · Markus Armbruster
Copying Luiz.
Quoted 5 lines · Max Reitz
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=onQuoted 7 lines
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Quoted 5 lines
Yet another "convenience" option *groan*
Why can't we simply make -qmp set pretty=on and be done with it? It's a convenience option, i.e. meant for humans, and why would humans *not* want pretty=on?
Agreed, it is valid JSON anyway so there is no backwards compatibility issue.
Paolo
Quoted 16 lines · Markus Armbruster
Copying Luiz.
Quoted 5 lines · Max Reitz
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=onQuoted 7 lines
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Quoted 5 lines
Yet another "convenience" option *groan*
Why can't we simply make -qmp set pretty=on and be done with it? It's a convenience option, i.e. meant for humans, and why would humans *not* want pretty=on?
Well, pretty=on produces really long output. I prefer short output if I don't expect to run commands like query-block which are completely unreadable with pretty=off.
I personally had a really bad taste when I saw that I couldn't modify -qmp somehow to get it to set pretty=on optionally. But then, after having implemented -qmp-pretty in basically five lines (the "case" statement for that option and the qemu_opt_set_bool() in monitor_parse()), I could send the series with a clear conscience. It's not that there's a new convenience option which is really bad to maintain and will break after the first gentle blow, as it reuses all the code paths from -qmp, which we will keep anyway.
Since this is only in block-next, I wouldn't object to it being dropped and making pretty=on the default for -qmp, in principle. But I personally like having a convenience pretty=off option, too, because I as a human often actually don't want pretty=on.
Max
Quoted 27 lines · Max Reitz
Quoted 16 lines · Markus Armbruster
Copying Luiz.
Quoted 5 lines · Max Reitz
This series does not add new functionality. Adding a QMP monitor with prettily formatted JSON output can be done as follows:
$ qemu -chardev stdio,id=mon0 -mon chardev=mon0,mode=control,pretty=onQuoted 7 lines
However, this is rather cumbersome, so this series (its first patch) adds a shortcut in the form of the new command line option -qmp-pretty.
Since the argument given to a monitor command line option (such as -qmp) is parsed depending on its prefix and probably also depending on the current phase of the moon, this is cleaner than trying to add a "switch" to -qmp itself (in the form of "-qmp stdio,pretty=on").
Quoted 5 lines
Yet another "convenience" option *groan*
Why can't we simply make -qmp set pretty=on and be done with it? It's a convenience option, i.e. meant for humans, and why would humans *not* want pretty=on?
Well, pretty=on produces really long output. I prefer short output if I don't expect to run commands like query-block which are completely unreadable with pretty=off.
Quoted 8 lines
I personally had a really bad taste when I saw that I couldn't modify -qmp somehow to get it to set pretty=on optionally. But then, after having implemented -qmp-pretty in basically five lines (the "case" statement for that option and the
qemu_opt_set_bool()inmonitor_parse()), I could send the series with a clear conscience. It's not that there's a new convenience option which is really bad to maintain and will break after the first gentle blow, as it reuses all the code paths from -qmp, which we will keep anyway.
The implementation complexity doesn't worry me. I dislike the interface complexity. We're stuck with two sugar options around -mon, but adding a *third* is pushing it too far for me.
Quoted 4 lines
Since this is only in block-next, I wouldn't object to it being dropped and making pretty=on the default for -qmp, in principle. But I personally like having a convenience pretty=off option, too, because I as a human often actually don't want pretty=on.
-set mon.compat_monitor0.pretty=off ;-P
Alternatively, define a pretty and an ugly monitor in a configuration file, and connect to the one you want:
[chardev "qmp"]
backend = "socket"
path = "sock-qmp"
server = "on"
wait = "off"
[mon "qmp"]
mode = "control"
chardev = "qmp"
pretty = "off"
[chardev "qmp-pretty"]
backend = "socket"
path = "sock-qmp-pretty"
server = "on"
wait = "off"
[mon "qmp-pretty"]
mode = "control"
chardev = "qmp-pretty"
pretty = "on"
Alternatively^2, create a QMP command to toggle prettiness.