qemu-option, keyval, vl: switch -object/-M/-accel to keyval parsing
cover qemu-option, keyval, vl: switch -object/-M/-accel to keyval parsing
This series switches -object, -M and -accel from QemuOpts to keyval. Monitor commands device_add and netdev_add are also switched to keyval, though -device and -netdev for now are not.
Along the way, the syntax of keyval and QemuOpts becomes more consistent and support for keyval-based options is added to -readconfig. -writeconfig instead is removed (see patch 13 for rationale).
The reason to do this is:
- to make qemu-io, qemu-nbd, qemu-img and QEMU's parsing of -object consistent with qemu-storage-daemon's
- to allow using compound properties in -object, -M and -accel
Patch 1-3: make QemuOpts parsing a bit more restrictive, warning for short-form boolean options and removing weird ways to request help such as "help=foo" or "no?".
Patch 4-10: let keyval accept escaped commas in implied options, switch comma-separated syntax for HMP from QemuOpts to keyval, add help support to object_add
Patch 11-16: plumbing for reading keyval-based options in vl.c, including -set and -readconfig. The patches up to this point are the ones that I'd like to get a relatively fast review, since the remaining nine are more "boring".
Patch 17-21: switch -object to keyval everywhere
Patch 22-25: switch -M and -accel to keyval
Based-on: <[email protected]>
Paolo Bonzini (25):
qemu-option: clean up id vs. list->merge_lists
qemu-option: move help handling to get_opt_name_value
qemu-option: warn for short-form boolean options
keyval: accept escaped commas in implied option
keyval: simplify keyval_parse_one
tests: convert check-qom-proplist to keyval
keyval: introduce keyval_parse_into
hmp: replace "O" parser with keyval
qom: use qemu_printf to print help for user-creatable objects
hmp: special case help options for object_add
remove -writeconfig
qemu-config: add error propagation to qemu_config_parse
qemu-option: support accept-any QemuOptsList in qemu_opts_absorb_qdict
qemu-config: parse configuration files to a QDict
vl: plumb keyval-based options into -set and -readconfig
qom: do not modify QDict argument in user_creatable_add_dict
qemu-io: use keyval for -object parsing
qemu-nbd: use keyval for -object parsing
qemu-img: use keyval for -object parsing
qemu: use keyval for -object parsing
storage-daemon: do not register the "object" group with QemuOpts
qom: export more functions for use with non-UserCreatable objects
vl: switch -M parsing to keyval
qemu-option: remove now-dead code
vl: switch -accel parsing to keyval
accel/accel.c | 6 + block/blkdebug.c | 3 +- docs/system/deprecated.rst | 6 + hmp-commands.hx | 6 +- include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 + include/qemu/config-file.h | 9 +- include/qemu/help_option.h | 11 - include/qemu/option.h | 6 +- include/qom/object.h | 21 + include/qom/object_interfaces.h | 68 +-- include/sysemu/accel.h | 1 + monitor/hmp-cmds.c | 22 +- monitor/hmp.c | 20 +- qemu-img.c | 258 +++------- qemu-io.c | 42 +- qemu-nbd.c | 42 +- qemu-options.hx | 13 +- qom/object_interfaces.c | 152 ++---- softmmu/vl.c | 673 ++++++++++++++------------- storage-daemon/qemu-storage-daemon.c | 10 - tests/check-qom-proplist.c | 58 ++- tests/test-keyval.c | 58 ++- tests/test-qemu-opts.c | 37 +- util/keyval.c | 231 +++++---- util/qemu-config.c | 141 +++--- util/qemu-option.c | 126 +++-- 27 files changed, 918 insertions(+), 1107 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/25 qemu-option: clean up id vs. list->merge_lists
Looking at all merge-lists QemuOptsList, here is how they access their QemuOpts:
reopen_opts in qemu-io-cmds.c ("qemu-img reopen -o")
qemu_opts_find(&reopen_opts, NULL)
empty_opts in qemu-io.c ("qemu-io open -o")
qemu_opts_find(&empty_opts, NULL)
qemu_rtc_opts ("-rtc")
qemu_find_opts_singleton("rtc")
qemu_machine_opts ("-M")
qemu_find_opts_singleton("machine")
qemu_boot_opts ("-boot")
QTAILQ_FIRST(&qemu_find_opts("bootopts")->head)qemu_name_opts ("-name")
qemu_opts_foreach->parse_name parse_name does not use id
qemu_mem_opts ("-m")
qemu_find_opts_singleton("memory")
qemu_icount_opts ("-icount")
qemu_opts_foreach->do_configuree_icount do_configure_icount->icount_configure icount_configure does not use id
qemu_smp_opts ("-smp")
qemu_opts_find(qemu_find_opts("smp-opts"), NULL)
qemu_spice_opts ("-spice")
QTAILQ_FIRST(&qemu_spice_opts.head)
i.e. they don't need an id. Sometimes its presence is ignored (e.g. when using qemu_opts_foreach), sometimes all the options with the id are skipped, sometimes only the first option on the command line is considered. With this patch we just forbid id on merge-lists QemuOptsLists; if the command line still works, it has the same semantics as before.
qemu_opts_create's fail_if_exists parameter is now unnecessary:
- it is unused if id is NULL
- opts_parse only passes false if reached from qemu_opts_set_defaults, in which case this patch enforces that id must be NULL
- other callers that can pass a non-NULL id always set it to true
Assert that it is true in the only case where "fail_if_exists" matters, i.e. "id && !lists->merge_lists". This means that if an id is present, duplicates are always forbidden, which was already the status quo.
Discounting the case that aborts as it's not user-controlled (it's "just" a matter of inspecting qemu_opts_create callers), the paths through qemu_opts_create can be summarized as:
- merge_lists = true: singleton opts with NULL id; non-NULL id fails
- merge_lists = false: always return new opts; non-NULL id fails if dup
--- util/qemu-option.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
util/qemu-option.c +14 -13
@@ -619,7 +619,17 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, {QemuOpts *opts =NULL ; -if (id) { +if (list->merge_lists) { +if (id) { +error_setg (errp,QERR_INVALID_PARAMETER ,"id" ); +return NULL ; + } + opts =qemu_opts_find (list,NULL ); +if (opts) { +return opts; + } + }else if (id) { +assert (fail_if_exists);if (!id_wellformed (id)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"id" ,"an identifier" );
@@ -629,17 +639,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, } opts =qemu_opts_find (list, id);if (opts !=NULL ) { -if (fail_if_exists && !list->merge_lists) { -error_setg (errp,"Duplicate ID '%s' for %s" , id, list->name); -return NULL ; - }else { -return opts; - } - } - }else if (list->merge_lists) { - opts =qemu_opts_find (list,NULL ); -if (opts) { -return opts; +error_setg (errp,"Duplicate ID '%s' for %s" , id, list->name); +return NULL ; } } opts =g_malloc0 (sizeof (*opts));
@@ -893,7 +894,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,* (if unlikely) future misuse: */ assert (!defaults || list->merge_lists); - opts =qemu_opts_create (list, id, !defaults, errp); + opts =qemu_opts_create (list, id, !list->merge_lists, errp);g_free (id);if (opts ==NULL ) {return NULL ;
Signature · 1 line
2.26.2
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
Am 18.01.2021 um 17:30 hat Paolo Bonzini geschrieben:
Quoted 22 lines
Looking at all merge-lists QemuOptsList, here is how they access their QemuOpts:
reopen_optsinqemu-io-cmds.c("qemu-img reopen -o")
qemu_opts_find(&reopen_opts, NULL)
empty_optsinqemu-io.c("qemu-io open -o")
qemu_opts_find(&empty_opts, NULL)
qemu_rtc_opts("-rtc")
qemu_find_opts_singleton("rtc")
qemu_machine_opts("-M")
qemu_find_opts_singleton("machine")
qemu_boot_opts("-boot")QTAILQ_FIRST(&qemu_find_opts("bootopts")->head)
qemu_name_opts("-name")qemu_opts_foreach->parse_name parse_name does not use id
Quoted 7 lines
qemu_mem_opts("-m")
qemu_find_opts_singleton("memory")
qemu_icount_opts("-icount")qemu_opts_foreach->do_configuree_icount do_configure_icount->icount_configure icount_configure does not use id
qemu_action_opts has been added since the last version of this series. It's fine, too (gets converted to a QAPI type that doesn't have an "id" field), but you may want to update the commit message.
With this:
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
In reply to Paolo BonziniQuoted 1 line · Paolo Bonzini
Looking at all merge-lists QemuOptsList
outside tests/
Quoted 6 lines
here is how they access their
QemuOpts:
reopen_optsinqemu-io-cmds.c("qemu-img reopen -o")
qemu_opts_find(&reopen_opts, NULL)
Quoted 8 lines
empty_optsinqemu-io.c("qemu-io open -o")
qemu_opts_find(&empty_opts, NULL)
qemu_rtc_opts("-rtc")
qemu_find_opts_singleton("rtc")
qemu_machine_opts("-M")
qemu_find_opts_singleton("machine")
Gone since your commit 4988a4ea4d "vl: switch -M parsing to keyval". Did it change behavior when multiple -M are given, with various id=? I didn't look at the patch back then, and I'm not going to look at it now. Feel free to ignore the question.
Quoted 3 lines
qemu_boot_opts("-boot")QTAILQ_FIRST(&qemu_find_opts("bootopts")->head)
That one's in hw/nvram/fw_cfg.c and hw/s390x/ipl.c. However, softmmu/vl.c uses
qemu_opts_find(qemu_find_opts("boot-opts"), NULL);If the user passes multiple -boot with different ID, we merge the ones with same ID, and then vl.c gets the (merged) one without ID, but the other two get the (merged) one that contains the first -boot. All three silently ignore the ones they don't get. Awesomely weird. I'd call it a bug.
Test case:
$ upstream-qemu -S -display none -boot strict=on,id=id -boot strict=off
vl.c uses strict=off, but fw_cfg.c uses strinct=on,id=id.
Outlawing "id" with .merge_lists like this patch does turns the cases where the two methods yield different results into errors. A bug fix of sorts. Should the commit message should cover it?
I believe we could use qemu_find_opts_singleton() in all three spots. Not this patch's job.
Quoted 2 lines
qemu_name_opts("-name")qemu_opts_foreach->parse_name
Funny way to explain qemu_opts_foreach(qemu_name_opts, parse_name, ...)
Quoted 1 line
parse_namedoes not use id
We first use .merge-lists = true to merge all -name with the same ID, then we iterate over all the merges. Combined effect is "merge ignoring ID".
Quoted 7 lines
qemu_mem_opts("-m")
qemu_find_opts_singleton("memory")
qemu_icount_opts("-icount")qemu_opts_foreach->do_configuree_icount do_configure_icount->icount_configure icount_configure does not use id
Just like qemu_name_opts. My comments apply, plus one:
s/do_configuree_icount/do_configure_icount/.
A recent addition is missing:
qemu_action_opts ("-action")
Again, just like qemu_name_opts; my comments apply, plus one aside: this should not use QemuOpts at all. Use of qmp_marshal_FOO() is an anti-pattern. Needs cleanup. Not in this patch, and probably not even in this series.
Quoted 2 lines
qemu_smp_opts("-smp")
qemu_opts_find(qemu_find_opts("smp-opts"), NULL)
That's one access in vl.c. There's another one that uses qemu_find_opts_singleton(). Okay, I think.
Quoted 2 lines
qemu_spice_opts("-spice")
QTAILQ_FIRST(&qemu_spice_opts.head)
There's also machine_opts in qemu-config.c, but that's only to make query-command-line-options lie backward-compatibly.
Quoted 3 lines
i.e. they don't need an id. Sometimes its presence is ignored (e.g. when using
qemu_opts_foreach), sometimes all the options with the id are skipped,
(when using qemu_find_opts_singleton() or qemu_opts_find(list, NULL))
Quoted 2 lines
sometimes only the first option on the
command line is considered.
(when using QTAILQ_FIRST)
Quoted 3 lines
command line is considered. With this patch we just forbid id on merge-lists QemuOptsLists; if the command line still works, it has the same semantics as before.
It can break working (if weird) command lines, such as ones relying on "merge ignoring ID" behavior of -name, -icount, -action. Okay.
Quoted 4 lines
qemu_opts_create's
fail_if_existsparameter is now unnecessary:- it is unused if id is NULL
Quoted 8 lines
-
opts_parseonly passes false if reached fromqemu_opts_set_defaults, in which case this patch enforces that id must be NULL- other callers that can pass a non-NULL id always set it to true
Assert that it is true in the only case where "
fail_if_exists" matters, i.e. "id && !lists->merge_lists". This means that if an id is present, duplicates are always forbidden, which was already the status quo.
Hmm.
If ->merge_lists, id= is forbidden, and all (id-less) opts are merged into one.
Else, if id= is specified, it must be unique, i.e. no prior opts with the same id.
Else, we don't check for prior opts without id.
There's at most one opts with a certain id, but there could be any number without id. Is this what we want?
Quoted 7 lines
Discounting the case that aborts as it's not user-controlled (it's "just" a matter of inspecting
qemu_opts_createcallers), the paths throughqemu_opts_createcan be summarized as:-
merge_lists= true: singleton opts with NULL id; non-NULL id fails-
merge_lists= false: always return new opts; non-NULL id fails if dup
This renders the qemu_opts_foreach() silly. Cleanup is in order, not necessarily in this patch.
Quoted 49 lines
Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-option.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)util/qemu-option.c +13
-12@@ -619,7 +619,17 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, {QemuOpts *opts =NULL ; -if (id) { +if (list->merge_lists) { +if (id) { +error_setg (errp,QERR_INVALID_PARAMETER ,"id" ); +return NULL ; + } + opts =qemu_opts_find (list,NULL ); +if (opts) { +return opts; + } + }else if (id) { +assert (fail_if_exists);if (!id_wellformed (id)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"id" ,"an identifier" );@@ -629,17 +639,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, } opts =qemu_opts_find (list, id);if (opts !=NULL ) { -if (fail_if_exists && !list->merge_lists) { -error_setg (errp,"Duplicate ID '%s' for %s" , id, list->name); -return NULL ; - }else { -return opts; - } - } - }else if (list->merge_lists) { - opts =qemu_opts_find (list,NULL ); -if (opts) { -return opts; +error_setg (errp,"Duplicate ID '%s' for %s" , id, list->name); +return NULL ; } } opts =g_malloc0 (sizeof (*opts));
util/qemu-option.c static QemuOpts *opts_parse(QemuOptsList *list, const char *params, · line 900
Quoted 8 lines
util/qemu-option.c +1
-1@@ -893,7 +894,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,* (if unlikely) future misuse: */ assert (!defaults || list->merge_lists); - opts =qemu_opts_create (list, id, !defaults, errp); + opts =qemu_opts_create (list, id, !list->merge_lists, errp);g_free (id);if (opts ==NULL ) {return NULL ;
My dread of QemuOpts has been refreshed to its nominal level.
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
Quoted 4 lines · Markus Armbruster
Quoted 2 lines
qemu_machine_opts("-M")
qemu_find_opts_singleton("machine")Gone since your commit
4988a4ea4d"vl: switch -M parsing to keyval".
Which is part of this series and not yet included in QEMU. Hence the commit message talks about it in the present tense.
Quoted 8 lines
If the user passes multiple -boot with different ID, we merge the ones with same ID, and then
vl.cgets the (merged) one without ID, but the other two get the (merged) one that contains the first -boot. All three silently ignore the ones they don't get. Awesomely weird. I'd call it a bug.Test case:
Quoted 7 lines
$ upstream-qemu -S -display none -boot strict=on,id=id -boot strict=off
vl.cuses strict=off, butfw_cfg.cuses strinct=on,id=id.Outlawing "id" with .merge_lists like this patch does turns the cases where the two methods yield different results into errors. A bug fix of sorts. Should the commit message should cover it?
Yeah, I can add that.
Quoted 4 lines
[
qemu_action_opts]
should not use QemuOpts at all. Use ofqmp_marshal_FOO()is an anti-pattern. Needs cleanup. Not in this patch, and probably not even in this series.
--verbose needed. Why is it an anti-pattern? I found it a clever way to avoid code duplication. :) Doesn't matter for this series, anyway.
Quoted 6 lines
Quoted 3 lines
command line is considered. With this patch we just forbid id on merge-lists QemuOptsLists; if the command line still works, it has the same semantics as before.
It can break working (if weird) command lines, such as ones relying on "merge ignoring ID" behavior of -name, -icount, -action. Okay.
Right, I wrote that down as a feature. The important thing is keeping things the same if they still work.
Quoted 7 lines
[If !lists->merge_lists], if id= is specified, it must be unique, i.e. no prior opts with the same id.
Else, we don't check for prior opts without id.
There's at most one opts with a certain id, but there could be any number without id. Is this what we want?
Yes, positively. Example: "qemu-system-x86_64 -device foo -device bar".
Quoted 10 lines
Quoted 7 lines
Discounting the case that aborts as it's not user-controlled (it's "just" a matter of inspecting
qemu_opts_createcallers), the paths throughqemu_opts_createcan be summarized as:-
merge_lists= true: singleton opts with NULL id; non-NULL id fails-
merge_lists= false: always return new opts; non-NULL id fails if dupThis renders the
qemu_opts_foreach()silly. Cleanup is in order, not necessarily in this patch.
Agreed. This one is already tricky enough (though I like the outcome).
Paolo
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Markus Armbruster
Quoted 2 lines
qemu_machine_opts("-M")
qemu_find_opts_singleton("machine")Gone since your commit
4988a4ea4d"vl: switch -M parsing to keyval".Which is part of this series and not yet included in QEMU. Hence the commit message talks about it in the present tense.
I got confused.
Quoted 10 lines
Quoted 10 lines
If the user passes multiple -boot with different ID, we merge the ones with same ID, and then
vl.cgets the (merged) one without ID, but the other two get the (merged) one that contains the first -boot. All three silently ignore the ones they don't get. Awesomely weird. I'd call it a bug.Test case:
$ upstream-qemu -S -display none -boot strict=on,id=id -boot strict=off
Quoted 7 lines
Quoted 5 lines
vl.cuses strict=off, butfw_cfg.cuses strinct=on,id=id.Outlawing "id" with .merge_lists like this patch does turns the cases where the two methods yield different results into errors. A bug fix of sorts. Should the commit message should cover it?
Yeah, I can add that.
Thanks!
Quoted 7 lines
Quoted 4 lines
[
qemu_action_opts]
should not use QemuOpts at all. Use ofqmp_marshal_FOO()is an anti-pattern. Needs cleanup. Not in this patch, and probably not even in this series.--verbose needed. Why is it an anti-pattern? I found it a clever way to avoid code duplication. :) Doesn't matter for this series, anyway.
Because it's a clever way to do something that should not be done :)
-action wraps around QMP command set-action. This means we need to parse -action's argument into set-action's argument type. That's a QAPI type. It's anonymous in the schema, and q_obj_set_action_arg in C.
As implemented, the parsing takes a detour through QemuOpts:
char *optarg
|
| opts = qemu_opts_parse_noisily(optarg);
v
QemuOpts *opts
|
| qdict = qemu_opts_to_qdict(opts, NULL);
v
QDict *qdict
|
| in qmp_marshal_set_action(qdict):
| v = qobject_input_visitor_new_str(qdict);
| visit_type_q_obj_set_action_arg_members(v, &arg, errp);
v q_obj_set_action_arg arg
qmp_marshal_set_action() then passes the members of q_obj_set_action_arg() to qmp_set_action().
The detour should be avoided, because QemuOpts should be avoided. Using the appropriate visitor, we get:
char *optarg
|
| v = qobject_input_visitor_new_str(string, NULL, errp)
| visit_type_q_obj_set_action_arg(v, NULL, &arg, errp);
v q_obj_set_action_arg arg
except visit_type_q_obj_set_action_arg() doesn't exist, because the QAPI type is anonymous. So give it a name:
{ 'struct: 'Action',
'data': { '*reboot': 'RebootAction',
'*shutdown': 'ShutdownAction',
'*panic': 'PanicAction',
'*watchdog': 'WatchdogAction' } }
{ 'command': 'set-action',
'data': 'Action',
'allow-preconfig': true }
char *optarg
|
| v = qobject_input_visitor_new_str(string, NULL, errp)
| visit_type_Action(v, NULL, &arg, errp);
v
Action actTo avoid having to pass the members of Action to qmp_set_action(), throw in 'boxed': true, so you can simply call qmp_set_action(&act, errp).
Aside: I'd like to have this QAPI/CLI boilerplate generated, like we generate the QAPI/QMP boilerplate. Not today; QAPI-land is busy with John's static typing work.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
command line is considered. With this patch we just forbid id on merge-lists QemuOptsLists; if the command line still works, it has the same semantics as before.
It can break working (if weird) command lines, such as ones relying on "merge ignoring ID" behavior of -name, -icount, -action. Okay.
Right, I wrote that down as a feature. The important thing is keeping things the same if they still work.
Yes.
Quoted 9 lines
Quoted 7 lines
[If !lists->merge_lists], if id= is specified, it must be unique, i.e. no prior opts with the same id.
Else, we don't check for prior opts without id.
There's at most one opts with a certain id, but there could be any number without id. Is this what we want?
Yes, positively. Example: "qemu-system-x86_64 -device foo -device bar".
D'oh! QemuOpts left me no brain capacity for remembering the simplest things %-}
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Discounting the case that aborts as it's not user-controlled (it's "just" a matter of inspecting
qemu_opts_createcallers), the paths throughqemu_opts_createcan be summarized as:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
-
merge_lists= true: singleton opts with NULL id; non-NULL id fails-
merge_lists= false: always return new opts; non-NULL id fails if dupThis renders the
qemu_opts_foreach()silly. Cleanup is in order, not necessarily in this patch.Agreed. This one is already tricky enough (though I like the outcome).
Me too.
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
Quoted 30 lines · Markus Armbruster
The detour should be avoided, because QemuOpts should be avoided. Using the appropriate visitor, we get:
char *optarg | | v = qobject_input_visitor_new_str(string, NULL, errp) | visit_type_q_obj_set_action_arg(v, NULL, &arg, errp); v
q_obj_set_action_argargexcept
visit_type_q_obj_set_action_arg()doesn't exist, because the QAPI type is anonymous. So give it a name:{ 'struct: 'Action', 'data': { '*reboot': 'RebootAction', '*shutdown': 'ShutdownAction', '*panic': 'PanicAction', '*watchdog': 'WatchdogAction' } } { 'command': 'set-action', 'data': 'Action', 'allow-preconfig': true } char *optarg | | v = qobject_input_visitor_new_str(string, NULL, errp) | visit_type_Action(v, NULL, &arg, errp); v Action act
Quoted 2 lines
To avoid having to pass the members of Action to
qmp_set_action(), throw in 'boxed': true, so you can simply callqmp_set_action(&act, errp).
Ok, so the idea of a 1:1 CLI<->QMP mapping is good, the implementation is bad. The reason it was done with QemuOpts was mostly to have "-action help" for free. Something to remember when working on autogenerated boilerplate.
Paolo
Re: [PATCH 01/25] qemu-option: clean up id vs. list->merge_lists
Quoted 30 lines · Paolo Bonzini
Quoted 25 lines · Markus Armbruster
The detour should be avoided, because QemuOpts should be avoided. Using the appropriate visitor, we get:
char *optarg | | v = qobject_input_visitor_new_str(string, NULL, errp) | visit_type_q_obj_set_action_arg(v, NULL, &arg, errp); v
q_obj_set_action_argarg
exceptvisit_type_q_obj_set_action_arg()doesn't exist, because the QAPI
type is anonymous. So give it a name:{ 'struct: 'Action', 'data': { '*reboot': 'RebootAction', '*shutdown': 'ShutdownAction', '*panic': 'PanicAction', '*watchdog': 'WatchdogAction' } } { 'command': 'set-action', 'data': 'Action', 'allow-preconfig': true } char *optarg | | v = qobject_input_visitor_new_str(string, NULL, errp) | visit_type_Action(v, NULL, &arg, errp); v Action actQuoted 3 lines
To avoid having to pass the members of Action to
qmp_set_action(), throw
in 'boxed': true, so you can simply callqmp_set_action(&act, errp).
Quoted 4 lines
Ok, so the idea of a 1:1 CLI<->QMP mapping is good, the implementation is bad. The reason it was done with QemuOpts was mostly to have "-action help" for free. Something to remember when working on autogenerated boilerplate.
Yes, help is another gap we still need to bridge.
PATCH 2/25 qemu-option: move help handling to get_opt_name_value
In reply to Paolo BonziniRight now, help options are parsed normally and then checked specially in opt_validate, but only if coming from qemu_opts_parse_noisily. has_help_option does the check on its own.
opt_validate() has two callers: qemu_opt_set(), which passes null and is therefore unaffected, and opts_do_parse(), which is affected.
opts_do_parse() is called by qemu_opts_do_parse(), which passes null and is therefore unaffected, and opts_parse().
opts_parse() is called by qemu_opts_parse() and qemu_opts_set_defaults(), which pass null and are therefore unaffected, and qemu_opts_parse_noisily().
Move the check from opt_validate to the parsing workhorse of QemuOpts, get_opt_name_value. This will come in handy in the next patch, which will raise a warning for "-object memory-backend-ram,share" ("flag" option with no =on/=off part) but not for "-object memory-backend-ram,help".
As a result:
- opts_parse and opts_do_parse do not return an error anymore when help is requested; qemu_opts_parse_noisily does not have to work around that anymore.
- various crazy ways to request help are not recognized anymore:
- "help=..."
- "nohelp" (sugar for "help=off")
- "?=..."
- "no?" (sugar for "?=off")
--- util/qemu-option.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
util/qemu-option.c +23 -15
@@ -496,8 +496,7 @@ static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value,return opt; } -static bool opt_validate (QemuOpt *opt,bool *help_wanted, -Error **errp) +static bool opt_validate (QemuOpt *opt,Error **errp) {const QemuOptDesc *desc;const QemuOptsList *list = opt->opts->list;
@@ -505,9 +504,6 @@ static bool opt_validate(QemuOpt *opt, bool *help_wanted, desc =find_desc_by_name (list->desc, opt->name);if (!desc && !opts_accepts_any (list)) {error_setg (errp,QERR_INVALID_PARAMETER , opt->name); -if (help_wanted &&is_help_option (opt->name)) { - *help_wanted = true; - }return false; }
@@ -524,7 +520,7 @@ bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, {QemuOpt *opt =opt_create (opts, name,g_strdup (value), false); -if (!opt_validate (opt,NULL , errp)) { +if (!opt_validate (opt, errp)) {qemu_opt_del (opt);return false; }
@@ -760,10 +756,12 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)static const char *get_opt_name_value (const char *params,const char *firstname, +bool *help_wanted,char **name,char **value) {const char *p;size_t len; +bool is_help = false; len =strcspn (params,"=," );if (params[len] !='=' ) {
@@ -780,6 +778,7 @@ static const char *get_opt_name_value(const char *params, *value =g_strdup ("off" ); }else { *value =g_strdup ("on" ); + is_help =is_help_option (*name); } } }else {
@@ -791,6 +790,9 @@ static const char *get_opt_name_value(const char *params, }assert (!*p || *p ==',' ); +if (help_wanted && is_help) { + *help_wanted = true; + }if (*p ==',' ) { p++; }
@@ -806,7 +808,12 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,QemuOpt *opt;for (p = params; *p;) { - p =get_opt_name_value (p, firstname, &option, &value); + p =get_opt_name_value (p, firstname, help_wanted, &option, &value); +if (help_wanted && *help_wanted) { +g_free (option); +g_free (value); +return false; + } firstname =NULL ;if (!strcmp (option,"id" )) {
@@ -817,7 +824,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *params, opt =opt_create (opts, option, value, prepend);g_free (option); -if (!opt_validate (opt, help_wanted, errp)) { +if (!opt_validate (opt, errp)) {qemu_opt_del (opt);return false; }
@@ -832,7 +839,7 @@ static char *opts_parse_id(const char *params)char *name, *value;for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &name, &value); + p =get_opt_name_value (p,NULL ,NULL , &name, &value);if (!strcmp (name,"id" )) {g_free (name);return value;
@@ -848,11 +855,10 @@ bool has_help_option(const char *params) {const char *p;char *name, *value; -bool ret; +bool ret = false;for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &name, &value); - ret =is_help_option (name); + p =get_opt_name_value (p,NULL , &ret, &name, &value);g_free (name);g_free (value);if (ret) {
@@ -937,11 +943,13 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,QemuOpts *opts;bool help_wanted = false; - opts =opts_parse (list, params, permit_abbrev, false, &help_wanted, &err); -if (err) { + opts =opts_parse (list, params, permit_abbrev, false, +opts_accepts_any (list) ?NULL : &help_wanted, + &err); +if (!opts) { +assert (!!err + !!help_wanted ==1 );if (help_wanted) {qemu_opts_print_help (list, true); -error_free (err); }else {error_report_err (err); }
Signature · 1 line
2.26.2
Re: [PATCH 02/25] qemu-option: move help handling to get_opt_name_value
Quoted 91 lines · Paolo Bonzini
Right now, help options are parsed normally and then checked specially in
opt_validate, but only if coming fromqemu_opts_parse_noisily.has_help_optiondoes the check on its own.
opt_validate()has two callers:qemu_opt_set(), which passes null and is therefore unaffected, andopts_do_parse(), which is affected.
opts_do_parse()is called byqemu_opts_do_parse(), which passes null and is therefore unaffected, andopts_parse().
opts_parse()is called byqemu_opts_parse()andqemu_opts_set_defaults(), which pass null and are therefore unaffected, andqemu_opts_parse_noisily().Move the check from
opt_validateto the parsing workhorse of QemuOpts,get_opt_name_value. This will come in handy in the next patch, which will raise a warning for "-object memory-backend-ram,share" ("flag" option with no =on/=off part) but not for "-object memory-backend-ram,help".As a result:
-
opts_parseandopts_do_parsedo not return an error anymore when help is requested;qemu_opts_parse_noisilydoes not have to work around that anymore.- various crazy ways to request help are not recognized anymore:
- "help=..."
- "nohelp" (sugar for "help=off")
- "?=..."
- "no?" (sugar for "?=off")Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-option.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)util/qemu-option.c +5
-6@@ -496,8 +496,7 @@ static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value,return opt; } -static bool opt_validate (QemuOpt *opt,bool *help_wanted, -Error **errp) +static bool opt_validate (QemuOpt *opt,Error **errp) {const QemuOptDesc *desc;const QemuOptsList *list = opt->opts->list;@@ -505,9 +504,6 @@ static bool opt_validate(QemuOpt *opt, bool *help_wanted, desc =find_desc_by_name (list->desc, opt->name);if (!desc && !opts_accepts_any (list)) {error_setg (errp,QERR_INVALID_PARAMETER , opt->name); -if (help_wanted &&is_help_option (opt->name)) { - *help_wanted = true; - }return false; }@@ -524,7 +520,7 @@ bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, {QemuOpt *opt =opt_create (opts, name,g_strdup (value), false); -if (!opt_validate (opt,NULL , errp)) { +if (!opt_validate (opt, errp)) {qemu_opt_del (opt);return false; }@@ -760,10 +756,12 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)static const char *get_opt_name_value (const char *params,const char *firstname, +bool *help_wanted,char **name,char **value) {const char *p;size_t len; +bool is_help = false; len =strcspn (params,"=," );if (params[len] !='=' ) {@@ -780,6 +778,7 @@ static const char *get_opt_name_value(const char *params, *value =g_strdup ("off" ); }else { *value =g_strdup ("on" ); + is_help =is_help_option (*name); } } }else {
util/qemu-option.c static const char *get_opt_name_value(const char *params, · line 794
Quoted 5 lines
util/qemu-option.c +2
-0@@ -791,6 +790,9 @@ static const char *get_opt_name_value(const char *params, }assert (!*p || *p ==',' ); +if (help_wanted && is_help) { + *help_wanted = true;
Note [1] for later: we only ever set *help_wanted to true.
Quoted 37 lines
util/qemu-option.c +9
-3+ }if (*p ==',' ) { p++; }@@ -806,7 +808,12 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,QemuOpt *opt;for (p = params; *p;) { - p =get_opt_name_value (p, firstname, &option, &value); + p =get_opt_name_value (p, firstname, help_wanted, &option, &value); +if (help_wanted && *help_wanted) { +g_free (option); +g_free (value); +return false; + } firstname =NULL ;if (!strcmp (option,"id" )) {@@ -817,7 +824,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *params, opt =opt_create (opts, option, value, prepend);g_free (option); -if (!opt_validate (opt, help_wanted, errp)) { +if (!opt_validate (opt, errp)) {qemu_opt_del (opt);return false; }@@ -832,7 +839,7 @@ static char *opts_parse_id(const char *params)char *name, *value;for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &name, &value); + p =get_opt_name_value (p,NULL ,NULL , &name, &value);if (!strcmp (name,"id" )) {g_free (name);return value;
util/qemu-option.c bool has_help_option(const char *params) · line 858
Quoted 5 lines
util/qemu-option.c +1
-1@@ -848,11 +855,10 @@ bool has_help_option(const char *params) {const char *p;char *name, *value; -bool ret; +bool ret = false;
This initializer is required due to [1].
util/qemu-option.c bool has_help_option(const char *params) · line 864
Quoted 8 lines
util/qemu-option.c +1
-2for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &name, &value); - ret =is_help_option (name); + p =get_opt_name_value (p,NULL , &ret, &name, &value);g_free (name);g_free (value);if (ret) {
Works, but I'd prefer get_opt_name_value() to always set *help_wanted when help_wanted isn't null. Up to you.
util/qemu-option.c QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, · line 950
Quoted 11 lines
util/qemu-option.c +5
-2@@ -937,11 +943,13 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,QemuOpts *opts;bool help_wanted = false; - opts =opts_parse (list, params, permit_abbrev, false, &help_wanted, &err); -if (err) { + opts =opts_parse (list, params, permit_abbrev, false, +opts_accepts_any (list) ?NULL : &help_wanted, + &err); +if (!opts) { +assert (!!err + !!help_wanted ==1 );
Either err or help_wanted. This is logical inequality. I'd write it as
assert(!err != !help_wanted);
or maybe as
assert(!err ^ !help_wanted);
But your artistic license applies.
util/qemu-option.c QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, · line 955
Quoted 6 lines
util/qemu-option.c +0
-1if (help_wanted) {qemu_opts_print_help (list, true); -error_free (err); }else {error_report_err (err); }
Before the patch, we recognize help requests only if they aren't captured by a (foolishly named) parameter name.
Afterwards, we recognize only sane help requests regardless of parameters. In other words:
- various crazy ways to request help are not recognized anymore:
- "help=..."
- "nohelp" (sugar for "help=off")
- "?=..."
- "no?" (sugar for "?=off")
- "help" is recognized as help request even if there is a (foolishly named) parameter "help". No such parameters exist.
Let's add the last item to the commit message, too.
Preferably with the commit message amended:
PATCH 3/25 qemu-option: warn for short-form boolean options
In reply to Paolo BonziniOptions such as "server" or "nowait", that are commonly found in -chardev, are sugar for "server=on" and "wait=off". This is quite surprising and also does not have any notion of typing attached. It is even possible to do "-device e1000,noid" and get a device with "id=off".
Deprecate it and print a warning when it is encountered. In general, this short form for boolean options only seems to be in wide use for -chardev and -spice.
--- docs/system/deprecated.rst | 6 ++++++ tests/test-qemu-opts.c | 2 +- util/qemu-option.c | 29 ++++++++++++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-)
docs/system/deprecated.rst +6 -0
@@ -127,6 +127,12 @@ Drives with interface types other than ``if=none`` are for onboard devices. It is possible to use drives the board doesn't pick up with -device. This usage is now deprecated. Use ``if=none`` instead. +Short-form boolean options (since 5.2) +'''''''''''''''''''''''''''''''''''''' + +Boolean options such as ``share=on``/``share=off`` can be written +in short form as ``share`` and ``noshare``. This is deprecated +and will cause a warning. QEMU Machine Protocol (QMP) commands ------------------------------------
tests/test-qemu-opts.c +1 -1
@@ -515,7 +515,7 @@ static void test_opts_parse(void)error_free_or_abort (&err);g_assert (!opts); -/* Implied value */ +/* Implied value (qemu_opts_parse warns but accepts it) */ opts =qemu_opts_parse (&opts_list_03,"an,noaus,noaus=" , false, &error_abort); g_assert_cmpuint(opts_count(opts), ==, 3);
util/qemu-option.c +18 -11
@@ -756,10 +756,12 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)static const char *get_opt_name_value (const char *params,const char *firstname, +bool warn_on_flag,bool *help_wanted,char **name,char **value) {const char *p; +const char *prefix ="" ;size_t len;bool is_help = false;
@@ -776,10 +778,15 @@ static const char *get_opt_name_value(const char *params,if (strncmp (*name,"no" ,2 ) ==0 ) {memmove (*name, *name +2 ,strlen (*name +2 ) +1 ); *value =g_strdup ("off" ); + prefix ="no" ; }else { *value =g_strdup ("on" ); is_help =is_help_option (*name); } +if (!is_help && warn_on_flag) { +warn_report ("short-form boolean option '%s%s' deprecated" , prefix, *name); +error_printf ("Please use %s=%s instead\n" , *name, *value); + } } }else {/* found "foo=bar,more" */
@@ -801,14 +808,14 @@ static const char *get_opt_name_value(const char *params,static bool opts_do_parse (QemuOpts *opts,const char *params,const char *firstname,bool prepend, -bool *help_wanted,Error **errp) +bool warn_on_flag,bool *help_wanted,Error **errp) {char *option, *value;const char *p;QemuOpt *opt;for (p = params; *p;) { - p =get_opt_name_value (p, firstname, help_wanted, &option, &value); + p =get_opt_name_value (p, firstname, warn_on_flag, help_wanted, &option, &value);if (help_wanted && *help_wanted) {g_free (option);g_free (value);
@@ -839,7 +846,7 @@ static char *opts_parse_id(const char *params)char *name, *value;for (p = params; *p;) { - p =get_opt_name_value (p,NULL ,NULL , &name, &value); + p =get_opt_name_value (p,NULL , false,NULL , &name, &value);if (!strcmp (name,"id" )) {g_free (name);return value;
@@ -858,7 +865,7 @@ bool has_help_option(const char *params)bool ret = false;for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &ret, &name, &value); + p =get_opt_name_value (p,NULL , false, &ret, &name, &value);g_free (name);g_free (value);if (ret) {
@@ -878,12 +885,12 @@ bool has_help_option(const char *params)bool qemu_opts_do_parse (QemuOpts *opts,const char *params,const char *firstname,Error **errp) { -return opts_do_parse (opts, params, firstname, false,NULL , errp); +return opts_do_parse (opts, params, firstname, false, false,NULL , errp); }static QemuOpts *opts_parse (QemuOptsList *list,const char *params,bool permit_abbrev,bool defaults, -bool *help_wanted,Error **errp) +bool warn_on_flag,bool *help_wanted,Error **errp) {const char *firstname;char *id =opts_parse_id (params);
@@ -906,8 +913,8 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,return NULL ; } -if (!opts_do_parse (opts, params, firstname, defaults, help_wanted, - errp)) { +if (!opts_do_parse (opts, params, firstname, defaults, + warn_on_flag, help_wanted, errp)) {qemu_opts_del (opts);return NULL ; }
@@ -925,7 +932,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,QemuOpts *qemu_opts_parse (QemuOptsList *list,const char *params,bool permit_abbrev,Error **errp) { -return opts_parse (list, params, permit_abbrev, false,NULL , errp); +return opts_parse (list, params, permit_abbrev, false, false,NULL , errp); }/**
@@ -943,7 +950,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,QemuOpts *opts;bool help_wanted = false; - opts =opts_parse (list, params, permit_abbrev, false, + opts =opts_parse (list, params, permit_abbrev, false, true,opts_accepts_any (list) ?NULL : &help_wanted, &err);if (!opts) {
@@ -962,7 +969,7 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char *params, {QemuOpts *opts; - opts =opts_parse (list, params, permit_abbrev, true,NULL ,NULL ); + opts =opts_parse (list, params, permit_abbrev, true, false,NULL ,NULL );assert (opts); }
Signature · 1 line
2.26.2
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 21 lines · Paolo Bonzini
Options such as "server" or "nowait", that are commonly found in -chardev, are sugar for "server=on" and "wait=off". This is quite surprising and also does not have any notion of typing attached. It is even possible to do "-device e1000,noid" and get a device with "id=off".
Deprecate it and print a warning when it is encountered. In general, this short form for boolean options only seems to be in wide use for -chardev and -spice.
Signed-off-by Paolo Bonzini <[email protected]>--- docs/system/deprecated.rst | 6 ++++++ tests/test-qemu-opts.c | 2 +- util/qemu-option.c | 29 ++++++++++++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-)docs/system/deprecated.rst +0
-0
docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 130
Quoted 4 lines
docs/system/deprecated.rst +1
-0@@ -127,6 +127,12 @@ Drives with interface types other than ``if=none`` are for onboard devices. It is possible to use drives the board doesn't pick up with -device. This usage is now deprecated. Use ``if=none`` instead. +Short-form boolean options (since 5.2)
6.0
Quoted 41 lines
docs/system/deprecated.rst +5
-0+'''''''''''''''''''''''''''''''''''''' + +Boolean options such as ``share=on``/``share=off`` can be written +in short form as ``share`` and ``noshare``. This is deprecated +and will cause a warning. QEMU Machine Protocol (QMP) commands ------------------------------------tests/test-qemu-opts.c +1
-1@@ -515,7 +515,7 @@ static void test_opts_parse(void)error_free_or_abort (&err);g_assert (!opts); -/* Implied value */ +/* Implied value (qemu_opts_parse warns but accepts it) */ opts =qemu_opts_parse (&opts_list_03,"an,noaus,noaus=" , false, &error_abort); g_assert_cmpuint(opts_count(opts), ==, 3);util/qemu-option.c +2
-0@@ -756,10 +756,12 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)static const char *get_opt_name_value (const char *params,const char *firstname, +bool warn_on_flag,bool *help_wanted,char **name,char **value) {const char *p; +const char *prefix ="" ;size_t len;bool is_help = false;@@ -776,10 +778,15 @@ static const char *get_opt_name_value(const char *params,if (strncmp (*name,"no" ,2 ) ==0 ) {memmove (*name, *name +2 ,strlen (*name +2 ) +1 );
util/qemu-option.c static const char *get_opt_name_value(const char *params, · line 789
Quoted 10 lines
util/qemu-option.c +5
-0*value =g_strdup ("off" ); + prefix ="no" ; }else { *value =g_strdup ("on" ); is_help =is_help_option (*name); } +if (!is_help && warn_on_flag) { +warn_report ("short-form boolean option '%s%s' deprecated" , prefix, *name); +error_printf ("Please use %s=%s instead\n" , *name, *value); + }
If @warn_on_flag, we warn except for "help" and "?". The exception applies regardless of @help_wanted. Shouldn't we except *only* recognized help requests?
Quoted 7 lines
util/qemu-option.c +0
-0} }else {/* found "foo=bar,more" */ @@ -801,14 +808,14 @@ static const char *get_opt_name_value(const char *params, static bool opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, bool prepend,
util/qemu-option.c static const char *get_opt_name_value(const char *params, · line 818
Quoted 10 lines
util/qemu-option.c +2
-2- bool *help_wanted, Error **errp) + bool warn_on_flag, bool *help_wanted, Error **errp) { char *option, *value;const char *p;QemuOpt *opt;for (p = params; *p;) { - p =get_opt_name_value (p, firstname, help_wanted, &option, &value); + p =get_opt_name_value (p, firstname, warn_on_flag, help_wanted, &option, &value);
Long line. Break it before the three output arguments.
Quoted 57 lines
util/qemu-option.c +7
-7if (help_wanted && *help_wanted) {g_free (option);g_free (value);@@ -839,7 +846,7 @@ static char *opts_parse_id(const char *params)char *name, *value;for (p = params; *p;) { - p =get_opt_name_value (p,NULL ,NULL , &name, &value); + p =get_opt_name_value (p,NULL , false,NULL , &name, &value);if (!strcmp (name,"id" )) {g_free (name);return value;@@ -858,7 +865,7 @@ bool has_help_option(const char *params)bool ret = false;for (p = params; *p;) { - p =get_opt_name_value (p,NULL , &ret, &name, &value); + p =get_opt_name_value (p,NULL , false, &ret, &name, &value);g_free (name);g_free (value);if (ret) {@@ -878,12 +885,12 @@ bool has_help_option(const char *params)bool qemu_opts_do_parse (QemuOpts *opts,const char *params,const char *firstname,Error **errp) { -return opts_do_parse (opts, params, firstname, false,NULL , errp); +return opts_do_parse (opts, params, firstname, false, false,NULL , errp); }static QemuOpts *opts_parse (QemuOptsList *list,const char *params,bool permit_abbrev,bool defaults, -bool *help_wanted,Error **errp) +bool warn_on_flag,bool *help_wanted,Error **errp) {const char *firstname;char *id =opts_parse_id (params);@@ -906,8 +913,8 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,return NULL ; } -if (!opts_do_parse (opts, params, firstname, defaults, help_wanted, - errp)) { +if (!opts_do_parse (opts, params, firstname, defaults, + warn_on_flag, help_wanted, errp)) {qemu_opts_del (opts);return NULL ; }@@ -925,7 +932,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,QemuOpts *qemu_opts_parse (QemuOptsList *list,const char *params,bool permit_abbrev,Error **errp) { -return opts_parse (list, params, permit_abbrev, false,NULL , errp); +return opts_parse (list, params, permit_abbrev, false, false,NULL , errp); }/**
util/qemu-option.c QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, · line 956
Quoted 8 lines
util/qemu-option.c +1
-1@@ -943,7 +950,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,QemuOpts *opts;bool help_wanted = false; - opts =opts_parse (list, params, permit_abbrev, false, + opts =opts_parse (list, params, permit_abbrev, false, true,opts_accepts_any (list) ?NULL : &help_wanted, &err);if (!opts) {
This function now warns, except for "help" and "?". The exception applies even when we treat "help" and "?" as sugar for "help=on" and "?=on" because opts_accepts_any().
It is the only spot that enables the warning.
Does all user input flow through qemu_opts_parse_noisily()?
Quoted 8 lines
util/qemu-option.c +1
-1@@ -962,7 +969,7 @@ void qemu_opts_set_defaults(QemuOptsList *list, const char *params, {QemuOpts *opts; - opts =opts_parse (list, params, permit_abbrev, true,NULL ,NULL ); + opts =opts_parse (list, params, permit_abbrev, true, false,NULL ,NULL );assert (opts); }
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 8 lines · Markus Armbruster
util/qemu-option.c static const char *get_opt_name_value(const char *params, · line 789
Quoted 4 lines
util/qemu-option.c +4
-0+if (!is_help && warn_on_flag) { +warn_report ("short-form boolean option '%s%s' deprecated" , prefix, *name); +error_printf ("Please use %s=%s instead\n" , *name, *value); + }If @warn_on_flag, we warn except for "help" and "?". The exception applies regardless of @help_wanted. Shouldn't we except*only* recognized help requests?
Suggesting "help=yes" would be worse.
Quoted 7 lines
util/qemu-option.c QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, · line 956
Quoted 6 lines
util/qemu-option.c +1
-1- opts =opts_parse (list, params, permit_abbrev, false, + opts =opts_parse (list, params, permit_abbrev, false, true,opts_accepts_any (list) ?NULL : &help_wanted, &err);if (!opts) {
Quoted 8 lines
This function now warns, except for "help" and "?". The exception applies even when we treat "help" and "?" as sugar for "help=on" and "?=on" because
opts_accepts_any().It is the only spot that enables the warning.
Does all user input flow through
qemu_opts_parse_noisily()?
I was going to say yes, but -vnc (and worse, the QMP version of "change vnc") is parsed by qemu_opts_parse() via ui/vnc.c (besides being used by lots of tests). -vnc has several boolean options, and though Libvirt only uses "sasl" it does so in the short form.
My solution would be to deprecate the QMP "change vnc" command, and postpone switching -vnc to qemu_opts_parse_noisily to 6.2.
The main reason to warn for short-form boolean options, is to block them for command line options that are switched to keyval[1]. Adding a warning does not necessarily imply removing in two releases.
Paolo
[1] This series already does that for -M, -accel and -object. This means that applying this series would change the command line incompatibly without a two-release deprecation. It's up for discussion whether to do so, or delay the application of those patches to 6.2. It would be a pity to hold the dependent changes for effectively a year, but it's not a big deal.
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Markus Armbruster
util/qemu-option.c static const char *get_opt_name_value(const char *params, · line 789
Quoted 4 lines
util/qemu-option.c +4
-0+if (!is_help && warn_on_flag) { +warn_report ("short-form boolean option '%s%s' deprecated" , prefix, *name); +error_printf ("Please use %s=%s instead\n" , *name, *value); + }If @warn_on_flag, we warn except for "help" and "?". The exception applies regardless of @help_wanted. Shouldn't we except*only* recognized help requests?
Suggesting "help=yes" would be worse.
Would it?
get_opt_name_value() parses one parameter from params into *name and *value. if help_wanted && is_help, it additionally sets *help_wanted to true. is_help is true when the parameter is "help" or "?".
How could a parameter "help" be handled?
get_opt_name_value() will set
*name = g_strdup("help");
*value = g_strdup("on");If help_wanted, additionally:
*help_wanted = true;
Callers that pass non-null help_wanted can do whatever they want with that. The actual callers do honor the help request. The deprecation warning obviously needs to be suppressed for them.
Callers that pass null help_wanted will treat this just like any other parameter. Use of the boolean sugar is just as deprecated for this parameter as it is for all the others. Suppressing the deprecation warning feels wrong.
The alternative is to *outlaw* parameters "help" and "?" in QemuOpts. I'd be cool with that.
Quoted 15 lines
Quoted 6 lines
util/qemu-option.c QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, · line 956
Quoted 5 lines
util/qemu-option.c +1
-1- opts =opts_parse (list, params, permit_abbrev, false, + opts =opts_parse (list, params, permit_abbrev, false, true,opts_accepts_any (list) ?NULL : &help_wanted, &err);if (!opts) {Quoted 8 lines
This function now warns, except for "help" and "?". The exception applies even when we treat "help" and "?" as sugar for "help=on" and "?=on" because
opts_accepts_any().It is the only spot that enables the warning.
Does all user input flow through
qemu_opts_parse_noisily()?
Quoted 7 lines
I was going to say yes, but -vnc (and worse, the QMP version of "change vnc") is parsed by
qemu_opts_parse()viaui/vnc.c(besides being used by lots of tests). -vnc has several boolean options, and though Libvirt only uses "sasl" it does so in the short form.My solution would be to deprecate the QMP "change vnc" command, and postpone switching -vnc to
qemu_opts_parse_noisilyto 6.2.
QMP command 'change' was deprecated long ago, in 2.5.0 (commit 24fb41330, in 2015). This predated appendix "Deprecated features" (which has since become docs/system/deprecated.rst), and remained missing there until I corrected it in commit 6d570ca10 (v4.2.0).
Quoted 3 lines
The main reason to warn for short-form boolean options, is to block them for command line options that are switched to keyval[1]. Adding a warning does not necessarily imply removing in two releases.
Understand.
Quoted 8 lines
Paolo
[1] This series already does that for -M, -accel and -object. This means that applying this series would change the command line incompatibly without a two-release deprecation. It's up for discussion whether to do so, or delay the application of those patches to 6.2. It would be a pity to hold the dependent changes for effectively a year, but it's not a big deal.
Concur.
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 9 lines · Markus Armbruster
The alternative is to *outlaw* parameters "help" and "?" in QemuOpts. I'd be cool with that. >
Quoted 2 lines
My solution would be to deprecate the QMP "change vnc" command, and postpone switching -vnc to
qemu_opts_parse_noisilyto 6.2.QMP command 'change' was deprecated long ago, in 2.5.0 (commit
24fb41330, in 2015). This predated appendix "Deprecated features" (which has since becomedocs/system/deprecated.rst), and remained missing there until I corrected it in commit6d570ca10(v4.2.0).
Removal patch coming then, together with switching vnc_parse to qemu_opts_parse_noisily.
That would restrict qemu_opts_parse to tests, and implicitly outlaw parameters "help" and "?". The other problem would be solved, albeit a bit indirectly.
Quoted 6 lines
Quoted 3 lines
The main reason to warn for short-form boolean options, is to block them for command line options that are switched to keyval[1]. Adding a warning does not necessarily imply removing in two releases.
Understand.
Quoted 8 lines
Quoted 6 lines
[1] This series already does that for -M, -accel and -object. This means that applying this series would change the command line incompatibly without a two-release deprecation. It's up for discussion whether to do so, or delay the application of those patches to 6.2. It would be a pity to hold the dependent changes for effectively a year, but it's not a big deal.
Concur.
Verbose please. :) Do you think we should delay the conversion of -M/-accel/-object to keyval until 6.2?
Paolo
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Markus Armbruster
The alternative is to *outlaw* parameters "help" and "?" in QemuOpts. I'd be cool with that. >
Quoted 2 lines
My solution would be to deprecate the QMP "change vnc" command, and postpone switching -vnc to
qemu_opts_parse_noisilyto 6.2.QMP command 'change' was deprecated long ago, in 2.5.0 (commit
24fb41330, in 2015). This predated appendix "Deprecated features" (which has since becomedocs/system/deprecated.rst), and remained missing there until I corrected it in commit6d570ca10(v4.2.0).
Quoted 6 lines
Removal patch coming then, together with switching
vnc_parsetoqemu_opts_parse_noisily.That would restrict
qemu_opts_parseto tests, and implicitly outlaw parameters "help" and "?". The other problem would be solved, albeit a bit indirectly.
Please remember to mention the outlaws in a commit message.
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
The main reason to warn for short-form boolean options, is to block them for command line options that are switched to keyval[1]. Adding a warning does not necessarily imply removing in two releases.
Understand.
Quoted 6 lines
[1] This series already does that for -M, -accel and -object. This means that applying this series would change the command line incompatibly without a two-release deprecation. It's up for discussion whether to do so, or delay the application of those patches to 6.2. It would be a pity to hold the dependent changes for effectively a year, but it's not a big deal.
Quoted 4 lines
Quoted 1 line
Concur.
Verbose please. :) Do you think we should delay the conversion of -M/-accel/-object to keyval until 6.2?
I concurred with "it's up for discussion". I'm happy do discuss, of course.
Delaying reduces (but does not eliminate) the risk of breaking stuff that uses the sugar. Is that worth the loss of momentum? Hard to say.
I think we can ignore non-boolean parameters, because if you're using the sugar with those, you're kind of begging for some punishment :)
What are the boolean parameters, and is the *any* evidence of use with the sugar in the wild?
Re: [PATCH 03/25] qemu-option: warn for short-form boolean options
Quoted 8 lines · Markus Armbruster
Quoted 2 lines
Verbose please. Do you think we should delay the conversion of
-M/-accel/-object to keyval until 6.2?I concurred with "it's up for discussion". I'm happy do discuss, of course.
What are the boolean parameters, and is there *any* evidence of use with the sugar in the wild?
There is no evidence for -machine, -accel or -object.
Notably (and for Libvirt only):
- '-object' takes a detour through JSON, and uses sometimes =on/=off or sometimes =yes/=no.
- '-accel' is not used at all
- '-machine' does not use short-form boolean options by sheer luck.
The only known usage in Libvirt, for instance, is for "-chardev" and "-vnc".
Paolo
PATCH 4/25 keyval: accept escaped commas in implied option
In reply to Paolo BonziniThis is used with the weirdly-named device "SUNFD,fdtwo":
$ qemu-system-sparc -device SUNW,,fdtwo,help
SUNW,fdtwo options:
drive=<str> - Node name or ID of a block device to use as a backend
fallback=<FdcDriveType> - FDC drive type, 144/288/120/none/auto (default: "144")
...Therefore, accepting it is a preparatory step towards keyval-ifying -device and the device_add monitor command. In general, however, this unexpected wart of the keyval syntax leads to suboptimal errors compared to QemuOpts:
$ ./qemu-system-x86_64 -object foo,,bar,id=obj qemu-system-x86_64: -object foo,,bar,id=obj: invalid object type: foo,bar $ storage-daemon/qemu-storage-daemon --object foo,,bar,id=obj qemu-storage-daemon: Invalid parameter ''
To implement this, the flow of the parser is changed to first unescape everything up to the next comma or equal sign. This is done in a new function keyval_fetch_string for both the key and value part. Keys therefore are now parsed in unescaped form, but this makes no difference in practice because a comma is an invalid character for a QAPI name. Thus keys with a comma in them are rejected anyway, as demonstrated by the new testcase.
As a side effect of the new code, parse errors are slightly improved as
well: "Invalid parameter ''" becomes "Expected parameter before '='" when keyval is fed a string starting with an equal sign.
The slightly baroque interface of keyval_fetch_string lets me keep the key parsing loop mostly untouched. It is simplified in the next patch, however.
--- include/qemu/help_option.h | 11 --- tests/test-keyval.c | 21 ++++-- util/keyval.c | 145 ++++++++++++++++++++----------------- 3 files changed, 92 insertions(+), 85 deletions(-)
include/qemu/help_option.h +0 -11
@@ -19,15 +19,4 @@ static inline bool is_help_option(const char *s) return !strcmp(s, "?") || !strcmp(s, "help"); } -static inline int starts_with_help_option (const char *s) -{ -if (*s =='?' ) { -return 1 ; - } -if (g_str_has_prefix (s,"help" )) { -return 4 ; - } -return 0 ; -} -#endif
tests/test-keyval.c +13 -8
@@ -89,6 +89,11 @@ static void test_keyval_parse(void)error_free_or_abort (&err);g_assert (!qdict); +/* Keys must be QAPI identifiers */ + qdict =keyval_parse ("weird,,=key" ,NULL ,NULL , &err); +error_free_or_abort (&err); +g_assert (!qdict); +/* Multiple keys, last one wins */ qdict =keyval_parse ("a=1,b=2,,x,a=3" ,NULL ,NULL , &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 2);
@@ -178,15 +183,15 @@ static void test_keyval_parse(void)error_free_or_abort (&err);g_assert (!qdict); -/* Likewise (qemu_opts_parse(): implied key with comma value) */ - qdict =keyval_parse (",,,a=1" ,"implied" ,NULL , &err); -error_free_or_abort (&err); -g_assert (!qdict); +/* Implied key's value can have a comma */ + qdict =keyval_parse (",,,a=1" ,"implied" ,NULL , &error_abort); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, ","); + g_assert_cmpstr(qdict_get_try_str(qdict, "a"), ==, "1"); +qobject_unref (qdict); -/* Implied key's value can't have comma (qemu_opts_parse(): it can) */ - qdict =keyval_parse ("val,,ue" ,"implied" ,NULL , &err); -error_free_or_abort (&err); -g_assert (!qdict); + qdict =keyval_parse ("val,,ue" ,"implied" ,NULL , &error_abort); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val,ue"); +qobject_unref (qdict);/* Empty key is not an implied key */ qdict =keyval_parse ("=val" ,"implied" ,NULL , &err);
util/keyval.c +79 -66
226 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 04/25] keyval: accept escaped commas in implied option
Quoted 1 line · Paolo Bonzini
This is used with the weirdly-named device "SUNFD,fdtwo":
"SUNW,fdtwo"
Suggest "with weirdly-named devices such as "SUNW,fdtwo:", because we've got more weirdos.
Quoted 8 lines
$ qemu-system-sparc -device SUNW,,fdtwo,help SUNW,fdtwo options: drive=<str> - Node name or ID of a block device to use as a backend fallback=<FdcDriveType> - FDC drive type, 144/288/120/none/auto (default: "144") ...Therefore, accepting it is a preparatory step towards keyval-ifying -device and the
device_addmonitor command.
It's a preparatory step, but is it a necessary one? More on that below.
Quoted 8 lines
In general, however, this
unexpected wart of the keyval syntax leads to suboptimal errors compared to QemuOpts:$ ./qemu-system-x86_64 -object foo,,bar,id=obj qemu-system-x86_64: -object foo,,bar,id=obj: invalid object type: foo,bar $ storage-daemon/qemu-storage-daemon --object foo,,bar,id=obj qemu-storage-daemon: Invalid parameter ''
This is a second, independent argument supporting your patch.
As I remarked in reply to a prior post as "[PATCH 1/2] keyval: accept escaped commas in implied option", the suboptimal errors could be improved in a less invasive way. Your way has a distinct advantage,
though: a working patch.
A third argument you've put forward elsewhere, but modestly left out
here: nicer code. I'll get back to it after looking at the followup cleanup in the next patch.
Either one argument could justify the patch, I think.
I'm this explicit to avoid the impression that the critique of the first argument that comes next is me trying to find a reason to shoot down your patch.
I don't think -device *needs* to accept anti-social device names.
We have a few devices with anti-social names, but none of them works with -device, except in a help request.
We don't have to keep requests for human-readable help backwards compible.
Anti-social device names are a usability issue with or without this patch, with or without keyvalified -device. The patch ensures the sugared form of the help request continues to work after keyvalification (the unsugared from is unaffected). You could argue that loss of the sugared form is a usability regression. Maybe. But usability is *poor* in any case. If we really cared for it, we'd get rid of the anti-social names.
My point is: we're sitting in a hole, and the commit message starts with "we need to dig a bit deeper to keep us comfortable".
My first preference: get rid of the anti-social names, drop the first argument from the commit message, and let the patch rest on the other two.
Second preference: rephrase the commit message along the lines of "This is a step towards keyval-ifying -device without fixing the anti-social device names first, and without breaking backward compatibility for help requests".
Quoted 12 lines
To implement this, the flow of the parser is changed to first unescape everything up to the next comma or equal sign. This is done in a new function
keyval_fetch_stringfor both the key and value part. Keys therefore are now parsed in unescaped form, but this makes no difference in practice because a comma is an invalid character for a QAPI name. Thus keys with a comma in them are rejected anyway, as demonstrated by the new testcase.As a side effect of the new code, parse errors are slightly improved as
well: "Invalid parameter ''" becomes "Expected parameter before '='" when keyval is fed a string starting with an equal sign.
Quoted 5 lines
The slightly baroque interface of
keyval_fetch_stringlets me keep the key parsing loop mostly untouched. It is simplified in the next patch, however.Signed-off-by Paolo Bonzini <[email protected]>
I'll now look at the next patch, then get back to this one.
Re: [PATCH 04/25] keyval: accept escaped commas in implied option
In reply to Paolo BonziniPaolo Bonzini <[email protected]> writes:
[...]
Quoted 16 lines
util/keyval.c +2
-2@@ -16,8 +16,8 @@* key-vals = [ key-val { ',' key-val } [ ',' ] ] * key-val = key '=' val | help * key = key-fragment { '.' key-fragment } -* key-fragment = / [^=,.]+ / -* val = { / [^,]+ / | ',,' } +* key-fragment = { / [^=,.] / | ',,' } +* val = { / [^,] / | ',,' } * help = 'help' | '?' * * Semantics defined by reduction to JSON:
util/keyval.c line 82
Quoted 7 lines
util/keyval.c +2
-2@@ -78,13 +78,13 @@* Alternative syntax for use with an implied key: * * key-vals = [ key-val-1st { ',' key-val } [ ',' ] ] -* key-val-1st = val-no-key | key-val -* val-no-key = / [^=,]+ / - help +* key-val-1st = (val-no-key - help) | key-val +* val-no-key = { / [^=,] / | ',,' }
I finally remembered why I made val-no-key non-empty: to avoid amiguity.
Before the patch, "" can only be parsed as empty key-vals. Results in an empty QDict.
Afterwards, the grammar is ambiguous: "" can also be parsed as empty val-no-key, reduced via key-val-1st to non-empty key-vals. Results in a QDict with one entry mapping the implied key to "".
I'm a bit concerned I similarly forgot something that made me avoid ',,' escapes in val-no-key.
Even if we brushed off the ambiguous grammar issue (and we should not!), desugaring "" into "implied=" feels unwise, and ",k=v" into "implied=,k=v" only slightly less so.
Let's keep val-no-key non-empty.
Ripple effect... I made val-no-key match key (almost):
val-no-key = / [^=,]+ /
key = key-fragment { '.' key-fragment }
key-fragment = / [^=,.]+ /The only difference is val-no-key accepts consecutive '.'.
Commit 8bf12c4f75 "keyval: Parse help options" muddied the waters a bit by adding '- help' to val-no-key.
Your commit moves it to key-val-1st (good). It also permits empty key-fragment, and thus consecutive '.' (good because it makes val-no-key match key exactly, but also possibly confusing because key-fragment can't actually be empty due to the "Key-fragments must be valid QAPI names or consist only of decimal digits" condition). Okay.
It also changed both val-no-key and key to accept empty. We need to keep *both* non-empty.
Your change to val is not wrong, but I prefer the old version, because it's closer to how the code works.
util/keyval.c line 86
Quoted 6 lines
util/keyval.c +1
-2* * where val-no-key is syntactic sugar for implied-key=val-no-key. * -* Note that you can't use the sugared form when the value contains -* '=' or ','. +* Note that you can't use the sugared form when the value is empty
You can with your grammar change, unless the code doesn't match the grammar. Which would be a bug.
util/keyval.c line 88
Quoted 2 lines
util/keyval.c +1
-0+* or contains '='. */
[...]
I apologize for sitting on this patch for so long. Something felt wrong, but I couldn't put a finger on it. Now I can at least for the empty val-no-key part.
PATCH 5/25 keyval: simplify keyval_parse_one
In reply to Paolo BonziniNow that the key is NULL terminated, we can remove some of the contortions that were done to operate on possibly '='-terminated strings in keyval_parse_one.
--- util/keyval.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
util/keyval.c +10 -17
@@ -170,11 +170,10 @@ static QObject *keyval_parse_put(QDict *cur,* * On return: * - either NUL or the separator (comma or equal sign) is returned. -* - the length of the string is stored in @len. * - @start is advanced to either the NUL or the first character past the * separator. */ -static char keyval_fetch_string (char **start,size_t *len,bool key) +static char keyval_fetch_string (char **start,bool key) {char sep;char *p, *unescaped;
@@ -197,7 +196,6 @@ static char keyval_fetch_string(char **start, size_t *len, bool key) } *unescaped =0 ; - *len = unescaped - *start; *start = p;return sep; }
@@ -219,7 +217,7 @@ static char *keyval_parse_one(QDict *qdict, char *params, const char *implied_key, bool *help, Error **errp) { - const char *key, *key_end, *s, *end; + const char *key, *s, *end;const char *val =NULL ;char sep;size_t len;
@@ -229,8 +227,8 @@ static char *keyval_parse_one(QDict *qdict, char *params,QObject *next; key = params; - sep =keyval_fetch_string (¶ms, &len, true); -if (!len) { + sep =keyval_fetch_string (¶ms, true); +if (!*key) {if (sep) {error_setg (errp,"Expected parameter before '%c%s'" , sep, params); }else {
@@ -247,13 +245,11 @@ static char *keyval_parse_one(QDict *qdict, char *params,/* Desugar implied key */ val = key; key = implied_key; - len =strlen (implied_key); }else {error_setg (errp,"No implicit parameter name for value '%s'" , key);return NULL ; } } - key_end = key + len;/* * Loop over key fragments: @s points to current fragment, it
@@ -269,24 +265,21 @@ static char *keyval_parse_one(QDict *qdict, char *params, ret =parse_qapi_name (s, false); len = ret <0 ?0 : ret; } -assert (s + len <= key_end); -if (!len || (s + len < key_end && s[len] !='.' )) { +if (!len || (s[len] !='\0' && s[len] !='.' )) {assert (key != implied_key); -error_setg (errp,"Invalid parameter '%.*s'" , - (int )(key_end - key), key); +error_setg (errp,"Invalid parameter '%s'" , key);return NULL ; }if (len >=sizeof (key_in_cur)) {assert (key != implied_key);error_setg (errp,"Parameter%s '%.*s' is too long" , - s != key || s + len != key_end ?" fragment" :"" , + s != key || s[len] =='.' ?" fragment" :"" , (int )len, s);return NULL ; }if (s != key) { - next =keyval_parse_put (cur, key_in_cur,NULL , - key, s -1 , errp); + next =keyval_parse_put (cur, key_in_cur,NULL , key, s -1 , errp);if (!next) {return NULL ; }
@@ -301,9 +294,9 @@ static char *keyval_parse_one(QDict *qdict, char *params,if (key != implied_key) { val = params; -keyval_fetch_string (¶ms, &len, false); +keyval_fetch_string (¶ms, false); } -if (!keyval_parse_put (cur, key_in_cur, val, key, key_end, errp)) { +if (!keyval_parse_put (cur, key_in_cur, val, key, s -1 , errp)) {return NULL ; }return params;
Signature · 1 line
2.26.2
Re: [PATCH 05/25] keyval: simplify keyval_parse_one
Quoted 5 lines · Paolo Bonzini
Now that the key is NULL terminated, we can remove some of the contortions that were done to operate on possibly '='-terminated strings in
keyval_parse_one.Signed-off-by Paolo Bonzini <[email protected]>
Alright, I'm now ready to discuss the third argument: nicer code.
I think there is improvement, and I think it comes mostly from working on a copy. Could be done without the syntax change.
I feel further improvement is possible, but that's no reason to delay this series.
Second argument: better error messages. We discussed that in review of a prior post, but you've since improved your error reporting further, so let's have another look. I'm testing with
$ qemu-storage-daemon --nbd $ARG
because that one doesn't have an implied key, which permits slightly simpler $ARG.
* Empty key
--nbd ,
master: Invalid parameter ''
your patch: Expected parameter before ','
Improvement.
--nbd key=val,=,fob=
master: Invalid parameter ''
your patch: Expected parameter before '=,fob='
Improvement.
* Empty key fragment
--nbd key..=
master: Invalid parameter 'key..'
your patch: same
Could use some love. Not your patch's fault.
--nbd .key=
master: Invalid parameter '..key'
your patch: same
Likweise.
If I omit the '=', your patch's message changes to
No implicit parameter name for value 'key..'
I consider that worse than before, because it's talking about something outside the user's control (lack of an implict parameter name) where it should instead tell the user what needs fixing in the input.
* Missing value
--nbd key
master: Expected '=' after parameter 'key'
your patch: No implicit parameter name for value 'key'
Same criticism as above.
* Invalid key fragment
--nbd _=
master: Invalid parameter '_'
your patch: same
--nbd key.1a.b=
master: Invalid parameter 'key.1a.b'
your patch: same
Could perhaps use some love. Not your patch's fault.
--ndb anti,,social,,key=
master: Expected '=' after parameter 'anti'
your patch: Invalid parameter 'anti,social,key'
The new error message shows the *unescaped* string. Okay.
Your patch also adds an "Expected parameter at end of string" error. Can you tell me how to trigger it?
I think there is improvement, and I think it could also be done without the syntax change.
There also is one regression: "No implicit parameter name..." is no good. Looks fixable to me.
I feel further improvement is possible, but that's no reason to delay this series.
Now let me put the three arguments together.
Nicer code and better error reporting could be had with or without the syntax change. With is a bit easier, because we already have your patch.
The syntax change is a choice we can make. I'm reluctant to mess with the syntax, but if you want the change, I'm not going to block it.
Hmm, bartering opportunity... May I have your support for me eliminating anti-social device names in exchange? ;)
I believe your grammar is ambiguous. Your code seems to pick the sane alternative. If I'm wrong, you need to enlighten me. If I'm right, you need to fix your grammar.
Quoted 79 lines
--- util/keyval.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)util/keyval.c +6
-12@@ -170,11 +170,10 @@ static QObject *keyval_parse_put(QDict *cur,* * On return: * - either NUL or the separator (comma or equal sign) is returned. -* - the length of the string is stored in @len. * - @start is advanced to either the NUL or the first character past the * separator. */ -static char keyval_fetch_string (char **start,size_t *len,bool key) +static char keyval_fetch_string (char **start,bool key) {char sep;char *p, *unescaped;@@ -197,7 +196,6 @@ static char keyval_fetch_string(char **start, size_t *len, bool key) } *unescaped =0 ; - *len = unescaped - *start; *start = p;return sep; }@@ -219,7 +217,7 @@ static char *keyval_parse_one(QDict *qdict, char *params, const char *implied_key, bool *help, Error **errp) { - const char *key, *key_end, *s, *end; + const char *key, *s, *end;const char *val =NULL ;char sep;size_t len;@@ -229,8 +227,8 @@ static char *keyval_parse_one(QDict *qdict, char *params,QObject *next; key = params; - sep =keyval_fetch_string (¶ms, &len, true); -if (!len) { + sep =keyval_fetch_string (¶ms, true); +if (!*key) {if (sep) {error_setg (errp,"Expected parameter before '%c%s'" , sep, params); }else {@@ -247,13 +245,11 @@ static char *keyval_parse_one(QDict *qdict, char *params,/* Desugar implied key */ val = key; key = implied_key; - len =strlen (implied_key); }else {error_setg (errp,"No implicit parameter name for value '%s'" , key);return NULL ; } } - key_end = key + len;/* * Loop over key fragments: @s points to current fragment, it @@ -269,24 +265,21 @@ static char *keyval_parse_one(QDict *qdict, char *params, ret =parse_qapi_name (s, false); len = ret <0 ?0 : ret; } -assert (s + len <= key_end); -if (!len || (s + len < key_end && s[len] !='.' )) { +if (!len || (s[len] !='\0' && s[len] !='.' )) {assert (key != implied_key); -error_setg (errp,"Invalid parameter '%.*s'" , - (int )(key_end - key), key); +error_setg (errp,"Invalid parameter '%s'" , key);return NULL ; }if (len >=sizeof (key_in_cur)) {assert (key != implied_key); error_setg(errp, "Parameter%s '%.*s' is too long",
util/keyval.c static char *keyval_parse_one(QDict *qdict, char *params, · line 282
Quoted 10 lines
util/keyval.c +2
-3- s != key || s + len != key_end ?" fragment" :"" , + s != key || s[len] =='.' ?" fragment" :"" , (int)len, s);return NULL ; }if (s != key) { - next =keyval_parse_put (cur, key_in_cur,NULL , - key, s -1 , errp); + next =keyval_parse_put (cur, key_in_cur,NULL , key, s -1 , errp);
Unrelated line join.
Quoted 15 lines
util/keyval.c +2
-2if (!next) {return NULL ; }@@ -301,9 +294,9 @@ static char *keyval_parse_one(QDict *qdict, char *params,if (key != implied_key) { val = params; -keyval_fetch_string (¶ms, &len, false); +keyval_fetch_string (¶ms, false); } -if (!keyval_parse_put (cur, key_in_cur, val, key, key_end, errp)) { +if (!keyval_parse_put (cur, key_in_cur, val, key, s -1 , errp)) {return NULL ; }return params;
Re: [PATCH 05/25] keyval: simplify keyval_parse_one
Quoted 7 lines · Markus Armbruster
--nbd .key=
master: Invalid parameter '..key'
your patch: sameLikweise.
Quoted 8 lines
If I omit the '=', your patch's message changes to
No implicit parameter name for value 'key..'
I consider that worse than before, because it's talking about something outside the user's control (lack of an implict parameter name) where it should instead tell the user what needs fixing in the input.
I think whether it's better or worse depends on the specific erroneous command line (think "--nbd /path/to/file.qcow2"), but I can certainly change it.
Quoted 2 lines
Your patch also adds an "Expected parameter at end of string" error. Can you tell me how to trigger it?
It is meant for "--nbd ''" but it is effectively dead code due to the "while (*s)" in the caller. Possibilities:
1) leave it in as dead code
2) replace it with an assert
3) change the caller to use a do...while in such a way that it triggers it (and be careful not to change the grammar).
Quoted 3 lines
I believe your grammar is ambiguous. Your code seems to pick the sane alternative. If I'm wrong, you need to enlighten me. If I'm right, you need to fix your grammar.
Will do. Can I change the EBNF to use "+" and "*" for simplicity and clarity?
Quoted 2 lines
Hmm, bartering opportunity... May I have your support for me eliminating anti-social device names in exchange?
I do not mind removing them. What's the barter exactly like? :)
Paolo
Re: [PATCH 05/25] keyval: simplify keyval_parse_one
Quoted 12 lines · Paolo Bonzini
Quoted 10 lines · Markus Armbruster
--nbd .key=
master: Invalid parameter '..key'
your patch: same
Likweise.
If I omit the '=', your patch's message changes to
No implicit parameter name for value 'key..'
I consider that worse than before, because it's talking about something outside the user's control (lack of an implict parameter name) where it should instead tell the user what needs fixing in the input.
Quoted 3 lines
I think whether it's better or worse depends on the specific erroneous command line (think "--nbd /path/to/file.qcow2"), but I can certainly change it.
Quoting myself: Error messages based on guesses what the user has in mind can be quite confusing when we guess wrong. A strictly factual syntax error style like "I expected FOO instead of BAR here" may not be great, but has a relatively low risk of being confusing.
Quoted 7 lines
Quoted 2 lines
Your patch also adds an "Expected parameter at end of string" error. Can you tell me how to trigger it?
It is meant for "--nbd ''" but it is effectively dead code due to the "while (*s)" in the caller. Possibilities:
1) leave it in as dead code
I'd prefer not to.
Quoted 1 line
2) replace it with an assert
Works for me.
Quoted 2 lines
3) change the caller to use a do...while in such a way that it triggers it (and be careful not to change the grammar).
Only if it's not too hard, and results in better error messages.
Quoted 6 lines
Quoted 3 lines
I believe your grammar is ambiguous. Your code seems to pick the sane alternative. If I'm wrong, you need to enlighten me. If I'm right, you need to fix your grammar.
Will do. Can I change the EBNF to use "+" and "*" for simplicity and clarity?
I tried to stick to ISO 14977 as described in
<https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form>, less its foolish ',' for concatenation. I'm not at all enamored with it. All I want is something that is widely understood, and preferably not invented here. Switch to <https://www.w3.org/TR/xml/#sec-notation>
perhaps?
[...]
PATCH 6/25 tests: convert check-qom-proplist to keyval
In reply to Paolo BonziniThe command-line creation test is using QemuOpts. Switch it to keyval, since all the -object command line options will follow qemu-storage-daemon and do the same.
--- tests/check-qom-proplist.c | 58 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-)
tests/check-qom-proplist.c +38 -20
@@ -21,6 +21,8 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" #include "qom/object.h" #include "qemu/module.h" #include "qemu/option.h"
@@ -400,42 +402,58 @@ static void test_dummy_createlist(void)static void test_dummy_createcmdl (void ) { -QemuOpts *opts; +QDict *qdict;DummyObject *dobj;Error *err =NULL ; +bool help;const char *params =TYPE_DUMMY \",id=dev0," \"bv=yes,sv=Hiss hiss hiss,av=platypus" ; -qemu_add_opts (&qemu_object_opts); - opts =qemu_opts_parse (&qemu_object_opts, params, true, &err); + qdict =keyval_parse (params,"qom-type" , &help, &err);g_assert (err ==NULL ); -g_assert (opts); +g_assert (qdict); +g_assert (!help); - dobj =DUMMY_OBJECT (user_creatable_add_opts (opts, &err)); +g_assert (user_creatable_add_dict (qdict, true, &err));g_assert (err ==NULL ); +qobject_unref (qdict); + + dobj =DUMMY_OBJECT (object_resolve_path_component (object_get_objects_root (), +"dev0" ));g_assert (dobj); g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");g_assert (dobj->bv == true);g_assert (dobj->av ==DUMMY_PLATYPUS ); + qdict =keyval_parse (params,"qom-type" , &help, &err); +g_assert (!user_creatable_add_dict (qdict, true, &err)); +g_assert (err); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==OBJECT (dobj)); +qobject_unref (qdict); +error_free (err); + err =NULL ; + + qdict =keyval_parse (params,"qom-type" , &help, &err);user_creatable_del ("dev0" , &error_abort); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==NULL ); -object_unref (OBJECT (dobj)); - -/* -* cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry -* corresponding to the Object's ID to be added to the QemuOptsList -* for objects. To avoid having this entry conflict with future -* Objects using the same ID (which can happen in cases where -* qemu_opts_parse() is used to parse the object params, such as -* with hmp_object_add() at the time of this comment), we need to -* check for this in user_creatable_del() and remove the QemuOpts if -* it is present. -* -* The below check ensures this works as expected. -*/ -g_assert_null (qemu_opts_find (&qemu_object_opts,"dev0" )); +g_assert (user_creatable_add_dict (qdict, true, &err)); +g_assert (err ==NULL ); +qobject_unref (qdict); + + dobj =DUMMY_OBJECT (object_resolve_path_component (object_get_objects_root (), +"dev0" )); +g_assert (dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); +g_assert (dobj->bv == true); +g_assert (dobj->av ==DUMMY_PLATYPUS ); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==OBJECT (dobj)); + +object_unparent (OBJECT (dobj)); }static void test_dummy_badenum (void )
Signature · 1 line
2.26.2
Re: [PATCH 06/25] tests: convert check-qom-proplist to keyval
Quoted 5 lines · Paolo Bonzini
The command-line creation test is using QemuOpts. Switch it to keyval, since all the -object command line options will follow qemu-storage-daemon and do the same.
Signed-off-by Paolo Bonzini <[email protected]>
$ gdb tests/check-qom-proplist [...] (gdb) r [...] # random seed: R02S802948119789b5481f33f9842e3b5d1b 1..9 # Start of qom tests # Start of proplist tests ok 1 /qom/proplist/createlist ok 2 /qom/proplist/createv Unexpected error in find_list() at ../util/qemu-config.c:24: There is no option group 'object'
Thread 1 "check-qom-propl" received signal SIGABRT, Aborted.0x00007ffff7b839e5 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install glib2-2.64.6-1.fc32.x86_64 pcre-8.44-2.fc32.x86_64 (gdb) bt
#0 0x00007ffff7b839e5 in raise () from /lib64/libc.so.6
#1 0x00007ffff7b6c895 in abort () from /lib64/libc.so.6
#2 0x000055555557fe08 in error_handle_fatal (
errp=0x5555555aa300 <error_abort>, err=0x5555555b9580)
at ../util/error.c:40
#3 0x000055555557ff38 in error_setv (errp=0x5555555aa300 <error_abort>,
src=0x5555555914f1 "../util/qemu-config.c", line=24,
func=0x555555591ad0 <__func__.5> "find_list",
err_class=ERROR_CLASS_GENERIC_ERROR,
fmt=0x5555555914d3 "There is no option group '%s'", ap=0x7fffffffd690,
suffix=0x0) at ../util/error.c:73
#4 0x0000555555580116 in error_setg_internal (
errp=0x5555555aa300 <error_abort>,
src=0x5555555914f1 "../util/qemu-config.c", line=24,
func=0x555555591ad0 <__func__.5> "find_list",
fmt=0x5555555914d3 "There is no option group '%s'") at ../util/error.c:97
#5 0x000055555556fdb4 in find_list (lists=0x5555555aa060 <vm_config_groups>,
group=0x55555558e97a "object", errp=0x5555555aa300 <error_abort>)
at ../util/qemu-config.c:24
#6 0x0000555555570426 in qemu_find_opts_err (group=0x55555558e97a "object",
errp=0x5555555aa300 <error_abort>) at ../util/qemu-config.c:275
#7 0x000055555555f8bd in user_creatable_del (id=0x55555558e233 "dev0",
errp=0x5555555aa300 <error_abort>) at ../qom/object_interfaces.c:312
#8 0x000055555555dc8e in test_dummy_createcmdl ()
at ../tests/check-qom-proplist.c:439#9 0x00007ffff7ef429e in g_test_run_suite_internal ()
from /lib64/libglib-2.0.so.0
#10 0x00007ffff7ef409b in g_test_run_suite_internal ()
from /lib64/libglib-2.0.so.0
#11 0x00007ffff7ef409b in g_test_run_suite_internal ()
from /lib64/libglib-2.0.so.0
#12 0x00007ffff7ef478a in g_test_run_suite () from /lib64/libglib-2.0.so.0 #13 0x00007ffff7ef47a5 in g_test_run () from /lib64/libglib-2.0.so.0 #14 0x000055555555e98c in main (argc=1, argv=0x7fffffffdcf8)
at ../tests/check-qom-proplist.c:655
Quoted 9 lines
--- tests/check-qom-proplist.c | 58 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-)tests/check-qom-proplist.c +0
-0
tests/check-qom-proplist.c line 26
Quoted 6 lines
tests/check-qom-proplist.c +2
-0@@ -21,6 +21,8 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" #include "qom/object.h"
I expected this one to go.
Quoted 8 lines
tests/check-qom-proplist.c +1
-1#include "qemu/module.h" #include "qemu/option.h" @@ -400,42 +402,58 @@ static void test_dummy_createlist(void)static void test_dummy_createcmdl (void ) { -QemuOpts *opts; +QDict *qdict;
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 413
Quoted 10 lines
tests/check-qom-proplist.c +2
-2DummyObject *dobj;Error *err =NULL ; +bool help;const char *params =TYPE_DUMMY \",id=dev0," \"bv=yes,sv=Hiss hiss hiss,av=platypus" ; -qemu_add_opts (&qemu_object_opts); - opts =qemu_opts_parse (&qemu_object_opts, params, true, &err); + qdict =keyval_parse (params,"qom-type" , &help, &err);
Removes the only use of qemu_object_opts. You should remove qemu_object_opts, too.
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 423
Quoted 12 lines
tests/check-qom-proplist.c +7
-2g_assert (err ==NULL ); -g_assert (opts); +g_assert (qdict); +g_assert (!help); - dobj =DUMMY_OBJECT (user_creatable_add_opts (opts, &err)); +g_assert (user_creatable_add_dict (qdict, true, &err));g_assert (err ==NULL ); +qobject_unref (qdict); + + dobj =DUMMY_OBJECT (object_resolve_path_component (object_get_objects_root (), +"dev0" ));
Why does user_creatable_add_opts() return the object on success, null on failure, but user_creatable_add_dict() only a rather less useful bool?
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 429
Quoted 6 lines
tests/check-qom-proplist.c +1
-0g_assert (dobj); g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss");g_assert (dobj->bv == true);g_assert (dobj->av ==DUMMY_PLATYPUS ); + qdict =keyval_parse (params,"qom-type" , &help, &err);
Why parse again?
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 431
Quoted 2 lines
tests/check-qom-proplist.c +2
-0+g_assert (!user_creatable_add_dict (qdict, true, &err)); +g_assert (err);
Use error_free_or_abort(&err) instead, and ...
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 434
Quoted 3 lines
tests/check-qom-proplist.c +3
-0+g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==OBJECT (dobj)); +qobject_unref (qdict);
... drop the next two lines:
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 438
Quoted 4 lines
tests/check-qom-proplist.c +4
-0+error_free (err); + err =NULL ; + + qdict =keyval_parse (params,"qom-type" , &help, &err);
And again?
Quoted 10 lines
tests/check-qom-proplist.c +2
-6user_creatable_del ("dev0" , &error_abort); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==NULL ); -object_unref (OBJECT (dobj)); - -/* -* cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry -* corresponding to the Object's ID to be added to the QemuOptsList -* for objects. To avoid having this entry conflict with future
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 443
Quoted 10 lines
tests/check-qom-proplist.c +1
-9-* Objects using the same ID (which can happen in cases where -* qemu_opts_parse() is used to parse the object params, such as -* with hmp_object_add() at the time of this comment), we need to -* check for this in user_creatable_del() and remove the QemuOpts if -* it is present. -* -* The below check ensures this works as expected. -*/ -g_assert_null (qemu_opts_find (&qemu_object_opts,"dev0" )); +g_assert (user_creatable_add_dict (qdict, true, &err));
Am I confused, or are you going from two to three creates? Should this be in a separate patch?
Quoted 16 lines
tests/check-qom-proplist.c +13
-0+g_assert (err ==NULL ); +qobject_unref (qdict); + + dobj =DUMMY_OBJECT (object_resolve_path_component (object_get_objects_root (), +"dev0" )); +g_assert (dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); +g_assert (dobj->bv == true); +g_assert (dobj->av ==DUMMY_PLATYPUS ); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==OBJECT (dobj)); + +object_unparent (OBJECT (dobj)); }static void test_dummy_badenum (void )
Re: [PATCH 06/25] tests: convert check-qom-proplist to keyval
Quoted 3 lines · Markus Armbruster
ok 2 /qom/proplist/createv
Unexpected error infind_list()at../util/qemu-config.c:24:
There is no option group 'object'
Hmm, maybe a semantic conflict when I rebased. I'll take a look.
Quoted 3 lines
Quoted 1 line
+ qdict =
keyval_parse(params, "qom-type", &help, &err);Why parse again?
I don't remember why I did it that way, but it does seem cleaner. Unlike QemuOpts, which are persistent until qemu_opts_del and can be retrieved later, keyval's result only survives as long as you want it to survive, and are leaked if you don't unref the qdict. Parsing every time the object is created seems more similar to the way the vl.c code works.
Quoted 13 lines
tests/check-qom-proplist.c static void test_dummy_createlist(void) · line 443
Quoted 13 lines
tests/check-qom-proplist.c +1
-12-* cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry -* corresponding to the Object's ID to be added to the QemuOptsList -* for objects. To avoid having this entry conflict with future -* Objects using the same ID (which can happen in cases where -* qemu_opts_parse() is used to parse the object params, such as -* with hmp_object_add() at the time of this comment), we need to -* check for this in user_creatable_del() and remove the QemuOpts if -* it is present. -* -* The below check ensures this works as expected. -*/ -g_assert_null (qemu_opts_find (&qemu_object_opts,"dev0" )); +g_assert (user_creatable_add_dict (qdict, true, &err));
Quoted 2 lines
Am I confused, or are you going from two to three creates? Should this be in a separate patch?
It's a different way to test for "you can create another object with the same id" you had before. It used to check for NULL qemu_opts_find, now it checks directly that the creation succeeds. I can put it in the commit message.
Paolo
Quoted 13 lines
Quoted 13 lines
tests/check-qom-proplist.c +13
-0+g_assert (err ==NULL ); +qobject_unref (qdict); + + dobj =DUMMY_OBJECT (object_resolve_path_component (object_get_objects_root (), +"dev0" )); +g_assert (dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); +g_assert (dobj->bv == true); +g_assert (dobj->av ==DUMMY_PLATYPUS ); +g_assert (object_resolve_path_component (object_get_objects_root (),"dev0" ) + ==OBJECT (dobj)); + +object_unparent (OBJECT (dobj));
Re: [PATCH 06/25] tests: convert check-qom-proplist to keyval
In reply to Markus ArmbrusterQuoted 4 lines · Markus Armbruster
Review
Quoted 2 lines
(quoted diff) +2
-0+ dobj = DUMMY_OBJECT(object_resolve_path_component(object_get_objects_root(), + "dev0"));Why does
user_creatable_add_opts()return the object on success, null on failure, butuser_creatable_add_dict()only a rather less useful bool?
I would guess that nobody needs it outside tests (I didn't look at the code).
Quoted 8 lines
Quoted 6 lines
g_assert(dobj); g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); g_assert(dobj->bv == true); g_assert(dobj->av == DUMMY_PLATYPUS);+ qdict =
keyval_parse(params, "qom-type", &help, &err);Why parse again?
Besides the justification of the previous email, user_creatable_add_dict modifies its QDict argument, removing the "qom-type" and "id" keys. Wart fixed in patch 16.
Paolo
PATCH 7/25 keyval: introduce keyval_parse_into
In reply to Paolo BonziniAllow parsing multiple keyval sequences into the same dictionary.
--- include/qemu/option.h | 2 ++ util/keyval.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-)
include/qemu/option.h +2 -0
@@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool print_caption);void qemu_opts_free (QemuOptsList *list);QemuOptsList *qemu_opts_append (QemuOptsList *dst,QemuOptsList *list); +QDict *keyval_parse_into (QDict *qdict,const char *params,const char *implied_key, +bool *p_help,Error **errp);QDict *keyval_parse (const char *params,const char *implied_key,bool *help,Error **errp);
util/keyval.c +32 -7
@@ -436,13 +436,12 @@ static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp)* If @p_help is not NULL, store whether help is requested there. * If @p_help is NULL and help is requested, fail. * -* On success, return a dictionary of the parsed keys and values. +* On success, return @dict, now filled with the parsed keys and values. * On failure, store an error through @errp and return NULL. */ -QDict *keyval_parse (const char *params,const char *implied_key, -bool *p_help,Error **errp) +QDict *keyval_parse_into (QDict *qdict,const char *params,const char *implied_key, +bool *p_help,Error **errp) { -QDict *qdict =qdict_new ();QObject *listified; g_autofree char *dup;char *s;
@@ -452,7 +451,6 @@ QDict *keyval_parse(const char *params, const char *implied_key,while (*s) { s =keyval_parse_one (qdict, s, implied_key, &help, errp);if (!s) { -qobject_unref (qdict);return NULL ; } implied_key =NULL ;
@@ -462,15 +460,42 @@ QDict *keyval_parse(const char *params, const char *implied_key, *p_help = help; }else if (help) {error_setg (errp,"Help is not available for this option" ); -qobject_unref (qdict);return NULL ; } listified =keyval_listify (qdict,NULL , errp);if (!listified) { -qobject_unref (qdict);return NULL ; }assert (listified ==QOBJECT (qdict));return qdict; } + +/* +* Parse @params in QEMU's traditional KEY=VALUE,... syntax. +* +* If @implied_key, the first KEY= can be omitted. @implied_key is +* implied then, and VALUE can't be empty or contain ',' or '='. +* +* A parameter "help" or "?" without a value isn't added to the +* resulting dictionary, but instead is interpreted as help request. +* All other options are parsed and returned normally so that context +* specific help can be printed. +* +* If @p_help is not NULL, store whether help is requested there. +* If @p_help is NULL and help is requested, fail. +* +* On success, return a dictionary of the parsed keys and values. +* On failure, store an error through @errp and return NULL. +*/ +QDict *keyval_parse (const char *params,const char *implied_key, +bool *p_help,Error **errp) +{ +QDict *qdict =qdict_new (); +QDict *ret =keyval_parse_into (qdict, params, implied_key, p_help, errp); + +if (!ret) { +qobject_unref (qdict); + } +return ret; +}
Signature · 1 line
2.26.2
Re: [PATCH 07/25] keyval: introduce keyval_parse_into
Quoted 3 lines · Paolo Bonzini
Allow parsing multiple keyval sequences into the same dictionary.
Signed-off-by Paolo Bonzini <[email protected]>
I trust later patches will make the need for this obvious.
I guess we could use qdict_join() instead. Observation, not objection.
Quoted 23 lines
--- include/qemu/option.h | 2 ++ util/keyval.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-)include/qemu/option.h +2
-0@@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool print_caption);void qemu_opts_free (QemuOptsList *list);QemuOptsList *qemu_opts_append (QemuOptsList *dst,QemuOptsList *list); +QDict *keyval_parse_into (QDict *qdict,const char *params,const char *implied_key, +bool *p_help,Error **errp);QDict *keyval_parse (const char *params,const char *implied_key,bool *help,Error **errp);util/keyval.c +0
-0
util/keyval.c static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp) · line 440
Quoted 6 lines
util/keyval.c +1
-1@@ -436,13 +436,12 @@ static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp)* If @p_help is not NULL, store whether help is requested there. * If @p_help is NULL and help is requested, fail. * -* On success, return a dictionary of the parsed keys and values. +* On success, return @dict, now filled with the parsed keys and values. * On failure, store an error through @errp and return NULL.
May @dict be modified then?
Quoted 63 lines
util/keyval.c +31
-6*/ -QDict *keyval_parse (const char *params,const char *implied_key, -bool *p_help,Error **errp) +QDict *keyval_parse_into (QDict *qdict,const char *params,const char *implied_key, +bool *p_help,Error **errp) { -QDict *qdict =qdict_new ();QObject *listified; g_autofree char *dup;char *s;@@ -452,7 +451,6 @@ QDict *keyval_parse(const char *params, const char *implied_key,while (*s) { s =keyval_parse_one (qdict, s, implied_key, &help, errp);if (!s) { -qobject_unref (qdict);return NULL ; } implied_key =NULL ;@@ -462,15 +460,42 @@ QDict *keyval_parse(const char *params, const char *implied_key, *p_help = help; }else if (help) {error_setg (errp,"Help is not available for this option" ); -qobject_unref (qdict);return NULL ; } listified =keyval_listify (qdict,NULL , errp);if (!listified) { -qobject_unref (qdict);return NULL ; }assert (listified ==QOBJECT (qdict));return qdict; } + +/* +* Parse @params in QEMU's traditional KEY=VALUE,... syntax. +* +* If @implied_key, the first KEY= can be omitted. @implied_key is +* implied then, and VALUE can't be empty or contain ',' or '='. +* +* A parameter "help" or "?" without a value isn't added to the +* resulting dictionary, but instead is interpreted as help request. +* All other options are parsed and returned normally so that context +* specific help can be printed. +* +* If @p_help is not NULL, store whether help is requested there. +* If @p_help is NULL and help is requested, fail. +* +* On success, return a dictionary of the parsed keys and values. +* On failure, store an error through @errp and return NULL. +*/ +QDict *keyval_parse (const char *params,const char *implied_key, +bool *p_help,Error **errp) +{ +QDict *qdict =qdict_new (); +QDict *ret =keyval_parse_into (qdict, params, implied_key, p_help, errp); + +if (!ret) { +qobject_unref (qdict); + } +return ret; +}
Re: [PATCH 07/25] keyval: introduce keyval_parse_into
Quoted 3 lines · Markus Armbruster
Quoted 2 lines
+ * On success, return @dict, now filled with the parsed keys and values.
* On failure, store an error through @errp and return NULL.May @dict be modified then?
Yes, it can. Good point.
Paolo
PATCH 8/25 hmp: replace "O" parser with keyval
In reply to Paolo BonziniHMP is using QemuOpts to parse free-form commands device_add, netdev_add and object_add. However, none of these need QemuOpts for validation (these three QemuOptsLists are all of the catch-all kind), and keyval is already able to parse into QDict. So use keyval directly, avoiding the detour from
string to QemuOpts to QDict.
The args_type now stores the implied key. This arguably makes more sense than storing the QemuOptsList name; at least, it _is_ a key that might end up in the arguments QDict.
--- hmp-commands.hx | 6 +++--- monitor/hmp.c | 20 +++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-)
hmp-commands.hx +3 -3
@@ -669,7 +669,7 @@ ERST { .name = "device_add", - .args_type = "device:O", + .args_type = "driver:O", .params = "driver[,prop=value][,...]", .help = "add device, like -device on the command line", .cmd = hmp_device_add,
@@ -1315,7 +1315,7 @@ ERST { .name = "netdev_add", - .args_type = "netdev:O", + .args_type = "type:O", .params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]", .help = "add host network device", .cmd = hmp_netdev_add,
@@ -1343,7 +1343,7 @@ ERST { .name = "object_add", - .args_type = "object:O", + .args_type = "qom-type:O", .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .cmd = hmp_object_add,
monitor/hmp.c +9 -11
@@ -744,13 +744,9 @@ static QDict *monitor_parse_arguments(Monitor *mon,break ;case 'O' : { -QemuOptsList *opts_list; -QemuOpts *opts; +Error *errp; +bool help; - opts_list =qemu_find_opts (key); -if (!opts_list || opts_list->desc->name) { - goto bad_type; - }while (qemu_isspace (*p)) { p++; }
@@ -760,12 +756,14 @@ static QDict *monitor_parse_arguments(Monitor *mon,if (get_str (buf,sizeof (buf), &p) <0 ) { goto fail; } - opts =qemu_opts_parse_noisily (opts_list, buf, true); -if (!opts) { - goto fail; +keyval_parse_into (qdict, buf, key, &help, &errp); +if (help) { +if (qdict_haskey (qdict, key)) { +qdict_put_bool (qdict,"help" , true); + }else { +qdict_put_str (qdict, key,"help" ); + } } -qemu_opts_to_qdict (opts, qdict); -qemu_opts_del (opts); }break ;case '/' :
Signature · 1 line
2.26.2
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 7 lines · Paolo Bonzini
HMP is using QemuOpts to parse free-form commands
device_add,netdev_addandobject_add. However, none of these need QemuOpts for validation (these three QemuOptsLists are all of the catch-all kind), and keyval is already able to parse into QDict. So use keyval directly, avoiding the detour from
string to QemuOpts to QDict.
Quoted 5 lines
The
args_typenow stores the implied key. This arguably makes more sense than storing the QemuOptsList name; at least, it _is_ a key that might end up in the arguments QDict.Signed-off-by Paolo Bonzini <[email protected]>
Switching from QemuOpts to keyval changes the accepted language. We may change it, because HMP is not a stable interface. The commit message should point out the change, though. Maybe even release notes, not sure.
Let's recap the differences briefly:
* Boolean sugar: deprecated in QemuOpts, nonexistent in keyval
* QemuOpts accepts a number of more or less crazy corner cases keyval
rejects: invalid key, long key (silently truncated), first rather than last id= wins (unlike other keys), implied key with empty value.
* QemuOpts rejects anti-social ID such as id=666, keyval leaves this to the caller, because key "id" is not special in keyval.
Are these still rejected with your patch?
Quoted 57 lines
--- hmp-commands.hx | 6 +++--- monitor/hmp.c | 20 +++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-)hmp-commands.hx +3
-3@@ -669,7 +669,7 @@ ERST { .name = "device_add", - .args_type = "device:O", + .args_type = "driver:O", .params = "driver[,prop=value][,...]", .help = "add device, like -device on the command line", .cmd = hmp_device_add,@@ -1315,7 +1315,7 @@ ERST { .name = "netdev_add", - .args_type = "netdev:O", + .args_type = "type:O", .params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]", .help = "add host network device", .cmd = hmp_netdev_add,@@ -1343,7 +1343,7 @@ ERST { .name = "object_add", - .args_type = "object:O", + .args_type = "qom-type:O", .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .cmd = hmp_object_add,monitor/hmp.c +2
-6@@ -744,13 +744,9 @@ static QDict *monitor_parse_arguments(Monitor *mon,break ;case 'O' : { -QemuOptsList *opts_list; -QemuOpts *opts; +Error *errp; +bool help; - opts_list =qemu_find_opts (key); -if (!opts_list || opts_list->desc->name) { - goto bad_type; - }while (qemu_isspace (*p)) { p++; }
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 760
Quoted 8 lines
monitor/hmp.c +2
-3@@ -760,12 +756,14 @@ static QDict *monitor_parse_arguments(Monitor *mon,if (get_str (buf,sizeof (buf), &p) <0 ) { goto fail; } - opts =qemu_opts_parse_noisily (opts_list, buf, true); -if (!opts) { - goto fail; +keyval_parse_into (qdict, buf, key, &help, &errp); +if (help) {
Uh...
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 761
Quoted 1 line
monitor/hmp.c +1
-0+if (qdict_haskey (qdict, key)) {
If we parsed a value for the implied key (sugared or not),
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 762
Quoted 1 line
monitor/hmp.c +1
-0+qdict_put_bool (qdict,"help" , true);
then encode the help request by mapping key "help" to true,
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 764
Quoted 2 lines
monitor/hmp.c +2
-0+ }else { +qdict_put_str (qdict, key,"help" );
else by mapping the implied key to "help".
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 765
Quoted 1 line
monitor/hmp.c +1
-0+ }
Test cases:
* device_add help
@qdict before the patch:
{
"driver": "help"
}No change.
* device_add e1000,help
@qdict before the patch:
{
"driver": "e1000",
"help": "on"
}Afterwards:
{
"driver": "e1000",
"help": true
}If this is okay, the commit message should explain it.
* device_add help,e1000
{
"e1000": "on",
"driver": "help"
} Afterwards:
upstream-qemu: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed.
Quoted 6 lines
monitor/hmp.c +0
-2} -qemu_opts_to_qdict (opts, qdict); -qemu_opts_del (opts); }break ;case '/' :
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 24 lines · Markus Armbruster
Quoted 7 lines · Paolo Bonzini
HMP is using QemuOpts to parse free-form commands
device_add,netdev_addandobject_add. However, none of these need QemuOpts for validation (these three QemuOptsLists are all of the catch-all kind), and keyval is already able to parse into QDict. So use keyval directly, avoiding the detour from
string to QemuOpts to QDict.Quoted 5 lines
The
args_typenow stores the implied key. This arguably makes more sense than storing the QemuOptsList name; at least, it _is_ a key that might end up in the arguments QDict.Signed-off-by Paolo Bonzini <[email protected]>Switching from QemuOpts to keyval changes the accepted language. We may change it, because HMP is not a stable interface. The commit message should point out the change, though. Maybe even release notes, not sure.
Let's recap the differences briefly:
* Boolean sugar: deprecated in QemuOpts, nonexistent in keyval
Quoted 8 lines
* QemuOpts accepts a number of more or less crazy corner cases keyval
rejects: invalid key, long key (silently truncated), first rather than last id= wins (unlike other keys), implied key with empty value.* QemuOpts rejects anti-social ID such as id=666, keyval leaves this to the caller, because key "id" is not special in keyval.
Are these still rejected with your patch?
Back here... No, and that's a feature. There's no reason to reject those ids. However, this shows that Kevin's series to move --object to keyval propagates a bug from qemu-storage-daemon to QEMU:
$ storage-daemon/qemu-storage-daemon --object authz-simple,id=123/546,identity=abc --chardev stdio,id=foo --monitor chardev=foo
Quoted 2 lines
{'execute':'qmp_capabilities'} {'execute':'qom-list', 'arguments': {'path':'/objects'}}
< {"return": [{"name": "type", "type": "string"}, {"name": "123/546", "type": "child<authz-simple>"}]}
Good luck using that object anywhere. :)
Quoted 9 lines
*
device_addhelp,e1000{ "e1000": "on", "driver": "help" }Afterwards: upstream-qemu: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed.
I cannot reproduce it:
$ ./qemu-system-x86_64 -M none -monitor stdio -display none QEMU 5.2.50 monitor - type 'help' for more information (qemu) device_add help,e1000 Error: Parameter 'driver' is missing
Paolo
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 41 lines · Paolo Bonzini
Quoted 24 lines · Markus Armbruster
Quoted 7 lines · Paolo Bonzini
HMP is using QemuOpts to parse free-form commands
device_add,netdev_addandobject_add. However, none of these need QemuOpts for validation (these three QemuOptsLists are all of the catch-all kind), and keyval is already able to parse into QDict. So use keyval directly, avoiding the detour from
string to QemuOpts to QDict.Quoted 5 lines
The
args_typenow stores the implied key. This arguably makes more sense than storing the QemuOptsList name; at least, it _is_ a key that might end up in the arguments QDict.Signed-off-by Paolo Bonzini <[email protected]>Switching from QemuOpts to keyval changes the accepted language. We may change it, because HMP is not a stable interface. The commit message should point out the change, though. Maybe even release notes, not sure.
Let's recap the differences briefly:
* Boolean sugar: deprecated in QemuOpts, nonexistent in keyval
Quoted 8 lines
* QemuOpts accepts a number of more or less crazy corner cases keyval
rejects: invalid key, long key (silently truncated), first rather than last id= wins (unlike other keys), implied key with empty value.* QemuOpts rejects anti-social ID such as id=666, keyval leaves this to the caller, because key "id" is not special in keyval.
Are these still rejected with your patch?
Back here... No, and that's a feature. There's no reason to reject those ids. However, this shows that Kevin's series to move --object to keyval propagates a bug from qemu-storage-daemon to QEMU:
$ storage-daemon/qemu-storage-daemon --object authz-simple,id=123/546,identity=abc --chardev stdio,id=foo --monitor chardev=foo
Quoted 6 lines
Quoted 2 lines
{'execute':'qmp_capabilities'} {'execute':'qom-list', 'arguments': {'path':'/objects'}}
< {"return": [{"name": "type", "type": "string"}, {"name": "123/546", "type": "child<authz-simple>"}]}
Good luck using that object anywhere. :)
There is no reason to reject those IDs other than spoiling the fun we're having with setting traps for our users.
Since QOM is treating '/' specially in paths, and uses IDs as path components, it should reject '/' in IDs. Same reasoning as for file names.
We already restrict IDs to "letters, digits, '-', '.', '_', starting with a letter" in several places, including QemuOpts. We should do that more, not less.
Permitting arbitrary IDs buys us nothing but trouble.
Quoted 10 lines
Quoted 9 lines
*
device_addhelp,e1000{ "e1000": "on", "driver": "help" }Afterwards: upstream-qemu: ../util/error.c:59: error_setv: Assertion `*errp == NULL' failed.
Quoted 6 lines
I cannot reproduce it:
$ ./qemu-system-x86_64 -M none -monitor stdio -display none QEMU 5.2.50 monitor - type 'help' for more information (qemu) device_add help,e1000 Error: Parameter 'driver' is missing
I'll double-check and report back.
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 6 lines · Markus Armbruster
There is no reason to reject those IDs other than spoiling the fun we're having with setting traps for our users.
Since QOM is treating '/' specially in paths, and uses IDs as path components, it should reject '/' in IDs. Same reasoning as for file names.
I agree; however I don't think it buys anything to do that in HMP rather than further down the call chain, because in the end there are other ways to get "anti-social" ids than HMP or the command line. I commented on Kevin's object-add series about this issue.
Paolo
Quoted 5 lines
We already restrict IDs to "letters, digits, '-', '.', '_', starting with a letter" in several places, including QemuOpts. We should do that more, not less.
Permitting arbitrary IDs buys us nothing but trouble.
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Markus Armbruster
There is no reason to reject those IDs other than spoiling the fun we're having with setting traps for our users.
Quoted 8 lines
Quoted 3 lines
Since QOM is treating '/' specially in paths, and uses IDs as path components, it should reject '/' in IDs. Same reasoning as for file names.
I agree; however I don't think it buys anything to do that in HMP rather than further down the call chain, because in the end there are other ways to get "anti-social" ids than HMP or the command line. I commented on Kevin's object-add series about this issue.
Further down is better provided further down actually does it :)
Anyway, please amend the commit message to describe user-visible differences. Doesn't have to be perfectly exhaustive; glossing over the more eccentric corner cases should be okay.
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
In reply to Markus ArmbrusterQuoted 72 lines · Markus Armbruster
Quoted 7 lines · Paolo Bonzini
HMP is using QemuOpts to parse free-form commands
device_add,netdev_addandobject_add. However, none of these need QemuOpts for validation (these three QemuOptsLists are all of the catch-all kind), and keyval is already able to parse into QDict. So use keyval directly, avoiding the detour from
string to QemuOpts to QDict.Quoted 5 lines
The
args_typenow stores the implied key. This arguably makes more sense than storing the QemuOptsList name; at least, it _is_ a key that might end up in the arguments QDict.Signed-off-by Paolo Bonzini <[email protected]>Switching from QemuOpts to keyval changes the accepted language. We may change it, because HMP is not a stable interface. The commit message should point out the change, though. Maybe even release notes, not sure.
Let's recap the differences briefly:
* Boolean sugar: deprecated in QemuOpts, nonexistent in keyval
* QemuOpts accepts a number of more or less crazy corner cases keyval
rejects: invalid key, long key (silently truncated), first rather than last id= wins (unlike other keys), implied key with empty value.* QemuOpts rejects anti-social ID such as id=666, keyval leaves this to the caller, because key "id" is not special in keyval.
Are these still rejected with your patch?
Quoted 39 lines
--- hmp-commands.hx | 6 +++--- monitor/hmp.c | 20 +++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-)hmp-commands.hx +3
-3@@ -669,7 +669,7 @@ ERST { .name = "device_add", - .args_type = "device:O", + .args_type = "driver:O", .params = "driver[,prop=value][,...]", .help = "add device, like -device on the command line", .cmd = hmp_device_add,@@ -1315,7 +1315,7 @@ ERST { .name = "netdev_add", - .args_type = "netdev:O", + .args_type = "type:O", .params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]", .help = "add host network device", .cmd = hmp_netdev_add,@@ -1343,7 +1343,7 @@ ERST { .name = "object_add", - .args_type = "object:O", + .args_type = "qom-type:O", .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .cmd = hmp_object_add,monitor/hmp.c +0
-1--- a/monitor/hmp.c
Quoted 8 lines
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 747
Quoted 8 lines
+++
b/monitor/hmp.cmonitor/hmp.c +1
-2@@ -744,13 +744,9 @@ static QDict *monitor_parse_arguments(Monitor *mon,break ;case 'O' : { -QemuOptsList *opts_list; -QemuOpts *opts; +Error *errp;
Missing initializer. This is what causes the assertion failure reported below.
Quoted 68 lines
Quoted 10 lines
monitor/hmp.c +1
-4+bool help; - opts_list =qemu_find_opts (key); -if (!opts_list || opts_list->desc->name) { - goto bad_type; - }while (qemu_isspace (*p)) { p++; }monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 760
Quoted 8 lines
monitor/hmp.c +2
-3@@ -760,12 +756,14 @@ static QDict *monitor_parse_arguments(Monitor *mon,if (get_str (buf,sizeof (buf), &p) <0 ) { goto fail; } - opts =qemu_opts_parse_noisily (opts_list, buf, true); -if (!opts) { - goto fail; +keyval_parse_into (qdict, buf, key, &help, &errp); +if (help) {Uh...
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 761
Quoted 1 line
monitor/hmp.c +1
-0+if (qdict_haskey (qdict, key)) {If we parsed a value for the implied key (sugared or not),
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 762
Quoted 1 line
monitor/hmp.c +1
-0+qdict_put_bool (qdict,"help" , true);then encode the help request by mapping key "help" to true,
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 764
Quoted 2 lines
monitor/hmp.c +2
-0+ }else { +qdict_put_str (qdict, key,"help" );else by mapping the implied key to "help".
monitor/hmp.c static QDict *monitor_parse_arguments(Monitor *mon, · line 765
Quoted 1 line
monitor/hmp.c +1
-0+ }Test cases:
*
device_addhelp@qdict before the patch:
{ "driver": "help" }No change.
*
device_adde1000,help@qdict before the patch:
{ "driver": "e1000", "help": "on" }Afterwards:
{ "driver": "e1000", "help": true }If this is okay, the commit message should explain it.
*
device_addhelp,e1000
Quoted 7 lines
{ "e1000": "on", "driver": "help" }Afterwards:
upstream-qemu:../util/error.c:59:error_setv: Assertion `*errp == NULL' failed.
Optimization masks this crash for me.
With proper initialization, I get
{
"driver": "help"
}instead. If this change is okay, the commit message should explain it.
Quoted 7 lines
Quoted 7 lines
monitor/hmp.c +0
-2} -qemu_opts_to_qdict (opts, qdict); -qemu_opts_del (opts); }break ;case '/' :
Re: [PATCH 08/25] hmp: replace "O" parser with keyval
Quoted 8 lines · Markus Armbruster
With proper initialization, I get
{ "driver": "help" }instead. If this change is okay, the commit message should explain it.
Matches "qemu-system-x86_64 -device help,e1000", so it should be okay.
Paolo
PATCH 9/25 qom: use qemu_printf to print help for user-creatable objects
In reply to Paolo BonziniThis is needed when we add help support for object_add.
--- qom/object_interfaces.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
qom/object_interfaces.c +7 -6
@@ -12,6 +12,7 @@#include "qemu/option.h" #include "qapi/opts-visitor.h" #include "qemu/config-file.h" +#include "qemu/qemu-print.h" bool user_creatable_complete (UserCreatable *uc,Error **errp) {
@@ -214,15 +215,15 @@ char *object_property_help(const char *name, const char *type,return g_string_free (str, false); } -static void user_creatable_print_types (void ) +void user_creatable_print_types (void ) {GSList *l, *list; -printf ("List of user creatable objects:\n" ); +qemu_printf ("List of user creatable objects:\n" ); list =object_class_get_list_sorted (TYPE_USER_CREATABLE , false);for (l = list; l !=NULL ; l = l->next) {ObjectClass *oc =OBJECT_CLASS (l->data); -printf (" %s\n" ,object_class_get_name (oc)); +qemu_printf (" %s\n" ,object_class_get_name (oc)); }g_slist_free (list); }
@@ -253,12 +254,12 @@ static bool user_creatable_print_type_properites(const char *type) }g_ptr_array_sort (array, (GCompareFunc )qemu_pstrcmp0);if (array->len >0 ) { -printf ("%s options:\n" , type); +qemu_printf ("%s options:\n" , type); }else { -printf ("There are no options for %s.\n" , type); +qemu_printf ("There are no options for %s.\n" , type); }for (i =0 ; i < array->len; i++) { -printf ("%s\n" , (char *)array->pdata[i]); +qemu_printf ("%s\n" , (char *)array->pdata[i]); }g_ptr_array_set_free_func (array, g_free);g_ptr_array_free (array, true);
Signature · 1 line
2.26.2
Re: [PATCH 09/25] qom: use qemu_printf to print help for user-creatable objects
Quoted 3 lines · Paolo Bonzini
This is needed when we add help support for
object_add.Signed-off-by Paolo Bonzini <[email protected]>
PATCH 10/25 hmp: special case help options for object_add
In reply to Paolo BonziniFix "object_add help" and "object_add TYPE,help".
--- include/qom/object_interfaces.h | 9 ++++++++- monitor/hmp-cmds.c | 22 ++++++++-------------- qom/object_interfaces.c | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-)
include/qom/object_interfaces.h +8 -1
@@ -149,6 +149,13 @@ typedef bool (*user_creatable_add_opts_predicate)(const char *type);int user_creatable_add_opts_foreach (void *opaque,QemuOpts *opts,Error **errp); +/** +* user_creatable_print_types: +* +* Prints a list of user-creatable objects to stdout or the monitor. +*/ +void user_creatable_print_types (void ); +/** * user_creatable_print_help: * @type: the QOM type to be added
@@ -174,7 +181,7 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts);* no help was requested. It should only be called if we know that help is * requested and it will always print some help. */ -void user_creatable_print_help_from_qdict (QDict *args); +void user_creatable_print_help_from_qdict (const QDict *args);/** * user_creatable_del:
monitor/hmp-cmds.c +8 -14
@@ -1663,23 +1663,17 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)void hmp_object_add (Monitor *mon,const QDict *qdict) {Error *err =NULL ; -QemuOpts *opts; -Object *obj =NULL ; - opts =qemu_opts_from_qdict (qemu_find_opts ("object" ), qdict, &err); -if (err) { - goto end; +if (is_help_option (qdict_get_str (qdict,"qom-type" ))) { +user_creatable_print_types (); +return ; } - - obj =user_creatable_add_opts (opts, &err); -qemu_opts_del (opts); - -end: -hmp_handle_error (mon, err); - -if (obj) { -object_unref (obj); +if (qdict_haskey (qdict,"help" )) { +user_creatable_print_help_from_qdict (qdict); +return ; } +user_creatable_add_dict ((QDict *)qdict, true, &err); +hmp_handle_error (mon, err); }void hmp_getfd (Monitor *mon,const QDict *qdict)
qom/object_interfaces.c +1 -1
@@ -280,7 +280,7 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)return false; } -void user_creatable_print_help_from_qdict (QDict *args) +void user_creatable_print_help_from_qdict (const QDict *args) {const char *type =qdict_get_try_str (args,"qom-type" );
Signature · 1 line
2.26.2
Re: [PATCH 10/25] hmp: special case help options for object_add
Quoted 3 lines · Paolo Bonzini
Fix "
object_addhelp" and "object_addTYPE,help".Signed-off-by Paolo Bonzini <[email protected]>
Standard question when I read "Fix $interface" in a commit message: how exactly is it broken?
Re: [PATCH 10/25] hmp: special case help options for object_add
Quoted 8 lines · Markus Armbruster
Quoted 3 lines · Paolo Bonzini
Fix "
object_addhelp" and "object_addTYPE,help".Signed-off-by Paolo Bonzini <[email protected]>Standard question when I read "Fix $interface" in a commit message: how exactly is it broken?
It doesn't work at all ("Error: parameter 'id' is missing").
Paolo
Re: [PATCH 10/25] hmp: special case help options for object_add
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Markus Armbruster
Quoted 3 lines · Paolo Bonzini
Fix "
object_addhelp" and "object_addTYPE,help".Signed-off-by Paolo Bonzini <[email protected]>Standard question when I read "Fix $interface" in a commit message:
how
exactly is it broken?It doesn't work at all ("Error: parameter 'id' is missing").
Adding simple reproducers to commit messages won't hurt a bit, I promise!
;-P
PATCH 11/25 remove -writeconfig
In reply to Paolo BonziniLike -set and -readconfig, it would not really be too hard to extend -writeconfig to parsing mechanisms other than QemuOpts. However, the uses of -writeconfig are substantially more limited, as it is generally easier to write the configuration by hand in the first place. In addition, -writeconfig does not even try to detect cases where it prints incorrect syntax (for example if values have a quote in them, since qemu_config_parse does not support any kind of escaping. Just remove it.
--- include/qemu/config-file.h | 1 - qemu-options.hx | 13 ++---------- softmmu/vl.c | 19 ----------------- util/qemu-config.c | 42 -------------------------------------- 4 files changed, 2 insertions(+), 73 deletions(-)
include/qemu/config-file.h +0 -1
@@ -10,7 +10,6 @@ void qemu_add_opts(QemuOptsList *list);void qemu_add_drive_opts (QemuOptsList *list);int qemu_global_option (const char *str); -void qemu_config_write (FILE *fp);int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname);int qemu_read_config_file (const char *filename);
qemu-options.hx +2 -11
@@ -4301,23 +4301,14 @@ SRST ERST DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig <file>\n", QEMU_ARCH_ALL) + "-readconfig <file>\n" + " read config file\n", QEMU_ARCH_ALL) SRST ``-readconfig file`` Read device configuration from file. This approach is useful when you want to spawn QEMU process with many command line options but you don't want to exceed the command line character limit. ERST -DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, - "-writeconfig <file>\n" - " read/write config file\n", QEMU_ARCH_ALL) -SRST -``-writeconfig file`` - Write device configuration to file. The file can be either filename - to save command line and device configuration into file or dash - ``-``) character to print the output to stdout. This can be later - used as input file for ``-readconfig`` option. -ERST DEF("no-user-config", 0, QEMU_OPTION_nouserconfig, "-no-user-config\n"
softmmu/vl.c +0 -19
@@ -3337,25 +3337,6 @@ void qemu_init(int argc, char **argv, char **envp) } display_remote++;break ; -case QEMU_OPTION_writeconfig: - { -FILE *fp; -if (strcmp (optarg,"-" ) ==0 ) { - fp = stdout; - }else { - fp =fopen (optarg,"w" ); -if (fp ==NULL ) { -error_report ("open %s: %s" , optarg, -strerror (errno)); -exit (1 ); - } - } -qemu_config_write (fp); -if (fp != stdout) { -fclose (fp); - } -break ; - }case QEMU_OPTION_qtest: qtest_chrdev = optarg;break ;
util/qemu-config.c +0 -42
48 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 11/25] remove -writeconfig
Quoted 11 lines · Paolo Bonzini
Like -set and -readconfig, it would not really be too hard to extend -writeconfig to parsing mechanisms other than QemuOpts. However, the uses of -writeconfig are substantially more limited, as it is generally easier to write the configuration by hand in the first place. In addition, -writeconfig does not even try to detect cases where it prints incorrect syntax (for example if values have a quote in them, since
qemu_config_parsedoes not support any kind of escaping. Just remove it.Signed-off-by Paolo Bonzini <[email protected]>
I love the "and how give me a config file for all that" idea, but I agree our -writeconfig is flawed. I hope we can bring it back in more useful shape.
No deprecation grace period?
Quoted 24 lines
--- include/qemu/config-file.h | 1 - qemu-options.hx | 13 ++---------- softmmu/vl.c | 19 ----------------- util/qemu-config.c | 42 -------------------------------------- 4 files changed, 2 insertions(+), 73 deletions(-)include/qemu/config-file.h +0
-1@@ -10,7 +10,6 @@ void qemu_add_opts(QemuOptsList *list);void qemu_add_drive_opts (QemuOptsList *list);int qemu_global_option (const char *str); -void qemu_config_write (FILE *fp);int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname);int qemu_read_config_file (const char *filename);qemu-options.hx +0
-0
qemu-options.hx SRST · line 4305
Quoted 6 lines
qemu-options.hx +2
-1@@ -4301,23 +4301,14 @@ SRST ERST DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig <file>\n", QEMU_ARCH_ALL) + "-readconfig <file>\n" + " read config file\n", QEMU_ARCH_ALL)
Sure this belongs?
Quoted 102 lines
qemu-options.hx +0
-10SRST ``-readconfig file`` Read device configuration from file. This approach is useful when you want to spawn QEMU process with many command line options but you don't want to exceed the command line character limit. ERST -DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, - "-writeconfig <file>\n" - " read/write config file\n", QEMU_ARCH_ALL) -SRST -``-writeconfig file`` - Write device configuration to file. The file can be either filename - to save command line and device configuration into file or dash - ``-``) character to print the output to stdout. This can be later - used as input file for ``-readconfig`` option. -ERST DEF("no-user-config", 0, QEMU_OPTION_nouserconfig, "-no-user-config\n"softmmu/vl.c +0
-19@@ -3337,25 +3337,6 @@ void qemu_init(int argc, char **argv, char **envp) } display_remote++;break ; -case QEMU_OPTION_writeconfig: - { -FILE *fp; -if (strcmp (optarg,"-" ) ==0 ) { - fp = stdout; - }else { - fp =fopen (optarg,"w" ); -if (fp ==NULL ) { -error_report ("open %s: %s" , optarg, -strerror (errno)); -exit (1 ); - } - } -qemu_config_write (fp); -if (fp != stdout) { -fclose (fp); - } -break ; - }case QEMU_OPTION_qtest: qtest_chrdev = optarg;break ;util/qemu-config.c +0
-42@@ -307,48 +307,6 @@ void qemu_add_opts(QemuOptsList *list)abort (); } -struct ConfigWriteData { -QemuOptsList *list; -FILE *fp; -}; - -static int config_write_opt (void *opaque,const char *name,const char *value, -Error **errp) -{ -struct ConfigWriteData *data = opaque; - -fprintf (data->fp," %s = \"%s\"\n" , name, value); -return 0 ; -} - -static int config_write_opts (void *opaque,QemuOpts *opts,Error **errp) -{ -struct ConfigWriteData *data = opaque; -const char *id =qemu_opts_id (opts); - -if (id) { -fprintf (data->fp,"[%s \"%s\"]\n" , data->list->name, id); - }else { -fprintf (data->fp,"[%s]\n" , data->list->name); - } -qemu_opt_foreach (opts, config_write_opt, data,NULL ); -fprintf (data->fp,"\n" ); -return 0 ; -} - -void qemu_config_write (FILE *fp) -{ -struct ConfigWriteData data = { .fp = fp }; -QemuOptsList **lists = vm_config_groups; -int i; - -fprintf (fp,"# qemu config file\n\n" ); -for (i =0 ; lists[i] !=NULL ; i++) { - data.list = lists[i]; -qemu_opts_foreach (data.list, config_write_opts, &data,NULL ); - } -} -/* Returns number of config groups on success, -errno on error */ int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname) {
Re: [PATCH 11/25] remove -writeconfig
Quoted 6 lines · Markus Armbruster
I love the "and how give me a config file for all that" idea, but I agree our -writeconfig is flawed. I hope we can bring it back in more useful shape.
No deprecation grace period?
That's a decision that we have to take overall once the whole series is reviewed, I think. I have no problem having a grace period:
- the patches aren't 101% ready
- the real conflict magnets have been merged already
- I have a large KVM backlog so I don't mind leaving this aside for a few months
Paolo
Re: [PATCH 11/25] remove -writeconfig
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Markus Armbruster
I love the "and how give me a config file for all that" idea, but I agree our -writeconfig is flawed. I hope we can bring it back in more useful shape.
No deprecation grace period?
That's a decision that we have to take overall once the whole series is reviewed, I think. I have no problem having a grace period:
I'm normally in strongly pushing for honouring our deprecation policy, but in almost all past cases we're changing/removing something that is genuinely used by people in the real world.
I think it is possible to argue that -writeconfig is a special case becuase its functionality is so limited in scope that its real world use cases are fairly niche, and is majorly buggy in what it writes in some cases. IOW we could argue it is too broken + useless to justify going through the deprecation process.
So overall I'm ambivalent on whether we use deprecation for -writeconfig or not.
Quoted 7 lines
- the patches aren't 101% ready
- the real conflict magnets have been merged already
- I have a large KVM backlog so I don't mind leaving this aside for a few months
Regards,
Daniel
Signature · 3 lines
|: 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 :|
PATCH 12/25 qemu-config: add error propagation to qemu_config_parse
In reply to Paolo BonziniThis enables some simplification of vl.c via error_fatal.
--- block/blkdebug.c | 3 +-- include/qemu/config-file.h | 4 ++-- softmmu/vl.c | 30 ++++++++++++------------------ util/qemu-config.c | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 32 deletions(-)
block/blkdebug.c +1 -2
@@ -279,9 +279,8 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,return -errno; } - ret =qemu_config_parse (f, config_groups, filename); + ret =qemu_config_parse (f, config_groups, filename, errp);if (ret <0 ) { -error_setg (errp,"Could not parse blkdebug config file" ); goto fail; } }
include/qemu/config-file.h +2 -2
@@ -10,9 +10,9 @@ void qemu_add_opts(QemuOptsList *list);void qemu_add_drive_opts (QemuOptsList *list);int qemu_global_option (const char *str); -int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname); +int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp); -int qemu_read_config_file (const char *filename); +int qemu_read_config_file (const char *filename,Error **errp);/* Parse QDict options as a replacement for a config file (allowing multiple enumerated (0..(n-1)) configuration "sections") */
softmmu/vl.c +12 -18
@@ -2056,17 +2056,20 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -static int qemu_read_default_config_file (void ) +static void qemu_read_default_config_file (Error **errp) {int ret; +Error *local_err =NULL ; g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (file); -if (ret <0 && ret != -ENOENT ) { -return ret; + ret =qemu_read_config_file (file, &local_err); +if (ret <0 ) { +if (ret == -ENOENT ) { +error_free (local_err); + }else { +error_propagate (errp, local_err); + } } - -return 0 ; }static int qemu_set_option (const char *str)
@@ -2622,9 +2625,7 @@ void qemu_init(int argc, char **argv, char **envp) }if (userconfig) { -if (qemu_read_default_config_file () <0 ) { -exit (1 ); - } +qemu_read_default_config_file (&error_fatal); }/* second pass of option parsing */
@@ -3312,15 +3313,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_plugin_opt_parse (optarg, &plugin_list);break ;case QEMU_OPTION_readconfig: - { -int ret =qemu_read_config_file (optarg); -if (ret <0 ) { -error_report ("read config %s: %s" , optarg, -strerror (-ret)); -exit (1 ); - } -break ; - } +qemu_read_config_file (optarg, &error_fatal); +break ;case QEMU_OPTION_spice: olist =qemu_find_opts_err ("spice" ,NULL );if (!olist) {
util/qemu-config.c +10 -10
@@ -308,7 +308,7 @@ void qemu_add_opts(QemuOptsList *list) }/* Returns number of config groups on success, -errno on error */ -int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname) +int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp) {char line[1024 ], group[64 ], id[64 ], arg[64 ], value[1024 ];Location loc;
@@ -333,7 +333,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)/* group with id */ list =find_list (lists, group, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); goto out; } opts =qemu_opts_create (list, id,1 ,NULL );
@@ -344,7 +344,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)/* group without id */ list =find_list (lists, group, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); goto out; } opts =qemu_opts_create (list,NULL ,0 , &error_abort);
@@ -356,20 +356,19 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) sscanf(line, " %63s = \"\"", arg) == 1) {/* arg = value */ if (opts ==NULL ) { -error_report ("no group defined" ); +error_setg (errp,"no group defined" ); goto out; } -if (!qemu_opt_set (opts, arg, value, &local_err)) { -error_report_err (local_err); +if (!qemu_opt_set (opts, arg, value, errp)) { goto out; }continue ; } -error_report ("parse error" ); +error_setg (errp,"parse error" ); goto out; }if (ferror (fp)) { -error_report ("error reading file" ); +error_setg (errp,"error reading file" ); goto out; } res = count;
@@ -378,16 +377,17 @@ out:return res; } -int qemu_read_config_file (const char *filename) +int qemu_read_config_file (const char *filename,Error **errp) {FILE *f =fopen (filename,"r" );int ret;if (f ==NULL ) { +error_setg_errno (errp, errno,"Cannot read config file %s" , filename);return -errno; } - ret =qemu_config_parse (f, vm_config_groups, filename); + ret =qemu_config_parse (f, vm_config_groups, filename, errp);fclose (f);return ret; }
Signature · 1 line
2.26.2
Re: [PATCH 12/25] qemu-config: add error propagation to qemu_config_parse
Quoted 30 lines · Paolo Bonzini
This enables some simplification of
vl.cviaerror_fatal.Signed-off-by Paolo Bonzini <[email protected]>--- block/blkdebug.c | 3 +-- include/qemu/config-file.h | 4 ++-- softmmu/vl.c | 30 ++++++++++++------------------ util/qemu-config.c | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 32 deletions(-)block/blkdebug.c +1
-2@@ -279,9 +279,8 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,return -errno; } - ret =qemu_config_parse (f, config_groups, filename); + ret =qemu_config_parse (f, config_groups, filename, errp);if (ret <0 ) { -error_setg (errp,"Could not parse blkdebug config file" ); goto fail; } }include/qemu/config-file.h +0
-0
include/qemu/config-file.h void qemu_add_opts(QemuOptsList *list); · line 13
Quoted 5 lines
include/qemu/config-file.h +1
-1@@ -10,9 +10,9 @@ void qemu_add_opts(QemuOptsList *list);void qemu_add_drive_opts (QemuOptsList *list);int qemu_global_option (const char *str); -int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname); +int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp);
Long line.
Quoted 25 lines
include/qemu/config-file.h +1
-1-int qemu_read_config_file (const char *filename); +int qemu_read_config_file (const char *filename,Error **errp);/* Parse QDict options as a replacement for a config file (allowing multiple enumerated (0..(n-1)) configuration "sections") */ softmmu/vl.c +3
-4@@ -2056,17 +2056,20 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -static int qemu_read_default_config_file (void ) +static void qemu_read_default_config_file (Error **errp) {int ret; +Error *local_err =NULL ; g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (file); -if (ret <0 && ret != -ENOENT ) { -return ret; + ret =qemu_read_config_file (file, &local_err);
softmmu/vl.c static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 2073
Quoted 10 lines
softmmu/vl.c +6
-2+if (ret <0 ) { +if (ret == -ENOENT ) { +error_free (local_err); + }else { +error_propagate (errp, local_err); + } } - -return 0 ; }
Please use ERRP_GUARD() in new code:
static void qemu_read_default_config_file(Error **errp)
{
ERRP_GUARD();
int ret;
g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf"); ret = qemu_read_config_file(file, errp);
if (ret == -ENOENT) {
error_free(*errp);
*errp = NULL;
}}
Quoted 18 lines
softmmu/vl.c +1
-4static int qemu_set_option (const char *str)@@ -2622,9 +2625,7 @@ void qemu_init(int argc, char **argv, char **envp) }if (userconfig) { -if (qemu_read_default_config_file () <0 ) { -exit (1 ); - } +qemu_read_default_config_file (&error_fatal); }/* second pass of option parsing */ @@ -3312,15 +3313,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_plugin_opt_parse (optarg, &plugin_list);break ;case QEMU_OPTION_readconfig: - {
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3317
Quoted 10 lines
softmmu/vl.c +2
-8-int ret =qemu_read_config_file (optarg); -if (ret <0 ) { -error_report ("read config %s: %s" , optarg, -strerror (-ret)); -exit (1 ); - } -break ; - } +qemu_read_config_file (optarg, &error_fatal); +break ;
More than just code simplifcation: you're deleting an extra error message. Test case:
$ qemu-system-x86_64 -readconfig .
qemu: error reading file
qemu: -readconfig .: read config .: Invalid argumentPretty bad. With your patch applied:
qemu-system-x86_64: error reading file
Worse :)
I actually expected this to come out as
qemu-system-x86_64: -readconfig .: error reading file
That would be an improvement.
The reason for the bad location information is here:
int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp)
{
char line[1024], group[64], id[64], arg[64], value[1024];
Location loc;
QemuOptsList *list = NULL;
Error *local_err = NULL;
QemuOpts *opts = NULL;
int res = -EINVAL, lno = 0;
int count = 0;
loc_push_none(&loc);
while (fgets(line, sizeof(line), fp) != NULL) {If the very first fgets() fails setting @fp's error indicator, ...
loc_set_file(fname, ++lno);
[...]
}
if (ferror(fp)) {... we get here with error location "none", and ...
error_setg(errp, "error reading file");
... use it to report the error (remember, @errp is &error_fatal).
Independently, error_setg_errno() would be nice. Assuming we're willing to rely on errno being useful after fgets().
goto out;
}
res = count;
out:
loc_pop(&loc);
return res;
}Always, always, always test the error messages.
Quoted 17 lines
softmmu/vl.c +0
-0case QEMU_OPTION_spice: olist =qemu_find_opts_err ("spice" ,NULL );if (!olist) {util/qemu-config.c +1
-1@@ -308,7 +308,7 @@ void qemu_add_opts(QemuOptsList *list) }/* Returns number of config groups on success, -errno on error */ -int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname) +int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp) {char line[1024 ], group[64 ], id[64 ], arg[64 ], value[1024 ];Location loc;
util/qemu-config.c int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) · line 338
Quoted 7 lines
util/qemu-config.c +1
-1@@ -333,7 +333,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)/* group with id */ list =find_list (lists, group, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); goto out; }
Please avoid error_propagate() where possible:
list = find_list(lists, group, errp);
if (!list) {
goto out;
}util/qemu-config.c int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) · line 349
Quoted 9 lines
util/qemu-config.c +1
-1opts =qemu_opts_create (list, id,1 ,NULL );@@ -344,7 +344,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)/* group without id */ list =find_list (lists, group, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); goto out; }
Likewise.
Quoted 8 lines
util/qemu-config.c +1
-1opts =qemu_opts_create (list,NULL ,0 , &error_abort);@@ -356,20 +356,19 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) sscanf(line, " %63s = \"\"", arg) == 1) {/* arg = value */ if (opts ==NULL ) { -error_report ("no group defined" ); +error_setg (errp,"no group defined" ); goto out;
util/qemu-config.c int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) · line 367
Quoted 10 lines
util/qemu-config.c +2
-3} -if (!qemu_opt_set (opts, arg, value, &local_err)) { -error_report_err (local_err); +if (!qemu_opt_set (opts, arg, value, errp)) { goto out; }continue ; } -error_report ("parse error" ); +error_setg (errp,"parse error" );
*Ächz* Not your patch's fault.
Quoted 28 lines
util/qemu-config.c +4
-3goto out; }if (ferror (fp)) { -error_report ("error reading file" ); +error_setg (errp,"error reading file" ); goto out; } res = count;@@ -378,16 +377,17 @@ out:return res; } -int qemu_read_config_file (const char *filename) +int qemu_read_config_file (const char *filename,Error **errp) {FILE *f =fopen (filename,"r" );int ret;if (f ==NULL ) { +error_setg_errno (errp, errno,"Cannot read config file %s" , filename);return -errno; } - ret =qemu_config_parse (f, vm_config_groups, filename); + ret =qemu_config_parse (f, vm_config_groups, filename, errp);fclose (f);return ret; }
PATCH 13/25 qemu-option: support accept-any QemuOptsList in qemu_opts_absorb_qdict
In reply to Paolo Bonzini--- util/qemu-option.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
util/qemu-option.c +2 -1
@@ -1052,7 +1052,8 @@ bool qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp)while (entry !=NULL ) { next =qdict_next (qdict, entry); -if (find_desc_by_name (opts->list->desc, entry->key)) { +if (opts_accepts_any (opts->list) || +find_desc_by_name (opts->list->desc, entry->key)) {if (!qemu_opts_from_qdict_entry (opts, entry, errp)) {return false; }
Signature · 1 line
2.26.2
PATCH 14/25 qemu-config: parse configuration files to a QDict
In reply to Paolo BonziniChange the parser to put the values into a QDict and pass them to a callback. qemu_config_parse's QemuOpts creation is itself turned into a callback function.
--- include/qemu/config-file.h | 6 ++- softmmu/vl.c | 4 +- util/qemu-config.c | 91 +++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 33 deletions(-)
include/qemu/config-file.h +5 -1
@@ -1,6 +1,7 @@#ifndef QEMU_CONFIG_FILE_H #define QEMU_CONFIG_FILE_H +typedef void QEMUConfigCB (const char *group,QDict *qdict,void *opaque,Error **errp);QemuOptsList *qemu_find_opts (const char *group);QemuOptsList *qemu_find_opts_err (const char *group,Error **errp);
@@ -12,7 +13,10 @@ int qemu_global_option(const char *str);int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp); -int qemu_read_config_file (const char *filename,Error **errp); +/* A default callback for qemu_read_config_file(). */ +void qemu_config_do_parse (const char *group,QDict *qdict,void *opaque,Error **errp); + +int qemu_read_config_file (const char *filename,QEMUConfigCB *f,Error **errp);/* Parse QDict options as a replacement for a config file (allowing multiple enumerated (0..(n-1)) configuration "sections") */
softmmu/vl.c +2 -2
@@ -2062,7 +2062,7 @@ static void qemu_read_default_config_file(Error **errp)Error *local_err =NULL ; g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (file, &local_err); + ret =qemu_read_config_file (file, qemu_config_do_parse, &local_err);if (ret <0 ) {if (ret == -ENOENT ) {error_free (local_err);
@@ -3313,7 +3313,7 @@ void qemu_init(int argc, char **argv, char **envp)qemu_plugin_opt_parse (optarg, &plugin_list);break ;case QEMU_OPTION_readconfig: -qemu_read_config_file (optarg, &error_fatal); +qemu_read_config_file (optarg, qemu_config_do_parse, &error_fatal);break ;case QEMU_OPTION_spice: olist =qemu_find_opts_err ("spice" ,NULL );
util/qemu-config.c +61 -30
136 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 15/25 vl: plumb keyval-based options into -set and -readconfig
In reply to Paolo BonziniAdd generic machinery to support parsing command line options with keyval in -set and -readconfig, choosing between QDict and QemuOpts as the underlying data structure.
The keyval_merge function is slightly heavyweight as a way to do qemu_set_option for QDict-based options, but it will be put to further use later to merge entire -readconfig sections together with their command-line equivalents.
--- include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 + include/qemu/option.h | 1 + softmmu/vl.c | 131 ++++++++++++++++++++++++++++++++------- tests/test-keyval.c | 37 +++++++++++ util/keyval.c | 36 +++++++++++ 6 files changed, 187 insertions(+), 23 deletions(-)
include/block/qdict.h +0 -2
@@ -20,8 +20,6 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite);void qdict_extract_subqdict (QDict *src,QDict **dst,const char *start);void qdict_array_split (QDict *src,QList **dst);int qdict_array_entries (QDict *src,const char *subqdict); -QObject *qdict_crumple (const QDict *src,Error **errp); -void qdict_flatten (QDict *qdict); typedef struct QDictRenames { const char *from;
include/qapi/qmp/qdict.h +3 -0
@@ -64,4 +64,7 @@ const char *qdict_get_try_str(const QDict *qdict, const char *key);QDict *qdict_clone_shallow (const QDict *src); +QObject *qdict_crumple (const QDict *src,Error **errp); +void qdict_flatten (QDict *qdict); +#endif /* QDICT_H */
include/qemu/option.h +1 -0
@@ -151,5 +151,6 @@ QDict *keyval_parse_into(QDict *qdict, const char *params, const char *implied_k bool *p_help, Error **errp);QDict *keyval_parse (const char *params,const char *implied_key,bool *help,Error **errp); +void keyval_merge (QDict *old,const QDict *new,Error **errp);#endif
softmmu/vl.c +110 -21
181 lines not on this page · raw message
tests/test-keyval.c +37 -0
@@ -737,6 +737,41 @@ static void test_keyval_visit_any(void)visit_free (v); } +static void test_keyval_merge_success (void ) +{ +QDict *old =keyval_parse ("opt1=abc,opt2.sub1=def,opt2.sub2=ghi,opt3=xyz" , +NULL ,NULL , &error_abort); +QDict *new =keyval_parse ("opt1=ABC,opt2.sub2=GHI,opt2.sub3=JKL" , +NULL ,NULL , &error_abort); +QDict *combined =keyval_parse ("opt1=ABC,opt2.sub1=def,opt2.sub2=GHI,opt2.sub3=JKL,opt3=xyz" , +NULL ,NULL , &error_abort); +Error *err =NULL ; + +keyval_merge (old, new, &err); +g_assert (!err); +g_assert (qobject_is_equal (QOBJECT (combined),QOBJECT (old))); +qobject_unref (old); +qobject_unref (new); +qobject_unref (combined); +} + +static void test_keyval_merge_conflict (void ) +{ +QDict *old =keyval_parse ("opt2.sub1=def,opt2.sub2=ghi" , +NULL ,NULL , &error_abort); +QDict *new =keyval_parse ("opt2=ABC" , +NULL ,NULL , &error_abort); +Error *err =NULL ; + +keyval_merge (new, old, &err); +error_free_or_abort (&err); +keyval_merge (old, new, &err); +error_free_or_abort (&err); + +qobject_unref (old); +qobject_unref (new); +} +int main (int argc,char *argv[]) {g_test_init (&argc, &argv,NULL );
@@ -750,6 +785,8 @@ int main(int argc, char *argv[])g_test_add_func ("/keyval/visit/optional" , test_keyval_visit_optional);g_test_add_func ("/keyval/visit/alternate" , test_keyval_visit_alternate);g_test_add_func ("/keyval/visit/any" , test_keyval_visit_any); +g_test_add_func ("/keyval/merge/success" , test_keyval_merge_success); +g_test_add_func ("/keyval/merge/conflict" , test_keyval_merge_conflict);g_test_run ();return 0 ; }
util/keyval.c +36 -0
@@ -315,6 +315,42 @@ static char *reassemble_key(GSList *key)return g_string_free (s, FALSE); } +/* Merge two dictionaries. */ +static void keyval_do_merge (QDict *old,const QDict *new,GString *str,Error **errp) +{ +size_t save_len = str->len; +const QDictEntry *ent; +QObject *old_value; + +for (ent =qdict_first (new); ent; ent =qdict_next (new, ent)) { + old_value =qdict_get (old, ent->key); +if (old_value &&qobject_type (old_value) !=qobject_type (ent->value)) { +error_setg (errp,"Parameter '%s%s' used inconsistently" , str->str, ent->key); +return ; + } +if (!old_value ||qobject_type (ent->value) !=QTYPE_QDICT ) { +qobject_ref (ent->value); +qdict_put_obj (old, ent->key, ent->value); +continue ; + } + +/* Merge sub-dictionaries. */ +g_string_append (str, ent->key); +g_string_append_c (str,'.' ); +keyval_do_merge (qobject_to (QDict, old_value), +qobject_to (QDict, ent->value), + str, errp); +g_string_truncate (str, save_len); + } +} + +void keyval_merge (QDict *old,const QDict *new,Error **errp) +{ +GString *str =g_string_new ("" ); +keyval_do_merge (old, new, str, errp); +g_string_free (str, TRUE); +} +/* * Listify @cur recursively. * Replace QDicts whose keys are all valid list indexes by QLists.
Signature · 1 line
2.26.2
Re: [PATCH 15/25] vl: plumb keyval-based options into -set and -readconfig
Quoted 10 lines · Paolo Bonzini
Add generic machinery to support parsing command line options with keyval in -set and -readconfig, choosing between QDict and QemuOpts as the underlying data structure.
The
keyval_mergefunction is slightly heavyweight as a way to doqemu_set_optionfor QDict-based options, but it will be put to further use later to merge entire -readconfig sections together with their command-line equivalents.Signed-off-by Paolo Bonzini <[email protected]>
Watch this:
$ cat test.cfg
[machine]
accel = "kvm"
usb = "on"
$ qemu-system-x86_64 -S -display none -readconfig test.cfg
Aborted (core dumped)Backtrace:
#0 0x00007ffff52f19e5 in raise () at /lib64/libc.so.6
#1 0x00007ffff52da895 in abort () at /lib64/libc.so.6
#2 0x0000555555c44a77 in qemu_record_config_group
(group=0x7fffffffd1b0 "machine", dict=0x5555565fb740, errp=0x5555564ffca0 <error_fatal>) at ../softmmu/vl.c:2103
#3 0x0000555555c44bd8 in qemu_parse_config_group
(group=0x7fffffffd1b0 "machine", qdict=0x5555565f9640, opaque=0x5555564ff9e0 <vm_config_groups>, errp=0x5555564ffca0 <error_fatal>) at ../softmmu/vl.c:2135
#4 0x0000555555eda3e6 in qemu_config_foreach
(fp=0x5555565f3e00, cb=0x555555c44af5 <qemu_parse_config_group>, opaque=0x5555564ff9e0 <vm_config_groups>, fname=0x7fffffffe0dd "test.cfg", errp=0x5555564ffca0 <error_fatal>) at ../util/qemu-config.c:378
#5 0x0000555555eda5d5 in qemu_read_config_file
(filename=0x7fffffffe0dd "test.cfg", cb=0x555555c44af5 <qemu_parse_config_group>, errp=0x5555564ffca0 <error_fatal>) at ../util/qemu-config.c:421
#6 0x0000555555c47d3f in qemu_init
(argc=6, argv=0x7fffffffdcc8, envp=0x7fffffffdd00) at ../softmmu/vl.c:3405
#7 0x00005555558234e1 in main
(argc=6, argv=0x7fffffffdcc8, envp=0x7fffffffdd00) at ../softmmu/main.c:49Similar result for
[memory]
size = "1024"and
[chardev "mon0"]
backend = "stdio"
I didn't look for more.
Re: [PATCH 15/25] vl: plumb keyval-based options into -set and -readconfig
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Paolo Bonzini
Add generic machinery to support parsing command line options with keyval in -set and -readconfig, choosing between QDict and QemuOpts as the underlying data structure.
The
keyval_mergefunction is slightly heavyweight as a way to doqemu_set_optionfor QDict-based options, but it will be put to further use later to merge entire -readconfig sections together with their command-line equivalents.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 8 lines
Watch this:
$ cat test.cfg [machine] accel = "kvm" usb = "on" $ qemu-system-x86_64 -S -display none -readconfig test.cfg Aborted (core dumped)
Probably something that fixes itself later in the series. I'll check it out.
Paolo
Quoted 29 lines
Backtrace:#0 0x00007ffff52f19e5 in raise () at /lib64/libc.so.6 #1 0x00007ffff52da895 in abort () at /lib64/libc.so.6 #2 0x0000555555c44a77 in qemu_record_config_group (group=0x7fffffffd1b0 "machine", dict=0x5555565fb740, errp=0x5555564ffca0 <error_fatal>) at ../softmmu/vl.c:2103 #3 0x0000555555c44bd8 in qemu_parse_config_group (group=0x7fffffffd1b0 "machine", qdict=0x5555565f9640, opaque=0x5555564ff9e0 <vm_config_groups>, errp=0x5555564ffca0 <error_fatal>) at ../softmmu/vl.c:2135 #4 0x0000555555eda3e6 in qemu_config_foreach (fp=0x5555565f3e00, cb=0x555555c44af5 <qemu_parse_config_group>, opaque=0x5555564ff9e0 <vm_config_groups>, fname=0x7fffffffe0dd "test.cfg", errp=0x5555564ffca0 <error_fatal>) at ../util/qemu-config.c:378 #5 0x0000555555eda5d5 in qemu_read_config_file (filename=0x7fffffffe0dd "test.cfg", cb=0x555555c44af5 <qemu_parse_config_group>, errp=0x5555564ffca0 <error_fatal>) at ../util/qemu-config.c:421 #6 0x0000555555c47d3f in qemu_init (argc=6, argv=0x7fffffffdcc8, envp=0x7fffffffdd00) at ../softmmu/vl.c:3405 #7 0x00005555558234e1 in main (argc=6, argv=0x7fffffffdcc8, envp=0x7fffffffdd00) at ../softmmu/main.c:49Similar result for
[memory] size = "1024"and
[chardev "mon0"]
backend = "stdio"I didn't look for more.
PATCH 16/25 qom: do not modify QDict argument in user_creatable_add_dict
In reply to Paolo Bonzini-object will process its QDicts in two steps, first for the "early" objects and then for the "late" objects. If qom-type is removed by the "early" pass, the late pass fails. So just create a shallow copy of the QDict in user_creatable_add_dict.
--- include/qom/object_interfaces.h | 2 +- qom/object_interfaces.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
include/qom/object_interfaces.h +1 -1
@@ -102,7 +102,7 @@ Object *user_creatable_add_type(const char *type, const char *id,* * Returns: %true on success, %false on failure. */ -bool user_creatable_add_dict (QDict *qdict,bool keyval,Error **errp); +bool user_creatable_add_dict (const QDict *qdict,bool keyval,Error **errp);/** * user_creatable_add_opts:
qom/object_interfaces.c +7 -4
@@ -105,24 +105,25 @@ out:return obj; } -bool user_creatable_add_dict (QDict *qdict,bool keyval,Error **errp) +bool user_creatable_add_dict (const QDict *dict,bool keyval,Error **errp) {Visitor *v; -Object *obj; +Object *obj =NULL ; +QDict *qdict =qdict_clone_shallow (dict); g_autofree char *type = NULL; g_autofree char *id = NULL; type =g_strdup (qdict_get_try_str (qdict,"qom-type" ));if (!type) {error_setg (errp,QERR_MISSING_PARAMETER ,"qom-type" ); -return false; + goto out; }qdict_del (qdict,"qom-type" ); id =g_strdup (qdict_get_try_str (qdict,"id" ));if (!id) {error_setg (errp,QERR_MISSING_PARAMETER ,"id" ); -return false; + goto out; }qdict_del (qdict,"id" );
@@ -134,6 +135,8 @@ bool user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp) obj =user_creatable_add_type (type, id, qdict, v, errp);visit_free (v);object_unref (obj); +out: +qobject_unref (qdict);return !!obj; }
Signature · 1 line
2.26.2
PATCH 17/25 qemu-io: use keyval for -object parsing
In reply to Paolo BonziniEnable creation of object with non-scalar properties.
--- qemu-io.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-)
qemu-io.c +13 -29
@@ -477,23 +477,6 @@ enum { OPTION_IMAGE_OPTS = 257, }; -static QemuOptsList qemu_object_opts = { - .name ="object" , - .implied_opt_name ="qom-type" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_object_opts.head), - .desc = { - { } - }, -}; - -static bool qemu_io_object_print_help (const char *type,QemuOpts *opts) -{ -if (user_creatable_print_help (type, opts)) { -exit (0 ); - } -return true; -} -static QemuOptsList file_opts = { .name ="file" , .implied_opt_name ="file" ,
@@ -550,7 +533,6 @@ int main(int argc, char **argv)qcrypto_init (&error_fatal);module_call_init (MODULE_INIT_QOM ); -qemu_add_opts (&qemu_object_opts);qemu_add_opts (&qemu_trace_opts);bdrv_init ();
@@ -612,14 +594,20 @@ int main(int argc, char **argv)case 'U' : force_share = true;break ; -case OPTION_OBJECT : { -QemuOpts *qopts; - qopts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!qopts) { -exit (1 ); +case OPTION_OBJECT : + { +QDict *args; +bool help; + + args =keyval_parse (optarg,"qom-type" , &help, &error_fatal); +if (help) { +user_creatable_print_help_from_qdict (args); +exit (EXIT_SUCCESS ); + } +user_creatable_add_dict (args, true, &error_fatal); +qobject_unref (args); +break ; } - }break ;case OPTION_IMAGE_OPTS : imageOpts = true;break ;
@@ -644,10 +632,6 @@ int main(int argc, char **argv)exit (1 ); } -qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_io_object_print_help, &error_fatal); -if (!trace_init_backends ()) {exit (1 ); }
Signature · 1 line
2.26.2
PATCH 18/25 qemu-nbd: use keyval for -object parsing
In reply to Paolo BonziniEnable creation of object with non-scalar properties.
--- qemu-nbd.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-)
qemu-nbd.c +13 -29
@@ -407,23 +407,6 @@ static QemuOptsList file_opts = { }, }; -static QemuOptsList qemu_object_opts = { - .name ="object" , - .implied_opt_name ="qom-type" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_object_opts.head), - .desc = { - { } - }, -}; - -static bool qemu_nbd_object_print_help (const char *type,QemuOpts *opts) -{ -if (user_creatable_print_help (type, opts)) { -exit (0 ); - } -return true; -} -static QCryptoTLSCreds *nbd_get_tls_creds (const char *id,bool list,Error **errp)
@@ -599,7 +582,6 @@ int main(int argc, char **argv)qcrypto_init (&error_fatal);module_call_init (MODULE_INIT_QOM ); -qemu_add_opts (&qemu_object_opts);qemu_add_opts (&qemu_trace_opts);qemu_init_exec_dir (argv[0 ]);
@@ -752,14 +734,20 @@ int main(int argc, char **argv)case '?' :error_report ("Try `%s --help' for more information." , argv[0 ]);exit (EXIT_FAILURE ); -case QEMU_NBD_OPT_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -exit (EXIT_FAILURE ); +case QEMU_NBD_OPT_OBJECT : + { +QDict *args; +bool help; + + args =keyval_parse (optarg,"qom-type" , &help, &error_fatal); +if (help) { +user_creatable_print_help_from_qdict (args); +exit (EXIT_SUCCESS ); + } +user_creatable_add_dict (args, true, &error_fatal); +qobject_unref (args); +break ; } - }break ;case QEMU_NBD_OPT_TLSCREDS : tlscredsid = optarg;break ;
@@ -807,10 +795,6 @@ int main(int argc, char **argv) export_name ="" ; } -qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_nbd_object_print_help, &error_fatal); -if (!trace_init_backends ()) {exit (1 ); }
Signature · 1 line
2.26.2
PATCH 19/25 qemu-img: use keyval for -object parsing
In reply to Paolo BonziniEnable creation of object with non-scalar properties.
--- qemu-img.c | 258 +++++++++++------------------------------------------ 1 file changed, 52 insertions(+), 206 deletions(-)
qemu-img.c +52 -206
@@ -226,21 +226,27 @@ static void QEMU_NORETURN help(void)exit (EXIT_SUCCESS ); } -static QemuOptsList qemu_object_opts = { - .name ="object" , - .implied_opt_name ="qom-type" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_object_opts.head), - .desc = { - { } - }, -}; - -static bool qemu_img_object_print_help (const char *type,QemuOpts *opts) +static void qemu_img_object_parse (const char *optarg,int exit_code) { -if (user_creatable_print_help (type, opts)) { -exit (0 ); +QDict *args; +bool help; +Error *local_error =NULL ; + + args =keyval_parse (optarg,"qom-type" , &help, &local_error); +if (local_error) { +error_report_err (local_error); +exit (exit_code); } -return true; +if (help) { +user_creatable_print_help_from_qdict (args); +exit (EXIT_SUCCESS ); + } +user_creatable_add_dict (args, true, &local_error); +if (local_error) { +error_report_err (local_error); +exit (exit_code); + } +qobject_unref (args); }/*
@@ -566,14 +572,9 @@ static int img_create(int argc, char **argv)case 'u' : flags |=BDRV_O_NO_BACKING ;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { - goto fail; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ; } }
@@ -589,12 +590,6 @@ static int img_create(int argc, char **argv) } optind++; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto fail; - } -/* Get image size, if specified */ if (optind < argc) {int64_t sval;
@@ -804,14 +799,9 @@ static int img_check(int argc, char **argv)case 'U' : force_share = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -831,12 +821,6 @@ static int img_check(int argc, char **argv)return 1 ; } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } - ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);
@@ -1034,14 +1018,9 @@ static int img_commit(int argc, char **argv)return 1 ; }break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -1058,12 +1037,6 @@ static int img_commit(int argc, char **argv) } filename = argv[optind++]; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } - flags =BDRV_O_RDWR |BDRV_O_UNMAP ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {
@@ -1423,15 +1396,9 @@ static int img_compare(int argc, char **argv)case 'U' : force_share = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { - ret =2 ; - goto out4; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,2 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -1450,13 +1417,6 @@ static int img_compare(int argc, char **argv) filename1 = argv[optind++]; filename2 = argv[optind++]; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret =2 ; - goto out4; - } -/* Initialize before goto out */ qemu_progress_init (progress,2.0 );
@@ -1641,7 +1601,6 @@ out2:blk_unref (blk1); out3:qemu_progress_end (); -out4:return ret; }
@@ -2342,15 +2301,9 @@ static int img_convert(int argc, char **argv) goto fail_getopt; }break ; -case OPTION_OBJECT : { -QemuOpts *object_opts; - object_opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!object_opts) { - goto fail_getopt; - } +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 );break ; - }case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -2378,12 +2331,6 @@ static int img_convert(int argc, char **argv) out_fmt ="raw" ; } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto fail_getopt; - } -if (s.compressed && s.copy_range) {error_report ("Cannot enable copy offloading when -c is used" ); goto fail_getopt;
@@ -2975,14 +2922,9 @@ static int img_info(int argc, char **argv)case OPTION_BACKING_CHAIN : chain = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -3002,12 +2944,6 @@ static int img_info(int argc, char **argv)return 1 ; } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } - list =collect_image_info_list (image_opts, filename, fmt, chain, force_share);if (!list) {
@@ -3217,14 +3153,9 @@ static int img_map(int argc, char **argv)return 1 ; }break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -3244,12 +3175,6 @@ static int img_map(int argc, char **argv)return 1 ; } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } - blk =img_open (image_opts, filename, fmt,0 , false, false, force_share);if (!blk) {return 1 ;
@@ -3388,14 +3313,9 @@ static int img_snapshot(int argc, char **argv)case 'U' : force_share = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -3407,12 +3327,6 @@ static int img_snapshot(int argc, char **argv) } filename = argv[optind++]; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } -/* Open the image */ blk =img_open (image_opts, filename,NULL , bdrv_oflags, false, quiet, force_share);
@@ -3546,14 +3460,9 @@ static int img_rebase(int argc, char **argv)case 'q' : quiet = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -3575,12 +3484,6 @@ static int img_rebase(int argc, char **argv) } filename = argv[optind++]; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } -qemu_progress_init (progress,2.0 );qemu_progress_print (0 ,100 );
@@ -3971,14 +3874,9 @@ static int img_resize(int argc, char **argv)case 'q' : quiet = true;break ; -case OPTION_OBJECT : { -QemuOpts *opts; - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { -return 1 ; - } - }break ; +case OPTION_OBJECT : +qemu_img_object_parse (optarg,1 ); +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -4000,12 +3898,6 @@ static int img_resize(int argc, char **argv) } filename = argv[optind++]; -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { -return 1 ; - } -/* Choose grow, shrink, or absolute resize mode */ switch (size[0 ]) {case '+' :
@@ -4185,12 +4077,7 @@ static int img_amend(int argc, char **argv) quiet = true;break ;case OPTION_OBJECT : - opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!opts) { - ret =-1 ; - goto out_no_progress; - } +qemu_img_object_parse (optarg,1 );break ;case OPTION_IMAGE_OPTS : image_opts = true;
@@ -4205,13 +4092,6 @@ static int img_amend(int argc, char **argv)error_exit ("Must specify options (-o)" ); } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret =-1 ; - goto out_no_progress; - } -if (quiet) { progress = false; }
@@ -4670,7 +4550,6 @@ static int img_bitmap(int argc, char **argv) {Error *err =NULL ;int c, ret =1 ; -QemuOpts *opts =NULL ;const char *fmt =NULL , *src_fmt =NULL , *src_filename =NULL ;const char *filename, *bitmap;BlockBackend *blk =NULL , *src =NULL ;
@@ -4764,10 +4643,7 @@ static int img_bitmap(int argc, char **argv) merge = true;break ;case OPTION_OBJECT : - opts =qemu_opts_parse_noisily (&qemu_object_opts, optarg, true); -if (!opts) { - goto out; - } +qemu_img_object_parse (optarg,1 );break ;case OPTION_IMAGE_OPTS : image_opts = true;
@@ -4775,12 +4651,6 @@ static int img_bitmap(int argc, char **argv) } } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto out; - } -if (QSIMPLEQ_EMPTY (&actions)) {error_report ("Need at least one of --add, --remove, --clear, " "--enable, --disable, or --merge" );
@@ -4876,7 +4746,6 @@ static int img_bitmap(int argc, char **argv) out:blk_unref (src);blk_unref (blk); -qemu_opts_del (opts);return ret; }
@@ -5038,10 +4907,7 @@ static int img_dd(int argc, char **argv) force_share = true;break ;case OPTION_OBJECT : -if (!qemu_opts_parse_noisily (&qemu_object_opts, optarg, true)) { - ret =-1 ; - goto out; - } +qemu_img_object_parse (optarg,1 );break ;case OPTION_IMAGE_OPTS : image_opts = true;
@@ -5088,13 +4954,6 @@ static int img_dd(int argc, char **argv) goto out; } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret =-1 ; - goto out; - } - blk1 =img_open (image_opts, in.filename, fmt,0 , false, false, force_share);
@@ -5270,7 +5129,6 @@ static int img_measure(int argc, char **argv)char *snapshot_name =NULL ;bool force_share = false;QemuOpts *opts =NULL ; -QemuOpts *object_opts =NULL ;QemuOpts *sn_opts =NULL ;QemuOptsList *create_opts =NULL ;bool image_opts = false;
@@ -5315,11 +5173,7 @@ static int img_measure(int argc, char **argv) force_share = true;break ;case OPTION_OBJECT : - object_opts =qemu_opts_parse_noisily (&qemu_object_opts, - optarg, true); -if (!object_opts) { - goto out; - } +qemu_img_object_parse (optarg,1 );break ;case OPTION_IMAGE_OPTS : image_opts = true;
@@ -5349,12 +5203,6 @@ static int img_measure(int argc, char **argv) } } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto out; - } -if (argc - optind >1 ) {error_report ("At most one filename argument is allowed." ); goto out;
@@ -5442,7 +5290,6 @@ static int img_measure(int argc, char **argv) out:qapi_free_BlockMeasureInfo (info); -qemu_opts_del (object_opts);qemu_opts_del (opts);qemu_opts_del (sn_opts);qemu_opts_free (create_opts);
@@ -5494,7 +5341,6 @@ int main(int argc, char **argv)error_exit ("Not enough arguments" ); } -qemu_add_opts (&qemu_object_opts);qemu_add_opts (&qemu_source_opts);qemu_add_opts (&qemu_trace_opts);
Signature · 1 line
2.26.2
PATCH 20/25 qemu: use keyval for -object parsing
In reply to Paolo Bonzini--- include/qom/object_interfaces.h | 65 +--------------------------- qom/object_interfaces.c | 75 --------------------------------- softmmu/vl.c | 75 +++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 167 deletions(-)
include/qom/object_interfaces.h +1 -64
@@ -104,51 +104,6 @@ Object *user_creatable_add_type(const char *type, const char *id,*/ bool user_creatable_add_dict (const QDict *qdict,bool keyval,Error **errp); -/** -* user_creatable_add_opts: -* @opts: the object definition -* @errp: if an error occurs, a pointer to an area to store the error -* -* Create an instance of the user creatable object whose type -* is defined in @opts by the 'qom-type' option, placing it -* in the object composition tree with name provided by the -* 'id' field. The remaining options in @opts are used to -* initialize the object properties. -* -* Returns: the newly created object or NULL on error -*/ -Object *user_creatable_add_opts (QemuOpts *opts,Error **errp); - - -/** -* user_creatable_add_opts_predicate: -* @type: the QOM type to be added -* -* A callback function to determine whether an object -* of type @type should be created. Instances of this -* callback should be passed to user_creatable_add_opts_foreach -*/ -typedef bool (*user_creatable_add_opts_predicate )(const char *type); - -/** -* user_creatable_add_opts_foreach: -* @opaque: a user_creatable_add_opts_predicate callback or NULL -* @opts: options to create -* @errp: unused -* -* An iterator callback to be used in conjunction with -* the qemu_opts_foreach() method for creating a list of -* objects from a set of QemuOpts -* -* The @opaque parameter can be passed a user_creatable_add_opts_predicate -* callback to filter which types of object are created during iteration. -* When it fails, report the error. -* -* Returns: 0 on success, -1 when an error was reported. -*/ -int user_creatable_add_opts_foreach (void *opaque, -QemuOpts *opts,Error **errp); -/** * user_creatable_print_types: *
@@ -156,30 +111,12 @@ int user_creatable_add_opts_foreach(void *opaque,*/ void user_creatable_print_types (void ); -/** -* user_creatable_print_help: -* @type: the QOM type to be added -* @opts: options to create -* -* Prints help if requested in @type or @opts. Note that if @type is neither -* "help"/"?" nor a valid user creatable type, no help will be printed -* regardless of @opts. -* -* Returns: true if a help option was found and help was printed, false -* otherwise. -*/ -bool user_creatable_print_help (const char *type,QemuOpts *opts); -/** * user_creatable_print_help_from_qdict: * @args: options to create * * Prints help considering the other options given in @args (if "qom-type" is -* given and valid, print properties for the type, otherwise print valid types) -* -* In contrast to user_creatable_print_help(), this function can't return that -* no help was requested. It should only be called if we know that help is -* requested and it will always print some help. +* given and valid, print properties for the type, otherwise print valid types). */ void user_creatable_print_help_from_qdict (const QDict *args);
qom/object_interfaces.c +0 -75
93 lines not on this page · raw message
softmmu/vl.c +47 -28
150 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 21/25 storage-daemon: do not register the "object" group with QemuOpts
In reply to Paolo BonziniSince qsd uses keyval instead of -object, do not bother registering qemu_object_opts. It used to be necessary for object-del; that requirement is not there anymore since emulators have switched to keyval.
--- storage-daemon/qemu-storage-daemon.c | 10 ---------- 1 file changed, 10 deletions(-)
storage-daemon/qemu-storage-daemon.c +0 -10
@@ -130,15 +130,6 @@ enum {extern QemuOptsList qemu_chardev_opts; -static QemuOptsList qemu_object_opts = { - .name ="object" , - .implied_opt_name ="qom-type" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_object_opts.head), - .desc = { - { } - }, -}; -static void init_qmp_commands (void ) {qmp_init_marshal (&qmp_commands);
@@ -295,7 +286,6 @@ int main(int argc, char *argv[])module_call_init (MODULE_INIT_QOM );module_call_init (MODULE_INIT_TRACE ); -qemu_add_opts (&qemu_object_opts);qemu_add_opts (&qemu_trace_opts);qcrypto_init (&error_fatal);bdrv_init ();
Signature · 1 line
2.26.2
PATCH 22/25 qom: export more functions for use with non-UserCreatable objects
In reply to Paolo BonziniMachines and accelerators are not user-creatable but they share similar parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c.
--- include/qom/object.h | 21 +++++++++++++++++ qom/object_interfaces.c | 51 +++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 15 deletions(-)
include/qom/object.h +21 -0
@@ -860,6 +860,27 @@ static void do_qemu_init_ ## type_array(void) \ } \ type_init(do_qemu_init_ ## type_array) +/** +* type_print_class_properties: +* @type: a QOM class name +* +* Print the object's class properties to stdout or the monitor. +* Return whether an object was found. +*/ +bool type_print_class_properties (const char *type); + +/** +* object_set_properties_from_keyval: +* @obj: a QOM object +* @qdict: a dictionary whose leaf values are strings +* @errp: pointer to error object +* +* For each key in the dictionary, parse the value string and set the +* corresponding property in @obj. +*/ +void object_set_properties_from_keyval (Object *obj,const QDict *qdict, +Error **errp); +/** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast.
qom/object_interfaces.c +36 -15
81 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 23/25 vl: switch -M parsing to keyval
In reply to Paolo BonziniSwitch from QemuOpts to keyval. This enables non-scalar machine properties.
--- softmmu/vl.c | 296 +++++++++++++++++++++++---------------------------- 1 file changed, 132 insertions(+), 164 deletions(-)
softmmu/vl.c +132 -164
@@ -136,6 +136,8 @@ static const char *cpu_option;static const char *mem_path;static const char *incoming;static const char *loadvm; +static const char *accelerators; +static QDict *machine_opts_dict;static GSList *object_opts_list =NULL ;static ram_addr_t maxram_size;static uint64_t ram_slots;
@@ -227,21 +229,6 @@ static QemuOptsList qemu_option_rom_opts = { }, }; -static QemuOptsList qemu_machine_opts = { - .name ="machine" , - .implied_opt_name ="type" , - .merge_lists = true, - .head =QTAILQ_HEAD_INITIALIZER (qemu_machine_opts.head), - .desc = { -/* -* no elements => accept any -* sanity checking will happen later -* when setting machine properties -*/ - { } - }, -}; -static QemuOptsList qemu_accel_opts = { .name ="accel" , .implied_opt_name ="accel" ,
@@ -481,16 +468,6 @@ static QemuOptsList qemu_action_opts = { }, }; -/** -* Get machine options -* -* Returns: machine options (never null). -*/ -static QemuOpts *qemu_get_machine_opts (void ) -{ -return qemu_find_opts_singleton ("machine" ); -} -const char *qemu_get_vm_name (void ) {return qemu_name;
@@ -798,33 +775,6 @@ static MachineClass *find_default_machine(GSList *machines)return default_machineclass; } -static int machine_help_func (QemuOpts *opts,MachineState *machine) -{ -ObjectProperty *prop; -ObjectPropertyIterator iter; - -if (!qemu_opt_has_help_opt (opts)) { -return 0 ; - } - -object_property_iter_init (&iter,OBJECT (machine)); -while ((prop =object_property_iter_next (&iter))) { -if (!prop->set) { -continue ; - } - -printf ("%s.%s=%s" ,MACHINE_GET_CLASS (machine)->name, - prop->name, prop->type); -if (prop->description) { -printf (" (%s)\n" , prop->description); - }else { -printf ("\n" ); - } - } - -return 1 ; -} -static void version (void ) { printf("QEMU emulator version " QEMU_FULL_VERSION "\n"
@@ -1515,33 +1465,28 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } -static MachineClass *machine_parse (const char *name,GSList *machines) +static void machine_help_func (const QDict *qdict) { -MachineClass *mc; -GSList *el; +GSList *machines, *el; +const char *type =qdict_get_try_str (qdict,"type" ); -if (is_help_option (name)) { -printf ("Supported machines are:\n" ); - machines =g_slist_sort (machines, machine_class_cmp); -for (el = machines; el; el = el->next) { -MachineClass *mc = el->data; -if (mc->alias) { -printf ("%-20s %s (alias of %s)\n" , mc->alias, mc->desc, mc->name); - } -printf ("%-20s %s%s%s\n" , mc->name, mc->desc, - mc->is_default ?" (default)" :"" , - mc->deprecation_reason ?" (deprecated)" :"" ); - } -exit (0 ); +if (type) { +type_print_class_properties (type); +return ; } - mc =find_machine (name, machines); -if (!mc) { -error_report ("unsupported machine type" ); -error_printf ("Use -machine help to list supported machines\n" ); -exit (1 ); +printf ("Supported machines are:\n" ); + machines =object_class_get_list (TYPE_MACHINE , false); + machines =g_slist_sort (machines, machine_class_cmp); +for (el = machines; el; el = el->next) { +MachineClass *mc = el->data; +if (mc->alias) { +printf ("%-20s %s (alias of %s)\n" , mc->alias, mc->desc, mc->name); + } +printf ("%-20s %s%s%s\n" , mc->name, mc->desc, + mc->is_default ?" (default)" :"" , + mc->deprecation_reason ?" (deprecated)" :"" ); } -return mc; }static const char *pid_file;
@@ -1594,32 +1539,31 @@ static const QEMUOption *lookup_opt(int argc, char **argv,return popt; } -static MachineClass *select_machine (void ) +static MachineClass *select_machine (QDict *qdict,Error **errp) { +const char *optarg =qdict_get_try_str (qdict,"type" );GSList *machines =object_class_get_list (TYPE_MACHINE , false); -MachineClass *machine_class =find_default_machine (machines); -const char *optarg; -QemuOpts *opts; -Location loc; - -loc_push_none (&loc); - - opts =qemu_get_machine_opts (); -qemu_opts_loc_restore (opts); +MachineClass *machine_class; +Error *local_err =NULL ; - optarg =qemu_opt_get (opts,"type" );if (optarg) { - machine_class =machine_parse (optarg, machines); - } - -if (!machine_class) { -error_report ("No machine specified, and there is no default" ); -error_printf ("Use -machine help to list supported machines\n" ); -exit (1 ); + machine_class =find_machine (optarg, machines); +qdict_del (qdict,"type" ); +if (!machine_class) { +error_setg (&local_err,"unsupported machine type" ); + } + }else { + machine_class =find_default_machine (machines); +if (!machine_class) { +error_setg (&local_err,"No machine specified, and there is no default" ); + } } -loc_pop (&loc);g_slist_free (machines); +if (local_err) { +error_append_hint (&local_err,"Use -machine help to list supported machines\n" ); +error_propagate (errp, local_err); + }return machine_class; }
@@ -1638,38 +1582,66 @@ static int object_parse_property_opt(Object *obj,return 0 ; } -static int machine_set_property (void *opaque, -const char *name,const char *value, -Error **errp) +/* *Non*recursively replace underscores with dashes in QDict keys. */ +static void keyval_dashify (QDict *qdict,Error **errp) { - g_autofree char *qom_name = g_strdup(name); +const QDictEntry *ent, *next;char *p; -for (p = qom_name; *p; p++) { -if (*p =='_' ) { - *p ='-' ; +for (ent =qdict_first (qdict); ent; ent = next) { + g_autofree char *new_key = NULL; + + next =qdict_next (qdict, ent); +if (!strchr (ent->key,'_' )) { +continue ; + } + new_key =g_strdup (ent->key); +for (p = new_key; *p; p++) { +if (*p =='_' ) { + *p ='-' ; + } } +if (qdict_haskey (qdict, new_key)) { +error_setg (errp,"Conflict between '%s' and '%s'" , ent->key, new_key); +return ; + } +qobject_ref (ent->value); +qdict_put_obj (qdict, new_key, ent->value); +qdict_del (qdict, ent->key); } +} + +static void qemu_apply_legacy_machine_options (QDict *qdict) +{ +const char *value; + +keyval_dashify (qdict, &error_fatal);/* Legacy options do not correspond to MachineState properties. */ -if (g_str_equal (qom_name,"accel" )) { -return 0 ; - } -if (g_str_equal (qom_name,"igd-passthru" )) { -object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); -return 0 ; + value =qdict_get_try_str (qdict,"accel" ); +if (value) { + accelerators =g_strdup (value); +qdict_del (qdict,"accel" ); } -if (g_str_equal (qom_name,"kvm-shadow-mem" )) { -object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ), qom_name, value); -return 0 ; + + value =qdict_get_try_str (qdict,"igd-passthru" ); +if (value) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ),"igd-passthru" , value); +qdict_del (qdict,"igd-passthru" ); } -if (g_str_equal (qom_name,"kernel-irqchip" )) { -object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ), qom_name, value); -object_register_sugar_prop (ACCEL_CLASS_NAME ("whpx" ), qom_name, value); -return 0 ; + + value =qdict_get_try_str (qdict,"kvm-shadow-mem" ); +if (value) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ),"kvm-shadow-mem" , value); +qdict_del (qdict,"kvm-shadow-mem" ); } -return object_parse_property_opt (opaque, name, value,"type" , errp); + value =qdict_get_try_str (qdict,"kernel-irqchip" ); +if (value) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ),"kernel-irqchip" , value); +object_register_sugar_prop (ACCEL_CLASS_NAME ("whpx" ),"kernel-irqchip" , value); +qdict_del (qdict,"kernel-irqchip" ); + } }/*
@@ -1727,16 +1699,14 @@ static bool object_create_early(const char *type)return true; } -static void qemu_apply_machine_options (void ) +static void qemu_apply_machine_options (QDict *qdict) {MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); -QemuOpts *machine_opts =qemu_get_machine_opts ();const char *boot_order =NULL ;const char *boot_once =NULL ;QemuOpts *opts; -qemu_opt_foreach (machine_opts, machine_set_property, current_machine, - &error_fatal); +object_set_properties_from_keyval (OBJECT (current_machine), qdict, &error_fatal); current_machine->ram_size = ram_size; current_machine->maxram_size = maxram_size; current_machine->ram_slots = ram_slots;
@@ -1765,10 +1735,8 @@ static void qemu_apply_machine_options(void) current_machine->boot_once = boot_once;if (semihosting_enabled () && !semihosting_get_argc ()) { -const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); -const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ) ?:"" ;/* fall back to the -kernel/-append */ -semihosting_arg_fallback (kernel_filename, kernel_cmdline); +semihosting_arg_fallback (current_machine->kernel_filename, current_machine->kernel_cmdline); } }
@@ -1833,8 +1801,7 @@ static void qemu_create_early_backends(void)/* * Note: we need to create audio and block backends before -* machine_set_property(), so machine properties can refer to -* them. +* setting machine properties, so they can be referred to. */ configure_blockdev (&bdo_queue, machine_class, snapshot);audio_init_audiodevs ();
@@ -2004,16 +1971,14 @@ static void set_memory_options(MachineClass *mc)loc_pop (&loc); } -static void qemu_create_machine (MachineClass *machine_class) +static void qemu_create_machine (QDict *qdict) { +MachineClass *machine_class =select_machine (qdict, &error_fatal);object_set_machine_compat_props (machine_class->compat_props);set_memory_options (machine_class); current_machine =MACHINE (object_new_with_class (OBJECT_CLASS (machine_class))); -if (machine_help_func (qemu_get_machine_opts (), current_machine)) { -exit (0 ); - }object_property_add_child (object_get_root (),"machine" ,OBJECT (current_machine)); object_property_add_child(container_get(OBJECT(current_machine),
@@ -2044,8 +2009,11 @@ static void qemu_create_machine(MachineClass *machine_class)* specified either by the configuration file or by the command line. */ if (machine_class->default_machine_opts) { -qemu_opts_set_defaults (qemu_find_opts ("machine" ), - machine_class->default_machine_opts,0 ); +QDict *default_opts = +keyval_parse (machine_class->default_machine_opts,NULL ,NULL , + &error_abort); +object_set_properties_from_keyval (OBJECT (current_machine), default_opts, &error_abort); +qobject_unref (default_opts); } }
@@ -2067,7 +2035,8 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)*/ static bool is_qemuopts_group (const char *group) { -if (g_str_equal (group,"object" )) { +if (g_str_equal (group,"object" ) || +g_str_equal (group,"machine" )) {return false; }return true;
@@ -2109,6 +2078,8 @@ static void qemu_record_config_group(const char *group, QDict *dict, Error **err p_head =qemu_config_list (group);if (p_head) { *p_head =g_slist_prepend (*p_head, dict); + }else if (g_str_equal (group,"machine" )) { +keyval_merge (machine_opts_dict, dict, errp); }else {abort (); }
@@ -2262,13 +2233,11 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)static void configure_accelerators (const char *progname) { -const char *accelerators;bool init_failed = false;qemu_opts_foreach (qemu_find_opts ("icount" ), do_configure_icount,NULL , &error_fatal); - accelerators =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (QTAILQ_EMPTY (&qemu_accel_opts.head)) {char **accel_list, **tmp;
@@ -2356,12 +2325,11 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } -static void qemu_validate_options (void ) +static void qemu_validate_options (const QDict *machine_opts) { -QemuOpts *machine_opts =qemu_get_machine_opts (); -const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); -const char *initrd_filename =qemu_opt_get (machine_opts,"initrd" ); -const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ); +const char *kernel_filename =qdict_get_try_str (machine_opts,"kernel" ); +const char *initrd_filename =qdict_get_try_str (machine_opts,"initrd" ); +const char *kernel_cmdline =qdict_get_try_str (machine_opts,"append" );if (kernel_filename ==NULL ) {if (kernel_cmdline !=NULL ) {
@@ -2683,7 +2651,6 @@ void qemu_init(int argc, char **argv, char **envp)qemu_add_opts (&qemu_trace_opts);qemu_plugin_add_opts ();qemu_add_opts (&qemu_option_rom_opts); -qemu_add_opts (&qemu_machine_opts);qemu_add_opts (&qemu_accel_opts);qemu_add_opts (&qemu_mem_opts);qemu_add_opts (&qemu_smp_opts);
@@ -2723,6 +2690,7 @@ void qemu_init(int argc, char **argv, char **envp) } } + machine_opts_dict =qdict_new ();if (userconfig) {qemu_read_default_config_file (&error_fatal); }
@@ -2812,8 +2780,7 @@ void qemu_init(int argc, char **argv, char **envp)parse_display (optarg);break ;case QEMU_OPTION_nographic: - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"graphics=off" , false); +qdict_put_str (machine_opts_dict,"graphics" ,"off" ); nographic = true; dpy.type =DISPLAY_TYPE_NONE ;break ;
@@ -2837,16 +2804,16 @@ void qemu_init(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_kernel: -qemu_opts_set (qemu_find_opts ("machine" ),"kernel" , optarg, &error_abort); +qdict_put_str (machine_opts_dict,"kernel" , optarg);break ;case QEMU_OPTION_initrd: -qemu_opts_set (qemu_find_opts ("machine" ),"initrd" , optarg, &error_abort); +qdict_put_str (machine_opts_dict,"initrd" , optarg);break ;case QEMU_OPTION_append: -qemu_opts_set (qemu_find_opts ("machine" ),"append" , optarg, &error_abort); +qdict_put_str (machine_opts_dict,"append" , optarg);break ;case QEMU_OPTION_dtb: -qemu_opts_set (qemu_find_opts ("machine" ),"dtb" , optarg, &error_abort); +qdict_put_str (machine_opts_dict,"dtb" , optarg);break ;case QEMU_OPTION_cdrom:drive_add (IF_DEFAULT ,2 , optarg,CDROM_OPTS );
@@ -2956,7 +2923,7 @@ void qemu_init(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_bios: -qemu_opts_set (qemu_find_opts ("machine" ),"firmware" , optarg, &error_abort); +qdict_put_str (machine_opts_dict,"firmware" , optarg);break ;case QEMU_OPTION_singlestep: singlestep =1 ;
@@ -3225,17 +3192,20 @@ void qemu_init(int argc, char **argv, char **envp) preconfig_requested = true;break ;case QEMU_OPTION_enable_kvm: - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"accel=kvm" , false); +qdict_put_str (machine_opts_dict,"accel" ,"kvm" );break ;case QEMU_OPTION_M :case QEMU_OPTION_machine: - olist =qemu_find_opts ("machine" ); - opts =qemu_opts_parse_noisily (olist, optarg, true); -if (!opts) { -exit (1 ); + { +bool help; + +keyval_parse_into (machine_opts_dict, optarg,"type" , &help, &error_fatal); +if (help) { +machine_help_func (machine_opts_dict); +exit (EXIT_SUCCESS ); + } +break ; } -break ;case QEMU_OPTION_accel: accel_opts =qemu_opts_parse_noisily (qemu_find_opts ("accel" ), optarg, true);
@@ -3262,14 +3232,12 @@ void qemu_init(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_usb: - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"usb=on" , false); +qdict_put_str (machine_opts_dict,"usb" ,"on" );break ;case QEMU_OPTION_usbdevice:error_report ("'-usbdevice' is deprecated, please use " "'-device usb-...' instead" ); - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"usb=on" , false); +qdict_put_str (machine_opts_dict,"usb" ,"on" );add_device_config (DEV_USB , optarg);break ;case QEMU_OPTION_device:
@@ -3288,12 +3256,10 @@ void qemu_init(int argc, char **argv, char **envp)vnc_parse (optarg, &error_fatal);break ;case QEMU_OPTION_no_acpi: - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"acpi=off" , false); +qdict_put_str (machine_opts_dict,"acpi" ,"off" );break ;case QEMU_OPTION_no_hpet: - olist =qemu_find_opts ("machine" ); -qemu_opts_parse_noisily (olist,"hpet=off" , false); +qdict_put_str (machine_opts_dict,"hpet" ,"off" );break ;case QEMU_OPTION_no_reboot: olist =qemu_find_opts ("action" );
@@ -3529,7 +3495,7 @@ void qemu_init(int argc, char **argv, char **envp)*/ loc_set_none (); -qemu_validate_options (); +qemu_validate_options (machine_opts_dict);qemu_process_sugar_options ();/*
@@ -3549,7 +3515,7 @@ void qemu_init(int argc, char **argv, char **envp)configure_rtc (qemu_find_opts_singleton ("rtc" )); -qemu_create_machine (select_machine ()); +qemu_create_machine (machine_opts_dict);suspend_mux_open ();
@@ -3557,12 +3523,14 @@ void qemu_init(int argc, char **argv, char **envp)qemu_create_default_devices ();qemu_create_early_backends (); -qemu_apply_machine_options (); +qemu_apply_legacy_machine_options (machine_opts_dict); +qemu_apply_machine_options (machine_opts_dict); +qobject_unref (machine_opts_dict);phase_advance (PHASE_MACHINE_CREATED );/* * Note: uses machine properties such as kernel-irqchip, must run -* after machine_set_property(). +* after qemu_apply_machine_options. */ configure_accelerators (argv[0 ]);phase_advance (PHASE_ACCEL_CREATED );
Signature · 1 line
2.26.2
PATCH 24/25 qemu-option: remove now-dead code
In reply to Paolo Bonzini-M was the sole user of qemu_opts_set and qemu_opts_set_defaults, remove them and the arguments that they used.
--- include/qemu/option.h | 3 --- tests/test-qemu-opts.c | 35 ----------------------------- util/qemu-option.c | 51 +++++++++--------------------------------- 3 files changed, 10 insertions(+), 79 deletions(-)
include/qemu/option.h +0 -3
@@ -119,7 +119,6 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists, Error **errp);void qemu_opts_reset (QemuOptsList *list);void qemu_opts_loc_restore (QemuOpts *opts); -bool qemu_opts_set (QemuOptsList *list,const char *name,const char *value,Error **errp);const char *qemu_opts_id (QemuOpts *opts);void qemu_opts_set_id (QemuOpts *opts,char *id);void qemu_opts_del (QemuOpts *opts);
@@ -130,8 +129,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, bool permit_abbrev);QemuOpts *qemu_opts_parse (QemuOptsList *list,const char *params,bool permit_abbrev,Error **errp); -void qemu_opts_set_defaults (QemuOptsList *list,const char *params, -int permit_abbrev);QemuOpts *qemu_opts_from_qdict (QemuOptsList *list,const QDict *qdict,Error **errp); QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict,
tests/test-qemu-opts.c +0 -35
@@ -410,40 +410,6 @@ static void test_qemu_opts_reset(void)g_assert (opts ==NULL ); } -static void test_qemu_opts_set (void ) -{ -QemuOptsList *list; -QemuOpts *opts; -const char *opt; - - list =qemu_find_opts ("opts_list_04" ); -g_assert (list !=NULL ); -g_assert (QTAILQ_EMPTY (&list->head)); - g_assert_cmpstr(list->name, ==, "opts_list_04"); - -/* should not find anything at this point */ - opts =qemu_opts_find (list,NULL ); -g_assert (opts ==NULL ); - -/* implicitly create opts and set str3 value */ -qemu_opts_set (list,"str3" ,"value" , &error_abort); -g_assert (!QTAILQ_EMPTY (&list->head)); - -/* get the just created opts */ - opts =qemu_opts_find (list,NULL ); -g_assert (opts !=NULL ); - -/* check the str3 value */ - opt =qemu_opt_get (opts,"str3" ); - g_assert_cmpstr(opt, ==, "value"); - -qemu_opts_del (opts); - -/* should not find anything at this point */ - opts =qemu_opts_find (list,NULL ); -g_assert (opts ==NULL ); -} -static int opts_count_iter (void *opaque,const char *name,const char *value,Error **errp) {
@@ -1030,7 +996,6 @@ int main(int argc, char *argv[])g_test_add_func ("/qemu-opts/opt_get_size" , test_qemu_opt_get_size);g_test_add_func ("/qemu-opts/opt_unset" , test_qemu_opt_unset);g_test_add_func ("/qemu-opts/opts_reset" , test_qemu_opts_reset); -g_test_add_func ("/qemu-opts/opts_set" , test_qemu_opts_set);g_test_add_func ("/qemu-opts/opts_parse/general" , test_opts_parse);g_test_add_func ("/qemu-opts/opts_parse/bool" , test_opts_parse_bool);g_test_add_func ("/qemu-opts/opts_parse/number" , test_opts_parse_number);
util/qemu-option.c +10 -41
126 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 25/25 vl: switch -accel parsing to keyval
In reply to Paolo BonziniSwitch from QemuOpts to keyval. This enables compound options for accelerators.
--- accel/accel.c | 6 ++ include/sysemu/accel.h | 1 + softmmu/vl.c | 134 ++++++++++++++++++----------------------- 3 files changed, 67 insertions(+), 74 deletions(-)
accel/accel.c +6 -0
@@ -46,6 +46,12 @@ AccelClass *accel_find(const char *opt_name)return ac; } +bool accel_print_class_properties (const char *opt_name) +{ + g_autofree char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); +return type_print_class_properties (class_name); +} +int accel_init_machine (AccelState *accel,MachineState *ms) {AccelClass *acc =ACCEL_GET_CLASS (accel);
include/sysemu/accel.h +1 -0
@@ -67,6 +67,7 @@ typedef struct AccelClass { OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)AccelClass *accel_find (const char *opt_name); +bool accel_print_class_properties (const char *opt_name);int accel_init_machine (AccelState *accel,MachineState *ms);/* Called just before os_setup_post (ie just before drop OS privs) */
softmmu/vl.c +60 -74
238 lines not on this page · raw message
Signature · 1 line
2.26.2
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH 00/25] qemu-option, keyval, vl: switch -object/-M/-accel to keyval parsing
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
ec26fa4 vl: switch -accel parsing to keyval
b9750c0 qemu-option: remove now-dead code
0ec053d vl: switch -M parsing to keyval
2bfede0 qom: export more functions for use with non-UserCreatable objects 2c8420d storage-daemon: do not register the "object" group with QemuOpts 6072877 qemu: use keyval for -object parsing
d597674 qemu-img: use keyval for -object parsing
4bf11fa qemu-nbd: use keyval for -object parsing
85a5e5a qemu-io: use keyval for -object parsing
9a44901 qom: do not modify QDict argument in user_creatable_add_dict 193c6a2 vl: plumb keyval-based options into -set and -readconfig 31579e0 qemu-config: parse configuration files to a QDict
bc20068 qemu-option: support accept-any QemuOptsList in qemu_opts_absorb_qdict ca390c3 qemu-config: add error propagation to qemu_config_parse 59b951f remove -writeconfig
fa45a78 hmp: special case help options for object_add
2561b79 qom: use qemu_printf to print help for user-creatable objects 0cab5f9 hmp: replace "O" parser with keyval
bd6519f keyval: introduce keyval_parse_into
d3fc628 tests: convert check-qom-proplist to keyval
437fd40 keyval: simplify keyval_parse_one
ffc5547 keyval: accept escaped commas in implied option
8a251bf qemu-option: warn for short-form boolean options
c2d9889 qemu-option: move help handling to get_opt_name_value e067ad6 qemu-option: clean up id vs. list->merge_lists
=== OUTPUT BEGIN ===
1/25 Checking commit e067ad67f18f (qemu-option: clean up id vs. list->merge_lists) 2/25 Checking commit c2d98893d095 (qemu-option: move help handling to get_opt_name_value) 3/25 Checking commit 8a251bf52737 (qemu-option: warn for short-form boolean options)
WARNING: line over 80 characters
#82: FILE: util/qemu-option.c:787:
+ warn_report("short-form boolean option '%s%s' deprecated", prefix, *name);
WARNING: line over 80 characters
#101: FILE: util/qemu-option.c:818:
+ p = get_opt_name_value(p, firstname, warn_on_flag, help_wanted, &option, &value);
total: 0 errors, 2 warnings, 127 lines checked
Patch 3/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
4/25 Checking commit ffc55478b1cb (keyval: accept escaped commas in implied option) 5/25 Checking commit 437fd4000b35 (keyval: simplify keyval_parse_one) 6/25 Checking commit d3fc62875f6a (tests: convert check-qom-proplist to keyval) 7/25 Checking commit bd6519ffd2d1 (keyval: introduce keyval_parse_into)
WARNING: line over 80 characters
#25: FILE: include/qemu/option.h:150:
+QDict *keyval_parse_into(QDict *qdict, const char *params, const char *implied_key,
WARNING: line over 80 characters
#44: FILE: util/keyval.c:442:
+QDict *keyval_parse_into(QDict *qdict, const char *params, const char *implied_key,
total: 0 errors, 2 warnings, 75 lines checked
Patch 7/25 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/25 Checking commit 0cab5f97ab3d (hmp: replace "O" parser with keyval)
9/25 Checking commit 2561b79c783e (qom: use qemu_printf to print help for user-creatable objects) 10/25 Checking commit fa45a78a9d8f (hmp: special case help options for object_add) 11/25 Checking commit 59b951f9b110 (remove -writeconfig)
12/25 Checking commit ca390c3ae7df (qemu-config: add error propagation to qemu_config_parse)
WARNING: line over 80 characters
#43: FILE: include/qemu/config-file.h:13:
+int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp);
WARNING: line over 80 characters
#119: FILE: util/qemu-config.c:311:
+int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp)
total: 0 errors, 2 warnings, 141 lines checked
Patch 12/25 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
13/25 Checking commit bc2006827446 (qemu-option: support accept-any QemuOptsList in qemu_opts_absorb_qdict) 14/25 Checking commit 31579e030854 (qemu-config: parse configuration files to a QDict)
WARNING: line over 80 characters
#28: FILE: include/qemu/config-file.h:4:
+typedef void QEMUConfigCB(const char *group, QDict *qdict, void *opaque, Error **errp);
WARNING: line over 80 characters
#38: FILE: include/qemu/config-file.h:17:
+void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, Error **errp);
WARNING: line over 80 characters
#62: FILE: softmmu/vl.c:3316:
+ qemu_read_config_file(optarg, qemu_config_do_parse, &error_fatal);
WARNING: line over 80 characters
#170: FILE: util/qemu-config.c:384:
+void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, Error **errp)
WARNING: line over 80 characters
#192: FILE: util/qemu-config.c:406:
+int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp)
total: 0 errors, 5 warnings, 170 lines checked
Patch 14/25 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
15/25 Checking commit 193c6a2cb171 (vl: plumb keyval-based options into -set and -readconfig)
WARNING: line over 80 characters
#115: FILE: softmmu/vl.c:2095:
+static void qemu_record_config_group(const char *group, QDict *dict, Error **errp)
WARNING: line over 80 characters
#127: FILE: softmmu/vl.c:2107:
+static void qemu_set_qdict_option(QDict *dict, const char *key, const char *value,
WARNING: line over 80 characters
#152: FILE: softmmu/vl.c:2132:
+ error_setg(errp, "Lists cannot be at top level of a configuration section");
WARNING: line over 80 characters
#250: FILE: softmmu/vl.c:3405:
+ qemu_read_config_file(optarg, qemu_parse_config_group, &error_fatal);
ERROR: line over 90 characters
#268: FILE: tests/test-keyval.c:746:
+ QDict *combined = keyval_parse("opt1=ABC,opt2.sub1=def,opt2.sub2=GHI,opt2.sub3=JKL,opt3=xyz",
WARNING: line over 80 characters
#318: FILE: util/keyval.c:319:
+static void keyval_do_merge(QDict *old, const QDict *new, GString *str, Error **errp)
WARNING: line over 80 characters
#327: FILE: util/keyval.c:328:
+ error_setg(errp, "Parameter '%s%s' used inconsistently", str->str, ent->key);
total: 1 errors, 6 warnings, 293 lines checked
Patch 15/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
16/25 Checking commit 9a449013c568 (qom: do not modify QDict argument in user_creatable_add_dict) 17/25 Checking commit 85a5e5a4aeee (qemu-io: use keyval for -object parsing) 18/25 Checking commit 4bf11facae8c (qemu-nbd: use keyval for -object parsing) 19/25 Checking commit d597674d23d7 (qemu-img: use keyval for -object parsing) 20/25 Checking commit 6072877b6226 (qemu: use keyval for -object parsing)
ERROR: do not initialise statics to 0 or NULL
#211: FILE: softmmu/vl.c:139:
+static GSList *object_opts_list = NULL;
WARNING: line over 80 characters
#346: FILE: softmmu/vl.c:3471:
+ args = keyval_parse(optarg, "qom-type", &help, &error_fatal);
total: 1 errors, 1 warnings, 324 lines checked
Patch 20/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
21/25 Checking commit 2c8420d34e62 (storage-daemon: do not register the "object" group with QemuOpts) 22/25 Checking commit 2bfede05a80b (qom: export more functions for use with non-UserCreatable objects)
ERROR: code indent should never use tabs
#45: FILE: include/qom/object.h:882:
+^I^I^I^I Error **errp);$
total: 1 errors, 0 warnings, 108 lines checked
Patch 22/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
23/25 Checking commit 0ec053de9e5e (vl: switch -M parsing to keyval)
WARNING: line over 80 characters
#187: FILE: softmmu/vl.c:1558:
+ error_setg(&local_err, "No machine specified, and there is no default");
WARNING: line over 80 characters
#200: FILE: softmmu/vl.c:1564:
+ error_append_hint(&local_err, "Use -machine help to list supported machines\n");
WARNING: line over 80 characters
#237: FILE: softmmu/vl.c:1605:
+ error_setg(errp, "Conflict between '%s' and '%s'", ent->key, new_key);
WARNING: line over 80 characters
#277: FILE: softmmu/vl.c:1629:
+ object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value);
WARNING: line over 80 characters
#283: FILE: softmmu/vl.c:1635:
+ object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value);
WARNING: line over 80 characters
#289: FILE: softmmu/vl.c:1641:
+ object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value);
WARNING: line over 80 characters
#290: FILE: softmmu/vl.c:1642:
+ object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value);
WARNING: line over 80 characters
#311: FILE: softmmu/vl.c:1709:
+ object_set_properties_from_keyval(OBJECT(current_machine), qdict, &error_fatal);
ERROR: line over 90 characters
#323: FILE: softmmu/vl.c:1739:
+ semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline);
ERROR: line over 90 characters
#365: FILE: softmmu/vl.c:2015:
+ object_set_properties_from_keyval(OBJECT(current_machine), default_opts, &error_abort);
ERROR: line over 90 characters
#493: FILE: softmmu/vl.c:3202:
+ keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal);
total: 3 errors, 8 warnings, 523 lines checked
Patch 23/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
24/25 Checking commit b9750c0ad970 (qemu-option: remove now-dead code) 25/25 Checking commit ec26fa447263 (vl: switch -accel parsing to keyval)
WARNING: line over 80 characters
#29: FILE: accel/accel.c:51:
+ g_autofree char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
ERROR: do not initialise statics to 0 or NULL
#56: FILE: softmmu/vl.c:142:
+static GSList *accel_opts_list = NULL;
WARNING: line over 80 characters
#172: FILE: softmmu/vl.c:2198:
+ error_report("failed to initialize %s: %s", ac->name, strerror(-ret));
total: 1 errors, 2 warnings, 257 lines checked
Patch 25/25 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]