OSDN Git Service

vl: introduce machine_merge_property
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 29 Jul 2021 13:53:27 +0000 (15:53 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 30 Jul 2021 10:04:01 +0000 (12:04 +0200)
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>
softmmu/vl.c

index 4dee472..93aef8e 100644 (file)
@@ -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;