qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH] qapi: net: fix -set parameter with modern style


From: Laurent Vivier
Subject: [RFC PATCH] qapi: net: fix -set parameter with modern style
Date: Mon, 13 Mar 2023 12:42:55 +0100

With netdev modern style, parameters cannot be found using
qemu_find_opts_err() and then qemu_set_option() cannot find
them to update them with the new option.

To fix that, update the code to manage the modern style by
searching the parameter in nd_queue, and update the entry
using visit_type_Netdev_members().

Fixes: f3eedcddba36 ("qapi: net: introduce a way to bypass 
qemu_opts_parse_noisily()")
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 include/net/net.h |  2 ++
 net/net.c         | 35 +++++++++++++++++++++++++++++++++++
 softmmu/vl.c      |  8 ++++++++
 3 files changed, 45 insertions(+)

diff --git a/include/net/net.h b/include/net/net.h
index 1448d00afbc6..be42ba96ee3d 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -246,6 +246,8 @@ extern const char *host_net_devices[];
 extern NetClientStateList net_clients;
 bool netdev_is_modern(const char *optarg);
 void netdev_parse_modern(const char *optarg);
+Netdev *netdev_find_modern(const char *id);
+void netdev_set_modern(Netdev *net, const char *arg, Error **errp);
 void net_client_parse(QemuOptsList *opts_list, const char *str);
 void show_netdevs(void);
 void net_init_clients(void);
diff --git a/net/net.c b/net/net.c
index 6492ad530e21..9c384187255b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1624,6 +1624,41 @@ out:
     return ret;
 }
 
+Netdev *netdev_find_modern(const char *id)
+{
+    NetdevQueueEntry *e;
+
+    QSIMPLEQ_FOREACH(e, &nd_queue, entry) {
+        if (strcmp(id, e->nd->id) == 0) {
+            return e->nd;
+        }
+    }
+    return NULL;
+}
+
+void netdev_set_modern(Netdev *net, const char *arg, Error **errp)
+{
+    Visitor *v;
+    char *id = net->id;
+    char *opts = g_strdup_printf("type=%s,id=%s,%s",
+                                 NetClientDriver_lookup.array[net->type],
+                                 id, arg);
+
+    v = qobject_input_visitor_new_str(opts, NULL, errp);
+    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
+        goto out;
+    }
+    if (visit_type_Netdev_members(v, net, errp)) {
+        g_free(id); /* re-allocated in visit_type_Netdev_members() */
+        visit_check_struct(v, errp);
+        visit_end_struct(v, NULL);
+    }
+
+out:
+    visit_free(v);
+    g_free(opts);
+}
+
 static void netdev_init_modern(void)
 {
     while (!QSIMPLEQ_EMPTY(&nd_queue)) {
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 3340f63c3764..c063857867e2 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2162,6 +2162,14 @@ static void qemu_set_option(const char *str, Error 
**errp)
     if (!is_qemuopts_group(group)) {
         error_setg(errp, "-set is not supported with %s", group);
     } else {
+        if (strcmp(group, "netdev") == 0) {
+            Netdev *net = netdev_find_modern(id);
+            if (net) {
+                netdev_set_modern(net, str + strlen(group) + strlen(id) + 2,
+                                  errp);
+                return;
+            }
+        }
         list = qemu_find_opts_err(group, errp);
         if (list) {
             opts = qemu_opts_find(list, id);
-- 
2.39.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]