diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2021-07-29 15:53:27 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2021-07-30 12:04:01 +0200 |
commit | a3c2f12830683e285e1ef32d459717dcdf9b70c6 (patch) | |
tree | e816b25b0651f562c3c88e2ef0406a3c8f00e5fb /softmmu | |
parent | 7742fe64e5c2c2c9f9787d107b693eaac602eaae (diff) |
vl: introduce machine_merge_property
It will be used to parse smp-opts config groups from configuration
files. The point to note is that it does not steal a reference
from the caller. This is better because this function will be called
from qemu_config_foreach's callback; qemu_config_foreach does not cede
its reference to the qdict to the callback, and wants to free it. To
balance that extra reference, machine_parse_property_opt now needs
a qobject_unref.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'softmmu')
-rw-r--r-- | softmmu/vl.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/softmmu/vl.c b/softmmu/vl.c index 4dee472c79..93aef8e747 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1535,22 +1535,35 @@ static void machine_help_func(const QDict *qdict) } static void +machine_merge_property(const char *propname, QDict *prop, Error **errp) +{ + QDict *opts; + + opts = qdict_new(); + /* Preserve the caller's reference to prop. */ + qobject_ref(prop); + qdict_put(opts, propname, prop); + keyval_merge(machine_opts_dict, opts, errp); + qobject_unref(opts); +} + +static void machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, const char *arg, Error **errp) { - QDict *opts, *prop; + QDict *prop = NULL; bool help = false; - ERRP_GUARD(); prop = keyval_parse(arg, opts_list->implied_opt_name, &help, errp); if (help) { qemu_opts_print_help(opts_list, true); exit(0); } - opts = qdict_new(); - qdict_put(opts, propname, prop); - keyval_merge(machine_opts_dict, opts, errp); - qobject_unref(opts); + if (!prop) { + return; + } + machine_merge_property(propname, prop, errp); + qobject_unref(prop); } static const char *pid_file; |