qemu-config: use qemu_opts_from_qdict
PATCH 1/1 qemu-config: use qemu_opts_from_qdict
Using qemu_opts_absorb_qdict, and then checking for any leftover options, is redundant because there is already a function that does the same, qemu_opts_from_qdict. qemu_opts_from_qdict consumes the whole dictionary and therefore can just return an error message if an option fails to validate.
This also fixes a bug, because the "id" entry was retrieved in qemu_config_do_parse and then left there by qemu_opts_absorb_qdict. As a result, it was reported as an unrecognized option.
--- util/qemu-config.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
util/qemu-config.c +1 -16
@@ -429,29 +429,14 @@ out: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 ; } - opts =qemu_opts_create (list, id,1 , errp); -if (!opts) { -return ; - } -if (!qemu_opts_absorb_qdict (opts, qdict, errp)) { -qemu_opts_del (opts); -return ; - } - unrecognized =qdict_first (qdict); -if (unrecognized) { -error_setg (errp,QERR_INVALID_PARAMETER , unrecognized->key); -qemu_opts_del (opts); - } +qemu_opts_from_qdict (list, qdict, errp); }int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp)
Signature · 1 line
2.31.1
Quoted 25 lines · Paolo Bonzini
Using
qemu_opts_absorb_qdict, and then checking for any leftover options, is redundant because there is already a function that does the same,qemu_opts_from_qdict.qemu_opts_from_qdictconsumes the whole dictionary and therefore can just return an error message if an option fails to validate.This also fixes a bug, because the "id" entry was retrieved in
qemu_config_do_parseand then left there byqemu_opts_absorb_qdict. As a result, it was reported as an unrecognized option.Reported-by Markus Armbruster <[email protected]>Fixes 3770141139 ("qemu-config: parse configuration files to a QDict")Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-config.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)util/qemu-config.c +0
-0@@ -429,29 +429,14 @@ out:void qemu_config_do_parse (const char *group,QDict *qdict,void *opaque,Error **errp) {QemuOptsList **lists = opaque;
util/qemu-config.c out: · line 438
Quoted 10 lines
util/qemu-config.c +0
-3-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 ; }
Matter of taste I'd have inverted the if statement, but it fixes my problem, so thanks!
Quoted 5 lines
util/qemu-config.c +1
-0+qemu_opts_from_qdict (list, qdict, errp); }int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp)
Quoted 4 lines · Paolo Bonzini
Using
qemu_opts_absorb_qdict, and then checking for any leftover options, is redundant because there is already a function that does the same,qemu_opts_from_qdict.qemu_opts_from_qdictconsumes the whole dictionary and therefore can just return an error message if an option fails to validate.
I missed this when I reviewed the series...
Quoted 37 lines
This also fixes a bug, because the "id" entry was retrieved in
qemu_config_do_parseand then left there byqemu_opts_absorb_qdict. As a result, it was reported as an unrecognized option.Reported-by Markus Armbruster <[email protected]>Fixes 3770141139 ("qemu-config: parse configuration files to a QDict")Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-config.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)util/qemu-config.c +0
-10@@ -429,29 +429,14 @@ out: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 ; } - opts =qemu_opts_create (list, id,1 , errp); -if (!opts) { -return ; - } -if (!qemu_opts_absorb_qdict (opts, qdict, errp)) { -qemu_opts_del (opts); -return ;
util/qemu-config.c out: · line 442
Quoted 10 lines
util/qemu-config.c +1
-6- } - unrecognized =qdict_first (qdict); -if (unrecognized) { -error_setg (errp,QERR_INVALID_PARAMETER , unrecognized->key); -qemu_opts_del (opts); - } +qemu_opts_from_qdict (list, qdict, errp); }int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname,Error **errp)
Creation of @opts is now in qemu_opts_from_qdict(). Works the same as before. Good. Let's compare the remainder.
Before the patch:
qemu_opts_absorb_qdict() absorbs entries with keys the QemuOpts accepts. It either accepts a (non-empty) list of keys, or any key.
It fails when any of the absorbed entries fails qemu_opts_from_qdict_entry().
qemu_config_do_parse() additionally fails when unabsorbed keys remain.
After the patch:
qemu_opts_from_qdict() feeds all entries to qemu_opts_from_qdict_entry(). Which silently ignores entry "id", and fails for keys the QemuOpts doesn't accept.
Good. The part 'ignores entry "id"' fixes the bug.
Tangent: we silently ignore entries whose value is a QTYPE_QNULL, QTYPE_QDICT, or QTYPE_QLIST, because qemu_opts_from_qdict_entry() does. Not changed by this patch, I believe.