[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/13] char: Add qemu_chr_translate_legacy_options()
From: |
Kevin Wolf |
Subject: |
[PATCH 04/13] char: Add qemu_chr_translate_legacy_options() |
Date: |
Thu, 12 Nov 2020 18:58:56 +0100 |
This translates legacy command line options that can't be made
compatible with QAPI just by using aliases from the traditional command
line structure into the structure of ChardevOptions.
As a first step, add support for backend name aliases if 'backend' is
given instead of 'type'.
Also add a todo comment for everything that is still incompatible
between the QemuOpts based -chardev and chardev creation by going
through a keyval parser, qemu_chr_translate_legacy_options() and
qemu_chr_new_cli().
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/chardev/char.h | 13 +++++++++++++
chardev/char.c | 23 +++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 54fa2ed8e2..7795e17ca5 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -94,6 +94,19 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
*/
Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp);
+/**
+ * qemu_chr_translate_legacy_options:
+ * @args: Character device creation options as returned by the keyval parser
+ *
+ * Change @args so that the legacy command line options in it are translated
+ * and @args can be used as the input for a ChardevOptions visitor.
+ *
+ * If @args was not a valid legacy command line, translation may be partially
+ * skipped and the visitor may return an error if @args was not already
+ * suitable for QAPI parsing.
+ */
+void qemu_chr_translate_legacy_options(QDict *args);
+
/**
* qemu_chr_parse_common:
* @opts: the options that still need parsing
diff --git a/chardev/char.c b/chardev/char.c
index 9f00e475d4..40c3f02ec9 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -32,6 +32,7 @@
#include "chardev/char.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-char.h"
+#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "sysemu/replay.h"
#include "qemu/help_option.h"
@@ -717,6 +718,28 @@ out:
return chr;
}
+void qemu_chr_translate_legacy_options(QDict *args)
+{
+ const char *name;
+
+ /* "backend" instead of "type" enables legacy CLI compatibility */
+ name = qdict_get_try_str(args, "backend");
+ if (!name || qdict_haskey(args, "type")) {
+ return;
+ }
+
+ name = chardev_alias_translate(name);
+ qdict_put_str(args, "type", name);
+ qdict_del(args, "backend");
+
+ /*
+ * TODO:
+ * All backend types: "mux"
+ * socket: "addr.type", "delay", "server", "wait", "fd"
+ * udp: defaults for "host"/"localaddr"/"localport"
+ */
+}
+
Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
bool permit_mux_mon, GMainContext *context)
{
--
2.28.0
- [PATCH 00/13] char: QAPIfy the command line parsing, Kevin Wolf, 2020/11/12
- [PATCH 01/13] char: Factor out qemu_chr_print_types(), Kevin Wolf, 2020/11/12
- [PATCH 03/13] char: Some QAPI aliases for CLI compatibility, Kevin Wolf, 2020/11/12
- [PATCH 02/13] char: Add ChardevOptions and qemu_chr_new_cli(), Kevin Wolf, 2020/11/12
- [PATCH 04/13] char: Add qemu_chr_translate_legacy_options(),
Kevin Wolf <=
- [PATCH 05/13] char-socket: Implement compat code for CLI QAPIfication, Kevin Wolf, 2020/11/12
- [PATCH 06/13] char-udp: Implement compat code for CLI QAPIfication, Kevin Wolf, 2020/11/12
- [PATCH 07/13] char: Add qemu_chr_parse_cli_dict/str(), Kevin Wolf, 2020/11/12
- [PATCH 08/13] char: Add mux option to ChardevOptions, Kevin Wolf, 2020/11/12
- [PATCH 09/13] qemu-storage-daemon: QAPIfy --chardev, Kevin Wolf, 2020/11/12
- [PATCH 10/13] char: Implement qemu_chr_new_from_opts() in terms of QAPI, Kevin Wolf, 2020/11/12
- [PATCH 11/13] hmp/char: Use qemu_chr_parse_cli_str() for chardev-change, Kevin Wolf, 2020/11/12