vl: add -object support back into -readconfig
v4 cover vl: add -object support back into -readconfig
LXD developers have reported that [object] stanzas have stopped working in configuration files.
The problem is that QEMU 6.0 switched the creation of objects from qemu_opts_foreach to a bespoke QTAILQ, in preparation for supporting JSON syntax in -object. Entries from the configuration file however do not go through object_option_parse, and are thus lost. Of the many fixes that are possible, I chose one that is slightly more invasive but more consistent with the plans for keyval-ification of options such as -M and -accel.
-set was also broken by the same change. For simplicity I chose not to add it back yet, however this series will report the breakage instead of failing silently.
The first two patches of this series are thus a reduced version of
https://patchew.org/QEMU/[email protected]/
([PATCH 00/14] vl: compound properties for machines and accelerators), with the -set infrastructure removed. The third is very simple and uses the newly-provided hooks to parse objects from configuration files.
Paolo
Based-on: <[email protected]>
Paolo Bonzini (3):
qemu-config: parse configuration files to a QDict
vl: plumb keyval-based options into -readconfig
vl: plug -object back into -readconfig
include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 ++ include/qemu/config-file.h | 7 ++- softmmu/vl.c | 105 +++++++++++++++++++++++++++---------- util/qemu-config.c | 98 +++++++++++++++++++++++----------- 5 files changed, 153 insertions(+), 62 deletions(-)
Signature · 1 line
2.27.0
PATCH v4 1/3 qemu-config: parse configuration files to a QDict
Change 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.
This is useful for -readconfig to support keyval-based options; getting a QDict from the parser removes a roundtrip from QDict to QemuOpts and then back to QDict.
Unfortunately there is a disadvantage in that semantic errors will point to the last line of the group, because the entries of the QDict do not have a location attached.
---v1->v2: check for unrecognized entries in the QDict, move a loc_pop for
better error messages
v2->v3->v4: fix error propagation
include/qemu/config-file.h | 7 ++- softmmu/vl.c | 4 +- util/qemu-config.c | 98 ++++++++++++++++++++++++++------------ 3 files changed, 76 insertions(+), 33 deletions(-)
include/qemu/config-file.h +6 -1
@@ -1,6 +1,8 @@#ifndef QEMU_CONFIG_FILE_H #define QEMU_CONFIG_FILE_H +typedef void QEMUConfigCB (const char *group,QDict *qdict,void *opaque,Error **errp); +void qemu_load_module_for_opts (const char *group);QemuOptsList *qemu_find_opts (const char *group);QemuOptsList *qemu_find_opts_err (const char *group,Error **errp);
@@ -14,7 +16,10 @@ void qemu_config_write(FILE *fp);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
@@ -2133,7 +2133,7 @@ static void qemu_read_default_config_file(Error **errp)int ret; g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); - ret =qemu_read_config_file (file, errp); + ret =qemu_read_config_file (file, qemu_config_do_parse, errp);if (ret <0 ) {if (ret == -ENOENT ) {error_free (*errp);
@@ -3399,7 +3399,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 +67 -30
149 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v4 1/3] qemu-config: parse configuration files to a QDict
Hi Paolo,
Quoted 40 lines · Paolo Bonzini
Change 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.
This is useful for -readconfig to support keyval-based options; getting a QDict from the parser removes a roundtrip from QDict to QemuOpts and then back to QDict.
Unfortunately there is a disadvantage in that semantic errors will point to the last line of the group, because the entries of the QDict do not have a location attached.
Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>---
v1->v2: check for unrecognized entries in the QDict, move aloc_popfor
better error messages
v2->v3->v4: fix error propagationinclude/qemu/config-file.h | 7 ++- softmmu/vl.c | 4 +- util/qemu-config.c | 98 ++++++++++++++++++++++++++------------ 3 files changed, 76 insertions(+), 33 deletions(-)util/qemu-config.c +12
-1-int qemu_read_config_file (const char *filename,Error **errp) +void qemu_config_do_parse (const char *group,QDict *qdict,void *opaque,Error **errp) +{ +QemuOptsList **lists = opaque; +const char *id =qdict_get_try_str (qdict,"id" ); +QemuOptsList *list; +QemuOpts *opts; +const QDictEntry *unrecognized; + + list =find_list (lists, group, errp); +if (!list) { +return ; + }
util/qemu-config.c int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error * · line 450
Quoted 10 lines
util/qemu-config.c +10
-0+ + opts =qemu_opts_create (list, id,1 , errp); +if (!opts) { +return ; + } +if (!qemu_opts_absorb_qdict (opts, qdict, errp)) { +return ; + } + unrecognized =qdict_first (qdict); +if (unrecognized) {
Using the qemu-qmp.conf from:
https://wiki.qemu.org/Documentation/QMP#By_hand
I'm getting:
qemu-system-i386:qemu-qmp.conf:5: Invalid parameter 'id'
I don't see any "id" in my config. Is it broken? Do we need to update the wiki?
Quoted 1 line
+
error_setg(errp, QERR_INVALID_PARAMETER, unrecognized->key);
FYI about QERR_INVALID_PARAMETER in "qapi/qmp/qerror.h":
/*
* These macros will go away, please don't use in new code, and do not
* add new ones!
*/
Quoted 3 lines
util/qemu-config.c +3
-0+qemu_opts_del (opts); + } +}
PATCH v4 2/3 vl: plumb keyval-based options into -readconfig
In reply to Paolo BonziniLet -readconfig support parsing command line options into QDict or QemuOpts. This will be used to add back support for objects in -readconfig.
---v1->v2: fix overlong line
include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 ++ softmmu/vl.c | 83 ++++++++++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 26 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 */
softmmu/vl.c +59 -24
129 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v4 3/3 vl: plug -object back into -readconfig
In reply to Paolo BonziniCommit bc2f4fcb1d ("qom: move user_creatable_add_opts logic to vl.c and QAPIfy it", 2021-03-19) switched the creation of objects from qemu_opts_foreach to a bespoke QTAILQ in preparation for supporting JSON syntax in -object.
Unfortunately in doing so it lost support for [object] stanzas in configuration files and also for "-set object.ID.KEY=VAL". The latter is hard to re-establish and probably best solved by deprecating -set. This patch uses the infrastructure introduced by the previous two patches in order to parse QOM objects correctly from configuration files.
--- softmmu/vl.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
softmmu/vl.c +18 -6
@@ -1722,9 +1722,15 @@ static void object_option_foreach_add(bool (*type_opt_predicate)(const char *)) } } +static void object_option_add_visitor (Visitor *v) +{ +ObjectOption *opt =g_new0 (ObjectOption,1 ); +visit_type_ObjectOptions (v,NULL , &opt->opts, &error_fatal); +QTAILQ_INSERT_TAIL (&object_opts, opt, next); +} +static void object_option_parse (const char *optarg) { -ObjectOption *opt;QemuOpts *opts;const char *type;Visitor *v;
@@ -1752,11 +1758,8 @@ static void object_option_parse(const char *optarg) v =opts_visitor_new (opts); } - opt =g_new0 (ObjectOption,1 ); -visit_type_ObjectOptions (v,NULL , &opt->opts, &error_fatal); +object_option_add_visitor (v);visit_free (v); - -QTAILQ_INSERT_TAIL (&object_opts, opt, next); }/*
@@ -2134,13 +2137,22 @@ 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" )) { +return false; + }return true; }static void qemu_record_config_group (const char *group,QDict *dict,bool from_json,Error **errp) { -abort (); +if (g_str_equal (group,"object" )) { +Visitor *v =qobject_input_visitor_new_keyval (QOBJECT (dict)); +object_option_add_visitor (v); +visit_free (v); + }else { +abort (); + } }/*
Signature · 1 line
2.27.0
Quoted 21 lines · Paolo Bonzini
LXD developers have reported that [object] stanzas have stopped working in configuration files.
The problem is that QEMU 6.0 switched the creation of objects from
qemu_opts_foreachto a bespoke QTAILQ, in preparation for supporting JSON syntax in -object. Entries from the configuration file however do not go throughobject_option_parse, and are thus lost. Of the many fixes that are possible, I chose one that is slightly more invasive but more consistent with the plans for keyval-ification of options such as(quoted diff) +0
-2-M and -accel. -set was also broken by the same change. For simplicity I chosenot to add it back yet, however this series will report the breakage instead of failing silently.
The first two patches of this series are thus a reduced version of
https://patchew.org/QEMU/[email protected]/
([PATCH 00/14] vl: compound properties for machines and accelerators), with the -set infrastructure removed. The third is very simple and uses the newly-provided hooks to parse objects from configuration files.
Quoted 3 lines
Paolo
Based-on: <[email protected]>
This series is now in master. It doesn't fix the following regression:
$ cat bug.cfg
[chardev "mon0"]
backend = "stdio"
$ upstream-qemu -S -display none -readconfig bug.cfg
upstream-qemu:bug.cfg:2: Invalid parameter 'id'
[Exit 1 ]Regressed in commit 3770141139 "qemu-config: parse configuration files to a QDict".
Regressions are hard to avoid when automated tests are lacking. You touched it, you own it, now write the tests, please ;-P
Quoted 3 lines · Markus Armbruster
Regressions are hard to avoid when automated tests are lacking. You touched it, you own it, now write the tests, please;-P
Patch sent. Tests will come too.
Paolo