qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] qapi: net: fix -set parameter with modern style
@ 2023-03-13 11:42 Laurent Vivier
  2023-03-13 13:07 ` Markus Armbruster
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2023-03-13 11:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Markus Armbruster, Eugenio Perez Martin,
	Yalan Zhang, Jason Wang, Laurent Vivier

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-13 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-13 11:42 [RFC PATCH] qapi: net: fix -set parameter with modern style Laurent Vivier
2023-03-13 13:07 ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).