chardev: qom-ify
v2 cover chardev: qom-ify
qemu-char.c is quite a large file (~130k, 5000 loc) with many chardev and a lot of #ifdef. It doesn't use qemu Object. Using qemu Object hopefully brings cleaner, more consitent code base. It helps to split the various backends in different files. Eventually, we could also allow or switch to -object-add CLI option instead of -chardev.
This series is the first of a pretty large chardev refactoring series that I keep here:
https://github.com/elmarco/qemu/commits/chrfe
The series is based after "char: fix ctrl-a b not working" patch sent earlier.
For "spice-char: improve error reporting" to not introduce a regression, "error: report hints on stderr when no monitor" is required (sent earlier in the ML).
v1->v2:
- fix intermediate patches regressions spotted by Eric
- code style improvements
- add r-b tags
WIP->v1:
- took most of Eric review comments, they were mostly about style
Marc-André Lureau (20):
tests: fix linking test-char on win32
qemu-options: stdio is available on win32
char: add qemu_chr_fe_add_watch() Returns description
doc: fix spelling
char: use a const CharDriver
char: use a static array for backends
char: move callbacks in CharDriver
char: fold single-user functions in caller
char: introduce generic qemu_chr_get_kind()
char: use a feature bit for replay
char: allocate CharDriverState as a single object
bt: use qemu_chr_alloc()
char: rename CharDriverState Chardev
char: rename TCPChardev and NetChardev
spice-char: improve error reporting
char: use error_report()
gtk: overwrite the console.c char driver
baum: use a common prefix for chr callbacks
vc: use a common prefix for chr callbacks
chardev: qom-ify
hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 155 +-- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/console.h | 2 + include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- backends/baum.c | 102 +- backends/msmouse.c | 77 +- backends/rng-egd.c | 4 +- backends/testdev.c | 53 +- gdbstub.c | 45 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 64 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- monitor.c | 6 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 1914 ++++++++++++++++++++----------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 231 +++-- stubs/get-next-serial.c | 2 +- stubs/monitor-init.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 111 ++- ui/gtk.c | 86 +- vl.c | 12 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- qemu-options.hx | 4 +- tests/Makefile.include | 2 +- 84 files changed, 1729 insertions(+), 1343 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/20 tests: fix linking test-char on win32
test.char.exe fails to link:
qemu-char.o: In function `win_chr_free':/home/elmarco/src/qemu/qemu-char.c:2149: undefined reference to qemu_del_polling_cb' /home/elmarco/src/qemu/qemu-char.c:2151: undefined reference to qemu_del_polling_cb' qemu-char.o: In function `win_stdio_thread':/home/elmarco/src/qemu/qemu-char.c:2568: undefined reference to qemu_del_wait_object' qemu-char.o: In function qemu_chr_open_stdio':/home/elmarco/src/qemu/qemu-char.c:2661: undefined reference to qemu_add_wait_object' /home/elmarco/src/qemu/qemu-char.c:2646: undefined reference to qemu_add_wait_object'
...
It needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile.include +1 -1
@@ -489,7 +489,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) -tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) +tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
Signature · 1 line
2.11.0
PATCH v2 2/20 qemu-options: stdio is available on win32
In reply to Marc-André LureauAvailable since commit db418a0a7ef5887ea0f3d167584e6f500bb0c4c5 (October 2011, qemu 1.0)
--- qemu-options.hx | 2 -- 1 file changed, 2 deletions(-)
qemu-options.hx +0 -2
@@ -2431,8 +2431,6 @@ Connect to standard input and standard output of the QEMU process. exiting QEMU with the key sequence @key{Control-c}. This option is enabled by default, use @option{signal=off} to disable it. -@option{stdio} is not available on Windows hosts. - @item -chardev braille ,id=@var{id} Connect to a local BrlAPI server. @option{braille} does not take any options.
Signature · 1 line
2.11.0
PATCH v2 3/20 char: add qemu_chr_fe_add_watch() Returns description
In reply to Marc-André Lureau--- include/sysemu/char.h | 2 ++ 1 file changed, 2 insertions(+)
include/sysemu/char.h +2 -0
@@ -258,6 +258,8 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)* @cond the condition to poll for * @func the function to call when the condition happens * @user_data the opaque pointer to pass to @func +* +* Returns: the source tag */ guint qemu_chr_fe_add_watch (CharBackend *be,GIOCondition cond,GIOFunc func,void *user_data);
Signature · 1 line
2.11.0
PATCH v2 4/20 doc: fix spelling
In reply to Marc-André LureauI am pretty sure that's the word Fabrice Bellard intended to write.
--- qemu-options.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-options.hx +1 -1
@@ -3016,7 +3016,7 @@ udp::4555@@:4556} to QEMU. Another approach is to use a patched version of netcat which can listen to a TCP port and send and receive characters via udp. If you have a patched version of netcat which activates telnet remote echo and single char transfer, then you can -use the following options to step up a netcat redirector to allow +use the following options to set up a netcat redirector to allow telnet on port 5555 to access the QEMU port. @table @code @item QEMU Options:
Signature · 1 line
2.11.0
PATCH v2 5/20 char: use a const CharDriver
In reply to Marc-André LureauNo need to allocate & copy fields, let's use static const struct instead.
--- include/sysemu/char.h | 20 +++--- backends/baum.c | 8 ++- backends/msmouse.c | 7 ++- backends/testdev.c | 7 ++- qemu-char.c | 169 +++++++++++++++++++++++++++++++------------------- spice-qemu-char.c | 16 +++-- ui/console.c | 10 ++- 7 files changed, 151 insertions(+), 86 deletions(-)
include/sysemu/char.h +11 -9
@@ -475,15 +475,17 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef void CharDriverParse (QemuOpts *opts,ChardevBackend *backend, -Error **errp); -typedef CharDriverState *CharDriverCreate (const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); - -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create); +typedef struct CharDriver { +ChardevBackendKind kind; +const char *alias; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +CharDriverState *(*create)(const char *id, +ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp); +}CharDriver ; + +void register_char_driver (const CharDriver *driver);extern int term_escape_char;
backends/baum.c +6 -2
@@ -671,8 +671,12 @@ fail_handle:static void register_types (void ) { -register_char_driver ("braille" ,CHARDEV_BACKEND_KIND_BRAILLE ,NULL , - chr_baum_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_BRAILLE , + .create = chr_baum_init, + }; + +register_char_driver (&driver); }type_init (register_types);
backends/msmouse.c +5 -2
@@ -179,8 +179,11 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,static void register_types (void ) { -register_char_driver ("msmouse" ,CHARDEV_BACKEND_KIND_MSMOUSE ,NULL , - qemu_chr_open_msmouse); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_MSMOUSE , + .create = qemu_chr_open_msmouse, + }; +register_char_driver (&driver); }type_init (register_types);
backends/testdev.c +5 -2
@@ -130,8 +130,11 @@ static CharDriverState *chr_testdev_init(const char *id,static void register_types (void ) { -register_char_driver ("testdev" ,CHARDEV_BACKEND_KIND_TESTDEV ,NULL , - chr_testdev_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_TESTDEV , + .create = chr_testdev_init, + }; +register_char_driver (&driver); }type_init (register_types);
qemu-char.c +105 -64
232 lines not on this page · raw message
spice-qemu-char.c +12 -4
@@ -389,10 +389,18 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) { -register_char_driver ("spicevmc" ,CHARDEV_BACKEND_KIND_SPICEVMC , - qemu_chr_parse_spice_vmc, qemu_chr_open_spice_vmc); -register_char_driver ("spiceport" ,CHARDEV_BACKEND_KIND_SPICEPORT , - qemu_chr_parse_spice_port, qemu_chr_open_spice_port); +static const CharDriver vmc_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEVMC , + .parse = qemu_chr_parse_spice_vmc, + .create = qemu_chr_open_spice_vmc, + }; +static const CharDriver port_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEPORT , + .parse = qemu_chr_parse_spice_port, + .create = qemu_chr_open_spice_port, + }; +register_char_driver (&vmc_driver); +register_char_driver (&port_driver); }type_init (register_types);
ui/console.c +7 -3
@@ -2191,12 +2191,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; -static void register_types (void ) { +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + }; +type_register_static (&qemu_console_info); -register_char_driver ("vc" ,CHARDEV_BACKEND_KIND_VC , qemu_chr_parse_vc, - vc_init); +register_char_driver (&vc_driver); }type_init (register_types);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v2 05/20] char: use a const CharDriver
Quoted 2 lines · Marc-André Lureau
No need to allocate & copy fields, let's use static const struct instead.
Missing these sentences:
Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names. The name field is no longer necessary, since we can now use a QAPI enum lookup.
Quoted 4 lines
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Eric Blake <[email protected]>---
R-by stands, just the commit message needs improvement.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 6/20 char: use a static array for backends
In reply to Marc-André LureauNumber and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups. Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names.
--- qemu-char.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-)
qemu-char.c +34 -34
@@ -4099,21 +4099,20 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, } } -static GSList *backends; +static const CharDriver *backends[CHARDEV_BACKEND_KIND__MAX ];void register_char_driver (const CharDriver *driver) { -/* casting away const */ - backends =g_slist_append (backends, (void *)driver); + backends[driver->kind] = driver; }CharDriverState *qemu_chr_new_from_opts (QemuOpts *opts,Error **errp) {Error *local_err =NULL ; -CharDriver *cd; +const CharDriver *cd =NULL ;CharDriverState *chr; -GSList *i; +int i;ChardevReturn *ret =NULL ;ChardevBackend *backend;const char *name =qemu_opt_get (opts,"backend" );
@@ -4128,11 +4127,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (is_help_option (name)) {fprintf (stderr,"Available chardev backend types:\n" ); -for (i = backends; i; i = i->next) { - cd = i->data; -fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); -if (cd->alias) { -fprintf (stderr,"%s\n" , cd->alias); +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; +if (cd) { +fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +if (cd->alias) { +fprintf (stderr,"%s\n" , cd->alias); + } } }exit (0 );
@@ -4143,15 +4144,17 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, goto err; } -for (i = backends; i; i = i->next) { - cd = i->data; - +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; +if (!cd) { +continue ; + }if (g_strcmp0 (ChardevBackendKind_lookup[cd->kind], name) ==0 ||g_strcmp0 (cd->alias, name) ==0 ) {break ; } } -if (i ==NULL ) { +if (i ==ARRAY_SIZE (backends)) {error_setg (errp,"chardev: backend \"%s\" not found" , name); goto err; }
@@ -4368,11 +4371,15 @@ qmp_prepend_backend(ChardevBackendInfoList *list, const char *name)ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -CharDriver *c; -GSList *i; +const CharDriver *c; +int i; + +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + c = backends[i]; +if (!c) { +continue ; + } -for (i = backends; i; i = i->next) { - c = i->data; backend_list =qmp_prepend_backend (backend_list, ChardevBackendKind_lookup[c->kind]);if (c->alias) {
@@ -4833,9 +4840,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, {ChardevReturn *ret =g_new0 (ChardevReturn,1 );CharDriverState *chr =NULL ; +const CharDriver *cd;Error *local_err =NULL ; -GSList *i; -CharDriver *cd;bool be_opened = true; chr =qemu_chr_find (id);
@@ -4844,22 +4850,16 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, goto out_error; } -for (i = backends; i; i = i->next) { - cd = i->data; - -if (cd->kind == backend->type) { - chr = cd->create (id, backend, ret, &be_opened, &local_err); -if (local_err) { -error_propagate (errp, local_err); - goto out_error; - } -break ; - } + cd = (int )backend->type >=0 && backend->type <ARRAY_SIZE (backends) ? + backends[backend->type] :NULL ; +if (cd ==NULL ) { +error_setg (errp,"chardev backend not available" ); + goto out_error; } -if (chr ==NULL ) { -assert (!i); -error_setg (errp,"chardev backend not available" ); + chr = cd->create (id, backend, ret, &be_opened, &local_err); +if (local_err) { +error_propagate (errp, local_err); goto out_error; }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v2 06/20] char: use a static array for backends
Quoted 2 lines · Marc-André Lureau
Number and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups.
This part is okay;
Quoted 3 lines
Add an alias field to the
CharDriver structure to cover the cases where we previously registered a driver twice under two names.
but this part belongs in the 5/20 commit message.
Quoted 18 lines
Signed-off-by Marc-André Lureau <[email protected]>--- qemu-char.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-)qemu-char.c +2
-3@@ -4143,15 +4144,17 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, goto err; } -for (i = backends; i; i = i->next) { - cd = i->data; - +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i];@@ -4368,11 +4371,15 @@ qmp_prepend_backend(ChardevBackendInfoList *list, const char *name)ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp)
qemu-char.c qmp_prepend_backend(ChardevBackendInfoList *list, const char *name) · line 4379
Quoted 10 lines
qemu-char.c +6
-2{ChardevBackendInfoList *backend_list =NULL ; -CharDriver *c; -GSList *i; +const CharDriver *c; +int i; + +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + c = backends[i]; +if (!c) {
Worth using the name 'cd' everywhere for consistency?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 7/20 char: move callbacks in CharDriver
In reply to Marc-André LureauThis makes the code more declarative, and avoids duplicating the information on all instances.
--- include/sysemu/char.h | 46 ++--- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 8 +- gdbstub.c | 7 +- hw/bt/hci-csr.c | 8 +- qemu-char.c | 479 ++++++++++++++++++++++++++++++-------------------- spice-qemu-char.c | 32 ++-- ui/console.c | 28 +-- ui/gtk.c | 11 +- 10 files changed, 381 insertions(+), 260 deletions(-)
include/sysemu/char.h +26 -20
@@ -85,24 +85,11 @@ typedef struct CharBackend {int fe_open; } CharBackend; +typedef struct CharDriver CharDriver ; +struct CharDriverState { +const CharDriver *driver;QemuMutex chr_write_lock; -int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); -int (*chr_sync_read)(struct CharDriverState *s, -const uint8_t *buf,int len); -GSource *(*chr_add_watch)(struct CharDriverState *s,GIOCondition cond); -void (*chr_update_read_handler)(struct CharDriverState *s, -GMainContext *context); -int (*chr_ioctl)(struct CharDriverState *s,int cmd,void *arg); -int (*get_msgfds)(struct CharDriverState *s,int * fds,int num); -int (*set_msgfds)(struct CharDriverState *s,int *fds,int num); -int (*chr_add_client)(struct CharDriverState *chr,int fd); -int (*chr_wait_connected)(struct CharDriverState *chr,Error **errp); -void (*chr_free)(struct CharDriverState *chr); -void (*chr_disconnect)(struct CharDriverState *chr); -void (*chr_accept_input)(struct CharDriverState *chr); -void (*chr_set_echo)(struct CharDriverState *chr,bool echo); -void (*chr_set_fe_open)(struct CharDriverState *chr,int fe_open);CharBackend *be;void *opaque;char *label;
@@ -125,7 +112,8 @@ struct CharDriverState {* * Returns: a newly allocated CharDriverState, or NULL on error. */ -CharDriverState *qemu_chr_alloc (ChardevCommon *backend,Error **errp); +CharDriverState *qemu_chr_alloc (const CharDriver *driver, +ChardevCommon *backend,Error **errp);/** * @qemu_chr_new_from_opts:
@@ -475,15 +463,33 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef struct CharDriver { +struct CharDriver {ChardevBackendKind kind;const char *alias;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); -CharDriverState *(*create)(const char *id, +CharDriverState *(*create)(const CharDriver *driver, +const char *id,ChardevBackend *backend,ChardevReturn *ret,bool *be_opened,Error **errp); -}CharDriver ; + +int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); +int (*chr_sync_read)(struct CharDriverState *s, +const uint8_t *buf,int len); +GSource *(*chr_add_watch)(struct CharDriverState *s,GIOCondition cond); +void (*chr_update_read_handler)(struct CharDriverState *s, +GMainContext *context); +int (*chr_ioctl)(struct CharDriverState *s,int cmd,void *arg); +int (*get_msgfds)(struct CharDriverState *s,int * fds,int num); +int (*set_msgfds)(struct CharDriverState *s,int *fds,int num); +int (*chr_add_client)(struct CharDriverState *chr,int fd); +int (*chr_wait_connected)(struct CharDriverState *chr,Error **errp); +void (*chr_free)(struct CharDriverState *chr); +void (*chr_disconnect)(struct CharDriverState *chr); +void (*chr_accept_input)(struct CharDriverState *chr); +void (*chr_set_echo)(struct CharDriverState *chr,bool echo); +void (*chr_set_fe_open)(struct CharDriverState *chr,int fe_open); +};void register_char_driver (const CharDriver *driver);
backends/baum.c +6 -5
@@ -622,7 +622,8 @@ static void baum_free(struct CharDriverState *chr)g_free (baum); } -static CharDriverState *chr_baum_init(const char *id, +static CharDriverState *chr_baum_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -633,7 +634,7 @@ static CharDriverState *chr_baum_init(const char *id,CharDriverState *chr;brlapi_handle_t *handle; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; }
@@ -641,9 +642,6 @@ static CharDriverState *chr_baum_init(const char *id, baum->chr = chr; chr->opaque = baum; - chr->chr_write = baum_write; - chr->chr_accept_input = baum_accept_input; - chr->chr_free = baum_free; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -674,6 +672,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, + .chr_write = baum_write, + .chr_accept_input = baum_accept_input, + .chr_free = baum_free, };register_char_driver (&driver);
backends/msmouse.c +6 -5
@@ -148,7 +148,8 @@ static QemuInputHandler msmouse_handler = { .sync = msmouse_input_sync, }; -static CharDriverState *qemu_chr_open_msmouse(const char *id, +static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -158,13 +159,10 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,MouseState *mouse;CharDriverState *chr; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = msmouse_chr_write; - chr->chr_free = msmouse_chr_free; - chr->chr_accept_input = msmouse_chr_accept_input; *be_opened = false; mouse =g_new0 (MouseState,1 );
@@ -182,6 +180,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, + .chr_write = msmouse_chr_write, + .chr_accept_input = msmouse_chr_accept_input, + .chr_free = msmouse_chr_free, };register_char_driver (&driver); }
backends/testdev.c +5 -3
@@ -109,7 +109,8 @@ static void testdev_free(struct CharDriverState *chr)g_free (testdev); } -static CharDriverState *chr_testdev_init(const char *id, +static CharDriverState *chr_testdev_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -121,9 +122,8 @@ static CharDriverState *chr_testdev_init(const char *id, testdev =g_new0 (TestdevCharState,1 ); testdev->chr = chr =g_new0 (CharDriverState,1 ); + chr->driver = driver; chr->opaque = testdev; - chr->chr_write = testdev_write; - chr->chr_free = testdev_free;return chr; }
@@ -133,6 +133,8 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, + .chr_write = testdev_write, + .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +5 -2
@@ -1730,6 +1730,10 @@ int gdbserver_start(const char *device)CharDriverState *chr =NULL ;CharDriverState *mon_chr;ChardevCommon common = {0 }; +static const CharDriver driver = { + .kind =-1 , + .chr_write = gdb_monitor_write, + };if (!device)return -1 ;
@@ -1762,8 +1766,7 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&common, &error_abort); - mon_chr->chr_write = gdb_monitor_write; + mon_chr =qemu_chr_alloc (&driver, &common, &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
hw/bt/hci-csr.c +6 -2
@@ -462,12 +462,16 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) { +static const CharDriver hci_driver = { + .kind =-1 , + .chr_write = csrhci_write, + .chr_ioctl = csrhci_ioctl, + };struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); s->chr.opaque = s; - s->chr.chr_write = csrhci_write; - s->chr.chr_ioctl = csrhci_ioctl; + s->chr.driver = &hci_driver; s->hci =qemu_next_hci (); s->hci->opaque = s;
qemu-char.c +284 -195
1,027 lines not on this page · raw message
spice-qemu-char.c +19 -13
@@ -260,16 +260,15 @@ static void spice_chr_accept_input(struct CharDriverState *chr)spice_server_char_device_wakeup (&s->sin); } -static CharDriverState *chr_open (const char *subtype, -void (*set_fe_open)(struct CharDriverState *, -int ), +static CharDriverState *chr_open (const CharDriver *driver, +const char *subtype,ChardevCommon *backend,Error **errp) {CharDriverState *chr;SpiceCharDriver *s; - chr =qemu_chr_alloc (backend, errp); + chr =qemu_chr_alloc (driver, backend, errp);if (!chr) {return NULL ; }
@@ -278,18 +277,14 @@ static CharDriverState *chr_open(const char *subtype, s->active = false; s->sin.subtype =g_strdup (subtype); chr->opaque = s; - chr->chr_write = spice_chr_write; - chr->chr_add_watch = spice_chr_add_watch; - chr->chr_free = spice_chr_free; - chr->chr_set_fe_open = set_fe_open; - chr->chr_accept_input = spice_chr_accept_input;QLIST_INSERT_HEAD (&spice_chars, s, next);return chr; } -static CharDriverState *qemu_chr_open_spice_vmc(const char *id, +static CharDriverState *qemu_chr_open_spice_vmc(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -312,11 +307,12 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id, } *be_opened = false; -return chr_open (type, spice_vmc_set_fe_open, common, errp); +return chr_open (driver, type, common, errp); }#if SPICE_SERVER_VERSION >=0x000c02 -static CharDriverState *qemu_chr_open_spice_port(const char *id, +static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -333,7 +329,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id,return NULL ; } - chr =chr_open ("port" , spice_port_set_fe_open, common, errp); + chr =chr_open (driver,"port" , common, errp);if (!chr) {return NULL ; }
@@ -393,11 +389,21 @@ static void register_types(void) .kind = CHARDEV_BACKEND_KIND_SPICEVMC, .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_vmc_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };static const CharDriver port_driver = { .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_port_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };register_char_driver (&vmc_driver);register_char_driver (&port_driver);
ui/console.c +17 -11
@@ -1051,6 +1051,10 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)QemuConsole *s = chr->opaque;int i; +if (!s->ds) { +return 0 ; + } + s->update_x0 = s->width *FONT_WIDTH ; s->update_y0 = s->height *FONT_HEIGHT ; s->update_x1 =0 ;
@@ -2000,8 +2004,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) s = chr->opaque; - chr->chr_write = console_puts; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2048,6 +2050,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)qemu_chr_be_generic_open (chr); } +static const CharDriver vc_driver; +static CharDriverState *text_console_init (ChardevVC *vc,Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2056,7 +2060,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)unsigned width =0 ;unsigned height =0 ; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&vc_driver, common, errp);if (!chr) {return NULL ; }
@@ -2089,7 +2093,6 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) s->chr = chr; chr->opaque = s; - chr->chr_set_echo = text_console_set_echo;if (display_state) {text_console_do_init (chr, display_state);
@@ -2099,7 +2102,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)static VcHandler *vc_handler = text_console_init; -static CharDriverState *vc_init (const char *id,ChardevBackend *backend, +static CharDriverState *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend,ChardevReturn *ret,bool *be_opened,Error **errp) {
@@ -2191,14 +2195,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + .chr_write = console_puts, + .chr_set_echo = text_console_set_echo, +}; +static void register_types (void ) { -static const CharDriver vc_driver = { - .kind =CHARDEV_BACKEND_KIND_VC , - .parse = qemu_chr_parse_vc, - .create = vc_init, - }; -type_register_static (&qemu_console_info);register_char_driver (&vc_driver); }
ui/gtk.c +7 -4
@@ -1703,6 +1703,12 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) { +static const CharDriver gd_vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, + }; +ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr;
@@ -1711,14 +1717,11 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&gd_vc_driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = gd_vc_chr_write; - chr->chr_set_echo = gd_vc_chr_set_echo; -/* Temporary, until gd_vc_vte_init runs. */ chr->opaque =g_new0 (VirtualConsole,1 );
Signature · 1 line
2.11.0
PATCH v2 8/20 char: fold single-user functions in caller
In reply to Marc-André LureauThis shortens the code a bit.
--- qemu-char.c | 95 +++++++++++++++++++------------------------------------------ 1 file changed, 29 insertions(+), 66 deletions(-)
qemu-char.c +29 -66
@@ -1891,22 +1891,6 @@ static void qemu_chr_free_tty(CharDriverState *chr) {fd_chr_free (chr); } - -static CharDriverState *qemu_chr_open_tty_fd (const CharDriver *driver, -int fd, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr; - -tty_serial_init (fd,115200 ,'N' ,8 ,1 ); - chr =qemu_chr_open_fd (driver, fd, fd, backend, errp); -if (!chr) { -return NULL ; - } -return chr; -}#endif /* __linux__ || __sun__ */ #if defined(__linux__)
@@ -2327,29 +2311,6 @@ static int win_chr_poll(void *opaque)return 0 ; } -static CharDriverState *qemu_chr_open_win_path (const CharDriver *driver, -const char *filename, -ChardevCommon *backend, -Error **errp) -{ -CharDriverState *chr; -WinCharState *s; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (WinCharState,1 ); - chr->opaque = s; - -if (win_chr_init (chr, filename, errp) <0 ) { -g_free (s); -qemu_chr_free_common (chr); -return NULL ; - } -return chr; -} -static int win_chr_pipe_poll (void *opaque) {CharDriverState *chr = opaque;
@@ -2806,30 +2767,6 @@ static void udp_chr_free(CharDriverState *chr)qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); } -static CharDriverState *qemu_chr_open_udp (const CharDriver *driver, -QIOChannelSocket *sioc, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr =NULL ; -NetCharDriver *s =NULL ; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (NetCharDriver,1 ); - - s->ioc =QIO_CHANNEL (sioc); - s->bufcnt =0 ; - s->bufptr =0 ; - chr->opaque = s; -/* be isn't opened until we get a connection */ - *be_opened = false; -return chr; -} -/***********************************************************/ /* TCP Net console */
@@ -4612,8 +4549,23 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, {ChardevHostdev *serial = backend->u.serial.data;ChardevCommon *common =qapi_ChardevHostdev_base (serial); +CharDriverState *chr; +WinCharState *s; + + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } -return qemu_chr_open_win_path (driver, serial->device, common, errp); + s =g_new0 (WinCharState,1 ); + chr->opaque = s; +if (win_chr_init (chr, serial->device, errp) <0 ) { +g_free (s); +qemu_chr_free_common (chr); +return NULL ; + } + +return chr; }#else /* WIN32 */
@@ -4682,8 +4634,9 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, return NULL; }qemu_set_nonblock (fd); +tty_serial_init (fd,115200 ,'N' ,8 ,1 ); -return qemu_chr_open_tty_fd (driver, fd, common, be_opened, errp); +return qemu_chr_open_fd (driver, fd, fd, common, errp); }#endif
@@ -4939,6 +4892,7 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;CharDriverState *chr; +NetCharDriver *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4947,12 +4901,21 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,return NULL ; } - chr =qemu_chr_open_udp (driver, sioc, common, be_opened, errp); + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } name =g_strdup_printf ("chardev-udp-%s" , chr->label);qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); + s =g_new0 (NetCharDriver,1 ); + s->ioc =QIO_CHANNEL (sioc); + chr->opaque = s; +/* be isn't opened until we get a connection */ + *be_opened = false; +return chr; }
Signature · 1 line
2.11.0
PATCH v2 9/20 char: introduce generic qemu_chr_get_kind()
In reply to Marc-André LureauThis allows to remove the "is_mux" field from CharDriverState.
--- include/sysemu/char.h | 15 +++++++++++++-- monitor.c | 2 +- qemu-char.c | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-)
include/sysemu/char.h +13 -2
@@ -96,7 +96,6 @@ struct CharDriverState {char *filename;int logfd;int be_open; -int is_mux;guint fd_in_tag;bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );
@@ -455,7 +454,19 @@ void qemu_chr_be_generic_open(CharDriverState *s);void qemu_chr_fe_accept_input (CharBackend *be);int qemu_chr_add_client (CharDriverState *s,int fd);CharDriverState *qemu_chr_find (const char *name); -bool chr_is_ringbuf (const CharDriverState *chr); + +/** +* @qemu_chr_get_kind: +* +* Returns the kind of char backend, or -1 if unspecified. +*/ +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr); + +static inline bool qemu_chr_is_ringbuf (const CharDriverState *chr) +{ +return qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_RINGBUF || +qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MEMORY ; +}bool qemu_chr_has_feature (CharDriverState *chr,CharDriverFeature feature);
monitor.c +1 -1
@@ -3194,7 +3194,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {CharDriverState *chr =qemu_chr_find (chr_info->label); -if (chr &&chr_is_ringbuf (chr)) { +if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +10 -11
@@ -781,7 +781,7 @@ static void muxes_realize_done(Notifier *notifier, void *unused)CharDriverState *chr; QTAILQ_FOREACH(chr, &chardevs, next) { -if (chr->is_mux) { +if (qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = chr->opaque;int i;
@@ -888,7 +888,6 @@ static CharDriverState *qemu_chr_open_mux(const CharDriver *driver,* set of muxes */ *be_opened = muxes_realized; - chr->is_mux =1 ;if (!qemu_chr_fe_init (&d->chr, drv, errp)) {qemu_chr_free (chr);return NULL ;
@@ -906,7 +905,7 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp) {int tag =0 ; -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;if (d->mux_cnt >=MAX_MUX ) {
@@ -933,7 +932,7 @@ unavailable:static bool qemu_chr_is_busy (CharDriverState *s) { -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;return d->mux_cnt >=0 ; }else {
@@ -950,7 +949,7 @@ void qemu_chr_fe_deinit(CharBackend *b)if (b->chr->be == b) { b->chr->be =NULL ; } -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = b->chr->opaque; d->backends[b->tag] =NULL ; }
@@ -1001,7 +1000,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, } } -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {mux_chr_set_handlers (s, context); } }
@@ -1012,7 +1011,7 @@ void qemu_chr_fe_take_focus(CharBackend *b)return ; } -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {mux_set_focus (b->chr, b->tag); } }
@@ -3557,9 +3556,9 @@ fail:return NULL ; } -bool chr_is_ringbuf (const CharDriverState *chr) +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr) { -return chr->driver->chr_write == ringbuf_chr_write; +return chr->driver->kind; } void qmp_ringbuf_write(const char *device, const char *data,
@@ -3577,7 +3576,7 @@ void qmp_ringbuf_write(const char *device, const char *data,return ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return ; }
@@ -3621,7 +3620,7 @@ char *qmp_ringbuf_read(const char *device, int64_t size,return NULL ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return NULL ; }
Signature · 1 line
2.11.0
PATCH v2 10/20 char: use a feature bit for replay
In reply to Marc-André LureauUse a feature flag rather than a structure field for "replay".
--- include/sysemu/char.h | 3 ++- qemu-char.c | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-)
include/sysemu/char.h +2 -1
@@ -69,6 +69,8 @@ typedef enum {/* Whether it is possible to send/recv file descriptors * over the data channel */ QEMU_CHAR_FEATURE_FD_PASS , +/* Whether replay or record mode is enabled */ +QEMU_CHAR_FEATURE_REPLAY ,QEMU_CHAR_FEATURE_LAST , } CharDriverFeature;
@@ -97,7 +99,6 @@ struct CharDriverState {int logfd;int be_open;guint fd_in_tag; -bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );QTAILQ_ENTRY (CharDriverState) next; };
qemu-char.c +20 -13
@@ -277,6 +277,11 @@ static int qemu_chr_fe_write_buffer(CharDriverState *s, const uint8_t *buf, intreturn res; } +static bool qemu_chr_replay (CharDriverState *chr) +{ +return qemu_chr_has_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); +} +int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len) {CharDriverState *s = be->chr;
@@ -286,7 +291,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {int offset;replay_char_write_event_load (&ret, &offset);assert (offset <= len);
@@ -303,7 +308,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)qemu_mutex_unlock (&s->chr_write_lock); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (ret, ret <0 ?0 : ret); }
@@ -315,7 +320,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)int offset;int res; -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {replay_char_write_event_load (&res, &offset);assert (offset <= len);qemu_chr_fe_write_buffer (s, buf, offset, &offset);
@@ -324,7 +329,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len) res =qemu_chr_fe_write_buffer (s, buf, len, &offset); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (res, offset); }
@@ -355,7 +360,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {return replay_char_read_all_load (buf); }
@@ -372,7 +377,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) }if (res <0 ) { -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_error (res); }return res;
@@ -385,7 +390,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) } } -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_buf (buf, offset); }return offset;
@@ -396,7 +401,7 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)CharDriverState *s = be->chr;int res; -if (!s || !s->driver->chr_ioctl || s->replay) { +if (!s || !s->driver->chr_ioctl ||qemu_chr_replay (s)) { res = -ENOTSUP ; }else { res = s->driver->chr_ioctl (s, cmd, arg);
@@ -427,7 +432,7 @@ void qemu_chr_be_write_impl(CharDriverState *s, uint8_t *buf, int len)void qemu_chr_be_write (CharDriverState *s,uint8_t *buf,int len) { -if (s->replay) { +if (qemu_chr_replay (s)) {if (replay_mode ==REPLAY_MODE_PLAY ) {return ; }
@@ -442,7 +447,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)CharDriverState *s = be->chr;int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ; -if (s && s->replay) { +if (s &&qemu_chr_replay (s)) {fprintf (stderr,"Replay: get msgfd is not supported for serial devices yet\n" );exit (1 );
@@ -4247,8 +4252,10 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename)CharDriverState *chr; chr =qemu_chr_new_noreplay (label, filename);if (chr) { - chr->replay = replay_mode !=REPLAY_MODE_NONE ; -if (chr->replay && chr->driver->chr_ioctl) { +if (replay_mode !=REPLAY_MODE_NONE ) { +qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); + } +if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) {fprintf (stderr,"Replay: ioctl is not supported for serial devices yet\n" ); }
@@ -4995,7 +5002,7 @@ void qmp_chardev_remove(const char *id, Error **errp)error_setg (errp,"Chardev '%s' is busy" , id);return ; } -if (chr->replay) { +if (qemu_chr_replay (chr)) {error_setg (errp,"Chardev '%s' cannot be unplugged in record/replay mode" , id);return ;
Signature · 1 line
2.11.0
PATCH v2 11/20 char: allocate CharDriverState as a single object
In reply to Marc-André LureauUse a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver.
Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init().
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- include/sysemu/char.h | 2 +- backends/baum.c | 23 ++--- backends/msmouse.c | 16 +-- backends/testdev.c | 22 ++-- gdbstub.c | 1 + hw/bt/hci-csr.c | 10 +- qemu-char.c | 280 ++++++++++++++++++++++++++------------------------ spice-qemu-char.c | 39 +++---- ui/console.c | 21 ++-- ui/gtk.c | 30 ++++-- 10 files changed, 230 insertions(+), 214 deletions(-)
include/sysemu/char.h +1 -1
@@ -93,7 +93,6 @@ struct CharDriverState {const CharDriver *driver;QemuMutex chr_write_lock;CharBackend *be; -void *opaque;char *label;char *filename;int logfd;
@@ -484,6 +483,7 @@ struct CharDriver { ChardevBackend *backend, ChardevReturn *ret, bool *be_opened, Error **errp); +size_t instance_size;int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); int (*chr_sync_read)(struct CharDriverState *s,
backends/baum.c +10 -13
@@ -85,7 +85,7 @@#define BUF_SIZE 256 typedef struct { - CharDriverState *chr; + CharDriverState parent; brlapi_handle_t *brlapi; int brlapi_fd;
@@ -255,7 +255,7 @@ static int baum_deferred_init(BaumDriverState *baum)/* The serial port can receive more of our data */ static void baum_accept_input (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int room, first;if (!baum->out_buf_used)
@@ -281,22 +281,23 @@ static void baum_accept_input(struct CharDriverState *chr)/* We want to send a packet */ static void baum_write_packet (BaumDriverState *baum,const uint8_t *buf,int len) { +CharDriverState *chr = (CharDriverState *)baum;uint8_t io_buf[1 +2 * len], *cur = io_buf;int room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC ) *cur++ =ESC ; - room =qemu_chr_be_can_write (baum->chr); + room =qemu_chr_be_can_write (chr); len = cur - io_buf;if (len <= room) {/* Fits */ -qemu_chr_be_write (baum->chr, io_buf, len); +qemu_chr_be_write (chr, io_buf, len); }else {int first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ -qemu_chr_be_write (baum->chr, io_buf, room); +qemu_chr_be_write (chr, io_buf, room); len -= room; cur = io_buf + room;if (len >BUF_SIZE - baum->out_buf_used) {
@@ -471,7 +472,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)/* The other end is writing some data. Store it and try to interpret */ static int baum_write (CharDriverState *chr,const uint8_t *buf,int len) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int tocopy, cur, eaten, orig_len = len;if (!len)
@@ -612,14 +613,13 @@ static void baum_chr_read(void *opaque)static void baum_free (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;timer_free (baum->cellCount_timer);if (baum->brlapi) {brlapi__closeConnection (baum->brlapi);g_free (baum->brlapi); } -g_free (baum); } static CharDriverState *chr_baum_init(const CharDriver *driver,
@@ -638,10 +638,7 @@ static CharDriverState *chr_baum_init(const CharDriver *driver,if (!chr) {return NULL ; } - baum =g_malloc0 (sizeof (BaumDriverState)); - baum->chr = chr; - - chr->opaque = baum; + baum = (BaumDriverState *)chr; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -663,13 +660,13 @@ static CharDriverState *chr_baum_init(const CharDriver *driver, fail_handle:g_free (handle);g_free (chr); -g_free (baum);return NULL ; }static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (BaumDriverState), .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, .chr_write = baum_write,
backends/msmouse.c +8 -8
@@ -31,7 +31,8 @@#define MSMOUSE_HI2 (n) (((n) & 0xc0) >> 6) typedef struct { - CharDriverState *chr; + CharDriverState parent; + QemuInputHandlerState *hs; int axis[INPUT_AXIS__MAX]; bool btns[INPUT_BUTTON__MAX];
@@ -42,7 +43,7 @@ typedef struct {static void msmouse_chr_accept_input (CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;int len; len =qemu_chr_be_can_write (chr);
@@ -122,9 +123,10 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,static void msmouse_input_sync (DeviceState *dev) {MouseState *mouse = (MouseState *)dev; +CharDriverState *chr = (CharDriverState *)dev;msmouse_queue_event (mouse); -msmouse_chr_accept_input (mouse->chr); +msmouse_chr_accept_input (chr); }static int msmouse_chr_write (struct CharDriverState *s,const uint8_t *buf,int len)
@@ -135,10 +137,9 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, intstatic void msmouse_chr_free (struct CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;qemu_input_handler_unregister (mouse->hs); -g_free (mouse); }static QemuInputHandler msmouse_handler = {
@@ -165,12 +166,10 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, } *be_opened = false; - mouse =g_new0 (MouseState,1 ); + mouse = (MouseState *)chr; mouse->hs =qemu_input_handler_register ((DeviceState *)mouse, &msmouse_handler); - mouse->chr = chr; - chr->opaque = mouse;return chr; }
@@ -178,6 +177,7 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (MouseState), .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, .chr_write = msmouse_chr_write,
backends/testdev.c +6 -16
@@ -30,7 +30,8 @@#define BUF_SIZE 32typedef struct { -CharDriverState *chr; +CharDriverState parent; +uint8_t in_buf[32 ];int in_buf_used; }TestdevCharState ;
@@ -79,7 +80,7 @@ static int testdev_eat_packet(TestdevCharState *testdev)/* The other end is writing some data. Store it and try to interpret */ static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = chr->opaque; +TestdevCharState *testdev = (TestdevCharState *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -102,13 +103,6 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static void testdev_free (struct CharDriverState *chr) -{ -TestdevCharState *testdev = chr->opaque; - -g_free (testdev); -} - static CharDriverState *chr_testdev_init(const CharDriver *driver, const char *id, ChardevBackend *backend,
@@ -116,14 +110,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,bool *be_opened, Error **errp) { - TestdevCharState *testdev; -CharDriverState *chr; - - testdev =g_new0 (TestdevCharState,1 ); - testdev->chr = chr =g_new0 (CharDriverState,1 ); + TestdevCharState *testdev = g_new0(TestdevCharState, 1);; +CharDriverState *chr = (CharDriverState *)testdev; chr->driver = driver; - chr->opaque = testdev;return chr; }
@@ -131,10 +121,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (TestdevCharState), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write, - .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +1 -0
@@ -1731,6 +1731,7 @@ int gdbserver_start(const char *device)CharDriverState *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { + .instance_size =sizeof (CharDriverState), .kind =-1 , .chr_write = gdb_monitor_write, };
hw/bt/hci-csr.c +5 -5
@@ -28,11 +28,11 @@#include "hw/bt.h" struct csrhci_s { +CharDriverState chr;int enable;qemu_irq *pins;int pin_state;int modem_state; -CharDriverState chr;#define FIFO_LEN 4096int out_start;int out_len;
@@ -314,7 +314,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s)static int csrhci_write (struct CharDriverState *chr,const uint8_t *buf,int len) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *)chr;int total =0 ;if (!s->enable)
@@ -387,7 +387,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp; -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;int prev_state = s->modem_state;switch (cmd) {
@@ -455,7 +455,7 @@ static void csrhci_pins(void *opaque, int line, int level)qemu_irq *csrhci_pins_get (CharDriverState *chr) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; }
@@ -463,6 +463,7 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) {static const CharDriver hci_driver = { + .instance_size =sizeof (struct csrhci_s ), .kind =-1 , .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl,
@@ -470,7 +471,6 @@ CharDriverState *uart_hci_init(void)struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); - s->chr.opaque = s; s->chr.driver = &hci_driver; s->hci =qemu_next_hci ();
qemu-char.c +144 -136
1,101 lines not on this page · raw message
spice-qemu-char.c +21 -18
@@ -7,7 +7,8 @@ typedef struct SpiceCharDriver { - CharDriverState* chr; + CharDriverState parent; + SpiceCharDeviceInstance sin; bool active; bool blocked;
@@ -27,17 +28,18 @@ static QLIST_HEAD(, SpiceCharDriver) spice_chars =static int vmc_write (SpiceCharDeviceInstance *sin,const uint8_t *buf,int len) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;ssize_t out =0 ;ssize_t last_out;uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (scd->chr); +int can_write =qemu_chr_be_can_write (chr); last_out =MIN (len, can_write);if (last_out <=0 ) {break ; } -qemu_chr_be_write (scd->chr, p, last_out); +qemu_chr_be_write (chr, p, last_out); out += last_out; len -= last_out; p += last_out;
@@ -70,6 +72,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)static void vmc_event (SpiceCharDeviceInstance *sin,uint8_t event) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;int chr_event;switch (event) {
@@ -81,20 +84,21 @@ static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event) }trace_spice_vmc_event (chr_event); -qemu_chr_be_event (scd->chr, chr_event); +qemu_chr_be_event (chr, chr_event); }#endif static void vmc_state (SpiceCharDeviceInstance *sin,int connected) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd; -if ((scd->chr->be_open && connected) || - (!scd->chr->be_open && !connected)) { +if ((chr->be_open && connected) || + (!chr->be_open && !connected)) {return ; } -qemu_chr_be_event (scd->chr, +qemu_chr_be_event (chr, connected ?CHR_EVENT_OPENED :CHR_EVENT_CLOSED ); }
@@ -168,7 +172,7 @@ static GSourceFuncs SpiceCharSourceFuncs = {static GSource *spice_chr_add_watch (CharDriverState *chr,GIOCondition cond) { -SpiceCharDriver *scd = chr->opaque; +SpiceCharDriver *scd = (SpiceCharDriver *)chr;SpiceCharSource *src;assert (cond &G_IO_OUT );
@@ -182,7 +186,7 @@ static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)static int spice_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;int read_bytes;assert (s->datalen ==0 );
@@ -201,7 +205,7 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void spice_chr_free (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;vmc_unregister_interface (s);QLIST_REMOVE (s, next);
@@ -210,12 +214,11 @@ static void spice_chr_free(struct CharDriverState *chr)#if SPICE_SERVER_VERSION >=0x000c02 g_free ((char *)s->sin.portname);#endif -g_free (s); }static void spice_vmc_set_fe_open (struct CharDriverState *chr,int fe_open) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {vmc_register_interface (s); }else {
@@ -226,7 +229,7 @@ static void spice_vmc_set_fe_open(struct CharDriverState *chr, int fe_open)static void spice_port_set_fe_open (struct CharDriverState *chr,int fe_open) {#if SPICE_SERVER_VERSION >=0x000c02 -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {spice_server_port_event (&s->sin,SPICE_PORT_EVENT_OPENED );
@@ -255,7 +258,7 @@ static void print_allowed_subtypes(void)static void spice_chr_accept_input (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;spice_server_char_device_wakeup (&s->sin); }
@@ -272,11 +275,9 @@ static CharDriverState *chr_open(const CharDriver *driver,if (!chr) {return NULL ; } - s =g_malloc0 (sizeof (SpiceCharDriver)); - s->chr = chr; + s = (SpiceCharDriver *)chr; s->active = false; s->sin.subtype =g_strdup (subtype); - chr->opaque = s;QLIST_INSERT_HEAD (&spice_chars, s, next);
@@ -334,7 +335,7 @@ static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver,return NULL ; } *be_opened = false; - s = chr->opaque; + s = (SpiceCharDriver *)chr; s->sin.portname =g_strdup (name);return chr;
@@ -386,6 +387,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) {static const CharDriver vmc_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEVMC , .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc,
@@ -396,6 +398,7 @@ static void register_types(void) .chr_free = spice_chr_free, };static const CharDriver port_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port,
ui/console.c +15 -6
@@ -1046,9 +1046,15 @@ void console_select(unsigned int index) } } +typedef struct VCDriverState { +CharDriverState parent; +QemuConsole *console; +}VCDriverState ; +static int console_puts (CharDriverState *chr,const uint8_t *buf,int len) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int i;if (!s->ds) {
@@ -1958,7 +1964,8 @@ int qemu_console_get_height(QemuConsole *con, int fallback)static void text_console_set_echo (CharDriverState *chr,bool echo) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console; s->echo = echo; }
@@ -1998,12 +2005,11 @@ static const GraphicHwOps text_console_ops = {static void text_console_do_init (CharDriverState *chr,DisplayState *ds) { -QemuConsole *s; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int g_width =80 *FONT_WIDTH ;int g_height =24 *FONT_HEIGHT ; - s = chr->opaque; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2056,6 +2062,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr; +VCDriverState *drv;QemuConsole *s;unsigned width =0 ;unsigned height =0 ;
@@ -2092,7 +2099,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) } s->chr = chr; - chr->opaque = s; + drv = (VCDriverState *)chr; + drv->console = s;if (display_state) {text_console_do_init (chr, display_state);
@@ -2196,6 +2204,7 @@ static const TypeInfo qemu_console_info = { };static const CharDriver vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .parse = qemu_chr_parse_vc, .create = vc_init,
ui/gtk.c +19 -11
@@ -181,6 +181,12 @@ struct GtkDisplayState {bool ignore_keys; }; +typedef struct VCDriverState { +CharDriverState parent; +VirtualConsole *console; +bool echo; +}VCDriverState ; +static void gd_grab_pointer (VirtualConsole *vc,const char *reason);static void gd_ungrab_pointer (GtkDisplayState *s);static void gd_grab_keyboard (VirtualConsole *vc,const char *reason);
@@ -1685,7 +1691,8 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)static int gd_vc_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console;vte_terminal_feed (VTE_TERMINAL (vc->vte.terminal), (const char *)buf, len);return len;
@@ -1693,9 +1700,14 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void gd_vc_chr_set_echo (CharDriverState *chr,bool echo) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console; - vc->vte.echo = echo; +if (vc) { + vc->vte.echo = echo; + }else { + vcd->echo = echo; + } }static int nb_vcs;
@@ -1704,6 +1716,7 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) {static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .chr_write = gd_vc_chr_write, .chr_set_echo = gd_vc_chr_set_echo,
@@ -1722,9 +1735,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } -/* Temporary, until gd_vc_vte_init runs. */ - chr->opaque =g_new0 (VirtualConsole,1 ); - vcs[nb_vcs++] = chr;return chr;
@@ -1765,14 +1775,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,GtkWidget *box;GtkWidget *scrollbar;GtkAdjustment *vadjustment; -VirtualConsole *tmp_vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; vc->s = s; - vc->vte.echo = tmp_vc->vte.echo; - + vc->vte.echo = vcd->echo; vc->vte.chr = chr; - chr->opaque = vc; -g_free (tmp_vc); + vcd->console = vc;snprintf (buffer,sizeof (buffer),"vc%d" , idx); vc->label = g_strdup_printf("%s", vc->vte.chr->label
Signature · 1 line
2.11.0
PATCH v2 12/20 bt: use qemu_chr_alloc()
In reply to Marc-André LureauUse common allocator for CharDriverState.
Rename the now untouched parent field.
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- hw/bt/hci-csr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
hw/bt/hci-csr.c +13 -6
@@ -26,9 +26,10 @@#include "hw/irq.h" #include "sysemu/bt.h" #include "hw/bt.h" +#include "qapi/error.h" struct csrhci_s { -CharDriverState chr; +CharDriverState parent;int enable;qemu_irq *pins;int pin_state;
@@ -78,7 +79,8 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharBackend *be = s->chr.be; +CharDriverState *chr = (CharDriverState *)s; +CharBackend *be = chr->be;if (!s->enable || !s->out_len)return ;
@@ -468,10 +470,15 @@ CharDriverState *uart_hci_init(void) .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl, }; -struct csrhci_s *s = (struct csrhci_s *) -g_malloc0 (sizeof (struct csrhci_s )); +Error *err =NULL ; +ChardevCommon common = {0 , }; +CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +struct csrhci_s *s = (struct csrhci_s *)chr; - s->chr.driver = &hci_driver; +if (err) { +error_report_err (err); +return NULL ; + } s->hci =qemu_next_hci (); s->hci->opaque = s;
@@ -482,5 +489,5 @@ CharDriverState *uart_hci_init(void) s->pins =qemu_allocate_irqs (csrhci_pins, s, __csrhci_pins);csrhci_reset (s); -return &s->chr; +return chr; }
Signature · 1 line
2.11.0
PATCH v2 13/20 char: rename CharDriverState Chardev
In reply to Marc-André LureauPick a uniform chardev type name.
--- hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 94 ++--- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- backends/baum.c | 56 +-- backends/msmouse.c | 42 +- backends/rng-egd.c | 4 +- backends/testdev.c | 28 +- gdbstub.c | 12 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 14 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- monitor.c | 4 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 839 +++++++++++++++++++------------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 80 ++-- stubs/get-next-serial.c | 2 +- stubs/monitor-init.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 40 +- ui/gtk.c | 26 +- vl.c | 10 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- 81 files changed, 728 insertions(+), 725 deletions(-)
hw/lm32/lm32.h +2 -2
@@ -16,7 +16,7 @@ static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)return dev; } -static inline DeviceState *lm32_juart_init (CharDriverState *chr) +static inline DeviceState *lm32_juart_init (Chardev *chr) {DeviceState *dev;
@@ -29,7 +29,7 @@ static inline DeviceState *lm32_juart_init(CharDriverState *chr)static inline DeviceState *lm32_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
hw/lm32/milkymist-hw.h +1 -1
@@ -6,7 +6,7 @@static inline DeviceState *milkymist_uart_create (hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;
include/hw/arm/exynos4210.h +1 -1
@@ -131,7 +131,7 @@ void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq);#endif /* EXYNOS4210_H */
include/hw/arm/omap.h +3 -3
@@ -664,14 +664,14 @@ struct omap_uart_s;struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);struct omap_uart_s *omap2_uart_init (MemoryRegion *sysmem,struct omap_target_agent_s *ta,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);void omap_uart_reset (struct omap_uart_s *s); -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr); +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr);struct omap_mpuio_s ;qemu_irq *omap_mpuio_in_get (struct omap_mpuio_s *s);
include/hw/bt.h +2 -2
@@ -127,8 +127,8 @@ enum { csrhci_pin_wakeup, __csrhci_pins, }; -qemu_irq *csrhci_pins_get (CharDriverState *chr); -CharDriverState *uart_hci_init (void ); +qemu_irq *csrhci_pins_get (Chardev *chr); +Chardev *uart_hci_init (void );/* bt-l2cap.c */ struct bt_l2cap_device_s ;
include/hw/char/cadence_uart.h +1 -1
@@ -51,7 +51,7 @@ typedef struct {static inline DeviceState *cadence_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/escc.h +1 -1
@@ -5,7 +5,7 @@#define TYPE_ESCC "escc"#define ESCC_SIZE 4MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift); void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
include/hw/char/pl011.h +2 -2
@@ -17,7 +17,7 @@static inline DeviceState *pl011_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
@@ -34,7 +34,7 @@ static inline DeviceState *pl011_create(hwaddr addr,static inline DeviceState *pl011_luminary_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/serial.h +2 -2
@@ -88,11 +88,11 @@ void serial_set_frequency(SerialState *s, uint32_t frequency);/* legacy pre qom */ SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io); +Chardev *chr,MemoryRegion *system_io);SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end); +Chardev *chr,enum device_endian end);/* serial-isa.c */ #define TYPE_ISA_SERIAL "isa-serial"
include/hw/char/xilinx_uartlite.h +1 -1
@@ -17,7 +17,7 @@static inline DeviceState *xilinx_uartlite_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/cris/etraxfs.h +1 -1
@@ -48,7 +48,7 @@ etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr,static inline DeviceState *etraxfs_ser_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/devices.h +1 -1
@@ -65,6 +65,6 @@ qemu_irq tc6393xb_l3v_get(TC6393xbState *s);/* sm501.c */ void sm501_init (struct MemoryRegion *address_space_mem,uint32_t base,uint32_t local_mem_bytes,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);#endif
include/hw/i386/pc.h +1 -1
@@ -181,7 +181,7 @@ void parallel_hds_isa_init(ISABus *bus, int n);bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);/* i8259.c */
include/hw/m68k/mcf.h +2 -2
@@ -11,10 +11,10 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr, unsigned size);void mcf_uart_write (void *opaque,hwaddr addr,uint64_t val,unsigned size); -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr); +void *mcf_uart_init (qemu_irq irq,Chardev *chr);void mcf_uart_mm_init (struct MemoryRegion *sysmem,hwaddr base, -qemu_irq irq,CharDriverState *chr); +qemu_irq irq,Chardev *chr);/* mcf_intc.c */ qemu_irq *mcf_intc_init(struct MemoryRegion *sysmem,
include/hw/ppc/spapr_vio.h +1 -1
@@ -127,7 +127,7 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);VIOsPAPRDevice *vty_lookup (sPAPRMachineState *spapr,target_ulong reg);void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev); +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev);void spapr_vlan_create (VIOsPAPRBus *bus,NICInfo *nd);void spapr_vscsi_create (VIOsPAPRBus *bus);
include/hw/qdev-properties.h +1 -1
@@ -184,7 +184,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);void qdev_prop_set_int32 (DeviceState *dev,const char *name,int32_t value);void qdev_prop_set_uint64 (DeviceState *dev,const char *name,uint64_t value);void qdev_prop_set_string (DeviceState *dev,const char *name,const char *value); -void qdev_prop_set_chr (DeviceState *dev,const char *name,CharDriverState *value); +void qdev_prop_set_chr (DeviceState *dev,const char *name,Chardev *value);void qdev_prop_set_netdev (DeviceState *dev,const char *name,NetClientState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,BlockBackend *value,Error **errp);
include/hw/sh4/sh.h +1 -1
@@ -42,7 +42,7 @@ void tmu012_init(struct MemoryRegion *sysmem, hwaddr base,#define SH_SERIAL_FEAT_SCIF (1 << 0) void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
include/hw/sparc/grlib.h +1 -1
@@ -100,7 +100,7 @@ DeviceState *grlib_gptimer_create(hwaddr base,static inline DeviceState *grlib_apbuart_create (hwaddr base, -CharDriverState *serial, +Chardev *serial,qemu_irq irq) {DeviceState *dev;
include/hw/xen/xen.h +1 -1
@@ -37,7 +37,7 @@ int xen_is_pirq_msi(uint32_t msi_data);qemu_irq *xen_interrupt_controller_init (void ); -void xenstore_store_pv_console_info (int i,struct CharDriverState *chr); +void xenstore_store_pv_console_info (int i,struct Chardev *chr);void xen_hvm_init (PCMachineState *pcms,MemoryRegion **ram_memory);
include/monitor/monitor.h +1 -1
@@ -16,7 +16,7 @@ extern Monitor *cur_mon;bool monitor_cur_is_qmp (void ); -void monitor_init (CharDriverState *chr,int flags); +void monitor_init (Chardev *chr,int flags);void monitor_cleanup (void );int monitor_suspend (Monitor *mon);
include/qemu/typedefs.h +1 -1
@@ -17,7 +17,7 @@ typedef struct BlockBackendRootState BlockBackendRootState;typedef struct BlockDriverState BlockDriverState ;typedef struct BusClass BusClass ;typedef struct BusState BusState ; -typedef struct CharDriverState CharDriverState ; +typedef struct Chardev Chardev ;typedef struct CompatProperty CompatProperty ;typedef struct CPUAddressSpace CPUAddressSpace ;typedef struct CPUState CPUState ;
include/sysemu/char.h +47 -47
223 lines not on this page · raw message
include/sysemu/replay.h +2 -2
@@ -125,9 +125,9 @@ uint64_t blkreplay_next_id(void);/* Character device */ /*! Registers char driver to save it's events */ -void replay_register_char_driver (struct CharDriverState *chr); +void replay_register_char_driver (struct Chardev *chr);/*! Saves write to char device event to the log */ -void replay_chr_be_write (struct CharDriverState *s,uint8_t *buf,int len); +void replay_chr_be_write (struct Chardev *s,uint8_t *buf,int len);/*! Writes char write return value to the replay log. */ void replay_char_write_event_save (int res,int offset);/*! Reads char write return value from the replay log. */
include/sysemu/sysemu.h +2 -2
@@ -197,13 +197,13 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);#define MAX_SERIAL_PORTS 4 -extern CharDriverState *serial_hds[MAX_SERIAL_PORTS ]; +extern Chardev *serial_hds[MAX_SERIAL_PORTS ];/* parallel ports */ #define MAX_PARALLEL_PORTS 3 -extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; +extern Chardev *parallel_hds[MAX_PARALLEL_PORTS ];void hmp_usb_add (Monitor *mon,const QDict *qdict);void hmp_usb_del (Monitor *mon,const QDict *qdict);
include/ui/gtk.h +1 -1
@@ -64,7 +64,7 @@ typedef struct VirtualVteConsole {GtkWidget *box;GtkWidget *scrollbar;GtkWidget *terminal; -CharDriverState *chr; +Chardev *chr; bool echo; } VirtualVteConsole;#endif
include/ui/qemu-spice.h +1 -1
@@ -51,7 +51,7 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#if SPICE_SERVER_VERSION >=0x000c02 void qemu_spice_register_ports (void );#else -static inline CharDriverState *qemu_chr_open_spice_port (const char *name) +static inline Chardev *qemu_chr_open_spice_port (const char *name) {return NULL ; }#endif
backends/baum.c +29 -27
151 lines not on this page · raw message
backends/msmouse.c +21 -21
105 lines not on this page · raw message
backends/rng-egd.c +2 -2
@@ -86,7 +86,7 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)static void rng_egd_opened (RngBackend *b,Error **errp) {RngEgd *s =RNG_EGD (b); -CharDriverState *chr; +Chardev *chr;if (s->chr_name ==NULL ) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
@@ -125,7 +125,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)static char *rng_egd_get_chardev (Object *obj,Error **errp) {RngEgd *s =RNG_EGD (obj); -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);if (chr && chr->label) {return g_strdup (chr->label);
backends/testdev.c +14 -14
@@ -30,14 +30,14 @@#define BUF_SIZE 32typedef struct { -CharDriverState parent; +Chardev parent;uint8_t in_buf[32 ];int in_buf_used; -}TestdevCharState ; +}TestdevChardev ;/* Try to interpret a whole incoming packet */ -static int testdev_eat_packet (TestdevCharState *testdev) +static int testdev_eat_packet (TestdevChardev *testdev) {const uint8_t *cur = testdev->in_buf;int len = testdev->in_buf_used;
@@ -78,9 +78,9 @@ static int testdev_eat_packet(TestdevCharState *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) +static int testdev_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = (TestdevCharState *)chr; +TestdevChardev *testdev = (TestdevChardev *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -103,15 +103,15 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static CharDriverState *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static Chardev *chr_testdev_init (const CharDriver *driver, +const char *id, +ChardevBackend *backend, +ChardevReturn *ret, +bool *be_opened, +Error **errp) { -TestdevCharState *testdev =g_new0 (TestdevCharState,1 );; -CharDriverState *chr = (CharDriverState *)testdev; +TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; +Chardev *chr = (Chardev *)testdev; chr->driver = driver;
@@ -121,7 +121,7 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevCharState), + .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write,
gdbstub.c +6 -6
@@ -303,7 +303,7 @@ typedef struct GDBState {int running_state;#else CharBackend chr; -CharDriverState *mon_chr; +Chardev *mon_chr;#endif char syscall_buf[256 ];gdb_syscall_complete_cb current_syscall_cb;
@@ -1471,7 +1471,7 @@ void gdb_exit(CPUArchState *env, int code)GDBState *s;char buf[4 ];#ifndef CONFIG_USER_ONLY -CharDriverState *chr; +Chardev *chr;#endif s = gdbserver_state;
@@ -1696,7 +1696,7 @@ static void gdb_monitor_output(GDBState *s, const char *msg, int len)put_packet (s, buf); } -static int gdb_monitor_write (CharDriverState *chr,const uint8_t *buf,int len) +static int gdb_monitor_write (Chardev *chr,const uint8_t *buf,int len) {const char *p = (const char *)buf;int max_sz;
@@ -1727,11 +1727,11 @@ int gdbserver_start(const char *device) {GDBState *s;char gdbstub_device_name[128 ]; -CharDriverState *chr =NULL ; -CharDriverState *mon_chr; +Chardev *chr =NULL ; +Chardev *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { - .instance_size =sizeof (CharDriverState), + .instance_size =sizeof (Chardev), .kind =-1 , .chr_write = gdb_monitor_write, };
hw/arm/fsl-imx25.c +1 -1
@@ -118,7 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx31.c +1 -1
@@ -107,7 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx6.c +1 -1
@@ -187,7 +187,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/nseries.c +1 -1
@@ -786,7 +786,7 @@ static void n8x0_cbus_setup(struct n800_s *s)static void n8x0_uart_setup (struct n800_s *s) { -CharDriverState *radio =uart_hci_init (); +Chardev *radio =uart_hci_init ();qdev_connect_gpio_out (s->mpu->gpio,N8X0_BT_RESET_GPIO ,csrhci_pins_get (radio)[csrhci_pin_reset]);
hw/arm/omap2.c +1 -1
@@ -792,7 +792,7 @@ static const MemoryRegionOps omap_sti_fifo_ops = {static struct omap_sti_s *omap_sti_init (struct omap_target_agent_s *ta,MemoryRegion *sysmem,hwaddr channel_base,qemu_irq irq,omap_clk clk, -CharDriverState *chr) +Chardev *chr) { struct omap_sti_s *s = g_new0(struct omap_sti_s, 1);
hw/arm/pxa2xx.c +1 -1
@@ -2024,7 +2024,7 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,hwaddr base, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma, - CharDriverState *chr) + Chardev *chr) { DeviceState *dev;SysBusDevice *sbd;
hw/arm/virt.c +1 -1
@@ -590,7 +590,7 @@ static void create_gic(VirtMachineState *vms, qemu_irq *pic) }static void create_uart (const VirtMachineState *vms,qemu_irq *pic,int uart, -MemoryRegion *mem,CharDriverState *chr) +MemoryRegion *mem,Chardev *chr) {char *nodename;hwaddr base = vms->memmap[uart].base;
hw/bt/hci-csr.c +7 -7
@@ -29,7 +29,7 @@#include "qapi/error.h" struct csrhci_s { -CharDriverState parent; +Chardev parent;int enable;qemu_irq *pins;int pin_state;
@@ -79,7 +79,7 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharDriverState *chr = (CharDriverState *)s; +Chardev *chr = (Chardev *)s;CharBackend *be = chr->be;if (!s->enable || !s->out_len)
@@ -313,7 +313,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s) s->in_hdr =INT_MAX ; } -static int csrhci_write (struct CharDriverState *chr, +static int csrhci_write (struct Chardev *chr,const uint8_t *buf,int len) {struct csrhci_s *s = (struct csrhci_s *)chr;
@@ -386,7 +386,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,csrhci_fifo_wake (s); } -static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) +static int csrhci_ioctl (struct Chardev *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp;struct csrhci_s *s = (struct csrhci_s *) chr;
@@ -455,14 +455,14 @@ static void csrhci_pins(void *opaque, int line, int level) } } -qemu_irq *csrhci_pins_get (CharDriverState *chr) +qemu_irq *csrhci_pins_get (Chardev *chr) {struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; } -CharDriverState *uart_hci_init (void ) +Chardev *uart_hci_init (void ) {static const CharDriver hci_driver = { .instance_size =sizeof (struct csrhci_s ),
@@ -472,7 +472,7 @@ CharDriverState *uart_hci_init(void) };Error *err =NULL ;ChardevCommon common = {0 , }; -CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +Chardev *chr =qemu_chr_alloc (&hci_driver, &common, &err);struct csrhci_s *s = (struct csrhci_s *)chr;if (err) {
hw/char/escc.c +1 -1
@@ -689,7 +689,7 @@ static const VMStateDescription vmstate_escc = { };MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift) {DeviceState *dev;
hw/char/exynos4210_uart.c +1 -1
@@ -586,7 +586,7 @@ static const VMStateDescription vmstate_exynos4210_uart = {DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq) {DeviceState *dev;
hw/char/imx_serial.c +1 -1
@@ -170,7 +170,7 @@ static void imx_serial_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) {IMXSerialState *s = (IMXSerialState *)opaque; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);unsigned char ch; DPRINTF("write(offset=0x%" HWADDR_PRIx ", value = 0x%x) to %s\n",
hw/char/mcf_uart.c +2 -2
@@ -275,7 +275,7 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)mcf_uart_push_byte (s, buf[0 ]); } -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr) +void *mcf_uart_init (qemu_irq irq,Chardev *chr) {mcf_uart_state *s;
@@ -300,7 +300,7 @@ static const MemoryRegionOps mcf_uart_ops = {void mcf_uart_mm_init (MemoryRegion *sysmem,hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {mcf_uart_state *s;
hw/char/omap_uart.c +3 -3
@@ -54,7 +54,7 @@ void omap_uart_reset(struct omap_uart_s *s)struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr) +const char *label,Chardev *chr) { struct omap_uart_s *s = g_new0(struct omap_uart_s, 1);
@@ -163,7 +163,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,struct omap_target_agent_s *ta, qemu_irq irq, omap_clk fclk, omap_clk iclk, qemu_irq txdma, qemu_irq rxdma, - const char *label, CharDriverState *chr) + const char *label, Chardev *chr) { hwaddr base = omap_l4_attach(ta, 0, NULL); struct omap_uart_s *s = omap_uart_init(base, irq,
@@ -178,7 +178,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,return s; } -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr) +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr) {/* TODO: Should reuse or destroy current s->serial */ s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
hw/char/parallel.c +1 -1
@@ -603,7 +603,7 @@ static const MemoryRegionOps parallel_mm_ops = {/* If fd is zero, it means that the parallel device uses the console */ bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {ParallelState *s;
hw/char/serial-isa.c +1 -1
@@ -121,7 +121,7 @@ static void serial_register_types(void)type_init (serial_register_types) -static void serial_isa_init(ISABus *bus, int index, CharDriverState *chr) +static void serial_isa_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/char/serial.c +2 -2
@@ -927,7 +927,7 @@ const MemoryRegionOps serial_io_ops = { };SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io) +Chardev *chr,MemoryRegion *system_io) {SerialState *s;
@@ -983,7 +983,7 @@ static const MemoryRegionOps serial_mm_ops[3] = {SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end) +Chardev *chr,enum device_endian end) {SerialState *s;
hw/char/sh_serial.c +1 -1
@@ -356,7 +356,7 @@ static const MemoryRegionOps sh_serial_ops = { void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
hw/char/spapr_vty.c +1 -1
@@ -141,7 +141,7 @@ static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_SUCCESS ; } -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev) +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev) {DeviceState *dev;
hw/char/virtio-console.c +1 -1
@@ -168,7 +168,7 @@ static void virtconsole_realize(DeviceState *dev, Error **errp)VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (dev);VirtConsole *vcon =VIRTIO_CONSOLE (dev);VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (dev); -CharDriverState *chr =qemu_chr_fe_get_driver (&vcon->chr); +Chardev *chr =qemu_chr_fe_get_driver (&vcon->chr);if (port->id ==0 && !k->is_console) { error_setg(errp, "Port number 0 on virtio-serial devices reserved "
hw/core/qdev-properties-system.c +2 -2
@@ -179,7 +179,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,Error *local_err =NULL ;Property *prop = opaque;CharBackend *be =qdev_get_prop_ptr (dev, prop); -CharDriverState *s; +Chardev *s;char *str;if (dev->realized) {
@@ -411,7 +411,7 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name, }void qdev_prop_set_chr (DeviceState *dev,const char *name, -CharDriverState *value) +Chardev *value) {assert (!value || value->label); object_property_set_str(OBJECT(dev),
hw/display/milkymist-tmu2.c +1 -1
@@ -85,7 +85,7 @@ struct MilkymistTMU2State {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/display/sm501.c +1 -1
@@ -1392,7 +1392,7 @@ static const GraphicHwOps sm501_ops = { };void sm501_init (MemoryRegion *address_space_mem,uint32_t base, -uint32_t local_mem_bytes,qemu_irq irq,CharDriverState *chr) +uint32_t local_mem_bytes,qemu_irq irq,Chardev *chr) {SM501State * s;DeviceState *dev;
hw/isa/isa-bus.c +1 -1
@@ -287,7 +287,7 @@ MemoryRegion *isa_address_space_io(ISADevice *dev)type_init (isabus_register_types) -static void parallel_init(ISABus *bus, int index, CharDriverState *chr) +static void parallel_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/isa/pc87312.c +1 -1
@@ -268,7 +268,7 @@ static void pc87312_realize(DeviceState *dev, Error **errp)DeviceState *d;ISADevice *isa;ISABus *bus; -CharDriverState *chr; +Chardev *chr;DriveInfo *drive;char name[5 ];int i;
hw/mips/mips_malta.c +2 -2
@@ -551,10 +551,10 @@ static void malta_fgpa_display_event(void *opaque, int event) }static MaltaFPGAState *malta_fpga_init (MemoryRegion *address_space, -hwaddr base,qemu_irq uart_irq,CharDriverState *uart_chr) +hwaddr base,qemu_irq uart_irq,Chardev *uart_chr) {MaltaFPGAState *s; -CharDriverState *chr; +Chardev *chr; s = (MaltaFPGAState *)g_malloc0 (sizeof (MaltaFPGAState));
hw/misc/ivshmem.c +1 -1
@@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem, &error_abort); }else { -CharDriverState *chr =qemu_chr_fe_get_driver (&s->server_chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->server_chr);assert (chr); IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
hw/misc/milkymist-pfpu.c +1 -1
@@ -125,7 +125,7 @@ struct MilkymistPFPUState {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/usb/ccid-card-passthru.c +1 -1
@@ -264,7 +264,7 @@ static void ccid_card_vscard_handle_message(PassthruState *card,static void ccid_card_vscard_drop_connection (PassthruState *card) { -CharDriverState *chr =qemu_chr_fe_get_driver (&card->cs); +Chardev *chr =qemu_chr_fe_get_driver (&card->cs);qemu_chr_fe_deinit (&card->cs);qemu_chr_delete (chr);
hw/usb/dev-serial.c +3 -3
@@ -483,7 +483,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp) {USBSerialState *s =USB_SERIAL_DEV (dev);Error *local_err =NULL ; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->cs); +Chardev *chr =qemu_chr_fe_get_driver (&s->cs);usb_desc_create_serial (dev);usb_desc_init (dev);
@@ -512,7 +512,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)static USBDevice *usb_serial_init (USBBus *bus,const char *filename) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv;uint32_t vendorid =0 , productid =0 ;char label[32 ];static int index;
@@ -564,7 +564,7 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)static USBDevice *usb_braille_init (USBBus *bus,const char *unused) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv; cdrv =qemu_chr_new ("braille" ,"braille" );if (!cdrv)
hw/usb/redirect.c +2 -2
@@ -284,7 +284,7 @@ static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,static int usbredir_write (void *priv,uint8_t *data,int count) {USBRedirDevice *dev = priv; -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);int r;if (!chr->be_open) {
@@ -1430,7 +1430,7 @@ static void usbredir_cleanup_device_queues(USBRedirDevice *dev)static void usbredir_handle_destroy (USBDevice *udev) {USBRedirDevice *dev =USB_REDIRECT (udev); -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);qemu_chr_fe_deinit (&dev->cs);qemu_chr_delete (chr);
monitor.c +2 -2
@@ -3193,7 +3193,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)ChardevInfo *chr_info = list->value;if (!strncmp (chr_info->label, str, len)) { -CharDriverState *chr =qemu_chr_find (chr_info->label); +Chardev *chr =qemu_chr_find (chr_info->label);if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); }
@@ -3981,7 +3981,7 @@ static void __attribute__((constructor)) monitor_lock_init(void)qemu_mutex_init (&monitor_lock); } -void monitor_init (CharDriverState *chr,int flags) +void monitor_init (Chardev *chr,int flags) {static int is_first_init =1 ;Monitor *mon;
net/colo-compare.c +2 -2
@@ -564,7 +564,7 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)* Return 0 is success. * Return 1 is failed. */ -static int find_and_check_chardev (CharDriverState **chr, +static int find_and_check_chardev (Chardev **chr,char *chr_name,Error **errp) {
@@ -611,7 +611,7 @@ static void check_old_packet_regular(void *opaque)static void colo_compare_complete (UserCreatable *uc,Error **errp) {CompareState *s =COLO_COMPARE (uc); -CharDriverState *chr; +Chardev *chr;char thread_name[64 ];static int compare_id;
net/filter-mirror.c +2 -2
@@ -191,7 +191,7 @@ static void filter_redirector_cleanup(NetFilterState *nf)static void filter_mirror_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_MIRROR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->outdev) { error_setg(errp, "filter mirror needs 'outdev' "
@@ -220,7 +220,7 @@ static void redirector_rs_finalize(SocketReadState *rs)static void filter_redirector_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->indev && !s->outdev) { error_setg(errp, "filter redirector needs 'indev' or "
net/slirp.c +1 -1
@@ -748,7 +748,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, } }else {Error *err =NULL ; -CharDriverState *chr =qemu_chr_new (buf, p); +Chardev *chr =qemu_chr_new (buf, p);if (!chr) {error_report ("could not open guest forwarding device '%s'" , buf);
net/vhost-user.c +5 -5
@@ -195,7 +195,7 @@ static void net_vhost_user_event(void *opaque, int event)const char *name = opaque;NetClientState *ncs[MAX_QUEUE_NUM ];VhostUserState *s; -CharDriverState *chr; +Chardev *chr;Error *err =NULL ;int queues;
@@ -232,7 +232,7 @@ static void net_vhost_user_event(void *opaque, int event) }static int net_vhost_user_init (NetClientState *peer,const char *device, -const char *name,CharDriverState *chr, +const char *name,Chardev *chr,int queues) {Error *err =NULL ;
@@ -274,10 +274,10 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,return 0 ; } -static CharDriverState *net_vhost_claim_chardev ( +static Chardev *net_vhost_claim_chardev (const NetdevVhostUserOptions *opts,Error **errp) { -CharDriverState *chr =qemu_chr_find (opts->chardev); +Chardev *chr =qemu_chr_find (opts->chardev);if (chr ==NULL ) {error_setg (errp,"chardev \"%s\" not found" , opts->chardev);
@@ -324,7 +324,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, {int queues;const NetdevVhostUserOptions *vhost_user_opts; -CharDriverState *chr; +Chardev *chr;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_USER ); vhost_user_opts = &netdev->u.vhost_user;
qemu-char.c +420 -419
1,715 lines not on this page · raw message
spice-qemu-char.c +40 -40
80 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
PATCH v2 14/20 char: rename TCPChardev and NetChardev
In reply to Marc-André LureauRename the types to follow the name of the chardev kind.
- socket: TCPChardev -> SocketChardev
- udp: NetChardev -> UdpChardev
--- qemu-char.c | 74 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
qemu-char.c +37 -37
@@ -2691,12 +2691,12 @@ typedef struct {int bufcnt;int bufptr;int max_size; -} NetChardev; +} UdpChardev;/* Called with chr_write_lock held. */ static int udp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;return qio_channel_write ( s->ioc, (const char *)buf, len,NULL );
@@ -2705,7 +2705,7 @@ static int udp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int udp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque; s->max_size =qemu_chr_be_can_write (chr);
@@ -2723,7 +2723,7 @@ static int udp_chr_read_poll(void *opaque)static gboolean udp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque;ssize_t ret;if (s->max_size ==0 ) {
@@ -2750,7 +2750,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static void udp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2763,7 +2763,7 @@ static void udp_chr_update_read_handler(Chardev *chr,static void udp_chr_free (Chardev *chr) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2799,13 +2799,13 @@ typedef struct {guint reconnect_timer;int64_t reconnect_time;bool connect_err_reported; -} TCPChardev; +} SocketChardev;static gboolean socket_reconnect_timeout (gpointer opaque);static void qemu_chr_socket_restart_timer (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name;assert (s->connected ==0 );
@@ -2819,7 +2819,7 @@ static void qemu_chr_socket_restart_timer(Chardev *chr)static void check_report_connect_error (Chardev *chr,Error *err) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connect_err_reported) { error_report("Unable to connect character device %s: %s",
@@ -2836,7 +2836,7 @@ static gboolean tcp_chr_accept(QIOChannel *chan,/* Called with chr_write_lock held. */ static int tcp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->connected) { int ret = io_channel_send_full(s->ioc, buf, len,
@@ -2860,7 +2860,7 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int tcp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;if (!s->connected)return 0 ; s->max_size =qemu_chr_be_can_write (chr);
@@ -2870,7 +2870,7 @@ static int tcp_chr_read_poll(void *opaque)#define IAC 255#define IAC_BREAK 243static void tcp_chr_process_IAC_bytes (Chardev *chr, -TCPChardev *s, +SocketChardev *s,uint8_t *buf,int *size) {/* Handle any telnet client's basic IAC options to satisfy char by
@@ -2919,7 +2919,7 @@ static void tcp_chr_process_IAC_bytes(Chardev *chr,static int tcp_get_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
@@ -2945,7 +2945,7 @@ static int tcp_get_msgfds(Chardev *chr, int *fds, int num)static int tcp_set_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;/* clear old pending fd array */ g_free (s->write_msgfds);
@@ -2970,7 +2970,7 @@ static int tcp_set_msgfds(Chardev *chr, int *fds, int num)static ssize_t tcp_chr_recv (Chardev *chr,char *buf,size_t len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;struct iovec iov = { .iov_base = buf, .iov_len = len };int ret;size_t i;
@@ -3027,13 +3027,13 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)static GSource *tcp_chr_add_watch (Chardev *chr,GIOCondition cond) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;return qio_channel_create_watch (s->ioc, cond); }static void tcp_chr_free_connection (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int i;if (!s->connected) {
@@ -3062,7 +3062,7 @@ static void tcp_chr_free_connection(Chardev *chr)static void tcp_chr_disconnect (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3085,7 +3085,7 @@ static void tcp_chr_disconnect(Chardev *chr)static gboolean tcp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;uint8_t buf[READ_BUF_LEN ];int len, size;
@@ -3111,7 +3111,7 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static int tcp_chr_sync_read (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int size;if (!s->connected) {
@@ -3130,7 +3130,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)static void tcp_chr_connect (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;g_free (chr->filename); chr->filename = sockaddr_to_str(
@@ -3151,7 +3151,7 @@ static void tcp_chr_connect(void *opaque)static void tcp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3202,7 +3202,7 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,static void tcp_chr_telnet_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;TCPCharDriverTelnetInit *init =g_new0 (TCPCharDriverTelnetInit,1 );size_t n =0 ;
@@ -3238,7 +3238,7 @@ static void tcp_chr_tls_handshake(Object *source, gpointer user_data) {Chardev *chr = user_data; -TCPChardev *s = user_data; +SocketChardev *s = user_data;if (err) {tcp_chr_disconnect (chr);
@@ -3254,7 +3254,7 @@ static void tcp_chr_tls_handshake(Object *source,static void tcp_chr_tls_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelTLS *tioc;Error *err =NULL ;gchar *name;
@@ -3293,7 +3293,7 @@ static void tcp_chr_tls_init(Chardev *chr)static void tcp_chr_set_client_ioc_name (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name; name = g_strdup_printf("chardev-tcp-%s-%s", s->is_listen ? "server" : "client",
@@ -3305,7 +3305,7 @@ static void tcp_chr_set_client_ioc_name(Chardev *chr,static int tcp_chr_new_client (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->ioc !=NULL ) {return -1 ;
@@ -3377,7 +3377,7 @@ static gboolean tcp_chr_accept(QIOChannel *channel,static int tcp_chr_wait_connected (Chardev *chr,Error **errp) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelSocket *sioc;/* It can't wait on s->connected, since it is set asynchronously
@@ -3425,7 +3425,7 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)static void tcp_chr_free (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;tcp_chr_free_connection (chr);
@@ -3453,7 +3453,7 @@ static void qemu_chr_socket_connected(Object *src, Error *err, void *opaque) {QIOChannelSocket *sioc =QIO_CHANNEL_SOCKET (src);Chardev *chr = opaque; -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (err) {check_report_connect_error (chr, err);
@@ -4731,7 +4731,7 @@ static const CharDriver serial_driver = {static gboolean socket_reconnect_timeout (gpointer opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;QIOChannelSocket *sioc; s->reconnect_timer =0 ;
@@ -4757,7 +4757,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, Error **errp) {Chardev *chr; -TCPChardev *s; +SocketChardev *s;ChardevSocket *sock = backend->u.socket.data;SocketAddress *addr = sock->addr;bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
@@ -4772,7 +4772,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver,if (!chr) {return NULL ; } - s = (TCPChardev *)chr; + s = (SocketChardev *)chr; s->is_unix = addr->type ==SOCKET_ADDRESS_KIND_UNIX ; s->is_listen = is_listen;
@@ -4879,7 +4879,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, }static const CharDriver socket_driver = { - .instance_size =sizeof (TCPChardev), + .instance_size =sizeof (SocketChardev), .kind =CHARDEV_BACKEND_KIND_SOCKET , .parse = qemu_chr_parse_socket, .create = qmp_chardev_open_socket,
@@ -4907,7 +4907,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;Chardev *chr; -NetChardev *s; +UdpChardev *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4925,7 +4925,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); - s = (NetChardev *)chr; + s = (UdpChardev *)chr; s->ioc =QIO_CHANNEL (sioc);/* be isn't opened until we get a connection */ *be_opened = false;
@@ -4934,7 +4934,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver, }static const CharDriver udp_driver = { - .instance_size =sizeof (NetChardev), + .instance_size =sizeof (UdpChardev), .kind =CHARDEV_BACKEND_KIND_UDP , .parse = qemu_chr_parse_udp, .create = qmp_chardev_open_udp,
Signature · 1 line
2.11.0
PATCH v2 15/20 spice-char: improve error reporting
In reply to Marc-André LureauSet errp to report errors up to the right monitor.
Use error_append_hint() to give hints about parameters on !qmp monitors, instead of a direct fprintf() call.
--- spice-qemu-char.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
spice-qemu-char.c +10 -20
@@ -2,6 +2,7 @@#include "trace.h" #include "ui/qemu-spice.h" #include "sysemu/char.h" +#include "qemu/error-report.h" #include <spice.h> #include <spice/protocol.h>
@@ -239,23 +240,6 @@ static void spice_port_set_fe_open(struct Chardev *chr, int fe_open)#endif } -static void print_allowed_subtypes (void ) -{ -const char ** psubtype; -int i; - -fprintf (stderr,"allowed names: " ); -for (i=0 , psubtype =spice_server_char_device_recognized_subtypes (); - *psubtype !=NULL ; ++psubtype, ++i) { -if (i ==0 ) { -fprintf (stderr,"%s" , *psubtype); - }else { -fprintf (stderr,", %s" , *psubtype); - } - } -fprintf (stderr,"\n" ); -} -static void spice_chr_accept_input (struct Chardev *chr) {SpiceChardev *s = (SpiceChardev *)chr;
@@ -302,8 +286,14 @@ static Chardev *qemu_chr_open_spice_vmc(const CharDriver *driver, } }if (*psubtype ==NULL ) { -fprintf (stderr,"spice-qemu-char: unsupported type: %s\n" , type); -print_allowed_subtypes (); +char *subtypes =g_strjoinv (", " , + (gchar **)spice_server_char_device_recognized_subtypes ()); + +error_setg (errp,"unsupported type name: %s" , type); +error_append_hint (errp,"allowed spice char type names: %s\n" , + subtypes); + +g_free (subtypes);return NULL ; }
@@ -326,7 +316,7 @@ static Chardev *qemu_chr_open_spice_port(const CharDriver *driver,SpiceChardev *s;if (name ==NULL ) { -fprintf (stderr,"spice-qemu-char: missing name parameter\n" ); +error_setg (errp,"missing name parameter" );return NULL ; }
Signature · 1 line
2.11.0
PATCH v2 16/20 char: use error_report()
In reply to Marc-André LureauPrefer error_report() over fprintf(stderr..)
--- qemu-char.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
qemu-char.c +14 -11
@@ -451,8 +451,8 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ;if (s &&qemu_chr_replay (s)) { -fprintf (stderr, -"Replay: get msgfd is not supported for serial devices yet\n" ); +error_report ("Replay: get msgfd is not supported " +"for serial devices yet" );exit (1 ); }return res;
@@ -1680,8 +1680,8 @@ static Chardev *qemu_chr_open_pty(const CharDriver *driver, ret->pty =g_strdup (pty_name); ret->has_pty = true; -fprintf (stderr,"char device redirected to %s (label %s)\n" , - pty_name, id); +error_report ("char device redirected to %s (label %s)" , + pty_name, id); s = (PtyChardev *)chr; s->ioc =QIO_CHANNEL (qio_channel_file_new_fd (master_fd));
@@ -3384,8 +3384,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error **errp)* in TLS and telnet cases, only wait for an accepted socket */ while (!s->ioc) {if (s->is_listen) { -fprintf (stderr,"QEMU waiting for connection on: %s\n" , - chr->filename); +error_report ("QEMU waiting for connection on: %s" , + chr->filename);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), true,NULL );tcp_chr_accept (QIO_CHANNEL (s->listen_ioc),G_IO_IN , chr);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), false,NULL );
@@ -4144,16 +4144,19 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, }if (is_help_option (name)) { -fprintf (stderr,"Available chardev backend types:\n" ); +GString *str =g_string_new ("" );for (i =0 ; i <ARRAY_SIZE (backends); i++) { cd = backends[i];if (cd) { -fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +g_string_append_printf (str,"\n%s" , ChardevBackendKind_lookup[cd->kind]);if (cd->alias) { -fprintf (stderr,"%s\n" , cd->alias); +g_string_append_printf (str,"\n%s" , cd->alias); } } } + +error_report ("Available chardev backend types: %s" , str->str); +g_string_free (str, true);exit (0 ); }
@@ -4265,8 +4268,8 @@ Chardev *qemu_chr_new(const char *label, const char *filename)qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); }if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) { -fprintf (stderr, -"Replay: ioctl is not supported for serial devices yet\n" ); +error_report ("Replay: ioctl is not supported " +"for serial devices yet" ); }replay_register_char_driver (chr); }
Signature · 1 line
2.11.0
PATCH v2 17/20 gtk: overwrite the console.c char driver
In reply to Marc-André LureauInstead of registering a vc handler to allocate the Gtk VC Chardev, overwrite the console.c char driver.
A later patch, when switching to QOM, will register a default console vc QOM class if none has been registered before.
--- include/sysemu/char.h | 4 +--- ui/console.c | 24 +++++++----------------- ui/gtk.c | 31 ++++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 29 deletions(-)
include/sysemu/char.h +1 -3
@@ -507,9 +507,7 @@ void register_char_driver(const CharDriver *driver);extern int term_escape_char; -/* console.c */ -typedef Chardev *(VcHandler )(ChardevVC *vc,Error **errp); -void register_vc_handler (VcHandler *handler); +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);#endif
ui/console.c +7 -17
@@ -2058,8 +2058,12 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *text_console_init (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;VCChardev *drv;
@@ -2105,26 +2109,13 @@ static Chardev *text_console_init(ChardevVC *vc, Error **errp)if (display_state) {text_console_do_init (chr, display_state); } -return chr; -} -static VcHandler *vc_handler = text_console_init; - -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) -{/* console/chardev init sometimes completes elsewhere in a 2nd * stage, so defer OPENED events until they are fully initialized */ *be_opened = false; -return vc_handler (backend->u.vc.data, errp); -} -void register_vc_handler (VcHandler *handler) -{ - vc_handler = handler; +return chr; }void qemu_console_resize (QemuConsole *s,int width,int height)
@@ -2162,8 +2153,7 @@ PixelFormat qemu_default_pixelformat(int bpp)return pf; } -static void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend, -Error **errp) +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp) {int val;ChardevVC *vc;
ui/gtk.c +22 -9
@@ -1712,16 +1712,14 @@ static void gd_vc_chr_set_echo(Chardev *chr, bool echo)static int nb_vcs;static Chardev *vcs[MAX_VCS ]; +static const CharDriver gd_vc_driver; -static Chardev *gd_vc_handler (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { -static const CharDriver gd_vc_driver = { - .instance_size =sizeof (VCChardev), - .kind =CHARDEV_BACKEND_KIND_VC , - .chr_write = gd_vc_chr_write, - .chr_set_echo = gd_vc_chr_set_echo, - }; - +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;
@@ -1737,9 +1735,23 @@ static Chardev *gd_vc_handler(ChardevVC *vc, Error **errp) vcs[nb_vcs++] = chr; +/* console/chardev init sometimes completes elsewhere in a 2nd +* stage, so defer OPENED events until they are fully initialized +*/ + *be_opened = false; +return chr; } +static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCChardev), + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, +}; +static gboolean gd_vc_in (VteTerminal *terminal,gchar *text,guint size,gpointer user_data) {
@@ -2336,6 +2348,7 @@ void early_gtk_display_init(int opengl) }#if defined(CONFIG_VTE ) -register_vc_handler (gd_vc_handler); +/* overwrite the console.c vc driver */ +register_char_driver (&gd_vc_driver);#endif }
Signature · 1 line
2.11.0
PATCH v2 18/20 baum: use a common prefix for chr callbacks
In reply to Marc-André Lureau--- backends/baum.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
backends/baum.c +8 -8
@@ -253,7 +253,7 @@ static int baum_deferred_init(BaumChardev *baum) }/* The serial port can receive more of our data */ -static void baum_accept_input (struct Chardev *chr) +static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;int room, first;
@@ -470,7 +470,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len) }/* The other end is writing some data. Store it and try to interpret */ -static int baum_write (Chardev *chr,const uint8_t *buf,int len) +static int baum_chr_write (Chardev *chr,const uint8_t *buf,int len) {BaumChardev *baum = (BaumChardev *)chr;int tocopy, cur, eaten, orig_len = len;
@@ -613,7 +613,7 @@ static void baum_chr_read(void *opaque) } } -static void baum_free (struct Chardev *chr) +static void baum_chr_free (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;
@@ -624,7 +624,7 @@ static void baum_free(struct Chardev *chr) } } -static Chardev *chr_baum_init(const CharDriver *driver, +static Chardev *baum_chr_init(const CharDriver *driver, const char *id, ChardevBackend *backend, ChardevReturn *ret,
@@ -670,10 +670,10 @@ static void register_types(void)static const CharDriver driver = { .instance_size =sizeof (BaumChardev), .kind =CHARDEV_BACKEND_KIND_BRAILLE , - .create = chr_baum_init, - .chr_write = baum_write, - .chr_accept_input = baum_accept_input, - .chr_free = baum_free, + .create = baum_chr_init, + .chr_write = baum_chr_write, + .chr_accept_input = baum_chr_accept_input, + .chr_free = baum_chr_free, };register_char_driver (&driver);
Signature · 1 line
2.11.0
PATCH v2 19/20 vc: use a common prefix for chr callbacks
In reply to Marc-André Lureauvc_chr_write() is more appropriate than _puts() since no newline is appended, even though it's not used only as a callback.
Keep "qemu_chr_parse" prefix, most chardev parse functions use this prefix atm.
--- ui/console.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
ui/console.c +12 -12
@@ -1051,7 +1051,7 @@ typedef struct VCChardev {QemuConsole *console; } VCChardev; -static int console_puts (Chardev *chr,const uint8_t *buf,int len) +static int vc_chr_write (Chardev *chr,const uint8_t *buf,int len) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -1139,13 +1139,13 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym) *q++ ='[' ; *q++ = keysym &0xff ; }else if (s->echo && (keysym =='\r' || keysym =='\n' )) { -console_puts (s->chr, (const uint8_t *)"\r" ,1 ); +vc_chr_write (s->chr, (const uint8_t *)"\r" ,1 ); *q++ ='\n' ; }else { *q++ = keysym; }if (s->echo) { -console_puts (s->chr, buf, q - buf); +vc_chr_write (s->chr, buf, q - buf); } be = s->chr->be;if (be && be->chr_read) {
@@ -1962,7 +1962,7 @@ int qemu_console_get_height(QemuConsole *con, int fallback)return con ?surface_height (con->surface) : fallback; } -static void text_console_set_echo (Chardev *chr,bool echo) +static void vc_chr_set_echo (Chardev *chr,bool echo) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -2049,7 +2049,7 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds) s->t_attrib.bgcol =QEMU_COLOR_BLUE ; len =snprintf (msg,sizeof (msg),"%s console\r\n" , chr->label); -console_puts (chr, (uint8_t *)msg, len); +vc_chr_write (chr, (uint8_t *)msg, len); s->t_attrib = s->t_attrib_default; }
@@ -2058,10 +2058,10 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) +static Chardev *vc_chr_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) {ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2197,9 +2197,9 @@ static const CharDriver vc_driver = { .instance_size = sizeof(VCChardev), .kind = CHARDEV_BACKEND_KIND_VC, .parse = qemu_chr_parse_vc, - .create = vc_init, - .chr_write = console_puts, - .chr_set_echo = text_console_set_echo, + .create = vc_chr_init, + .chr_write = vc_chr_write, + .chr_set_echo = vc_chr_set_echo, };static void register_types (void )
Signature · 1 line
2.11.0
PATCH v2 20/20 chardev: qom-ify
In reply to Marc-André LureauTurn Chardev into Object.
qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It will call qemu_char_open() to open/intialize the chardev with the ChardevCommon *backend settings.
The CharDriver::create() callback is turned into a ChardevClass::open() which is called from the newly introduced qemu_chardev_open().
"chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use TYPE_USER_CREATABLE interface instead, or perhaps allow -chardev usage.
Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for qemu-char.c are in char.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later.
--- include/sysemu/char.h | 107 ++-- include/ui/console.h | 2 + backends/baum.c | 66 +-- backends/msmouse.c | 57 ++- backends/testdev.c | 34 +- gdbstub.c | 39 +- hw/bt/hci-csr.c | 55 +- monitor.c | 2 +- qemu-char.c | 1327 ++++++++++++++++++++++++++----------------------- spice-qemu-char.c | 142 +++--- ui/console.c | 62 ++- ui/gtk.c | 50 +- vl.c | 2 + 13 files changed, 1072 insertions(+), 873 deletions(-)
include/sysemu/char.h +58 -49
@@ -10,6 +10,7 @@#include "qapi/qmp/qstring.h" #include "qemu/main-loop.h" #include "qemu/bitmap.h" +#include "qom/object.h" /* character device */
@@ -90,7 +91,8 @@ typedef struct CharBackend {typedef struct CharDriver CharDriver ;struct Chardev { -const CharDriver *driver; +Object parent_obj; +QemuMutex chr_write_lock;CharBackend *be;char *label;
@@ -102,18 +104,6 @@ struct Chardev {QTAILQ_ENTRY (Chardev) next; }; -/** -* qemu_chr_alloc: -* @backend: the common backend config -* @errp: pointer to a NULL-initialized error object -* -* Allocate and initialize a new Chardev. -* -* Returns: a newly allocated Chardev, or NULL on error. -*/ -Chardev *qemu_chr_alloc (const CharDriver *driver, -ChardevCommon *backend,Error **errp); -/** * @qemu_chr_new_from_opts: *
@@ -455,54 +445,73 @@ void qemu_chr_fe_accept_input(CharBackend *be);int qemu_chr_add_client (Chardev *s,int fd);Chardev *qemu_chr_find (const char *name); -/** -* @qemu_chr_get_kind: -* -* Returns the kind of char backend, or -1 if unspecified. -*/ -ChardevBackendKind qemu_chr_get_kind (const Chardev *chr); - -static inline bool qemu_chr_is_ringbuf (const Chardev *chr) -{ -return qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_RINGBUF || -qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MEMORY ; -} -bool qemu_chr_has_feature (Chardev *chr,CharDriverFeature feature);void qemu_chr_set_feature (Chardev *chr,CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +#define TYPE_CHARDEV "chardev" +#define CHARDEV (obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV) +#define CHARDEV_CLASS (klass) \ + OBJECT_CLASS_CHECK(ChardevClass, (klass), TYPE_CHARDEV) +#define CHARDEV_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ChardevClass, (obj), TYPE_CHARDEV) + +#define TYPE_CHARDEV_NULL "chardev-null" +#define TYPE_CHARDEV_MUX "chardev-mux" +#define TYPE_CHARDEV_RINGBUF "chardev-ringbuf" +#define TYPE_CHARDEV_PTY "chardev-pty" +#define TYPE_CHARDEV_CONSOLE "chardev-console" +#define TYPE_CHARDEV_STDIO "chardev-stdio" +#define TYPE_CHARDEV_PIPE "chardev-pipe" +#define TYPE_CHARDEV_MEMORY "chardev-memory" +#define TYPE_CHARDEV_PARALLEL "chardev-parallel" +#define TYPE_CHARDEV_FILE "chardev-file" +#define TYPE_CHARDEV_SERIAL "chardev-serial" +#define TYPE_CHARDEV_SOCKET "chardev-socket" +#define TYPE_CHARDEV_UDP "chardev-udp" + +#define CHARDEV_IS_MUX (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) +#define CHARDEV_IS_RINGBUF (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF) +#define CHARDEV_IS_PTY (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY) + +typedef struct ChardevClass { +ObjectClass parent_class; + +bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ + +void (*open)(Chardev *chr,ChardevBackend *backend, +bool *be_opened,Error **errp); + +int (*chr_write)(Chardev *s,const uint8_t *buf,int len); +int (*chr_sync_read)(Chardev *s,const uint8_t *buf,int len); +GSource *(*chr_add_watch)(Chardev *s,GIOCondition cond); +void (*chr_update_read_handler)(Chardev *s,GMainContext *context); +int (*chr_ioctl)(Chardev *s,int cmd,void *arg); +int (*get_msgfds)(Chardev *s,int * fds,int num); +int (*set_msgfds)(Chardev *s,int *fds,int num); +int (*chr_add_client)(Chardev *chr,int fd); +int (*chr_wait_connected)(Chardev *chr,Error **errp); +void (*chr_free)(Chardev *chr); +void (*chr_disconnect)(Chardev *chr); +void (*chr_accept_input)(Chardev *chr); +void (*chr_set_echo)(Chardev *chr,bool echo); +void (*chr_set_fe_open)(Chardev *chr,int fe_open); +}ChardevClass ; +struct CharDriver {ChardevBackendKind kind;const char *alias;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); -Chardev *(*create)(const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); -size_t instance_size; - -int (*chr_write)(struct Chardev *s,const uint8_t *buf,int len); -int (*chr_sync_read)(struct Chardev *s, -const uint8_t *buf,int len); -GSource *(*chr_add_watch)(struct Chardev *s,GIOCondition cond); -void (*chr_update_read_handler)(struct Chardev *s, -GMainContext *context); -int (*chr_ioctl)(struct Chardev *s,int cmd,void *arg); -int (*get_msgfds)(struct Chardev *s,int * fds,int num); -int (*set_msgfds)(struct Chardev *s,int *fds,int num); -int (*chr_add_client)(struct Chardev *chr,int fd); -int (*chr_wait_connected)(struct Chardev *chr,Error **errp); -void (*chr_free)(struct Chardev *chr); -void (*chr_disconnect)(struct Chardev *chr); -void (*chr_accept_input)(struct Chardev *chr); -void (*chr_set_echo)(struct Chardev *chr,bool echo); -void (*chr_set_fe_open)(struct Chardev *chr,int fe_open); }; +Chardev *qemu_chardev_new (const char *id,const char *typename, +ChardevBackend *backend,Error **errp); +void register_char_driver (const CharDriver *driver);extern int term_escape_char;
include/ui/console.h +2 -0
@@ -383,6 +383,8 @@ void graphic_hw_invalidate(QemuConsole *con);void graphic_hw_text_update (QemuConsole *con,console_ch_t *chardata);void graphic_hw_gl_block (QemuConsole *con,bool block); +void qemu_console_early_init (void ); +QemuConsole *qemu_console_lookup_by_index (unsigned int index);QemuConsole *qemu_console_lookup_by_device (DeviceState *dev,uint32_t head); QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
backends/baum.c +33 -33
141 lines not on this page · raw message
backends/msmouse.c +31 -26
104 lines not on this page · raw message
backends/testdev.c +18 -16
@@ -36,6 +36,10 @@ typedef struct {int in_buf_used; } TestdevChardev; +#define TYPE_CHARDEV_TESTDEV "chardev-testdev" +#define TESTDEV_CHARDEV (obj) \ + OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV) +/* Try to interpret a whole incoming packet */ static int testdev_eat_packet (TestdevChardev *testdev) {
@@ -78,9 +82,9 @@ static int testdev_eat_packet(TestdevChardev *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (Chardev *chr,const uint8_t *buf,int len) +static int testdev_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevChardev *testdev = (TestdevChardev *)chr; +TestdevChardev *testdev =TESTDEV_CHARDEV (chr);int tocopy, eaten, orig_len = len;while (len) {
@@ -103,30 +107,28 @@ static int testdev_write(Chardev *chr, const uint8_t *buf, int len)return orig_len; } -static Chardev *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static void char_testdev_class_init (ObjectClass *oc,void *data) { -TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; -Chardev *chr = (Chardev *)testdev; - - chr->driver = driver; +ChardevClass *cc =CHARDEV_CLASS (oc); -return chr; + cc->chr_write = testdev_chr_write; } +static const TypeInfo char_testdev_type_info = { + .name =TYPE_CHARDEV_TESTDEV , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (TestdevChardev), + .class_init = char_testdev_class_init, +}; +static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , - .create = chr_testdev_init, - .chr_write = testdev_write, }; +register_char_driver (&driver); +type_register_static (&char_testdev_type_info); }type_init (register_types);
gdbstub.c +32 -7
@@ -1723,18 +1723,35 @@ static void gdb_sigterm_handler(int signal) }#endif +static void gdb_monitor_open (Chardev *chr,ChardevBackend *backend, +bool *be_opened,Error **errp) +{ + *be_opened = false; +} + +static void char_gdb_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->internal = true; + cc->open = gdb_monitor_open; + cc->chr_write = gdb_monitor_write; +} + +#define TYPE_CHARDEV_GDB "chardev-gdb" + +static const TypeInfo char_gdb_type_info = { + .name =TYPE_CHARDEV_GDB , + .parent =TYPE_CHARDEV , + .class_init = char_gdb_class_init, +}; +int gdbserver_start (const char *device) {GDBState *s;char gdbstub_device_name[128 ];Chardev *chr =NULL ;Chardev *mon_chr; -ChardevCommon common = {0 }; -static const CharDriver driver = { - .instance_size =sizeof (Chardev), - .kind =-1 , - .chr_write = gdb_monitor_write, - };if (!device)return -1 ;
@@ -1767,7 +1784,8 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&driver, &common, &error_abort); + mon_chr =qemu_chardev_new (NULL ,TYPE_CHARDEV_GDB , +NULL , &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
@@ -1790,4 +1808,11 @@ int gdbserver_start(const char *device) return 0; } + +static void register_types (void ) +{ +type_register_static (&char_gdb_type_info); +} + +type_init (register_types);#endif
hw/bt/hci-csr.c +38 -17
73 lines not on this page · raw message
monitor.c +1 -1
@@ -3194,7 +3194,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {Chardev *chr =qemu_chr_find (chr_info->label); -if (chr &&qemu_chr_is_ringbuf (chr)) { +if (chr &&CHARDEV_IS_RINGBUF (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +712 -615
2,399 lines not on this page · raw message
spice-qemu-char.c +81 -61
142 lines not on this page · raw message
ui/console.c +37 -25
62 lines not on this page · raw message
ui/gtk.c +27 -23
50 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
qemu-char.c void qemu_chr_set_feature(Chardev *chr, · line 4999
Quoted 11 lines · Marc-André Lureau
Turn Chardev into Object.
qemu_chr_alloc()is replaced by theqemu_chardev_new()constructor. It will callqemu_char_open()to open/intialize the chardev with the ChardevCommon *backend settings.qemu-char.c +2
-2-ChardevReturn *qmp_chardev_add (const char *id,ChardevBackend *backend, -Error **errp) +static const ChardevClass *char_get_class (const char *driver,Error **errp) +{
Your followup "[PATCH 16/40] char: get rid of CharDriver" hoists this up earlier in the file. Can you minimize churn by just declaring it earlier to begin with?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Hi
----- Original Message -----
Quoted 8 lines · Marc-André Lureau
Quoted 6 lines
Turn Chardev into Object.
qemu_chr_alloc()is replaced by theqemu_chardev_new()constructor. It will callqemu_char_open()to open/intialize the chardev with the ChardevCommon *backend settings.
Quoted 9 lines
Quoted 5 lines
qemu-char.c +1
-2-ChardevReturn *qmp_chardev_add (const char *id,ChardevBackend *backend, -Error **errp) +static const ChardevClass *char_get_class(const char *driver, Error**errp)
+{Your followup "[PATCH 16/40] char: get rid of CharDriver" hoists this up earlier in the file. Can you minimize churn by just declaring it earlier to begin with?
Unless Paolo want me to respin the series, I think we will have to do with it ;)
thanks
Paolo Bonzini
AppliedQuoted 13 lines · Marc-André Lureau
qemu-char.cis quite a large file (~130k, 5000 loc) with many chardev and a lot of #ifdef. It doesn't use qemu Object. Using qemu Object hopefully brings cleaner, more consitent code base. It helps to split the various backends in different files. Eventually, we could also allow or switch to -object-add CLI option instead of -chardev.This series is the first of a pretty large chardev refactoring series that I keep here:
https://github.com/elmarco/qemu/commits/chrfeThe series is based after "char: fix ctrl-a b not working" patch sent earlier.
Quoted 8 lines
For "spice-char: improve error reporting" to not introduce a regression, "error: report hints on stderr when no monitor" is required (sent earlier in the ML).
v1->v2:
- fix intermediate patches regressions spotted by Eric
- code style improvements
- add r-b tags
Queued, thanks.
Paolo
Quoted 111 lines
WIP->v1:
- took most of Eric review comments, they were mostly about styleMarc-André Lureau (20):
tests: fix linking test-char on win32
qemu-options: stdio is available on win32
char: addqemu_chr_fe_add_watch()Returns description
doc: fix spelling
char: use a const CharDriver
char: use a static array for backends
char: move callbacks in CharDriver
char: fold single-user functions in caller
char: introduce genericqemu_chr_get_kind()
char: use a feature bit for replay
char: allocate CharDriverState as a single object
bt: useqemu_chr_alloc()
char: rename CharDriverState Chardev
char: rename TCPChardev and NetChardev
spice-char: improve error reporting
char: useerror_report()
gtk: overwrite theconsole.cchar driver
baum: use a common prefix for chr callbacks
vc: use a common prefix for chr callbacks
chardev: qom-ifyhw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 155 +-- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/console.h | 2 + include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- backends/baum.c | 102 +- backends/msmouse.c | 77 +- backends/rng-egd.c | 4 +- backends/testdev.c | 53 +- gdbstub.c | 45 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 64 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- monitor.c | 6 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 1914 ++++++++++++++++++++----------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 231 +++-- stubs/get-next-serial.c | 2 +- stubs/monitor-init.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 111 ++- ui/gtk.c | 86 +- vl.c | 12 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- qemu-options.hx | 4 +- tests/Makefile.include | 2 +- 84 files changed, 1729 insertions(+), 1343 deletions(-)