Get rid of the pattern qemu_parse_opts(qemu_find_opts("some-opt")) by
passing the string directly to qemu_parse_opts().

Don't check for NULL list at this time to preserve the old behavior. A
subsequent patch will correct that.

Signed-off-by: Fabiano Rosas <[email protected]>
---
 include/qemu/option.h          |  2 +-
 system/vl.c                    |  5 ++---
 tests/unit/test-opts-visitor.c | 12 ++++--------
 util/qemu-option.c             | 19 +++++++++++--------
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index f96d9fae42..dfe0d9b893 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -130,7 +130,7 @@ bool qemu_opts_do_parse(QemuOpts *opts, const char *params,
                         const char *firstname, Error **errp);
 QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
                                   bool permit_abbrev);
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
+QemuOpts *qemu_opts_parse(const char *group, const char *params,
                           bool permit_abbrev, Error **errp);
 QemuOpts *qemu_opts_parse_list(QemuOptsList *list, const char *params,
                                bool permit_abbrev, Error **errp);
diff --git a/system/vl.c b/system/vl.c
index 9bd7664b85..239c537e45 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -1441,10 +1441,9 @@ static void qemu_create_default_devices(void)
     }
 
     if (default_net) {
-        QemuOptsList *net = qemu_find_opts("net");
-        qemu_opts_parse(net, "nic", true, &error_abort);
+        qemu_opts_parse("net", "nic", true, &error_abort);
 #ifdef CONFIG_SLIRP
-        qemu_opts_parse(net, "user", true, &error_abort);
+        qemu_opts_parse("net", "user", true, &error_abort);
 #endif
     }
 
diff --git a/tests/unit/test-opts-visitor.c b/tests/unit/test-opts-visitor.c
index 23e897061c..a9e45c0251 100644
--- a/tests/unit/test-opts-visitor.c
+++ b/tests/unit/test-opts-visitor.c
@@ -39,8 +39,7 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data)
     QemuOpts *opts;
     Visitor *v;
 
-    opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, false,
-                           NULL);
+    opts = qemu_opts_parse("userdef", opts_string, false, NULL);
     g_assert(opts != NULL);
 
     v = opts_visitor_new(opts);
@@ -181,8 +180,7 @@ test_opts_range_unvisited(void)
     QemuOpts *opts;
     Visitor *v;
 
-    opts = qemu_opts_parse(qemu_find_opts("userdef"), "ilist=0-2", false,
-                           &error_abort);
+    opts = qemu_opts_parse("userdef", "ilist=0-2", false, &error_abort);
 
     v = opts_visitor_new(opts);
 
@@ -222,8 +220,7 @@ test_opts_range_beyond(void)
     Visitor *v;
     int64_t val;
 
-    opts = qemu_opts_parse(qemu_find_opts("userdef"), "ilist=0", false,
-                           &error_abort);
+    opts = qemu_opts_parse("userdef", "ilist=0", false, &error_abort);
 
     v = opts_visitor_new(opts);
 
@@ -257,8 +254,7 @@ test_opts_dict_unvisited(void)
     Visitor *v;
     UserDefOptions *userdef;
 
-    opts = qemu_opts_parse(qemu_find_opts("userdef"), "i64x=0,bogus=1", false,
-                           &error_abort);
+    opts = qemu_opts_parse("userdef", "i64x=0,bogus=1", false, &error_abort);
 
     v = opts_visitor_new(opts);
     visit_type_UserDefOptions(v, NULL, &userdef, &err);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index aa879b78f8..2c23841376 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -26,6 +26,7 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qobject/qbool.h"
 #include "qobject/qdict.h"
@@ -910,16 +911,18 @@ static QemuOpts *opts_parse(QemuOptsList *list, const 
char *params,
 }
 
 /**
- * Create a QemuOpts in @list and with options parsed from @params.
- * If @permit_abbrev, the first key=value in @params may omit key=,
- * and is treated as if key was @list->implied_opt_name.
- * On error, store an error object through @errp if non-null.
- * Return the new QemuOpts on success, null pointer on error.
+ * Find the @group and create a QemuOpts with options parsed from
+ * @params.  If @permit_abbrev, the first key=value in @params may
+ * omit key=.  On error, store an error object through @errp if
+ * non-null.  Return the new QemuOpts on success, null pointer on
+ * error.
  */
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
+QemuOpts *qemu_opts_parse(const char *group, const char *params,
                           bool permit_abbrev, Error **errp)
 {
-    return opts_parse(list, params, permit_abbrev, false, NULL, errp);
+    QemuOptsList *list = qemu_find_opts_err(group, errp);
+
+    return qemu_opts_parse_list(list, params, permit_abbrev, errp);
 }
 
 /**
@@ -932,7 +935,7 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const char 
*params,
 QemuOpts *qemu_opts_parse_list(QemuOptsList *list, const char *params,
                                bool permit_abbrev, Error **errp)
 {
-    return qemu_opts_parse(list, params, permit_abbrev, errp);
+    return opts_parse(list, params, permit_abbrev, false, NULL, errp);
 }
 
 /**
-- 
2.53.0


Reply via email to