[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/13] char: Add mux option to ChardevOptions
From: |
Kevin Wolf |
Subject: |
[PATCH 08/13] char: Add mux option to ChardevOptions |
Date: |
Thu, 12 Nov 2020 18:59:00 +0100 |
The final missing piece to achieve compatibility between
qemu_chr_parse_cli_str()/qemu_chr_new_cli() and the legacy command line
is support for the 'mux' option. Implement it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi/char.json | 4 +++-
chardev/char.c | 41 +++++++++++++++++++++++++++++++++++------
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/qapi/char.json b/qapi/char.json
index e1f9347044..d6733a5473 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -453,12 +453,14 @@
#
# @id: the chardev's ID, must be unique
# @backend: backend type and parameters
+# @mux: enable multiplexing mode (default: false)
#
# Since: 6.0
##
{ 'struct': 'ChardevOptions',
'data': { 'id': 'str',
- 'backend': 'ChardevBackend' },
+ 'backend': 'ChardevBackend',
+ '*mux': 'bool' },
'aliases': [ { 'source': ['backend'] } ] }
##
diff --git a/chardev/char.c b/chardev/char.c
index a5d6be9dc8..3bb6a743f7 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -742,11 +742,6 @@ void qemu_chr_translate_legacy_options(QDict *args)
/* name may refer to a QDict entry, so delete it only now */
qdict_del(args, "backend");
-
- /*
- * TODO:
- * All backend types: "mux"
- */
}
Chardev *qemu_chr_new_noreplay(const char *label, const char *filename,
@@ -1105,7 +1100,41 @@ ChardevReturn *qmp_chardev_add(const char *id,
ChardevBackend *backend,
Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp)
{
- return chardev_new_qapi(options->id, options->backend, errp);
+ Chardev *chr;
+ char *bid = NULL;
+
+ if (options->mux) {
+ bid = g_strdup_printf("%s-base", options->id);
+ }
+
+ chr = chardev_new_qapi(bid ?: options->id, options->backend, errp);
+ if (!chr) {
+ goto out;
+ }
+
+ if (options->mux) {
+ Chardev *mux;
+ ChardevMux mux_data = {
+ .chardev = bid,
+ };
+ ChardevBackend backend = {
+ .type = CHARDEV_BACKEND_KIND_MUX,
+ .u.mux.data = &mux_data,
+ };
+
+ mux = qemu_chardev_new(options->id, TYPE_CHARDEV_MUX, &backend, NULL,
+ errp);
+ if (mux == NULL) {
+ object_unparent(OBJECT(chr));
+ chr = NULL;
+ goto out;
+ }
+ chr = mux;
+ }
+
+out:
+ g_free(bid);
+ return chr;
}
ChardevOptions *qemu_chr_parse_cli_dict(QDict *args, bool help,
--
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, 2020/11/12
- [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 <=
- [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
- [PATCH 12/13] char: Remove qemu_chr_parse_opts(), Kevin Wolf, 2020/11/12
- [PATCH 13/13] char: Remove ChardevClass.parse, Kevin Wolf, 2020/11/12