chardev hotplug
cover chardev hotplug
Hi,
Chardev hotplug patch series reloaded. Not finished yet, commit messages not finalized yet, totally untested other than building on linux+windows.
I doubt I manage to finish (and test!) it before xmas. Nevertheless I wanna get the bits out of the door for you to see what is coming and for early reviews. It goes largely the route suggested by Paolo.
cheers,
Gerd
Gerd Hoffmann (9):
chardev: add error reporting for qemu_chr_new_from_opts
chardev: fix QemuOpts lifecycle
chardev: reduce chardev ifdef mess a bit
chardev: hotplug, qmp, null
chardev: hotplug, hmp
chardev: hotplug, qmp, file
chardev: hotplug, qmp, tty
chardev: hotplug, qmp, serial
chardev: hotplug, qmp, parallel
hmp-commands.hx | 32 ++++++ hmp.c | 23 +++++ hmp.h | 2 + qapi-schema.json | 47 +++++++++ qemu-char.c | 280 ++++++++++++++++++++++++++++++++++++++++++++--------- qemu-char.h | 4 +- qmp-commands.hx | 50 ++++++++++ vl.c | 9 +- 8 files changed, 395 insertions(+), 52 deletions(-)
PATCH 1/9 chardev: add error reporting for qemu_chr_new_from_opts
--- qemu-char.c | 24 +++++++++++++++--------- qemu-char.h | 3 ++- vl.c | 9 ++++++--- 3 files changed, 23 insertions(+), 13 deletions(-)
qemu-char.c +15 -9
@@ -2769,19 +2769,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++) {
@@ -2789,15 +2790,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 ; }
@@ -2827,6 +2828,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);
@@ -2836,7 +2838,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 ); }
qemu-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:
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 2/9 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.
--- qemu-char.c | 15 ++++++++++----- qemu-char.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-)
qemu-char.c +10 -5
@@ -2777,13 +2777,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 )
@@ -2792,14 +2792,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)
@@ -2820,7 +2820,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))
@@ -2846,7 +2851,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; }
@@ -2878,6 +2882,7 @@ void qemu_chr_delete(CharDriverState *chr) chr->chr_close (chr);g_free (chr->filename);g_free (chr->label); +qemu_opts_del (chr->opts);g_free (chr); }
qemu-char.h +1 -0
@@ -75,6 +75,7 @@ struct CharDriverState {char *filename;int opened;int avail_connections; +QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; };
Signature · 1 line
1.7.1
PATCH 3/9 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
@@ -853,6 +853,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;
@@ -1234,14 +1236,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;
@@ -1385,6 +1385,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;
@@ -2745,19 +2748,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
Re: [Qemu-devel] [PATCH 3/9] chardev: reduce chardev ifdef mess a bit
Quoted 10 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- qemu-char.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)qemu-char.c +0
-0
qemu-char.c static void cfmakeraw (struct termios *termios_p) · line 856
Quoted 4 lines
qemu-char.c +1
-0@@ -853,6 +853,8 @@ static void cfmakeraw (struct termios *termios_p) ||defined (__NetBSD__) ||defined (__OpenBSD__) ||defined (__DragonFly__) \ || defined(__GLIBC__) +#define HAVE_CHARDEV_TTY 1
Perhaps the next step should be configure generating these #defines.
Quoted 59 lines
qemu-char.c +10
-12+ typedef struct { int fd; int connected;@@ -1234,14 +1236,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;@@ -1385,6 +1385,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;@@ -2745,19 +2748,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 --1.7.1
PATCH 4/9 chardev: hotplug, qmp, null
In reply to Gerd Hoffmann--- qapi-schema.json | 32 ++++++++++++++++++++++++++++++++ qemu-char.c | 34 ++++++++++++++++++++++++++++++++++ qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 0 deletions(-)
qapi-schema.json +32 -0
@@ -3017,3 +3017,35 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-stop' } + +## +# @chardev-add: +# +# Add a file chardev +# +# @id: the chardev's ID, must be unique +# @backend: backend type and parameters +# +# Returns: Nothing on success +# +# Since: 1.4 +## +{ 'type': 'ChardevDummy', 'data': { } } + +{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } + +{ 'command': 'chardev-add', 'data': {'id' : 'str', + 'backend' : 'ChardevBackend' } } + +## +# @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 +34 -0
@@ -2925,3 +2925,37 @@ CharDriverState *qemu_char_get_next_serial(void)return serial_hds[next_serial++]; } +void qmp_chardev_add (const char *id,ChardevBackend *backend,Error **errp) +{ +CharDriverState *chr; + +switch (backend->kind) { +case CHARDEV_BACKEND_KIND_NULL : + chr =qemu_chr_open_null (NULL ); +break ; +default : +error_setg (errp,"unknown chardev backend (%d)" , backend->kind); +return ; + } + +if (chr ==NULL ) { +error_setg (errp,"Failed to create chardev" ); + } +} + +void qmp_chardev_remove (const char *id,Error **errp) +{ +CharDriverState *chr; + + chr =qemu_chr_find (id); +if (NULL == chr) { +error_setg (errp,"Chardev '%s' not found" , id); +return ; + } +if (chr->chr_can_read || chr->chr_read || + chr->chr_event || chr->handler_opaque) { +error_setg (errp,"Chardev '%s' is busy" , id); +return ; + } +qemu_chr_delete (chr); +}
qmp-commands.hx +50 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 5/9 chardev: hotplug, hmp
In reply to Gerd Hoffmann--- 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
@@ -1335,3 +1335,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 6/9 chardev: hotplug, qmp, file
In reply to Gerd Hoffmann--- qapi-schema.json | 9 +++++- qemu-char.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-)
qapi-schema.json +8 -1
@@ -3030,9 +3030,16 @@ # # Since: 1.4 ## +{ 'union': 'ChardevFileSource', 'data': { 'path' : 'str', + 'fd' : 'str' } } + +{ 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', + 'out' : 'ChardevFileSource' } } + { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'null' : 'ChardevDummy' } } { 'command': 'chardev-add', 'data': {'id' : 'str', 'backend' : 'ChardevBackend' } }
qemu-char.c +76 -1
94 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 7/9 chardev: hotplug, qmp, tty
In reply to Gerd Hoffmann--- qapi-schema.json | 6 ++++++ qemu-char.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-)
qapi-schema.json +6 -0
@@ -3036,9 +3036,15 @@ { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', 'out' : 'ChardevFileSource' } } +{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] } + +{ 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', + 'type' : 'ChardevPortKind'} } + { 'type': 'ChardevDummy', 'data': { } } { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', 'null' : 'ChardevDummy' } } { 'command': 'chardev-add', 'data': {'id' : 'str',
qemu-char.c +47 -6
92 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 8/9 chardev: hotplug, qmp, serial
In reply to Gerd Hoffmann--- qapi-schema.json | 3 ++- qemu-char.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-)
qapi-schema.json +2 -1
@@ -3036,7 +3036,8 @@ { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', 'out' : 'ChardevFileSource' } } -{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] } +{ 'enum': 'ChardevPortKind', 'data': [ 'tty', + 'serial' ] } { 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', 'type' : 'ChardevPortKind'} }
qemu-char.c +14 -2
@@ -1662,9 +1662,8 @@ static int win_chr_poll(void *opaque)return 0 ; } -static CharDriverState *qemu_chr_open_win (QemuOpts *opts) +static CharDriverState *qemu_chr_open_win_path (const char *filename) { -const char *filename =qemu_opt_get (opts,"path" );CharDriverState *chr;WinCharState *s;
@@ -1683,6 +1682,11 @@ static CharDriverState *qemu_chr_open_win(QemuOpts *opts)return chr; } +static CharDriverState *qemu_chr_open_win (QemuOpts *opts) +{ +return qemu_chr_open_win_path (qemu_opt_get (opts,"path" )); +} +static int win_chr_pipe_poll (void *opaque) {CharDriverState *chr = opaque;
@@ -2957,7 +2961,14 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)static CharDriverState *qmp_chardev_open_port (ChardevPort *port,Error **errp) { +if (port->device->kind !=CHARDEV_FILE_SOURCE_KIND_PATH ) { +error_setg (errp,"only file paths supported" ); +return NULL ; + } +switch (port->type) { +case CHARDEV_PORT_KIND_SERIAL : +return qemu_chr_open_win_path (port->device->path);default :error_setg (errp,"unknown chardev port (%d)" , port->type);return NULL ;
@@ -3020,6 +3031,7 @@ static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)switch (port->type) {#ifdef HAVE_CHARDEV_TTY case CHARDEV_PORT_KIND_TTY : +case CHARDEV_PORT_KIND_SERIAL : flags =O_RDWR |O_NONBLOCK ; fd =qmp_chardev_open_file_source (port->device, flags, errp);if (error_is_set (errp)) {
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 8/9] chardev: hotplug, qmp, serial
Il 19/12/2012 16:59, Gerd Hoffmann ha scritto:
Quoted 11 lines
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 3 ++- qemu-char.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-)qapi-schema.json +0
-0
qapi-schema.json line 3040
Quoted 6 lines
qapi-schema.json +2
-1@@ -3036,7 +3036,8 @@ { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', 'out' : 'ChardevFileSource' } } -{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] } +{ 'enum': 'ChardevPortKind', 'data': [ 'tty', + 'serial' ] }
I think 'tty' and 'serial' are really the same thing, just one for Windows and one for Linux.
We could make one a synonym of the other, even for -chardev.
Paolo
Quoted 53 lines
qapi-schema.json +0
-0{ 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', 'type' : 'ChardevPortKind'} }qemu-char.c +14
-2@@ -1662,9 +1662,8 @@ static int win_chr_poll(void *opaque)return 0 ; } -static CharDriverState *qemu_chr_open_win (QemuOpts *opts) +static CharDriverState *qemu_chr_open_win_path (const char *filename) { -const char *filename =qemu_opt_get (opts,"path" );CharDriverState *chr;WinCharState *s;@@ -1683,6 +1682,11 @@ static CharDriverState *qemu_chr_open_win(QemuOpts *opts)return chr; } +static CharDriverState *qemu_chr_open_win (QemuOpts *opts) +{ +return qemu_chr_open_win_path (qemu_opt_get (opts,"path" )); +} +static int win_chr_pipe_poll (void *opaque) {CharDriverState *chr = opaque;@@ -2957,7 +2961,14 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)static CharDriverState *qmp_chardev_open_port (ChardevPort *port,Error **errp) { +if (port->device->kind !=CHARDEV_FILE_SOURCE_KIND_PATH ) { +error_setg (errp,"only file paths supported" ); +return NULL ; + } +switch (port->type) { +case CHARDEV_PORT_KIND_SERIAL : +return qemu_chr_open_win_path (port->device->path);default :error_setg (errp,"unknown chardev port (%d)" , port->type);return NULL ;@@ -3020,6 +3031,7 @@ static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)switch (port->type) {#ifdef HAVE_CHARDEV_TTY case CHARDEV_PORT_KIND_TTY : +case CHARDEV_PORT_KIND_SERIAL : flags =O_RDWR |O_NONBLOCK ; fd =qmp_chardev_open_file_source (port->device, flags, errp);if (error_is_set (errp)) {
Re: [Qemu-devel] [PATCH 8/9] chardev: hotplug, qmp, serial
Quoted 15 lines · Paolo Bonzini
Il 19/12/2012 16:59, Gerd Hoffmann ha scritto:
Quoted 14 lines
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 3 ++- qemu-char.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-)qapi-schema.json +0
-0@@ -3036,7 +3036,8 @@ { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', 'out' : 'ChardevFileSource' } }
Quoted 6 lines
qapi-schema.json line 3040
Quoted 3 lines
qapi-schema.json +2
-1-{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] } +{ 'enum': 'ChardevPortKind', 'data': [ 'tty', + 'serial' ] }I think 'tty' and 'serial' are really the same thing, just one for Windows and one for Linux.
Partly disagree.
tty is a very unix-ish concept, having that on windows would be confusing I think.
serial lines happen to be a subset of tty on linux. The patch aliases serial to tty on unix because of that.
Quoted 1 line
We could make one a synonym of the other, even for -chardev.
Makes sense to be consistent here.
cheers,
Gerd
PATCH 9/9 chardev: hotplug, qmp, parallel
In reply to Gerd Hoffmann--- qapi-schema.json | 3 ++- qemu-char.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 17 deletions(-)
qapi-schema.json +2 -1
@@ -3037,7 +3037,8 @@ 'out' : 'ChardevFileSource' } } { 'enum': 'ChardevPortKind', 'data': [ 'tty', - 'serial' ] } + 'serial', + 'parport' ] } { 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', 'type' : 'ChardevPortKind'} }
qemu-char.c +27 -16
72 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 24 lines · Gerd Hoffmann
Hi,
Chardev hotplug patch series reloaded. Not finished yet, commit messages not finalized yet, totally untested other than building on linux+windows.
I doubt I manage to finish (and test!) it before xmas. Nevertheless I wanna get the bits out of the door for you to see what is coming and for early reviews. It goes largely the route suggested by Paolo.
cheers,
GerdGerd Hoffmann (9):
chardev: add error reporting forqemu_chr_new_from_opts
chardev: fix QemuOpts lifecycle
chardev: reduce chardev ifdef mess a bit
chardev: hotplug, qmp, null
chardev: hotplug, hmp
chardev: hotplug, qmp, file
chardev: hotplug, qmp, tty
chardev: hotplug, qmp, serial
chardev: hotplug, qmp, parallel
Quoted 10 lines
hmp-commands.hx | 32 ++++++ hmp.c | 23 +++++ hmp.h | 2 + qapi-schema.json | 47 +++++++++ qemu-char.c | 280 ++++++++++++++++++++++++++++++++++++++++++++--------- qemu-char.h | 4 +- qmp-commands.hx | 50 ++++++++++ vl.c | 9 +- 8 files changed, 395 insertions(+), 52 deletions(-)
Okay, the QMP interface seems sane to me (from libvirt POV). However, what about other chardev types like pipe and vc? And I guess pty can be covered by tty, right?
Michal
Quoted 36 lines · Michal Privoznik
Quoted 24 lines · Gerd Hoffmann
Hi,
Chardev hotplug patch series reloaded. Not finished yet, commit messages not finalized yet, totally untested other than building on linux+windows.
I doubt I manage to finish (and test!) it before xmas. Nevertheless I wanna get the bits out of the door for you to see what is coming and for early reviews. It goes largely the route suggested by Paolo.
cheers,
GerdGerd Hoffmann (9):
chardev: add error reporting forqemu_chr_new_from_opts
chardev: fix QemuOpts lifecycle
chardev: reduce chardev ifdef mess a bit
chardev: hotplug, qmp, null
chardev: hotplug, hmp
chardev: hotplug, qmp, file
chardev: hotplug, qmp, tty
chardev: hotplug, qmp, serial
chardev: hotplug, qmp, parallelQuoted 10 lines
hmp-commands.hx | 32 ++++++ hmp.c | 23 +++++ hmp.h | 2 + qapi-schema.json | 47 +++++++++ qemu-char.c | 280 ++++++++++++++++++++++++++++++++++++++++++++--------- qemu-char.h | 4 +- qmp-commands.hx | 50 ++++++++++ vl.c | 9 +- 8 files changed, 395 insertions(+), 52 deletions(-)
Quoted 3 lines
Okay, the QMP interface seems sane to me (from libvirt POV). However, what about other chardev types like pipe and vc? And I guess pty can be covered by tty, right?
No, QEMU's pty & tty types are different - the latter is about accessing host serial devices
Quoted 1 line
From libvirt's POV, I think the most important chardev types are pty,
unix and tcp. The other types are pretty rarely used AFAICT.
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Il 20/12/2012 11:56, Daniel P. Berrange ha scritto:
Quoted 9 lines · Michal Privoznik
Quoted 8 lines · Gerd Hoffmann
Quoted 7 lines
Hi,
Chardev hotplug patch series reloaded. Not finished yet, commit messages not finalized yet, totally untested other than building on linux+windows.
I doubt I manage to finish (and test!) it before xmas.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 3 lines
Quoted 3 lines
Okay, the QMP interface seems sane to me (from libvirt POV). However, what about other chardev types like pipe and vc? And I guess pty can be covered by tty, right?
I think that is the missing part.
Paolo
Quoted 9 lines
No, QEMU's pty & tty types are different - the latter is about accessing host serial devices
From libvirt's POV, I think the most important chardev types are pty, unix and tcp. The other types are pretty rarely used AFAICT.
Daniel
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
I doubt I manage to finish (and test!) it before xmas.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 3 lines
Quoted 3 lines
Okay, the QMP interface seems sane to me (from libvirt POV). However, what about other chardev types like pipe and vc? And I guess pty can be covered by tty, right?
I think that is the missing part.
Exactly.
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Quoted 2 lines
Quoted 2 lines
From libvirt's POV, I think the most important chardev types are pty, unix and tcp. The other types are pretty rarely used AFAICT.
pty looks like another non-trivial challenge. How does libvirt gather the pty device today? IIRC there is some stderr parsing? Or was it info chardev? With QMP we probably want switch to a more sane model here ...
cheers,
Gerd
Hi,
Quoted 2 lines
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Sneak preview attached. Goes on top of the series. Compile tested only so far.
enjoy,
Gerd
From 2c5568c20d97d497b43c9af1c1c1388db089c1e9 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Thu, 20 Dec 2012 13:53:12 +0100
Subject: [PATCH] chardev: hotplug, qmp, socket
qemu_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 | 13 +++- qemu-char.c | 168 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 124 insertions(+), 57 deletions(-)
qapi-schema.json +10 -3
@@ -3043,11 +3043,18 @@ { 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', 'type' : 'ChardevPortKind'} } +{ 'type': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', + '*server' : 'bool', + '*wait' : 'bool', + '*delay' : 'bool', + '*telnet' : 'bool' } } + { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', - 'port' : 'ChardevPort', - 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', + 'socket' : 'ChardevSocket', + 'null' : 'ChardevDummy' } } { 'command': 'chardev-add', 'data': {'id' : 'str', 'backend' : 'ChardevBackend' } }
qemu-char.c +114 -54
210 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Sneak preview attached. Goes on top of the series. Compile tested only so far.
Now that it comes to testing: how does the union look (in josn) at the wire?
thanks,
Gerd
Il 21/12/2012 12:45, Gerd Hoffmann ha scritto:
Quoted 10 lines · Gerd Hoffmann
Quoted 7 lines
Hi,
Quoted 2 lines
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Sneak preview attached. Goes on top of the series. Compile tested only so far.
Now that it comes to testing: how does the union look (in josn) at the wire?
Tests are your friends! (Especially qapi-schema-test.json and test-qmp-input-visitor.c). Something like this:
{ 'type': 'UserDefA',
'data': { 'boolean': 'bool' } }{ 'type': 'UserDefB',
'data': { 'integer': 'int' } }{ 'union': 'UserDefUnion',
'data': { 'a' : 'UserDefA', 'b' : 'UserDefB' } }looks like this:
{ 'type': 'b', 'data' : { 'integer': 42 } }
Paolo
Quoted 19 lines · Paolo Bonzini
Il 21/12/2012 12:45, Gerd Hoffmann ha scritto:
Quoted 10 lines · Gerd Hoffmann
Quoted 7 lines
Hi,
Quoted 2 lines
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Sneak preview attached. Goes on top of the series. Compile tested only so far.
Now that it comes to testing: how does the union look (in josn) at the wire?
Tests are your friends! (Especially qapi-schema-test.json and
test-qmp-input-visitor.c). Something like this:{ 'type': 'UserDefA',
'data': { 'boolean': 'bool' } }{ 'type': 'UserDefB',
Quoted 8 lines
'data': { 'integer': 'int' } }{ 'union': 'UserDefUnion',
'data': { 'a' : 'UserDefA', 'b' : 'UserDefB' } }looks like this:
{ 'type': 'b', 'data' : { 'integer': 42 } }
So ...
{ 'type': 'ChardevDummy', 'data': { } }
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
'port' : 'ChardevPort',
'socket' : 'ChardevSocket',
'pty' : 'ChardevDummy',
'null' : 'ChardevDummy' } }
{ 'command': 'chardev-add', 'data': {'id' : 'str',
'backend' : 'ChardevBackend' },
... should accept ...
{'id': 'test-null', 'backend': {'data': {}, 'type': 'null'}}
... as parameters for chardev-add, no? But I get back ...
{u'error': {u'class': u'GenericError', u'desc': u"Invalid parameter
'backend'"}}
... and can't see what is wrong there ...
cheers,
Gerd
Il 21/12/2012 13:17, Gerd Hoffmann ha scritto:
Quoted 13 lines
{ 'type': 'ChardevDummy', 'data': { } }
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
'port' : 'ChardevPort',
'socket' : 'ChardevSocket',
'pty' : 'ChardevDummy',
'null' : 'ChardevDummy' } }{ 'command': 'chardev-add', 'data': {'id' : 'str',
'backend' : 'ChardevBackend' },... should accept ...
Quoted 8 lines
{'id': 'test-null', 'backend': {'data': {}, 'type': 'null'}}
... as parameters for chardev-add, no? But I get back ...
{u'error': {u'class': u'GenericError', u'desc': u"Invalid parameter
'backend'"}}... and can't see what is wrong there ...
Me neither, but this quick test seems to work here:
$ tests/test-qmp-commands /gerd: test-null 1 OK
qapi-schema-test.json +9 -0
@@ -36,3 +36,12 @@ { 'command': 'user_def_cmd', 'data': {} } { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} } { 'command': 'user_def_cmd2', 'data': {'ud1a': 'UserDefOne', 'ud1b': 'UserDefOne'}, 'returns': 'UserDefTwo' } + + +{ 'type': 'ChardevDummy', 'data': { } } + +{ 'union': 'ChardevBackend', 'data': { 'pty' : 'ChardevDummy', + 'null' : 'ChardevDummy' } } + +{ 'command': 'chardev-add', 'data': {'id' : 'str', + 'backend' : 'ChardevBackend' } }
tests/test-qmp-commands.c +20 -0
@@ -55,6 +55,11 @@ static void test_dispatch_cmd(void)QDECREF (req); } +void qmp_chardev_add (const char *id,ChardevBackend *backend,Error **errp) +{ +printf ("%s %d\n" , id, backend->kind); +} +/* test commands that return an error due to invalid parameters */ static void test_dispatch_cmd_error (void ) {
@@ -71,6 +76,20 @@ static void test_dispatch_cmd_error(void)QDECREF (req); } +static void test_dispatch_gerd (void ) +{ +QObject *req =qobject_from_json ( +"{'execute': 'chardev-add', " +" 'arguments': {'id': 'test-null', " +" 'backend': {'data': {}, 'type': 'null'}}} " ); +QObject *resp =qmp_dispatch (req); +assert (resp !=NULL ); +assert (!qdict_haskey (qobject_to_qdict (resp),"error" )); + +qobject_decref (resp); +qobject_decref (req); +} +/* test commands that involve both input parameters and return values */ static void test_dispatch_cmd_io (void ) {
@@ -174,6 +193,7 @@ int main(int argc, char **argv)g_test_add_func ("/0.15/dispatch_cmd_io" , test_dispatch_cmd_io);g_test_add_func ("/0.15/dealloc_types" , test_dealloc_types);g_test_add_func ("/0.15/dealloc_partial" , test_dealloc_partial); +g_test_add_func ("/gerd" , test_dispatch_gerd);module_call_init (MODULE_INIT_QAPI );g_test_run ();
Paolo
Hi,
Quoted 3 lines
Quoted 1 line
... and can't see what is wrong there ...
Me neither, but this quick test seems to work here:
Test works for me too.
Bug turned out to be elsewhere: args_type in qmp-commands.hx not set correctly ...
cheers,
Gerd
Quoted 14 lines · Gerd Hoffmann
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
I doubt I manage to finish (and test!) it before xmas.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Quoted 3 lines
Quoted 3 lines
Okay, the QMP interface seems sane to me (from libvirt POV). However, what about other chardev types like pipe and vc? And I guess pty can be covered by tty, right?
I think that is the missing part.
Exactly.
/me wades through the socket code (unix+tcp) right now, which needs some refactoring to make it fly.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
From libvirt's POV, I think the most important chardev types are pty, unix and tcp. The other types are pretty rarely used AFAICT.
pty looks like another non-trivial challenge. How does libvirt gather the pty device today? IIRC there is some stderr parsing? Or was it info chardev? With QMP we probably want switch to a more sane model here ...
Yes, these days we use info chardev, or query-chardev as appropriate for the monitor mode.
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Hi,
Quoted 7 lines
Quoted 4 lines
pty looks like another non-trivial challenge. How does libvirt gather the pty device today? IIRC there is some stderr parsing? Or was it info chardev? With QMP we probably want switch to a more sane model here ...
Yes, these days we use info chardev, or query-chardev as appropriate for the monitor mode.
So do you want continue using query-chardev, or do you prefer to get the path returned directly, i.e. something like the attached patch?
cheers,
Gerd
From a616ae73d545a80b3a545fdc66bf141a9b3ba004 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Thu, 20 Dec 2012 14:39:13 +0100
Subject: [PATCH] chardev: hotplug, qmp, pty
--- qapi-schema.json | 7 ++++++- qemu-char.c | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-)
qapi-schema.json +6 -1
@@ -3054,10 +3054,15 @@ { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', 'port' : 'ChardevPort', 'socket' : 'ChardevSocket', + 'pty' : 'ChardevDummy', 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevReturn', 'data': { 'pty' : 'str', + 'nodata' : 'ChardevDummy' } } + { 'command': 'chardev-add', 'data': {'id' : 'str', - 'backend' : 'ChardevBackend' } } + 'backend' : 'ChardevBackend' }, + 'returns' : 'ChardevReturn' } ## # @chardev-remove:
qemu-char.c +21 -3
@@ -3115,9 +3115,13 @@ static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock, is_telnet, is_waitconnect, errp); } -void qmp_chardev_add (const char *id,ChardevBackend *backend,Error **errp) +ChardevReturn *qmp_chardev_add (const char *id,ChardevBackend *backend, +Error **errp) { -CharDriverState *chr; +ChardevReturn *ret =g_new0 (ChardevReturn,1 ); +CharDriverState *chr =NULL ; + + ret->kind =CHARDEV_RETURN_KIND_NODATA ;switch (backend->kind) {case CHARDEV_BACKEND_KIND_FILE :
@@ -3129,17 +3133,31 @@ void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)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->kind =CHARDEV_RETURN_KIND_PTY ; + ret->pty =g_strdup (qemu_opt_get (opts,"path" )); +qemu_opts_del (opts); +break ; + } +#endif case CHARDEV_BACKEND_KIND_NULL : chr =qemu_chr_open_null (NULL );break ;default :error_setg (errp,"unknown chardev backend (%d)" , backend->kind); -return ; +break ; }if (chr ==NULL && !error_is_set (errp)) {error_setg (errp,"Failed to create chardev" ); } +return ret; }void qmp_chardev_remove (const char *id,Error **errp)
Signature · 1 line
1.7.1
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
Quoted 4 lines
pty looks like another non-trivial challenge. How does libvirt gather the pty device today? IIRC there is some stderr parsing? Or was it info chardev? With QMP we probably want switch to a more sane model here ...
Quoted 5 lines
Quoted 2 lines
Yes, these days we use info chardev, or query-chardev as appropriate for the monitor mode.
So do you want continue using query-chardev, or do you prefer to get the path returned directly, i.e. something like the attached patch?
If you return the path directly, that'd certainly make life easier
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|