chardev hotplug patch series
cover chardev hotplug patch series
Hi,
Got stuck in discussions & 1.3 freeze. Resending series to resume merge effort, almost unmodified, only rebased & trivial conflicts resolved.
please review & comment,
Gerd
Gerd Hoffmann (3):
chardev: add error reporting for qemu_chr_new_from_opts
chardev: fix QemuOpts lifecycle
chardev: add hotplug support.
hmp-commands.hx | 44 +++++++++++++++++++++++++++++ hmp.c | 29 +++++++++++++++++++ hmp.h | 3 ++ qapi-schema.json | 43 +++++++++++++++++++++++++++++ qemu-char.c | 80 ++++++++++++++++++++++++++++++++++++++++++++--------- qemu-char.h | 6 +++- qmp-commands.hx | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 9 ++++-- 8 files changed, 272 insertions(+), 18 deletions(-)
PATCH 1/3 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
@@ -2766,19 +2766,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++) {
@@ -2786,15 +2787,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 ; }
@@ -2824,6 +2825,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);
@@ -2833,7 +2835,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
@@ -2057,11 +2057,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/3 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
@@ -2774,13 +2774,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 )
@@ -2789,14 +2789,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)
@@ -2817,7 +2817,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))
@@ -2843,7 +2848,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; }
@@ -2875,6 +2879,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/3 chardev: add hotplug support.
In reply to Gerd HoffmannThis patch adds chardev_add_file, chardev_add_tty and chardev_remove monitor commands.
chardev_add_file and chardev_add_tty expect an id and a path, they create a file/tty chardev.
chardev_del just takes an id argument and zaps the chardev specified.
--- hmp-commands.hx | 44 +++++++++++++++++++++++++++++++ hmp.c | 29 ++++++++++++++++++++ hmp.h | 3 ++ qapi-schema.json | 43 ++++++++++++++++++++++++++++++ qemu-char.c | 41 +++++++++++++++++++++++++++++ qemu-char.h | 2 + qmp-commands.hx | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 0 deletions(-)
hmp-commands.hx +44 -0
@@ -1485,6 +1485,50 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add_file", + .args_type = "id:s,path:s", + .params = "id path ", + .help = "add file chardev", + .mhandler.cmd = hmp_chardev_add_file, + }, + +STEXI +@item chardev_add_file id path +@findex chardev_add_file + +ETEXI + + { + .name = "chardev_add_tty", + .args_type = "id:s,path:s", + .params = "id path ", + .help = "add tty chardev", + .mhandler.cmd = hmp_chardev_add_tty, + }, + +STEXI +@item chardev_add_tty id path +@findex chardev_add_tty + +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 +29 -0
@@ -1335,3 +1335,32 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)qmp_nbd_server_stop (&errp);hmp_handle_error (mon, &errp); } + +static void hmp_chardev_add_path (Monitor *mon,const QDict *qdict, +const char *backend) +{ +const char *id =qdict_get_str (qdict,"args" ); +const char *path =qdict_get_str (qdict,"path" ); +Error *local_err =NULL ; + +qmp_chardev_add_path (id, path, backend, &local_err); +hmp_handle_error (mon, &local_err); +} + +void hmp_chardev_add_file (Monitor *mon,const QDict *qdict) +{ +hmp_chardev_add_path (mon, qdict,"file" ); +} + +void hmp_chardev_add_tty (Monitor *mon,const QDict *qdict) +{ +hmp_chardev_add_path (mon, qdict,"tty" ); +} + +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 +3 -0
@@ -80,5 +80,8 @@ 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_file (Monitor *mon,const QDict *qdict); +void hmp_chardev_add_tty (Monitor *mon,const QDict *qdict); +void hmp_chardev_remove (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +43 -0
46 lines not on this page · raw message
qemu-char.c +41 -0
44 lines not on this page · raw message
qemu-char.h +2 -0
@@ -239,6 +239,8 @@ void qemu_chr_info(Monitor *mon, QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +void qmp_chardev_add_path (const char *id,const char *path, +const char *backend,Error **errp);/* add an eventfd to the qemu devices that are polled */ CharDriverState *qemu_chr_open_eventfd (int eventfd);
qmp-commands.hx +76 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Il 14/12/2012 10:38, Gerd Hoffmann ha scritto:
Quoted 5 lines
This patch adds
chardev_add_file,chardev_add_ttyandchardev_removemonitor commands.
chardev_add_fileandchardev_add_ttyexpect an id and a path, they create a file/tty chardev.
I'd rather avoid introducing this interface. Using multiple commands is different from all previous examples, both HMP and QMP (including recent ones such as the NBD server). It is also hard to extend, for example file descriptor passing is hard to retrofit.
Perhaps you can define a QAPI union and slowly build it up? Something that ultimately can become this:
{ 'enum': 'ChardevFileMode', 'data':
# pty = console under Windows # serial = tty under POSIX [ 'file', 'pipe', 'parport', 'pty', 'serial' ] }
{ 'enum: 'ChardevFileSource', 'data':
[ 'path', 'fd' ] }
{ 'type': 'ChardevFile',
'data': {'source': 'string', 'source-type': 'ChardevFileSource',
'mode': 'ChardevFileMode'}}
{ 'type': 'ChardevVC',
'data': {'width': 'int', 'height': 'int', '*characters': 'bool'}}
{ 'type': 'ChardevSocket',
'data': {'addr': 'SocketAddress', '*server': 'bool',
'*wait': 'bool', '*nodelay': 'bool', '*telnet': 'bool'} }
# For future extensibility...
{ 'ChardevDummy', 'data': {} }
{ 'union': 'ChardevBackend', 'data': {
'socket': 'ChardevSocket',
'udp': 'UDPSocketAddress',
'file': 'ChardevFile',
'null': 'ChardevDummy',
'msmouse': 'ChardevDummy',
'braille': 'ChardevDummy',
'stdio': 'ChardevDummy',
'vc': 'ChardevVC',
# Solely for HMP usage.
'legacy': 'str'
}
{ 'command': 'chardev-add', 'data': {
'backend': 'ChardevBackend', 'id': 'str', '*mux': 'bool' } }
A simple conversion from this to QemuOpts should be easy, later the backends can move to taking a ChardevBackend *.
Paolo
Quoted 316 lines
chardev_deljust takes an id argument and zaps the chardev specified.Signed-off-by Gerd Hoffmann <[email protected]>--- hmp-commands.hx | 44 +++++++++++++++++++++++++++++++ hmp.c | 29 ++++++++++++++++++++ hmp.h | 3 ++ qapi-schema.json | 43 ++++++++++++++++++++++++++++++ qemu-char.c | 41 +++++++++++++++++++++++++++++ qemu-char.h | 2 + qmp-commands.hx | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 0 deletions(-)hmp-commands.hx +44
-0@@ -1485,6 +1485,50 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add_file", + .args_type = "id:s,path:s", + .params = "id path ", + .help = "add file chardev", + .mhandler.cmd = hmp_chardev_add_file, + }, + +STEXI +@item chardev_add_file id path +@findex chardev_add_file + +ETEXI + + { + .name = "chardev_add_tty", + .args_type = "id:s,path:s", + .params = "id path ", + .help = "add tty chardev", + .mhandler.cmd = hmp_chardev_add_tty, + }, + +STEXI +@item chardev_add_tty id path +@findex chardev_add_tty + +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 +29
-0@@ -1335,3 +1335,32 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)qmp_nbd_server_stop (&errp);hmp_handle_error (mon, &errp); } + +static void hmp_chardev_add_path (Monitor *mon,const QDict *qdict, +const char *backend) +{ +const char *id =qdict_get_str (qdict,"args" ); +const char *path =qdict_get_str (qdict,"path" ); +Error *local_err =NULL ; + +qmp_chardev_add_path (id, path, backend, &local_err); +hmp_handle_error (mon, &local_err); +} + +void hmp_chardev_add_file (Monitor *mon,const QDict *qdict) +{ +hmp_chardev_add_path (mon, qdict,"file" ); +} + +void hmp_chardev_add_tty (Monitor *mon,const QDict *qdict) +{ +hmp_chardev_add_path (mon, qdict,"tty" ); +} + +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 +3
-0@@ -80,5 +80,8 @@ 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_file (Monitor *mon,const QDict *qdict); +void hmp_chardev_add_tty (Monitor *mon,const QDict *qdict); +void hmp_chardev_remove (Monitor *mon,const QDict *qdict);#endif qapi-schema.json +43
-0@@ -3017,3 +3017,46 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-stop' } + +## +# @chardev-add-file: +# +# Add a file chardev +# +# @id: the chardev's ID, must be unique +# @path: file path +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev-add-file', 'data': {'id' : 'str', + 'path' : 'str' } } + +## +# @chardev-add-tty: +# +# Add a terminal chardev +# +# @id: the chardev's ID, must be unique +# @path: device path +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev-add-tty', 'data': {'id' : 'str', + 'path' : 'str' } } + +## +# @chardev-remove: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev-remove', 'data': {'id': 'str'} }qemu-char.c +41
-0@@ -2922,3 +2922,44 @@ CharDriverState *qemu_char_get_next_serial(void)return serial_hds[next_serial++]; } +void qmp_chardev_add_path (const char *id,const char *path, +const char *backend,Error **errp) +{ +QemuOpts *opts; + + opts =qemu_opts_create (qemu_find_opts ("chardev" ), id,1 , errp); +if (error_is_set (errp)) { +return ; + } + +qemu_opt_set (opts,"path" , path); +qemu_opt_set (opts,"backend" , backend); +qemu_chr_new_from_opts (opts,NULL , errp); +} + +void qmp_chardev_add_file (const char *id,const char *path,Error **errp) +{ +qmp_chardev_add_path (id, path,"file" , errp); +} + +void qmp_chardev_add_tty (const char *id,const char *path,Error **errp) +{ +qmp_chardev_add_path (id, path,"tty" , errp); +} + +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\n" , id); +return ; + } +if (chr->chr_can_read || chr->chr_read || + chr->chr_event || chr->handler_opaque) { +error_setg (errp,"Chardev '%s' is busy\n" , id); +return ; + } +qemu_chr_delete (chr); +}qemu-char.h +2
-0@@ -239,6 +239,8 @@ void qemu_chr_info(Monitor *mon, QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +void qmp_chardev_add_path (const char *id,const char *path, +const char *backend,Error **errp);/* add an eventfd to the qemu devices that are polled */ CharDriverState *qemu_chr_open_eventfd (int eventfd);qmp-commands.hx +76
-0@@ -2654,3 +2654,79 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_target, }, + + { + .name = "chardev-add-file", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_add_file, + }, + +SQMP +chardev-add-file +---------------- + +Add a file chardev. + +Arguments: + +- "id": the chardev's ID, must be unique (json-string) +- "path": file path (json-string) + +Example: + +-> { "execute" : "chardev-add-file", + "arguments" : { "id" : "foo", + "path" : "/tmp/foo" } } +<- { "return": {} } + +EQMP + + { + .name = "chardev-add-tty", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_add_tty, + }, + +SQMP +chardev-add-tty +--------------- + +Add a terminal chardev. + +Arguments: + +- "id": the chardev's ID, must be unique (json-string) +- "path": device path (json-string) + +Example: + +-> { "execute" : "chardev-add-tty", + "arguments" : { "id" : "serial", + "path" : "/dev/ttyS0" } } +<- { "return": {} } + +EQMP + + { + .name = "chardev-remove", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_remove, + }, + + +SQMP +chardev-remove +-------------- + +Remove a chardev. + +Arguments: + +- "id": the chardev's ID, must exist and not be in use (json-string) + +Example: + +-> { "execute": "chardev-remove", "arguments": { "id" : "foo" } } +<- { "return": {} } + +EQMP
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Quoted 11 lines · Paolo Bonzini
Il 14/12/2012 10:38, Gerd Hoffmann ha scritto:
Quoted 5 lines
This patch adds
chardev_add_file,chardev_add_ttyandchardev_removemonitor commands.
chardev_add_fileandchardev_add_ttyexpect an id and a path, they create a file/tty chardev.I'd rather avoid introducing this interface. Using multiple commands is different from all previous examples, both HMP and QMP (including recent ones such as the NBD server). It is also hard to extend, for example file descriptor passing is hard to retrofit.
File descriptor passing via magic /dev/fdset/nnn should probably already work. That said, a single command that uses a QAPI union, rather than one command per source type, would be nicer from the UI perspective, and it is the QMP UI perspective that libvirt is concerned about.
Quoted 36 lines
Perhaps you can define a QAPI union and slowly build it up? Something that ultimately can become this:
{ 'enum': 'ChardevFileMode', 'data':
# pty = console under Windows # serial = tty under POSIX [ 'file', 'pipe', 'parport', 'pty', 'serial' ] }{ 'enum: 'ChardevFileSource', 'data':
[ 'path', 'fd' ] }{ 'type': 'ChardevFile',
'data': {'source': 'string', 'source-type': 'ChardevFileSource','mode': 'ChardevFileMode'}}{ 'type': 'ChardevVC',
'data': {'width': 'int', 'height': 'int', '*characters': 'bool'}}{ 'type': 'ChardevSocket',
'data': {'addr': 'SocketAddress', '*server': 'bool','*wait': 'bool', '*nodelay': 'bool', '*telnet': 'bool'} }# For future extensibility...
{ 'ChardevDummy', 'data': {} }{ 'union': 'ChardevBackend', 'data': {
'socket': 'ChardevSocket',
'udp': 'UDPSocketAddress',
'file': 'ChardevFile',
'null': 'ChardevDummy',
'msmouse': 'ChardevDummy',
'braille': 'ChardevDummy',
'stdio': 'ChardevDummy',
'vc': 'ChardevVC',
Quoted 6 lines
# Solely for HMP usage.
'legacy': 'str'
}{ 'command': 'chardev-add', 'data': {
'backend': 'ChardevBackend', 'id': 'str', '*mux': 'bool' } }
Yes, this looks nicer.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
In reply to Paolo BonziniHi,
Quoted 4 lines
{ 'enum': 'ChardevFileMode', 'data':
# pty = console under Windows # serial = tty under POSIX [ 'file', 'pipe', 'parport', 'pty', 'serial' ] }
Hmm, why this enum? I'd stay close to -chardev, i.e. specify the type by backend name.
Quoted 2 lines
{ 'enum: 'ChardevFileSource', 'data':
[ 'path', 'fd' ] }
I guess I'd just create a new backend type for file descriptor passing instead of fitting that into all the existing ones.
Quoted 1 line
{ 'union': 'ChardevBackend', 'data': {
This union thing is new, isn't it?
Makes sense to use that indeed.
Quoted 8 lines
'socket': 'ChardevSocket',
'udp': 'UDPSocketAddress',
'file': 'ChardevFile',
'null': 'ChardevDummy',
'msmouse': 'ChardevDummy',
'braille': 'ChardevDummy',
'stdio': 'ChardevDummy',
'vc': 'ChardevVC',
I doubt we need them all hotpluggable.
cheers,
Gerd
Quoted 1 line
From
6ea61630245d8ff9f87ed56b825dcc5f8d1f6e6dMon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Thu, 11 Oct 2012 14:53:00 +0200
Subject: [PATCH] chardev: add hotplug support.
This patch adds chardev_add and chardev_remove monitor commands.
chardev_add expects a backend struct filled in and creates the chardev from that. For now only file and tty backends are supported.
chardev_del just takes an id argument and zaps the chardev specified.
--- hmp-commands.hx | 30 ++++++++++++++++++++++++++++++ hmp.c | 19 +++++++++++++++++++ hmp.h | 2 ++ qapi-schema.json | 31 +++++++++++++++++++++++++++++++ qemu-char.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ qemu-char.h | 2 ++ qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 180 insertions(+), 0 deletions(-)
hmp-commands.hx +30 -0
@@ -1485,6 +1485,36 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add", + .args_type = "id:s,backend:s,arg1:s", + .params = "id backend arg", + .help = "add chardev", + .mhandler.cmd = hmp_chardev_add, + }, + +STEXI +@item chardev_add id backend arg +@findex chardev_add + +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 +19 -0
@@ -1335,3 +1335,22 @@ 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 *id =qdict_get_str (qdict,"id" ); +const char *backend =qdict_get_str (qdict,"backend" ); +const char *path =qdict_get_str (qdict,"arg1" ); +Error *local_err =NULL ; + +qmp_chardev_add_path (id, path, backend, &local_err); +hmp_handle_error (mon, &local_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
qapi-schema.json +31 -0
@@ -3017,3 +3017,34 @@ # 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.3.0 +## +{ 'type': 'ChardevFile', 'data': { 'path': 'str' } } +{ 'union': 'ChardevBackend', 'data': { 'file': 'ChardevFile', + 'tty': 'ChardevFile' } } +{ '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.3.0 +## +{ 'command': 'chardev-remove', 'data': {'id': 'str'} }
qemu-char.c +46 -0
49 lines not on this page · raw message
qemu-char.h +2 -0
@@ -239,6 +239,8 @@ void qemu_chr_info(Monitor *mon, QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +void qmp_chardev_add_path (const char *id,const char *path, +const char *backend,Error **errp);/* add an eventfd to the qemu devices that are polled */ CharDriverState *qemu_chr_open_eventfd (int eventfd);
qmp-commands.hx +50 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Il 14/12/2012 14:18, Gerd Hoffmann ha scritto:
Quoted 9 lines
Hi,
Quoted 4 lines
{ 'enum': 'ChardevFileMode', 'data':
# pty = console under Windows # serial = tty under POSIX [ 'file', 'pipe', 'parport', 'pty', 'serial' ] }Hmm, why this enum? I'd stay close to -chardev, i.e. specify the type by backend name.
Because...
Quoted 5 lines
Quoted 2 lines
{ 'enum: 'ChardevFileSource', 'data':
[ 'path', 'fd' ] }I guess I'd just create a new backend type for file descriptor passing instead of fitting that into all the existing ones.
... are you passing a file descriptor for a pipe, a file or a parallel/serial port?
(pty and console have no arguments, I misremembered).
Quoted 3 lines
Quoted 1 line
{ 'union': 'ChardevBackend', 'data': {
This union thing is new, isn't it?
Yeah, a few months old.
Quoted 11 lines
Makes sense to use that indeed.
Quoted 8 lines
'socket': 'ChardevSocket',
'udp': 'UDPSocketAddress',
'file': 'ChardevFile',
'null': 'ChardevDummy',
'msmouse': 'ChardevDummy',
'braille': 'ChardevDummy',
'stdio': 'ChardevDummy',
'vc': 'ChardevVC',
Quoted 1 line
I doubt we need them all hotpluggable.
True, but:
1) I believe long term it's good to move away from QemuOpts; it's good to provide a complete interface even if all we're doing for now is building QemuOpts out of the struct.
2) most of them have no options and trivial anyway;
3) the complicated ones (socket, file, perhaps udp) are also the useful ones.
Paolo
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Quoted 13 lines · Paolo Bonzini
Il 14/12/2012 14:18, Gerd Hoffmann ha scritto:
Quoted 9 lines
Hi,
Quoted 4 lines
{ 'enum': 'ChardevFileMode', 'data':
# pty = console under Windows # serial = tty under POSIX [ 'file', 'pipe', 'parport', 'pty', 'serial' ] }Hmm, why this enum? I'd stay close to -chardev, i.e. specify the type by backend name.
Because...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
{ 'enum: 'ChardevFileSource', 'data':
[ 'path', 'fd' ] }I guess I'd just create a new backend type for file descriptor passing instead of fitting that into all the existing ones.
... are you passing a file descriptor for a pipe, a file or a parallel/serial port?
The open function of the file-based backends basically do (1) create file handles and (2) call qemu_chr_open_fd(). So of you already have an fd the differences are gone. Well, almost. tty has an special ioctl callback to configure line speed.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Hi,
Quoted 7 lines
Quoted 2 lines
... are you passing a file descriptor for a pipe, a file or a parallel/serial port?
The open function of the file-based backends basically do (1) create file handles and (2) call
qemu_chr_open_fd(). So of you already have an fd the differences are gone. Well, almost. tty has an special ioctl callback to configure line speed.
Also you might want to pass in a socket fd ...
So I really think a -chardev fd,type={listening-stream-socket,connected-stream-socket,datagram-socket,tty,fd-readwrite,fd-writeonly} (+ QMP for that) will be more useful.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/3] chardev: add hotplug support.
Il 14/12/2012 15:19, Gerd Hoffmann ha scritto:
Quoted 7 lines
Hi,
Quoted 5 lines
Quoted 2 lines
... are you passing a file descriptor for a pipe, a file or a parallel/serial port?
The open function of the file-based backends basically do (1) create file handles and (2) call
qemu_chr_open_fd().
Right, and there's the ugliness where you can only specify an output file, not an input.
Quoted 3 lines
Quoted 3 lines
So of you already have an
fd the differences are gone. Well, almost. tty has an special ioctl callback to configure line speed.
What about this then:
{ 'union': 'ChardevFileSource',
'data': {'path': 'str', 'fd': 'str'} }
{ 'type': 'ChardevFile',
'data': {'*in': 'ChardevFileSource', '*out': 'ChardevFileSource'} }
{ 'enum': 'ChardevPortKind',
'data': ['serial', 'parallel'] }
{ 'type': 'ChardevPort',
'data': {'device': 'ChardevFileSource', 'type': 'ChardevPortKind'} }
{ 'type': 'ChardevSpice',
'data': {'name': 'str', '*debug': 'bool'}}
{ 'type': 'ChardevVC',
'data': {'*width': 'int', '*height': 'int',
'*cols': 'int', '*rows': 'int'}}
{ 'type': 'ChardevSocket',
'data': {'addr': 'SocketAddress', '*server': 'bool',
'*wait': 'bool', '*nodelay': 'bool', '*telnet': 'bool'} }
{ 'type': 'ChardevUDP',
'data': {'peer': 'SocketAddress',
'*localhost': 'str', '*localport': 'str' } }
# For future extensibility...
{ 'ChardevDummy', 'data': {} }
{ 'union': 'ChardevBackend', 'data': {
'socket': 'ChardevSocket',
'winpipe': 'String', # "pipe" for _WIN32 case
'udp': 'ChardevUDP',
'file': 'ChardevFile',
'port': 'ChardevPort',
'pty': 'ChardevDummy',
'null': 'ChardevDummy',
'msmouse': 'ChardevDummy',
'braille': 'ChardevDummy',
'stdio': 'ChardevDummy',
'vc': 'ChardevVC',
# Solely for HMP usage.
'legacy': 'str'
}
Quoted 1 line
Also you might want to pass in a socket fd ...
This is already supported by socket_connect/socket_listen in qemu-sockets.c (thus by the SocketAddress QAPI union).
Paolo
Quoted 8 lines
So I really think a -chardev fd,type={listening-stream-socket,connected-stream-socket,datagram-socket,tty,fd-readwrite,fd-writeonly} (+ QMP for that) will be more useful.
cheers,
Gerd