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 02/13] char: Add ChardevOptions and qemu_chr_new_cli()
Date: Thu, 12 Nov 2020 18:58:54 +0100 [thread overview]
Message-ID: <20201112175905.404472-3-kwolf@redhat.com> (raw)
In-Reply-To: <20201112175905.404472-1-kwolf@redhat.com>
This provides an interface to create a chardev from a QAPI
representation of the command line.
At this point, the only difference between it and QMP chardev-add is
that it allows 'backend' to be flattened and returns a Chardev pointer.
We'll add support for mux=on and more compatibility glue to support
legacy command line syntax later.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi/char.json | 15 +++++++++++++++
include/chardev/char.h | 9 +++++++++
chardev/char.c | 24 ++++++++++++++++++------
3 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/qapi/char.json b/qapi/char.json
index 43486d1daa..14ee06a52d 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -435,6 +435,21 @@
{ 'struct' : 'ChardevReturn',
'data': { '*pty': 'str' } }
+##
+# @ChardevOptions:
+#
+# Command line options for creating a character device backend
+#
+# @id: the chardev's ID, must be unique
+# @backend: backend type and parameters
+#
+# Since: 6.0
+##
+{ 'struct': 'ChardevOptions',
+ 'data': { 'id': 'str',
+ 'backend': 'ChardevBackend' },
+ 'aliases': [ { 'source': ['backend'] } ] }
+
##
# @chardev-add:
#
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 3b91645081..54fa2ed8e2 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -85,6 +85,15 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
GMainContext *context,
Error **errp);
+/**
+ * qemu_chr_new_cli:
+ * @options: Character device creation options as defined in QAPI
+ *
+ * Returns: on success: a new character backend
+ * otherwise: NULL; @errp specifies the error
+ */
+Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp);
+
/**
* qemu_chr_parse_common:
* @opts: the options that still need parsing
diff --git a/chardev/char.c b/chardev/char.c
index de39e2d79b..9f00e475d4 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -1037,20 +1037,27 @@ Chardev *qemu_chardev_new(const char *id, const char *typename,
return chardev_new(id, typename, backend, gcontext, errp);
}
-ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
- Error **errp)
+static Chardev *chardev_new_qapi(const char *id, ChardevBackend *backend,
+ Error **errp)
{
const ChardevClass *cc;
- ChardevReturn *ret;
- Chardev *chr;
cc = char_get_class(ChardevBackendKind_str(backend->type), errp);
if (!cc) {
return NULL;
}
- chr = chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
- backend, NULL, errp);
+ return chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
+ backend, NULL, errp);
+}
+
+ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
+ Error **errp)
+{
+ ChardevReturn *ret;
+ Chardev *chr;
+
+ chr = chardev_new_qapi(id, backend, errp);
if (!chr) {
return NULL;
}
@@ -1064,6 +1071,11 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
return ret;
}
+Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp)
+{
+ return chardev_new_qapi(options->id, options->backend, errp);
+}
+
ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
Error **errp)
{
--
2.28.0
next prev parent reply other threads:[~2020-11-12 18:01 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 ` Kevin Wolf [this message]
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 ` [PATCH 06/13] char-udp: " Kevin Wolf
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-3-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).