char: QAPIfy the command line parsing
PATCH 1/13 char: Factor out qemu_chr_print_types()
In reply to Kevin WolfWe'll want to call the same from a non-QemuOpts code path.
--- include/chardev/char.h | 1 + chardev/char.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-)
include/chardev/char.h +1 -0
@@ -212,6 +212,7 @@ void qemu_chr_be_update_read_handlers(Chardev *s,*/ void qemu_chr_be_event (Chardev *s,QEMUChrEvent event); +void qemu_chr_print_types (void );int qemu_chr_add_client (Chardev *s,int fd);Chardev *qemu_chr_find (const char *name);
chardev/char.c +10 -6
@@ -644,6 +644,15 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)return backend; } +void qemu_chr_print_types (void ) +{ +g_autoptr (GString) str =g_string_new ("" ); + +chardev_name_foreach (help_string_append, str); + +qemu_printf ("Available chardev backend types: %s\n" , str->str); +} +Chardev *qemu_chr_new_from_opts (QemuOpts *opts,GMainContext *context,Error **errp) {
@@ -655,12 +664,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, GMainContext *context,char *bid =NULL ;if (name &&is_help_option (name)) { -GString *str =g_string_new ("" ); - -chardev_name_foreach (help_string_append, str); - -qemu_printf ("Available chardev backend types: %s\n" , str->str); -g_string_free (str, true); +qemu_chr_print_types ();return NULL ; }
Signature · 1 line
2.28.0
cover char: QAPIfy the command line parsing
The character device subsystem is special in that it uses QAPI objects (ChardevBackend) internally to configure the backends, but for mapping the command line to it, instead of making use of QAPI visitors, it uses a hand-crafted parser. At the same time, the QMP command chardev-add obviously does use the QAPI parser.
This is nasty because there is nothing that will make sure that the two parsers provide access to the same feature set or that the syntax to access features is consistent. We have also seen patches that changed things for one path, but forgot that the other one needed to be changed, too, resulting in regressions.
In order to solve this problem and make consistency between both paths automatic, this series removes the hand-crafted parser that goes from QemuOpts to ChardevBackend. Instead, QAPI aliases and only a few manual tweaks of the input are used to make a keyval parser and QAPI visitors suitable for parsing command lines while retaining backwards compatibility.
As a welcome side effect, this also makes features available on the command line that were previously restricted to QMP.
Another welcome side effect is the diffstat. :-)
QemuOpts is not entirely removed from the chardev interfaces yet. This is mostly because -readconfig still uses it and changing vl.c to work with a mix of QAPI object and QemuOpts would be harder than just keeping some QemuOpts based interfaces that just internally translate. This can be addressed after -readconfig has been reworked (probably resulting in another nice diffstat).
A git tag is available that contains this series and its prerequisites:
https://repo.or.cz/qemu/kevin.git qapi-alias-chardev-v1
Based-on: [email protected]
('[PATCH 0/2] char: Deprecate backend aliases')
Based-on: [email protected] ('[PATCH 0/6] qapi: Add support for aliases')
Kevin Wolf (13):
char: Factor out qemu_chr_print_types()
char: Add ChardevOptions and qemu_chr_new_cli()
char: Some QAPI aliases for CLI compatibility
char: Add qemu_chr_translate_legacy_options()
char-socket: Implement compat code for CLI QAPIfication
char-udp: Implement compat code for CLI QAPIfication
char: Add qemu_chr_parse_cli_dict/str()
char: Add mux option to ChardevOptions
qemu-storage-daemon: QAPIfy --chardev
char: Implement qemu_chr_new_from_opts() in terms of QAPI hmp/char: Use qemu_chr_parse_cli_str() for chardev-change
char: Remove qemu_chr_parse_opts()
char: Remove ChardevClass.parse
qapi/char.json | 42 ++++- qapi/sockets.json | 6 +- include/chardev/char.h | 56 ++++-- chardev/char-file.c | 20 -- chardev/char-mux.c | 17 -- chardev/char-parallel.c | 17 -- chardev/char-pipe.c | 17 -- chardev/char-ringbuf.c | 18 -- chardev/char-serial.c | 17 -- chardev/char-socket.c | 121 +++++-------- chardev/char-stdio.c | 13 -- chardev/char-udp.c | 79 +++----- chardev/char.c | 262 ++++++++++++++++----------- chardev/spice.c | 34 ---- monitor/hmp-cmds.c | 27 +-- storage-daemon/qemu-storage-daemon.c | 17 +- ui/console.c | 35 ---- ui/gtk.c | 1 - ui/spice-app.c | 1 - 19 files changed, 321 insertions(+), 479 deletions(-)
Signature · 1 line
2.28.0
PATCH 3/13 char: Some QAPI aliases for CLI compatibility
For all chardev backend types where this is enough to achieve compatibility with the old QemuOpts based command line parser, add aliases to the QAPI schema.
--- qapi/char.json | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
qapi/char.json +10 -5
@@ -227,7 +227,8 @@ 'data': { '*in': 'str', 'out': 'str', '*append': 'bool' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'aliases': [ {'alias': 'path', 'source': ['out'] } ] } ## # @ChardevHostdev:
@@ -241,7 +242,8 @@ ## { 'struct': 'ChardevHostdev', 'data': { 'device': 'str' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'aliases': [ {'alias': 'path', 'source': ['device'] } ] } ## # @ChardevSocket:
@@ -342,7 +344,8 @@ { 'struct': 'ChardevSpiceChannel', 'data': { 'type': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'defined(CONFIG_SPICE)', + 'aliases': [ {'alias': 'name', 'source': ['type'] } ] } ## # @ChardevSpicePort:
@@ -356,7 +359,8 @@ { 'struct': 'ChardevSpicePort', 'data': { 'fqdn': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'defined(CONFIG_SPICE)', + 'aliases': [ {'alias': 'name', 'source': ['fqdn'] } ] } ## # @ChardevVC:
@@ -420,7 +424,8 @@ 'vc': 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility - 'memory': 'ChardevRingbuf' } } + 'memory': 'ChardevRingbuf' }, + 'aliases': [ { 'source': ['data'] } ] } ## # @ChardevReturn:
Signature · 1 line
2.28.0
PATCH 2/13 char: Add ChardevOptions and qemu_chr_new_cli()
In reply to Kevin WolfThis 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.
--- qapi/char.json | 15 +++++++++++++++ include/chardev/char.h | 9 +++++++++ chardev/char.c | 24 ++++++++++++++++++------ 3 files changed, 42 insertions(+), 6 deletions(-)
qapi/char.json +15 -0
@@ -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: #
include/chardev/char.h +9 -0
@@ -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
chardev/char.c +18 -6
@@ -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) {
Signature · 1 line
2.28.0
PATCH 6/13 char-udp: Implement compat code for CLI QAPIfication
In reply to Kevin WolfUDP 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.
--- qapi/char.json | 7 ++++++- chardev/char-udp.c | 33 +++++++++++++++++++++++++++++++++ chardev/char.c | 1 - 3 files changed, 39 insertions(+), 2 deletions(-)
qapi/char.json +6 -1
@@ -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:
chardev/char-udp.c +33 -0
@@ -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;
chardev/char.c +0 -1
@@ -744,7 +744,6 @@ void qemu_chr_translate_legacy_options(QDict *args)/* * TODO: * All backend types: "mux" -* udp: defaults for "host"/"localaddr"/"localport" */ }
Signature · 1 line
2.28.0
PATCH 4/13 char: Add qemu_chr_translate_legacy_options()
In reply to Kevin WolfThis 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().
--- include/chardev/char.h | 13 +++++++++++++ chardev/char.c | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/chardev/char.h +13 -0
@@ -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
chardev/char.c +23 -0
@@ -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) {
Signature · 1 line
2.28.0
PATCH 7/13 char: Add qemu_chr_parse_cli_dict/str()
In reply to Kevin WolfThis adds a function that parses a command line definition of a character device into ChardevOptions, which can then be passed to qemu_chr_new_cli().
You can start both from a string (for actual CLI) or from a QDict, which is not only the intermediate representation after calling the keyval parser, but also what HMP handlers receive.
--- include/chardev/char.h | 30 ++++++++++++++++++++++++++++ chardev/char.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/chardev/char.h +30 -0
@@ -94,6 +94,36 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,*/ Chardev *qemu_chr_new_cli (ChardevOptions *options,Error **errp); +/** +* qemu_chr_parse_cli_dict: +* @args: Options defining a new character device +* @help: true if help should be printed instead of returning ChardevOptions +* +* Parses the given command line option QDict into ChardevOptions, using +* qemu_chr_translate_legacy_options() to maintain compatibility with +* legacy command line syntax. +* +* Returns: On successful conversion, a ChardevOptions object containing the +* requested options. NULL and @errp is unchanged if help was requested and +* printed. NULL and @errp is set in error cases. +*/ +ChardevOptions *qemu_chr_parse_cli_dict (QDict *args,bool help, +Error **errp); + +/** +* qemu_chr_parse_cli_str: +* @optarg: Command line argument defining a new character device +* +* Parses the given command line option into ChardevOptions, using +* qemu_chr_translate_legacy_options() to maintain compatibility with +* legacy command line syntax. +* +* Returns: On successful conversion, a ChardevOptions object containing the +* requested options. NULL and @errp is unchanged if help was requested and +* printed. NULL and @errp is set in error cases. +*/ +ChardevOptions *qemu_chr_parse_cli_str (const char *optarg,Error **errp); +/** * qemu_chr_translate_legacy_options: * @args: Character device creation options as returned by the keyval parser
chardev/char.c +45 -0
59 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 5/13 char-socket: Implement compat code for CLI QAPIfication
In reply to Kevin WolfSocket 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.
--- qapi/char.json | 3 ++- qapi/sockets.json | 6 ++++- include/chardev/char.h | 1 + chardev/char-socket.c | 53 ++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 10 +++++++- 5 files changed, 70 insertions(+), 3 deletions(-)
qapi/char.json +2 -1
@@ -287,7 +287,8 @@ '*tn3270': 'bool', '*websocket': 'bool', '*reconnect': 'int' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'aliases': [ { 'source': ['addr'] } ] } ## # @ChardevUdp:
qapi/sockets.json +5 -1
@@ -125,7 +125,11 @@ 'inet': 'InetSocketAddress', 'unix': 'UnixSocketAddress', 'vsock': 'VsockSocketAddress', - 'fd': 'String' } } + 'fd': 'String' }, + 'aliases': [ + {'source': ['data']}, + {'alias': 'fd', 'source': ['data', 'str']} + ]} ## # @SocketAddressType:
include/chardev/char.h +1 -0
@@ -275,6 +275,7 @@ struct ChardevClass {bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +void (*translate_legacy_options)(QDict *args);void (*open)(Chardev *chr,ChardevBackend *backend,bool *be_opened,Error **errp);
chardev/char-socket.c +53 -0
71 lines not on this page · raw message
chardev/char.c +9 -1
@@ -720,6 +720,7 @@ out:void qemu_chr_translate_legacy_options (QDict *args) { +const ChardevClass *cc;const char *name;/* "backend" instead of "type" enables legacy CLI compatibility */
@@ -730,12 +731,19 @@ void qemu_chr_translate_legacy_options(QDict *args) name =chardev_alias_translate (name);qdict_put_str (args,"type" , name); + + cc =char_get_class (name,NULL ); +if (cc !=NULL && cc->translate_legacy_options) { +QDict *backend_data =qdict_get_qdict (args,"data" ) ?: args; + cc->translate_legacy_options (backend_data); + } + +/* name may refer to a QDict entry, so delete it only now */ qdict_del (args,"backend" );/* * TODO: * All backend types: "mux" -* socket: "addr.type", "delay", "server", "wait", "fd" * udp: defaults for "host"/"localaddr"/"localport" */ }
Signature · 1 line
2.28.0
PATCH 8/13 char: Add mux option to ChardevOptions
In reply to Kevin WolfThe 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.
--- qapi/char.json | 4 +++- chardev/char.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 7 deletions(-)
qapi/char.json +3 -1
@@ -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'] } ] } ##
chardev/char.c +35 -6
53 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 10/13 char: Implement qemu_chr_new_from_opts() in terms of QAPI
In reply to Kevin WolfInstead of having a second parser, qemu_chr_new_from_opts() uses qemu_chr_translate_legacy_options() and qemu_chr_new_cli() now.
This switches -chardev of the system emulator to use the QAPI generated parser rather than the hand-written QemuOpts based parser. All existing command line options should keep working, but it gains support for anything that was previously only supported in QMP (e.g. vsock socket addresses).
--- chardev/char.c | 116 +++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 71 deletions(-)
chardev/char.c +45 -71
@@ -656,70 +656,6 @@ void qemu_chr_print_types(void)qemu_printf ("Available chardev backend types: %s\n" , str->str); } -Chardev *qemu_chr_new_from_opts (QemuOpts *opts,GMainContext *context, -Error **errp) -{ -const ChardevClass *cc; -Chardev *chr =NULL ; -ChardevBackend *backend =NULL ; -const char *name =chardev_alias_translate (qemu_opt_get (opts,"backend" )); -const char *id =qemu_opts_id (opts); -char *bid =NULL ; - -if (name &&is_help_option (name)) { -qemu_chr_print_types (); -return NULL ; - } - -if (id ==NULL ) { -error_setg (errp,"chardev: no id specified" ); -return NULL ; - } - - backend =qemu_chr_parse_opts (opts, errp); -if (backend ==NULL ) { -return NULL ; - } - - cc =char_get_class (name, errp); -if (cc ==NULL ) { - goto out; - } - -if (qemu_opt_get_bool (opts,"mux" ,0 )) { - bid =g_strdup_printf ("%s-base" , id); - } - - chr =qemu_chardev_new (bid ? bid : id, -object_class_get_name (OBJECT_CLASS (cc)), - backend, context, errp); - -if (chr ==NULL ) { - goto out; - } - -if (bid) { -Chardev *mux; -qapi_free_ChardevBackend (backend); - backend =g_new0 (ChardevBackend,1 ); - backend->type =CHARDEV_BACKEND_KIND_MUX ; - backend->u.mux.data =g_new0 (ChardevMux,1 ); - backend->u.mux.data->chardev =g_strdup (bid); - mux =qemu_chardev_new (id,TYPE_CHARDEV_MUX , backend, context, errp); -if (mux ==NULL ) { -object_unparent (OBJECT (chr)); - chr =NULL ; - goto out; - } - chr = mux; - } - -out: -qapi_free_ChardevBackend (backend); -g_free (bid); -return chr; -} -void qemu_chr_translate_legacy_options (QDict *args) {const ChardevClass *cc;
@@ -1065,7 +1001,7 @@ Chardev *qemu_chardev_new(const char *id, const char *typename, }static Chardev *chardev_new_qapi (const char *id,ChardevBackend *backend, -Error **errp) +GMainContext *context,Error **errp) {const ChardevClass *cc;
@@ -1075,7 +1011,7 @@ static Chardev *chardev_new_qapi(const char *id, ChardevBackend *backend, }return chardev_new (id,object_class_get_name (OBJECT_CLASS (cc)), - backend,NULL , errp); + backend, context, errp); } ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
@@ -1084,7 +1020,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,ChardevReturn *ret;Chardev *chr; - chr =chardev_new_qapi (id, backend, errp); + chr =chardev_new_qapi (id, backend,NULL , errp);if (!chr) {return NULL ; }
@@ -1098,7 +1034,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,return ret; } -Chardev *qemu_chr_new_cli (ChardevOptions *options,Error **errp) +static Chardev *qemu_chr_new_cli_gcontext (ChardevOptions *options, +GMainContext *context, +Error **errp) {Chardev *chr;char *bid =NULL ;
@@ -1107,7 +1045,7 @@ Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp) bid =g_strdup_printf ("%s-base" , options->id); } - chr =chardev_new_qapi (bid ?: options->id, options->backend, errp); + chr =chardev_new_qapi (bid ?: options->id, options->backend, context, errp);if (!chr) { goto out; }
@@ -1122,8 +1060,8 @@ Chardev *qemu_chr_new_cli(ChardevOptions *options, Error **errp) .u.mux.data = &mux_data, }; - mux =qemu_chardev_new (options->id,TYPE_CHARDEV_MUX , &backend,NULL , - errp); + mux =qemu_chardev_new (options->id,TYPE_CHARDEV_MUX , &backend, + context, errp);if (mux ==NULL ) {object_unparent (OBJECT (chr)); chr =NULL ;
@@ -1137,6 +1075,11 @@ out:return chr; } +Chardev *qemu_chr_new_cli (ChardevOptions *options,Error **errp) +{ +return qemu_chr_new_cli_gcontext (options,NULL , errp); +} +ChardevOptions *qemu_chr_parse_cli_dict (QDict *args,bool help,Error **errp) {
@@ -1180,6 +1123,37 @@ ChardevOptions *qemu_chr_parse_cli_str(const char *optarg, Error **errp)return chr_options; } +Chardev *qemu_chr_new_from_opts (QemuOpts *opts,GMainContext *context, +Error **errp) +{ +ChardevOptions *chr_options; +Chardev *chr; +QDict *args; +const char *name =qemu_opt_get (opts,"backend" ); +bool help; + + args =qemu_opts_to_qdict (opts,NULL ); + +if (name &&is_help_option (name)) { +qdict_del (args,"backend" ); +qdict_del (args,"type" ); + help = true; + }else { + help =qemu_opt_has_help_opt (opts); + } + + chr_options =qemu_chr_parse_cli_dict (args, help, errp); +qobject_unref (args); + +if (!chr_options) { +return NULL ; + } + + chr =qemu_chr_new_cli_gcontext (chr_options, context, errp); +qapi_free_ChardevOptions (chr_options); +return chr; +} +ChardevReturn *qmp_chardev_change (const char *id,ChardevBackend *backend,Error **errp) {
Signature · 1 line
2.28.0
PATCH 9/13 qemu-storage-daemon: QAPIfy --chardev
In reply to Kevin WolfMake use of the QAPIfied command line interface of the chardev subsystem. With this, --chardev supports QMP-like syntax (i.e. chardev-add mapped to the command line) as well as the legacy syntax that it already supported and which is shared with the system emulator.
--- storage-daemon/qemu-storage-daemon.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
storage-daemon/qemu-storage-daemon.c +6 -11
@@ -128,8 +128,6 @@ enum { OPTION_OBJECT, }; -extern QemuOptsList qemu_chardev_opts; -static QemuOptsList qemu_object_opts = { .name ="object" , .implied_opt_name ="qom-type" ,
@@ -207,18 +205,15 @@ static void process_options(int argc, char *argv[]) }case OPTION_CHARDEV : { -/* TODO This interface is not stable until we QAPIfy it */ -QemuOpts *opts =qemu_opts_parse_noisily (&qemu_chardev_opts, - optarg, true); -if (opts ==NULL ) { -exit (EXIT_FAILURE ); - } +ChardevOptions *options; -if (!qemu_chr_new_from_opts (opts,NULL , &error_fatal)) { -/* No error, but NULL returned means help was printed */ + options =qemu_chr_parse_cli_str (optarg, &error_fatal); +if (!options) { +/* Help was printed */ exit (EXIT_SUCCESS ); } -qemu_opts_del (opts); +qemu_chr_new_cli (options, &error_fatal); +qapi_free_ChardevOptions (options);break ; }case OPTION_EXPORT :
Signature · 1 line
2.28.0
PATCH 11/13 hmp/char: Use qemu_chr_parse_cli_str() for chardev-change
In reply to Kevin WolfInstead of going through the QemuOpts-based parser, go directly from the given option string to ChardevOptions. This doesn't only avoid legacy code, but it also simplifies the implementation.
--- monitor/hmp-cmds.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)
monitor/hmp-cmds.c +9 -18
@@ -1793,34 +1793,25 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict)void hmp_chardev_change (Monitor *mon,const QDict *qdict) {const char *args =qdict_get_str (qdict,"args" ); -const char *id; +const char *id =qdict_get_str (qdict,"id" ); +char *optstr;Error *err =NULL ; -ChardevBackend *backend =NULL ; +ChardevOptions *options =NULL ;ChardevReturn *ret =NULL ; -QemuOpts *opts =qemu_opts_parse_noisily (qemu_find_opts ("chardev" ), args, - true); -if (!opts) { -error_setg (&err,"Parsing chardev args failed" ); - goto end; - } - id =qdict_get_str (qdict,"id" ); -if (qemu_opts_id (opts)) { -error_setg (&err,"Unexpected 'id' parameter" ); - goto end; - } + optstr =g_strdup_printf ("%s,id=%s" , args, id); - backend =qemu_chr_parse_opts (opts, &err); -if (!backend) { + options =qemu_chr_parse_cli_str (optstr, &err); +if (!options) { goto end; } - ret =qmp_chardev_change (id, backend, &err); + ret =qmp_chardev_change (options->id, options->backend, &err); end: +g_free (optstr);qapi_free_ChardevReturn (ret); -qapi_free_ChardevBackend (backend); -qemu_opts_del (opts); +qapi_free_ChardevOptions (options);hmp_handle_error (mon, err); }
Signature · 1 line
2.28.0
PATCH 13/13 char: Remove ChardevClass.parse
In reply to Kevin WolfThe QemuOpts based ChardevClass.parse has been replaced by the QAPI parser and is unused now, remove it.
After removing all .parse implementations, qemu_chr_parse_common() is unused, too, so remove that one as well.
--- include/chardev/char.h | 10 ----- chardev/char-file.c | 20 --------- chardev/char-mux.c | 17 -------- chardev/char-parallel.c | 17 -------- chardev/char-pipe.c | 17 -------- chardev/char-ringbuf.c | 18 -------- chardev/char-serial.c | 17 -------- chardev/char-socket.c | 92 ----------------------------------------- chardev/char-stdio.c | 13 ------ chardev/char-udp.c | 60 --------------------------- chardev/char.c | 11 ----- chardev/spice.c | 34 --------------- ui/console.c | 35 ---------------- ui/gtk.c | 1 - ui/spice-app.c | 1 - 15 files changed, 363 deletions(-)
include/chardev/char.h +0 -10
@@ -137,15 +137,6 @@ ChardevOptions *qemu_chr_parse_cli_str(const char *optarg, Error **errp);*/ void qemu_chr_translate_legacy_options (QDict *args); -/** -* qemu_chr_parse_common: -* @opts: the options that still need parsing -* @backend: a new backend -* -* Parse the common options available to all character backends. -*/ -void qemu_chr_parse_common (QemuOpts *opts,ChardevCommon *backend); -/** * qemu_chr_new: * @label: the name of the backend
@@ -294,7 +285,6 @@ struct ChardevClass {ObjectClass parent_class;bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ -void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp);void (*translate_legacy_options)(QDict *args); void (*open)(Chardev *chr, ChardevBackend *backend,
chardev/char-file.c +0 -20
@@ -96,30 +96,10 @@ static void qmp_chardev_open_file(Chardev *chr,#endif } -static void qemu_chr_parse_file_out (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *path =qemu_opt_get (opts,"path" ); -ChardevFile *file; - - backend->type =CHARDEV_BACKEND_KIND_FILE ; -if (path ==NULL ) { -error_setg (errp,"chardev: file: no filename given" ); -return ; - } - file = backend->u.file.data =g_new0 (ChardevFile,1 ); -qemu_chr_parse_common (opts,qapi_ChardevFile_base (file)); - file->out =g_strdup (path); - - file->has_append = true; - file->append =qemu_opt_get_bool (opts,"append" , false); -} -static void char_file_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_file_out; cc->open = qmp_chardev_open_file; }
chardev/char-mux.c +0 -17
@@ -332,22 +332,6 @@ static void qemu_chr_open_mux(Chardev *chr,qemu_chr_fe_init (&d->chr, drv, errp); } -static void qemu_chr_parse_mux (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *chardev =qemu_opt_get (opts,"chardev" ); -ChardevMux *mux; - -if (chardev ==NULL ) { -error_setg (errp,"chardev: mux: no chardev given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_MUX ; - mux = backend->u.mux.data =g_new0 (ChardevMux,1 ); -qemu_chr_parse_common (opts,qapi_ChardevMux_base (mux)); - mux->chardev =g_strdup (chardev); -} -/** * Called after processing of default and command-line-specified * chardevs to deliver CHR_EVENT_OPENED events to any FEs attached
@@ -377,7 +361,6 @@ static void char_mux_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_mux; cc->open = qemu_chr_open_mux; cc->chr_write = mux_chr_write; cc->chr_accept_input = mux_chr_accept_input;
chardev/char-parallel.c +0 -17
@@ -254,27 +254,10 @@ static void qmp_chardev_open_parallel(Chardev *chr,qemu_chr_open_pp_fd (chr, fd, be_opened, errp); } -static void qemu_chr_parse_parallel (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *device =qemu_opt_get (opts,"path" ); -ChardevHostdev *parallel; - -if (device ==NULL ) { -error_setg (errp,"chardev: parallel: no device path given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_PARALLEL ; - parallel = backend->u.parallel.data =g_new0 (ChardevHostdev,1 ); -qemu_chr_parse_common (opts,qapi_ChardevHostdev_base (parallel)); - parallel->device =g_strdup (device); -} -static void char_parallel_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_parallel; cc->open = qmp_chardev_open_parallel;#if defined(__linux__) cc->chr_ioctl = pp_ioctl;
chardev/char-pipe.c +0 -17
@@ -154,27 +154,10 @@ static void qemu_chr_open_pipe(Chardev *chr,#endif /* !_WIN32 */ -static void qemu_chr_parse_pipe (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *device =qemu_opt_get (opts,"path" ); -ChardevHostdev *dev; - -if (device ==NULL ) { -error_setg (errp,"chardev: pipe: no device path given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_PIPE ; - dev = backend->u.pipe.data =g_new0 (ChardevHostdev,1 ); -qemu_chr_parse_common (opts,qapi_ChardevHostdev_base (dev)); - dev->device =g_strdup (device); -} -static void char_pipe_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_pipe; cc->open = qemu_chr_open_pipe; }
chardev/char-ringbuf.c +0 -18
@@ -206,28 +206,10 @@ char *qmp_ringbuf_read(const char *device, int64_t size,return data; } -static void qemu_chr_parse_ringbuf (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -int val; -ChardevRingbuf *ringbuf; - - backend->type =CHARDEV_BACKEND_KIND_RINGBUF ; - ringbuf = backend->u.ringbuf.data =g_new0 (ChardevRingbuf,1 ); -qemu_chr_parse_common (opts,qapi_ChardevRingbuf_base (ringbuf)); - - val =qemu_opt_get_size (opts,"size" ,0 ); -if (val !=0 ) { - ringbuf->has_size = true; - ringbuf->size = val; - } -} -static void char_ringbuf_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_ringbuf; cc->open = qemu_chr_open_ringbuf; cc->chr_write = ringbuf_chr_write; }
chardev/char-serial.c +0 -17
@@ -279,27 +279,10 @@ static void qmp_chardev_open_serial(Chardev *chr,#endif /* __linux__ || __sun__ */ #ifdef HAVE_CHARDEV_SERIAL -static void qemu_chr_parse_serial (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *device =qemu_opt_get (opts,"path" ); -ChardevHostdev *serial; - -if (device ==NULL ) { -error_setg (errp,"chardev: serial/tty: no device path given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_SERIAL ; - serial = backend->u.serial.data =g_new0 (ChardevHostdev,1 ); -qemu_chr_parse_common (opts,qapi_ChardevHostdev_base (serial)); - serial->device =g_strdup (device); -} -static void char_serial_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_serial; cc->open = qmp_chardev_open_serial;#ifndef _WIN32 cc->chr_ioctl = tty_serial_ioctl;
chardev/char-socket.c +0 -92
104 lines not on this page · raw message
chardev/char-stdio.c +0 -13
@@ -117,23 +117,10 @@ static void qemu_chr_open_stdio(Chardev *chr, }#endif -static void qemu_chr_parse_stdio (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -ChardevStdio *stdio; - - backend->type =CHARDEV_BACKEND_KIND_STDIO ; - stdio = backend->u.stdio.data =g_new0 (ChardevStdio,1 ); -qemu_chr_parse_common (opts,qapi_ChardevStdio_base (stdio)); - stdio->has_signal = true; - stdio->signal =qemu_opt_get_bool (opts,"signal" , true); -} -static void char_stdio_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_stdio;#ifndef _WIN32 cc->open = qemu_chr_open_stdio; cc->chr_set_echo = qemu_chr_set_echo_stdio;
chardev/char-udp.c +0 -60
72 lines not on this page · raw message
chardev/char.c +0 -11
@@ -497,17 +497,6 @@ fail:return NULL ; } -void qemu_chr_parse_common (QemuOpts *opts,ChardevCommon *backend) -{ -const char *logfile =qemu_opt_get (opts,"logfile" ); - - backend->has_logfile = logfile !=NULL ; - backend->logfile =g_strdup (logfile); - - backend->has_logappend = true; - backend->logappend =qemu_opt_get_bool (opts,"logappend" , false); -} -static const ChardevClass *char_get_class (const char *driver,Error **errp) {ObjectClass *oc;
chardev/spice.c +0 -34
@@ -317,38 +317,6 @@ static void qemu_chr_open_spice_port(Chardev *chr,vmc_register_interface (s); } -static void qemu_chr_parse_spice_vmc (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *name =qemu_opt_get (opts,"name" ); -ChardevSpiceChannel *spicevmc; - -if (name ==NULL ) { -error_setg (errp,"chardev: spice channel: no name given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_SPICEVMC ; - spicevmc = backend->u.spicevmc.data =g_new0 (ChardevSpiceChannel,1 ); -qemu_chr_parse_common (opts,qapi_ChardevSpiceChannel_base (spicevmc)); - spicevmc->type =g_strdup (name); -} - -static void qemu_chr_parse_spice_port (QemuOpts *opts,ChardevBackend *backend, -Error **errp) -{ -const char *name =qemu_opt_get (opts,"name" ); -ChardevSpicePort *spiceport; - -if (name ==NULL ) { -error_setg (errp,"chardev: spice port: no name given" ); -return ; - } - backend->type =CHARDEV_BACKEND_KIND_SPICEPORT ; - spiceport = backend->u.spiceport.data =g_new0 (ChardevSpicePort,1 ); -qemu_chr_parse_common (opts,qapi_ChardevSpicePort_base (spiceport)); - spiceport->fqdn =g_strdup (name); -} -static void char_spice_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc);
@@ -371,7 +339,6 @@ static void char_spicevmc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_spice_vmc; cc->open = qemu_chr_open_spice_vmc; cc->chr_set_fe_open = spice_vmc_set_fe_open; }
@@ -386,7 +353,6 @@ static void char_spiceport_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_spice_port; cc->open = qemu_chr_open_spice_port; cc->chr_set_fe_open = spice_port_set_fe_open; }
ui/console.c +0 -35
@@ -2386,40 +2386,6 @@ void qemu_display_help(void) } } -void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp) -{ -int val; -ChardevVC *vc; - - backend->type =CHARDEV_BACKEND_KIND_VC ; - vc = backend->u.vc.data =g_new0 (ChardevVC,1 ); -qemu_chr_parse_common (opts,qapi_ChardevVC_base (vc)); - - val =qemu_opt_get_number (opts,"width" ,0 ); -if (val !=0 ) { - vc->has_width = true; - vc->width = val; - } - - val =qemu_opt_get_number (opts,"height" ,0 ); -if (val !=0 ) { - vc->has_height = true; - vc->height = val; - } - - val =qemu_opt_get_number (opts,"cols" ,0 ); -if (val !=0 ) { - vc->has_cols = true; - vc->cols = val; - } - - val =qemu_opt_get_number (opts,"rows" ,0 ); -if (val !=0 ) { - vc->has_rows = true; - vc->rows = val; - } -} -static const TypeInfo qemu_console_info = { .name =TYPE_QEMU_CONSOLE , .parent =TYPE_OBJECT ,
@@ -2431,7 +2397,6 @@ static void char_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_vc; cc->open = vc_chr_open; cc->chr_write = vc_chr_write; cc->chr_set_echo = vc_chr_set_echo;
ui/gtk.c +0 -1
@@ -1738,7 +1738,6 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->parse = qemu_chr_parse_vc; cc->open = gd_vc_open; cc->chr_write = gd_vc_chr_write; cc->chr_set_echo = gd_vc_chr_set_echo;
ui/spice-app.c +0 -1
@@ -101,7 +101,6 @@ static void char_vc_class_init(ObjectClass *oc, void *data) vc->parent_open = cc->open; - cc->parse = qemu_chr_parse_vc; cc->open = vc_chr_open; cc->chr_set_echo = vc_chr_set_echo; }
Signature · 1 line
2.28.0
PATCH 12/13 char: Remove qemu_chr_parse_opts()
In reply to Kevin WolfThe function is unused now, remove it.
--- include/chardev/char.h | 10 ---------- chardev/char.c | 37 ------------------------------------- 2 files changed, 47 deletions(-)
include/chardev/char.h +0 -10
@@ -146,16 +146,6 @@ void qemu_chr_translate_legacy_options(QDict *args);*/ void qemu_chr_parse_common (QemuOpts *opts,ChardevCommon *backend); -/** -* qemu_chr_parse_opts: -* -* Parse the options to the ChardevBackend struct. -* -* Returns: a new backend or NULL on error -*/ -ChardevBackend *qemu_chr_parse_opts (QemuOpts *opts, -Error **errp); -/** * qemu_chr_new: * @label: the name of the backend
chardev/char.c +0 -37
@@ -610,43 +610,6 @@ static const char *chardev_alias_translate(const char *name)return name; } -ChardevBackend *qemu_chr_parse_opts (QemuOpts *opts,Error **errp) -{ -Error *local_err =NULL ; -const ChardevClass *cc; -ChardevBackend *backend =NULL ; -const char *name =chardev_alias_translate (qemu_opt_get (opts,"backend" )); - -if (name ==NULL ) { -error_setg (errp,"chardev: \"%s\" missing backend" , -qemu_opts_id (opts)); -return NULL ; - } - - cc =char_get_class (name, errp); -if (cc ==NULL ) { -return NULL ; - } - - backend =g_new0 (ChardevBackend,1 ); - backend->type =CHARDEV_BACKEND_KIND_NULL ; - -if (cc->parse) { - cc->parse (opts, backend, &local_err); -if (local_err) { -error_propagate (errp, local_err); -qapi_free_ChardevBackend (backend); -return NULL ; - } - }else { -ChardevCommon *ccom =g_new0 (ChardevCommon,1 ); -qemu_chr_parse_common (opts, ccom); - backend->u.null.data = ccom;/* Any ChardevCommon member would work */ - } - -return backend; -} -void qemu_chr_print_types (void ) {g_autoptr (GString) str =g_string_new ("" );
Signature · 1 line
2.28.0
Re: [PATCH 08/13] char: Add mux option to ChardevOptions
In reply to Kevin WolfQuoted 19 lines · Kevin Wolf
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<[email protected]>--- qapi/char.json | 4 +++- chardev/char.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 7 deletions(-)qapi/char.json +1
-0@@ -453,12 +453,14 @@ # # @id: the chardev's ID, must be unique # @backend: backend type and parameters +# @mux: enable multiplexing mode (default: false)
qapi/char.json line 465
Quoted 10 lines
qapi/char.json +2
-1# # Since: 6.0 ## { 'struct': 'ChardevOptions', 'data': { 'id': 'str', - 'backend': 'ChardevBackend' }, + 'backend': 'ChardevBackend', + '*mux': 'bool' }, 'aliases': [ { 'source': ['backend'] } ] }
I think this shows that -chardev and chardev-add are both kind of unrepairable. The right way to do a mux with a serial and monitor on top should be explicit:
stdio
↑
mux-controller
↑ ↑
mux mux
↑ ↑
serial monitor
-object chardev-stdio,id=stdio
-object chardev-mux-controller,id=mux,backend=stdio -object chardev-mux,id=serial-chardev,controller=mux -object chardev-mux,id=mon-chardev,controller=mux -serial chardev:serial-chardev
-monitor chardev:mon-chardev
Adding automagic "mux" creation to -chardev is wrong. I don't entirely object to the series since it's quite nice, but I see it as more of a cleanup than the final stage. It hinges on what Markus thinks of aliases, I guess.
Paolo
Re: [PATCH 08/13] char: Add mux option to ChardevOptions
Am 13.11.2020 um 12:50 hat Paolo Bonzini geschrieben:
Quoted 42 lines · Kevin Wolf
Quoted 18 lines
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<[email protected]>--- qapi/char.json | 4 +++- chardev/char.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 7 deletions(-)qapi/char.json +0
-0@@ -453,12 +453,14 @@ # # @id: the chardev's ID, must be unique # @backend: backend type and parametersqapi/char.json line 464
Quoted 10 lines
qapi/char.json +3
-1+# @mux: enable multiplexing mode (default: false) # # Since: 6.0 ## { 'struct': 'ChardevOptions', 'data': { 'id': 'str', - 'backend': 'ChardevBackend' }, + 'backend': 'ChardevBackend', + '*mux': 'bool' }, 'aliases': [ { 'source': ['backend'] } ] }I think this shows that -chardev and chardev-add are both kind of unrepairable. The right way to do a mux with a serial and monitor on top should be explicit:
stdio
↑
mux-controller
↑ ↑
mux mux
↑ ↑
serial monitor
Quoted 6 lines
-object chardev-stdio,id=stdio
-object chardev-mux-controller,id=mux,backend=stdio -object chardev-mux,id=serial-chardev,controller=mux -object chardev-mux,id=mon-chardev,controller=mux -serial chardev:serial-chardev
-monitor chardev:mon-chardev
I don't think these "mux" chardevs plugged to a "mux-controller" actually exist, at least today. You can directly plug serial and monitor to a mux chardev that sits on top of stdio.
This is the current syntax for explicitly configuring things:
-chardev stdio,id=stdio
-chardev mux,chardev=stdio,id=mux
-mon chardev=mux
-serial chardev:mux
And of course this is still possible after my series, and it is what management tools should be using.
Quoted 1 line
Adding automagic "mux" creation to -chardev is wrong.
I'm not really adding it, it's already there.
While the code is temporarily duplicated and it looks like an addition here, at the end of the series it's effectively just some preexisting code moved (and QAPIfied) from qemu_chr_new_from_opts().
Of course, we can deprecate it, but I don't think it's really in the way because it just desugars to two normal chardev definitions. On the other hand, I've never used it (apart from testing this patch), so I don't really care in practice if it exists or not.
Quoted 3 lines
I don't entirely object to the series since it's quite nice, but I see it as more of a cleanup than the final stage. It hinges on what Markus thinks of aliases, I guess.
Yes, I completely agree that this is mostly a cleanup. Most QAPIfication actually is, because QemuOpts and hand written parsers do work and we have been successfully using them for years. They just work in less consistent ways and take a bit more code.
I never said it has to be the final stage, but I think whatever the final stage is, having external interfaces that are consistent and use the QAPI schema as the one source of truth will be helpful.
This is basically what I meant when I said your QOM conversion and my QAPIfication work aren't conflicting (conceptually), but addressing separate problems.
Kevin
Re: [PATCH 08/13] char: Add mux option to ChardevOptions
Quoted 9 lines · Kevin Wolf
Quoted 6 lines
-object chardev-stdio,id=stdio
-object chardev-mux-controller,id=mux,backend=stdio -object chardev-mux,id=serial-chardev,controller=mux -object chardev-mux,id=mon-chardev,controller=mux -serial chardev:serial-chardev
-monitor chardev:mon-chardevI don't think these "mux" chardevs plugged to a "mux-controller" actually exist, at least today. You can directly plug serial and monitor to a mux chardev that sits on top of stdio.
Yes, you're right. There's 2 CharBackends plugged into a single mux Chardev.
Quoted 3 lines
This is basically what I meant when I said your QOM conversion and my QAPIfication work aren't conflicting (conceptually), but addressing separate problems.
Fair enough, I think I understand what you mean now. And I can't really argue with the diffstat and the usage of aliases to clean up dash vs. underscores.
Paolo
Re: [PATCH 11/13] hmp/char: Use qemu_chr_parse_cli_str() for chardev-change
In reply to Kevin WolfQuoted 5 lines · * Kevin Wolf ([email protected]) wrote:
Instead of going through the QemuOpts-based parser, go directly from the given option string to ChardevOptions. This doesn't only avoid legacy code, but it also simplifies the implementation.
Signed-off-by Kevin Wolf <[email protected]>
OK, from HMP I think
I'm assuming there's no change in the escaping from you extracting it from the qdict and then printfing it back to go throguh the parser?
Dave
Quoted 55 lines
--- monitor/hmp-cmds.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)monitor/hmp-cmds.c +9
-18@@ -1793,34 +1793,25 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict)void hmp_chardev_change (Monitor *mon,const QDict *qdict) {const char *args =qdict_get_str (qdict,"args" ); -const char *id; +const char *id =qdict_get_str (qdict,"id" ); +char *optstr;Error *err =NULL ; -ChardevBackend *backend =NULL ; +ChardevOptions *options =NULL ;ChardevReturn *ret =NULL ; -QemuOpts *opts =qemu_opts_parse_noisily (qemu_find_opts ("chardev" ), args, - true); -if (!opts) { -error_setg (&err,"Parsing chardev args failed" ); - goto end; - } - id =qdict_get_str (qdict,"id" ); -if (qemu_opts_id (opts)) { -error_setg (&err,"Unexpected 'id' parameter" ); - goto end; - } + optstr =g_strdup_printf ("%s,id=%s" , args, id); - backend =qemu_chr_parse_opts (opts, &err); -if (!backend) { + options =qemu_chr_parse_cli_str (optstr, &err); +if (!options) { goto end; } - ret =qmp_chardev_change (id, backend, &err); + ret =qmp_chardev_change (options->id, options->backend, &err); end: +g_free (optstr);qapi_free_ChardevReturn (ret); -qapi_free_ChardevBackend (backend); -qemu_opts_del (opts); +qapi_free_ChardevOptions (options);hmp_handle_error (mon, err); }Signature · 1 line
2.28.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK