From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Eugenio Perez Martin <eperezma@redhat.com>,
Yalan Zhang <yalzhang@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Laurent Vivier <lvivier@redhat.com>
Subject: [RFC PATCH] qapi: net: fix -set parameter with modern style
Date: Mon, 13 Mar 2023 12:42:55 +0100 [thread overview]
Message-ID: <20230313114255.1206609-1-lvivier@redhat.com> (raw)
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
next reply other threads:[~2023-03-13 11:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 11:42 Laurent Vivier [this message]
2023-03-13 13:07 ` [RFC PATCH] qapi: net: fix -set parameter with modern style Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313114255.1206609-1-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=armbru@redhat.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yalzhang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).