chardev hotplug patch series
v3 cover chardev hotplug patch series
Hi,
Next chardev hotplug round. Minor API tweak (s/delay/nodelay/ for ChardevSocket). More documentation improvements. Added sanity checks.
cheers,
Gerd
Gerd Hoffmann (10):
chardev: add error reporting for qemu_chr_new_from_opts
chardev: fix QemuOpts lifecycle
chardev: reduce chardev ifdef mess a bit
chardev: add qmp hotplug commands, with null chardev support
chardev: add hmp hotplug commands
chardev: add file chardev support to chardev-add (qmp)
chardev: add serial chardev support to chardev-add (qmp)
chardev: add parallel chardev support to chardev-add (qmp)
chardev: add socket chardev support to chardev-add (qmp)
chardev: add pty chardev support to chardev-add (qmp)
hmp-commands.hx | 32 ++++ hmp.c | 23 +++ hmp.h | 2 + include/char/char.h | 4 +- qapi-schema.json | 104 ++++++++++++ qemu-char.c | 464 +++++++++++++++++++++++++++++++++++++++------------ qemu-options.hx | 14 +- qmp-commands.hx | 61 +++++++ vl.c | 9 +- 9 files changed, 600 insertions(+), 113 deletions(-)
PATCH v3 1/10 chardev: add error reporting for qemu_chr_new_from_opts
--- include/char/char.h | 3 ++- qemu-char.c | 24 +++++++++++++++--------- vl.c | 9 ++++++--- 3 files changed, 23 insertions(+), 13 deletions(-)
include/char/char.h +2 -1
@@ -89,7 +89,8 @@ struct CharDriverState {* Returns: a new character backend */ CharDriverState *qemu_chr_new_from_opts (QemuOpts *opts, -void (*init)(struct CharDriverState *s)); +void (*init)(struct CharDriverState *s), +Error **errp);/** * @qemu_chr_new:
qemu-char.c +15 -9
@@ -2779,19 +2779,20 @@ static const struct { };CharDriverState *qemu_chr_new_from_opts (QemuOpts *opts, -void (*init)(struct CharDriverState *s)) +void (*init)(struct CharDriverState *s), +Error **errp) {CharDriverState *chr;int i;if (qemu_opts_id (opts) ==NULL ) { -fprintf (stderr,"chardev: no id specified\n" ); +error_setg (errp,"chardev: no id specified\n" );return NULL ; }if (qemu_opt_get (opts,"backend" ) ==NULL ) { -fprintf (stderr,"chardev: \"%s\" missing backend\n" , -qemu_opts_id (opts)); +error_setg (errp,"chardev: \"%s\" missing backend\n" , +qemu_opts_id (opts));return NULL ; }for (i =0 ; i <ARRAY_SIZE (backend_table); i++) {
@@ -2799,15 +2800,15 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,break ; }if (i ==ARRAY_SIZE (backend_table)) { -fprintf (stderr,"chardev: backend \"%s\" not found\n" , -qemu_opt_get (opts,"backend" )); +error_setg (errp,"chardev: backend \"%s\" not found\n" , +qemu_opt_get (opts,"backend" ));return NULL ; } chr = backend_table[i].open (opts);if (!chr) { -fprintf (stderr,"chardev: opening backend \"%s\" failed\n" , -qemu_opt_get (opts,"backend" )); +error_setg (errp,"chardev: opening backend \"%s\" failed\n" , +qemu_opt_get (opts,"backend" ));return NULL ; }
@@ -2837,6 +2838,7 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*inconst char *p;CharDriverState *chr;QemuOpts *opts; +Error *err =NULL ;if (strstart (filename,"chardev:" , &p)) {return qemu_chr_find (p);
@@ -2846,7 +2848,11 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*inif (!opts)return NULL ; - chr =qemu_chr_new_from_opts (opts, init); + chr =qemu_chr_new_from_opts (opts, init, &err); +if (error_is_set (&err)) { +fprintf (stderr,"%s\n" ,error_get_pretty (err)); +error_free (err); + }if (chr &&qemu_opt_get_bool (opts,"mux" ,0 )) {monitor_init (chr,MONITOR_USE_READLINE ); }
vl.c +6 -3
@@ -2052,11 +2052,14 @@ static int device_init_func(QemuOpts *opts, void *opaque)static int chardev_init_func (QemuOpts *opts,void *opaque) { -CharDriverState *chr; +Error *local_err =NULL ; - chr =qemu_chr_new_from_opts (opts,NULL ); -if (!chr) +qemu_chr_new_from_opts (opts,NULL , &local_err); +if (error_is_set (&local_err)) { +fprintf (stderr,"%s\n" ,error_get_pretty (local_err)); +error_free (local_err);return -1 ; + }return 0 ; }
Signature · 1 line
1.7.1
PATCH v3 2/10 chardev: fix QemuOpts lifecycle
In reply to Gerd Hoffmannqemu_chr_new_from_opts handles QemuOpts release now, so callers don't have to worry. It will either be saved in CharDriverState, then released in qemu_chr_delete, or in the error case released instantly.
--- include/char/char.h | 1 + qemu-char.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)
include/char/char.h +1 -0
@@ -75,6 +75,7 @@ struct CharDriverState {char *filename;int opened;int avail_connections; +QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; };
qemu-char.c +14 -6
@@ -2787,13 +2787,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (qemu_opts_id (opts) ==NULL ) {error_setg (errp,"chardev: no id specified\n" ); -return NULL ; + goto err; }if (qemu_opt_get (opts,"backend" ) ==NULL ) {error_setg (errp,"chardev: \"%s\" missing backend\n" ,qemu_opts_id (opts)); -return NULL ; + goto err; }for (i =0 ; i <ARRAY_SIZE (backend_table); i++) {if (strcmp (backend_table[i].name,qemu_opt_get (opts,"backend" )) ==0 )
@@ -2802,14 +2802,14 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (i ==ARRAY_SIZE (backend_table)) {error_setg (errp,"chardev: backend \"%s\" not found\n" ,qemu_opt_get (opts,"backend" )); -return NULL ; + goto err; } chr = backend_table[i].open (opts);if (!chr) {error_setg (errp,"chardev: opening backend \"%s\" failed\n" ,qemu_opt_get (opts,"backend" )); -return NULL ; + goto err; }if (!chr->filename)
@@ -2830,7 +2830,12 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, chr->avail_connections =1 ; } chr->label =g_strdup (qemu_opts_id (opts)); + chr->opts = opts;return chr; + +err: +qemu_opts_del (opts); +return NULL ; }CharDriverState *qemu_chr_new (const char *label,const char *filename,void (*init)(struct CharDriverState *s))
@@ -2856,7 +2861,6 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*inif (chr &&qemu_opt_get_bool (opts,"mux" ,0 )) {monitor_init (chr,MONITOR_USE_READLINE ); } -qemu_opts_del (opts);return chr; }
@@ -2884,10 +2888,14 @@ void qemu_chr_fe_close(struct CharDriverState *chr)void qemu_chr_delete (CharDriverState *chr) {QTAILQ_REMOVE (&chardevs, chr, next); -if (chr->chr_close) +if (chr->chr_close) { chr->chr_close (chr); + }g_free (chr->filename);g_free (chr->label); +if (chr->opts) { +qemu_opts_del (chr->opts); + }g_free (chr); }
Signature · 1 line
1.7.1
PATCH v3 3/10 chardev: reduce chardev ifdef mess a bit
In reply to Gerd Hoffmann--- qemu-char.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
qemu-char.c +11 -11
@@ -856,6 +856,8 @@ static void cfmakeraw (struct termios *termios_p) ||defined (__NetBSD__) ||defined (__OpenBSD__) ||defined (__DragonFly__) \ || defined(__GLIBC__) +#define HAVE_CHARDEV_TTY 1 + typedef struct { int fd; int connected;
@@ -1244,14 +1246,12 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts) chr->chr_close = qemu_chr_close_tty;return chr; } -#else /* ! __linux__ && ! __sun__ */ -static CharDriverState *qemu_chr_open_pty (QemuOpts *opts) -{ -return NULL ; -}#endif /* __linux__ || __sun__ */ #if defined(__linux__) + +#define HAVE_CHARDEV_PARPORT 1 + typedef struct { int fd; int mode;
@@ -1395,6 +1395,9 @@ static CharDriverState *qemu_chr_open_pp(QemuOpts *opts)#endif /* __linux__ */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) + +#define HAVE_CHARDEV_PARPORT 1 +static int pp_ioctl (CharDriverState *chr,int cmd,void *arg) {int fd = (int )(intptr_t )chr->opaque;
@@ -2755,19 +2758,16 @@ static const struct { #else { .name = "file", .open = qemu_chr_open_file_out }, { .name = "pipe", .open = qemu_chr_open_pipe }, - { .name = "pty", .open = qemu_chr_open_pty }, { .name = "stdio", .open = qemu_chr_open_stdio }, #endif #ifdef CONFIG_BRLAPI { .name = "braille", .open = chr_baum_init }, #endif -#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ - || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \ - || defined(__FreeBSD_kernel__) +#ifdef HAVE_CHARDEV_TTY { .name = "tty", .open = qemu_chr_open_tty }, + { .name = "pty", .open = qemu_chr_open_pty }, #endif -#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) \ - || defined(__FreeBSD_kernel__) +#ifdef HAVE_CHARDEV_PARPORT { .name = "parport", .open = qemu_chr_open_pp }, #endif #ifdef CONFIG_SPICE
Signature · 1 line
1.7.1
PATCH v3 4/10 chardev: add qmp hotplug commands, with null chardev support
In reply to Gerd HoffmannAdd chardev-add and chardev-remove qmp commands. Hotplugging a null chardev is supported for now, more will be added later.
--- qapi-schema.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 0 deletions(-)
qapi-schema.json +49 -0
@@ -3017,3 +3017,52 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-stop' } + +## +# @ChardevBackend: +# +# Configuration info for the new chardev backend. +# +# Since: 1.4 +## +{ 'type': 'ChardevDummy', 'data': { } } + +{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } + +## +# @ChardevReturn: +# +# Return info about the chardev backend just created. +# +# Since: 1.4 +## +{ 'type' : 'ChardevReturn', 'data': { } } + +## +# @chardev-add: +# +# Add a file chardev +# +# @id: the chardev's ID, must be unique +# @backend: backend type and parameters +# +# Returns: chardev info. +# +# Since: 1.4 +## +{ 'command': 'chardev-add', 'data': {'id' : 'str', + 'backend' : 'ChardevBackend' }, + 'returns': 'ChardevReturn' } + +## +# @chardev-remove: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.4 +## +{ 'command': 'chardev-remove', 'data': {'id': 'str'} }
qemu-char.c +52 -0
55 lines not on this page · raw message
qmp-commands.hx +50 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 5/10 chardev: add hmp hotplug commands
In reply to Gerd HoffmannAdd chardev-add and chardev-remove commands to the human monitor. chardev-add accepts the same syntax as -chardev, chardev-remove expects a chardev id.
--- hmp-commands.hx | 32 ++++++++++++++++++++++++++++++++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 2 ++ 3 files changed, 57 insertions(+), 0 deletions(-)
hmp-commands.hx +32 -0
@@ -1485,6 +1485,38 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev-add", + .args_type = "args:s", + .params = "args", + .help = "add chardev", + .mhandler.cmd = hmp_chardev_add, + }, + +STEXI +@item chardev_add args +@findex chardev_add + +chardev_add accepts the same parameters as the -chardev command line switch. + +ETEXI + + { + .name = "chardev-remove", + .args_type = "id:s", + .params = "id", + .help = "remove chardev", + .mhandler.cmd = hmp_chardev_remove, + }, + +STEXI +@item chardev_remove id +@findex chardev_remove + +Removes the chardev @var{id}. + +ETEXI + + { .name = "info", .args_type = "item:s?", .params = "[subcommand]",
hmp.c +23 -0
@@ -1336,3 +1336,26 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)qmp_nbd_server_stop (&errp);hmp_handle_error (mon, &errp); } + +void hmp_chardev_add (Monitor *mon,const QDict *qdict) +{ +const char *args =qdict_get_str (qdict,"args" ); +Error *err =NULL ; +QemuOpts *opts; + + opts =qemu_opts_parse (qemu_find_opts ("chardev" ), args,1 ); +if (opts ==NULL ) { +error_setg (&err,"Parsing chardev args failed\n" ); + }else { +qemu_chr_new_from_opts (opts,NULL , &err); + } +hmp_handle_error (mon, &err); +} + +void hmp_chardev_remove (Monitor *mon,const QDict *qdict) +{ +Error *local_err =NULL ; + +qmp_chardev_remove (qdict_get_str (qdict,"id" ), &local_err); +hmp_handle_error (mon, &local_err); +}
hmp.h +2 -0
@@ -80,5 +80,7 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict);void hmp_nbd_server_start (Monitor *mon,const QDict *qdict);void hmp_nbd_server_add (Monitor *mon,const QDict *qdict);void hmp_nbd_server_stop (Monitor *mon,const QDict *qdict); +void hmp_chardev_add (Monitor *mon,const QDict *qdict); +void hmp_chardev_remove (Monitor *mon,const QDict *qdict);#endif
Signature · 1 line
1.7.1
PATCH v3 6/10 chardev: add file chardev support to chardev-add (qmp)
In reply to Gerd HoffmannAdd support for file chardevs. Output file is mandatory, input file is optional.
--- qapi-schema.json | 16 +++++++++++++- qemu-char.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 8 ++++++- 3 files changed, 83 insertions(+), 2 deletions(-)
qapi-schema.json +15 -1
@@ -3019,6 +3019,19 @@ { 'command': 'nbd-server-stop' } ## +# @ChardevFile: +# +# Configuration info for file chardevs. +# +# @in: #optional The name of the input file +# @out: The name of the output file +# +# Since: 1.4 +## +{ 'type': 'ChardevFile', 'data': { '*in' : 'str', + 'out' : 'str' } } + +## # @ChardevBackend: # # Configuration info for the new chardev backend.
@@ -3027,7 +3040,8 @@ ## { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'null' : 'ChardevDummy' } } ## # @ChardevReturn:
qemu-char.c +61 -0
73 lines not on this page · raw message
qmp-commands.hx +7 -1
@@ -2672,13 +2672,19 @@ Arguments: - "id": the chardev's ID, must be unique (json-string) - "backend": chardev backend type + parameters -Example: +Examples: -> { "execute" : "chardev-add", "arguments" : { "id" : "foo", "backend" : { "type" : "null", "data" : {} } } } <- { "return": {} } +-> { "execute" : "chardev-add", + "arguments" : { "id" : "bar", + "backend" : { "type" : "file", + "data" : { "out" : "/tmp/bar.log" } } } } +<- { "return": {} } + EQMP {
Signature · 1 line
1.7.1
PATCH v3 7/10 chardev: add serial chardev support to chardev-add (qmp)
In reply to Gerd HoffmannSimilar to file, except that no separate in/out files are supported because it's pointless for direct device access. Also the special tty ioctl hooks (pass through linespeed settings etc) are activated on Unix.
--- qapi-schema.json | 17 ++++++++++++++ qemu-char.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++------- qemu-options.hx | 9 +++---- 3 files changed, 75 insertions(+), 13 deletions(-)
qapi-schema.json +17 -0
@@ -3032,6 +3032,22 @@ 'out' : 'str' } } ## +# @ChardevPort: +# +# Configuration info for device chardevs. +# +# @device: The name of the special file for the device, +# i.e. /dev/ttyS0 on Unix or COM1: on Windows +# @type: What kind of device this is. +# +# Since: 1.4 +## +{ 'enum': 'ChardevPortKind', 'data': [ 'serial' ] } + +{ 'type': 'ChardevPort', 'data': { 'device' : 'str', + 'type' : 'ChardevPortKind'} } + +## # @ChardevBackend: # # Configuration info for the new chardev backend.
@@ -3041,6 +3057,7 @@ { 'type': 'ChardevDummy', 'data': { } } { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', 'null' : 'ChardevDummy' } } ##
qemu-char.c +54 -8
114 lines not on this page · raw message
qemu-options.hx +4 -5
@@ -1742,6 +1742,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, #endif #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) + "-chardev serial,id=id,path=path[,mux=on|off]\n" "-chardev tty,id=id,path=path[,mux=on|off]\n" #endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
@@ -1910,8 +1911,8 @@ take any options. Send traffic from the guest to a serial device on the host. -@option{serial} is -only available on Windows hosts. +On Unix hosts serial will actually accept any tty device, +not only serial lines. @option{path} specifies the name of the serial device to open.
@@ -1937,10 +1938,8 @@ Connect to a local BrlAPI server. @option{braille} does not take any options. @item -chardev tty ,id=@var{id} ,path=@var{path} -Connect to a local tty device. - @option{tty} is only available on Linux, Sun, FreeBSD, NetBSD, OpenBSD and -DragonFlyBSD hosts. +DragonFlyBSD hosts. It is an alias for -serial. @option{path} specifies the path to the tty. @option{path} is required.
Signature · 1 line
1.7.1
PATCH v3 8/10 chardev: add parallel chardev support to chardev-add (qmp)
In reply to Gerd HoffmannAlso alias the old parport name to parallel for -chardev.
--- qapi-schema.json | 3 ++- qemu-char.c | 44 ++++++++++++++++++++++++++++---------------- qemu-options.hx | 5 ++++- 3 files changed, 34 insertions(+), 18 deletions(-)
qapi-schema.json +2 -1
@@ -3042,7 +3042,8 @@ # # Since: 1.4 ## -{ 'enum': 'ChardevPortKind', 'data': [ 'serial' ] } +{ 'enum': 'ChardevPortKind', 'data': [ 'serial', + 'parallel' ] } { 'type': 'ChardevPort', 'data': { 'device' : 'str', 'type' : 'ChardevPortKind'} }
qemu-char.c +28 -16
79 lines not on this page · raw message
qemu-options.hx +4 -1
@@ -1746,6 +1746,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev tty,id=id,path=path[,mux=on|off]\n" #endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) + "-chardev parallel,id=id,path=path[,mux=on|off]\n" "-chardev parport,id=id,path=path[,mux=on|off]\n" #endif #if defined(CONFIG_SPICE)
@@ -1776,6 +1777,7 @@ Backend is one of: @option{stdio}, @option{braille}, @option{tty}, +@option{parallel}, @option{parport}, @option{spicevmc}. @option{spiceport}.
@@ -1943,9 +1945,10 @@ DragonFlyBSD hosts. It is an alias for -serial. @option{path} specifies the path to the tty. @option{path} is required. +@item -chardev parallel ,id=@var{id} ,path=@var{path} @item -chardev parport ,id=@var{id} ,path=@var{path} -@option{parport} is only available on Linux, FreeBSD and DragonFlyBSD hosts. +@option{parallel} is only available on Linux, FreeBSD and DragonFlyBSD hosts. Connect to a local parallel port.
Signature · 1 line
1.7.1
PATCH v3 9/10 chardev: add socket chardev support to chardev-add (qmp)
In reply to Gerd Hoffmannqemu_chr_open_socket is splitted into two functions. All initialization after creating the socket file handler is splitted away into the new qemu_chr_open_socket_fd function.
chr->filename doesn't get filled from QemuOpts any more. Qemu gathers the information using getsockname and getnameinfo instead. This way it will also work correctly for file handles passed via file descriptor passing.
Finally qmp_chardev_open_socket() is the actual qmp hotplug implementation which basically just calls socket_listen or socket_connect and the new qemu_chr_open_socket_fd function.
--- qapi-schema.json | 28 ++++++++- qemu-char.c | 168 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 139 insertions(+), 57 deletions(-)
qapi-schema.json +25 -3
@@ -3049,6 +3049,27 @@ 'type' : 'ChardevPortKind'} } ## +# @ChardevSocket: +# +# Configuration info for socket chardevs. +# +# @addr: socket address to listen on (server=true) +# or connect to (server=false) +# @server: #optional create server socket (default: true) +# @wait: #optional wait for connect (not used for server +# sockets, default: false) +# @nodelay: #optional set TCP_NODELAY socket option (default: false) +# @telnet: #optional enable telnet protocol (default: false) +# +# Since: 1.4 +## +{ 'type': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', + '*server' : 'bool', + '*wait' : 'bool', + '*nodelay' : 'bool', + '*telnet' : 'bool' } } + +## # @ChardevBackend: # # Configuration info for the new chardev backend.
@@ -3057,9 +3078,10 @@ ## { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', - 'port' : 'ChardevPort', - 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', + 'socket' : 'ChardevSocket', + 'null' : 'ChardevDummy' } } ## # @ChardevReturn:
qemu-char.c +114 -54
210 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v3 09/10] chardev: add socket chardev support to chardev-add (qmp)
Quoted 2 lines · Gerd Hoffmann
qemu_chr_open_socketis splitted into two functions. All initialization after creating the socket file handler is splitted away into the new
You still haven't incorporated my fix of s/splitted/split/g that I raised against both v1 and v2.
qemu-char.c static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) · line 2539
Quoted 9 lines
qemu-char.c +1
-4@@ -2458,10 +2536,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)if (!is_listen) is_waitconnect =0 ; - chr =g_malloc0 (sizeof (CharDriverState)); - s =g_malloc0 (sizeof (TCPCharDriver)); - -if (is_unix) { +if (is_unix) {
And you still have a spurious mis-indentation here. What's going on?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v4 9/10 chardev: add socket chardev support to chardev-add (qmp)
qemu_chr_open_socket is split into two functions. All initialization after creating the socket file handler is split away into the new qemu_chr_open_socket_fd function.
chr->filename doesn't get filled from QemuOpts any more. Qemu gathers the information using getsockname and getnameinfo instead. This way it will also work correctly for file handles passed via file descriptor passing.
Finally qmp_chardev_open_socket() is the actual qmp hotplug implementation which basically just calls socket_listen or socket_connect and the new qemu_chr_open_socket_fd function.
--- qapi-schema.json | 28 ++++++++- qemu-char.c | 166 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 138 insertions(+), 56 deletions(-)
qapi-schema.json +25 -3
@@ -3049,6 +3049,27 @@ 'type' : 'ChardevPortKind'} } ## +# @ChardevSocket: +# +# Configuration info for socket chardevs. +# +# @addr: socket address to listen on (server=true) +# or connect to (server=false) +# @server: #optional create server socket (default: true) +# @wait: #optional wait for connect (not used for server +# sockets, default: false) +# @nodelay: #optional set TCP_NODELAY socket option (default: false) +# @telnet: #optional enable telnet protocol (default: false) +# +# Since: 1.4 +## +{ 'type': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', + '*server' : 'bool', + '*wait' : 'bool', + '*nodelay' : 'bool', + '*telnet' : 'bool' } } + +## # @ChardevBackend: # # Configuration info for the new chardev backend.
@@ -3057,9 +3078,10 @@ ## { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', - 'port' : 'ChardevPort', - 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', + 'socket' : 'ChardevSocket', + 'null' : 'ChardevDummy' } } ## # @ChardevReturn:
qemu-char.c +113 -53
208 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v4 9/10] chardev: add socket chardev support to chardev-add (qmp)
Quoted 13 lines · Gerd Hoffmann
qemu_chr_open_socketis split into two functions. All initialization after creating the socket file handler is split away into the newqemu_chr_open_socket_fdfunction.
chr->filenamedoesn't get filled from QemuOpts any more. Qemu gathers the information using getsockname and getnameinfo instead. This way it will also work correctly for file handles passed via file descriptor passing.Finally
qmp_chardev_open_socket()is the actual qmp hotplug implementation which basically just callssocket_listenorsocket_connectand the newqemu_chr_open_socket_fdfunction.
Quoted 5 lines
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 28 ++++++++- qemu-char.c | 166 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 138 insertions(+), 56 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v3 10/10 chardev: add pty chardev support to chardev-add (qmp)
In reply to Gerd HoffmannThe ptsname is returned directly, so there is no need to use query-chardev to figure the pty device path.
--- qapi-schema.json | 3 ++- qemu-char.c | 13 +++++++++++++ qmp-commands.hx | 5 +++++ 3 files changed, 20 insertions(+), 1 deletions(-)
qapi-schema.json +2 -1
@@ -3081,6 +3081,7 @@ { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', 'port' : 'ChardevPort', 'socket' : 'ChardevSocket', + 'pty' : 'ChardevDummy', 'null' : 'ChardevDummy' } } ##
@@ -3090,7 +3091,7 @@ # # Since: 1.4 ## -{ 'type' : 'ChardevReturn', 'data': { } } +{ 'type' : 'ChardevReturn', 'data': { '*pty' : 'str' } } ## # @chardev-add:
qemu-char.c +13 -0
@@ -3131,6 +3131,19 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,case CHARDEV_BACKEND_KIND_SOCKET : chr =qmp_chardev_open_socket (backend->socket, errp);break ; +#ifdef HAVE_CHARDEV_TTY +case CHARDEV_BACKEND_KIND_PTY : + { +/* qemu_chr_open_pty sets "path" in opts */ +QemuOpts *opts; + opts =qemu_opts_create_nofail (qemu_find_opts ("chardev" )); + chr =qemu_chr_open_pty (opts); + ret->pty =g_strdup (qemu_opt_get (opts,"path" )); + ret->has_pty = true; +qemu_opts_del (opts); +break ; + } +#endif case CHARDEV_BACKEND_KIND_NULL : chr =qemu_chr_open_null (NULL );break ;
qmp-commands.hx +5 -0
@@ -2685,6 +2685,11 @@ Examples: "data" : { "out" : "/tmp/bar.log" } } } } <- { "return": {} } +-> { "execute" : "chardev-add", + "arguments" : { "id" : "baz", + "backend" : { "type" : "pty", "data" : {} } } } +<- { "return": { "pty" : "/dev/pty/42" } } + EQMP {
Signature · 1 line
1.7.1
Quoted 4 lines · Gerd Hoffmann
Hi,
Next chardev hotplug round. Minor API tweak (s/delay/nodelay/ for ChardevSocket). More documentation improvements. Added sanity checks.
For 1-8 and 10,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org