From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com,
pbonzini@redhat.com, marcandre.lureau@redhat.com
Subject: [PATCH 06/13] char-udp: Implement compat code for CLI QAPIfication
Date: Thu, 12 Nov 2020 18:58:58 +0100 [thread overview]
Message-ID: <20201112175905.404472-7-kwolf@redhat.com> (raw)
In-Reply-To: <20201112175905.404472-1-kwolf@redhat.com>
UDP backends have a few differences between CLI and QMP. This adds
QAPI aliases and a .translate_legacy_options() implementation that
converts CLI inputs to a form that's usable for a QAPIfied --chardev.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi/char.json | 7 ++++++-
chardev/char-udp.c | 33 +++++++++++++++++++++++++++++++++
chardev/char.c | 1 -
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/qapi/char.json b/qapi/char.json
index 1930e90e95..e1f9347044 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -303,7 +303,12 @@
{ 'struct': 'ChardevUdp',
'data': { 'remote': 'SocketAddressLegacy',
'*local': 'SocketAddressLegacy' },
- 'base': 'ChardevCommon' }
+ 'base': 'ChardevCommon',
+ 'aliases': [
+ { 'source': ['remote'] },
+ { 'alias': 'localaddr', 'source': ['local', 'host'] },
+ { 'alias': 'localport', 'source': ['local', 'port'] }
+ ]}
##
# @ChardevMux:
diff --git a/chardev/char-udp.c b/chardev/char-udp.c
index 16b5dbce58..61752b1c51 100644
--- a/chardev/char-udp.c
+++ b/chardev/char-udp.c
@@ -23,9 +23,11 @@
*/
#include "qemu/osdep.h"
+#include "block/qdict.h"
#include "chardev/char.h"
#include "io/channel-socket.h"
#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
#include "qemu/module.h"
#include "qemu/option.h"
@@ -190,6 +192,36 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
}
}
+static void qemu_chr_translate_udp(QDict *args)
+{
+ QDict *remote;
+ QDict *local;
+
+ /*
+ * If "local" or "remote" are given, it's not a legacy command line.
+ * Not translating in this case saves us checking whether an alias is
+ * already given before applying defaults.
+ */
+ if (qdict_haskey(args, "local") || qdict_haskey(args, "remote")) {
+ return;
+ }
+
+ remote = qdict_new();
+ qdict_put_str(remote, "type", "inet");
+ qdict_put(args, "remote", remote);
+
+ qdict_set_default_str(args, "host", "localhost");
+
+ if (qdict_haskey(args, "localaddr") || qdict_haskey(args, "localport")) {
+ local = qdict_new();
+ qdict_put_str(local, "type", "inet");
+ qdict_put(args, "local", local);
+
+ qdict_set_default_str(args, "localaddr", "");
+ qdict_set_default_str(args, "localport", "0");
+ }
+}
+
static void qmp_chardev_open_udp(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
@@ -225,6 +257,7 @@ static void char_udp_class_init(ObjectClass *oc, void *data)
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->parse = qemu_chr_parse_udp;
+ cc->translate_legacy_options = qemu_chr_translate_udp;
cc->open = qmp_chardev_open_udp;
cc->chr_write = udp_chr_write;
cc->chr_update_read_handler = udp_chr_update_read_handler;
diff --git a/chardev/char.c b/chardev/char.c
index 91b44e53b6..99feaae275 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -744,7 +744,6 @@ void qemu_chr_translate_legacy_options(QDict *args)
/*
* TODO:
* All backend types: "mux"
- * udp: defaults for "host"/"localaddr"/"localport"
*/
}
--
2.28.0
next prev parent reply other threads:[~2020-11-12 18:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 17:58 [PATCH 00/13] char: QAPIfy the command line parsing Kevin Wolf
2020-11-12 17:58 ` [PATCH 01/13] char: Factor out qemu_chr_print_types() Kevin Wolf
2020-11-12 17:58 ` [PATCH 02/13] char: Add ChardevOptions and qemu_chr_new_cli() Kevin Wolf
2020-11-12 17:58 ` [PATCH 03/13] char: Some QAPI aliases for CLI compatibility Kevin Wolf
2020-11-12 17:58 ` [PATCH 04/13] char: Add qemu_chr_translate_legacy_options() Kevin Wolf
2020-11-12 17:58 ` [PATCH 05/13] char-socket: Implement compat code for CLI QAPIfication Kevin Wolf
2020-11-12 17:58 ` Kevin Wolf [this message]
2020-11-12 17:58 ` [PATCH 07/13] char: Add qemu_chr_parse_cli_dict/str() Kevin Wolf
2020-11-12 17:59 ` [PATCH 08/13] char: Add mux option to ChardevOptions Kevin Wolf
2020-11-13 11:50 ` Paolo Bonzini
2020-11-13 13:20 ` Kevin Wolf
2020-11-13 14:16 ` Paolo Bonzini
2020-11-12 17:59 ` [PATCH 09/13] qemu-storage-daemon: QAPIfy --chardev Kevin Wolf
2020-11-12 17:59 ` [PATCH 10/13] char: Implement qemu_chr_new_from_opts() in terms of QAPI Kevin Wolf
2020-11-12 17:59 ` [PATCH 11/13] hmp/char: Use qemu_chr_parse_cli_str() for chardev-change Kevin Wolf
2020-11-13 18:44 ` Dr. David Alan Gilbert
2020-11-12 17:59 ` [PATCH 12/13] char: Remove qemu_chr_parse_opts() Kevin Wolf
2020-11-12 17:59 ` [PATCH 13/13] char: Remove ChardevClass.parse Kevin Wolf
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=20201112175905.404472-7-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).