chardev: qom clean-up and split in various backend files
cover chardev: qom clean-up and split in various backend files
Finish qom-ification by using instance finalizers and split the big qemu-char.c file in many backend-specific units.
This is part of a larger refactoring series that I try to keep up to date here:
https://github.com/elmarco/qemu/commits/chrfe
It is based after qom-ify v2 series.
Marc-André Lureau (40):
spice-qemu-char: convert to finalize
baum: convert to finalize
msmouse: convert to finalize
mux: convert to finalize
char-udp: convert to finalize
char-socket: convert to finalize
char-pty: convert to finalize
char-ringbuf: convert to finalize
char-parallel: convert parallel to finalize
char-stdio: convert to finalize
char-win-stdio: convert to finalize
char-win: do not override chr_free
char-win: convert to finalize
char-fd: convert to finalize
char: remove chr_free
char: get rid of CharDriver
char: rename remaining CharDriver to Chardev
char: remove class kind field
char: move to chardev/
char: create chardev-obj-y
char: make null_chr_write() the default method
char: move null chardev to its own file
char: move mux to its own file
char: move ringbuf/memory to its own file
char: rename and move to header CHR_READ_BUF_LEN
char: remove unused READ_RETRIES
char: move QIOChannel-related in char-io.h
char: move fd chardev in its own file
char: move win chardev base class in its own file
char: move win-stdio into its own file
char: move socket chardev to its own file
char: move udp chardev in its own file
char: move file chardev in its own file
char: move stdio in its own file
char: move console in its own file
char: move pipe chardev in its own file
char: move pty chardev in its own file
char: move serial chardev to itw own file
char: move parallel chardev in its own file
char: headers clean-up
chardev/char-fd.h | 21 + chardev/char-io.h | 24 + chardev/char-mux.h | 40 + chardev/char-parallel.h | 9 + chardev/char-serial.h | 12 + chardev/char-win-stdio.h | 6 + chardev/char-win.h | 30 + include/sysemu/char.h | 69 +- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 5 - chardev/char-console.c | 30 + chardev/char-fd.c | 147 ++ chardev/char-file.c | 116 ++ chardev/char-io.c | 168 ++ chardev/char-mux.c | 335 +++ chardev/char-null.c | 31 + chardev/char-parallel.c | 293 +++ chardev/char-pipe.c | 168 ++ chardev/char-pty.c | 277 +++ chardev/char-ringbuf.c | 226 ++ chardev/char-serial.c | 295 +++ chardev/char-socket.c | 993 +++++++++ chardev/char-stdio.c | 141 ++ chardev/char-udp.c | 210 ++ chardev/char-win-stdio.c | 243 +++ chardev/char-win.c | 242 +++ chardev/char.c | 1311 ++++++++++++ hmp.c | 1 + monitor.c | 1 + qemu-char.c | 5169 ---------------------------------------------- qmp.c | 1 + spice-qemu-char.c | 21 +- tests/vhost-user-test.c | 1 + ui/console.c | 10 +- ui/gtk.c | 9 +- MAINTAINERS | 2 +- Makefile | 3 +- Makefile.objs | 4 +- Makefile.target | 3 + chardev/Makefile.objs | 17 + tests/Makefile.include | 6 +- 42 files changed, 5441 insertions(+), 5271 deletions(-) create mode 100644 chardev/char-fd.h create mode 100644 chardev/char-io.h create mode 100644 chardev/char-mux.h create mode 100644 chardev/char-parallel.h create mode 100644 chardev/char-serial.h create mode 100644 chardev/char-win-stdio.h create mode 100644 chardev/char-win.h create mode 100644 chardev/char-console.c create mode 100644 chardev/char-fd.c create mode 100644 chardev/char-file.c create mode 100644 chardev/char-io.c create mode 100644 chardev/char-mux.c create mode 100644 chardev/char-null.c create mode 100644 chardev/char-parallel.c create mode 100644 chardev/char-pipe.c create mode 100644 chardev/char-pty.c create mode 100644 chardev/char-ringbuf.c create mode 100644 chardev/char-serial.c create mode 100644 chardev/char-socket.c create mode 100644 chardev/char-stdio.c create mode 100644 chardev/char-udp.c create mode 100644 chardev/char-win-stdio.c create mode 100644 chardev/char-win.c create mode 100644 chardev/char.c delete mode 100644 qemu-char.c create mode 100644 chardev/Makefile.objs
Signature · 1 line
2.11.0
PATCH 1/40 spice-qemu-char: convert to finalize
--- spice-qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
spice-qemu-char.c +3 -3
@@ -210,9 +210,9 @@ static int spice_chr_write(Chardev *chr, const uint8_t *buf, int len)return read_bytes; } -static void spice_chr_free (struct Chardev *chr) +static void char_spice_finalize (Object *obj) { -SpiceChardev *s =SPICE_CHARDEV (chr); +SpiceChardev *s =SPICE_CHARDEV (obj);vmc_unregister_interface (s);QLIST_REMOVE (s, next);
@@ -365,13 +365,13 @@ static void char_spice_class_init(ObjectClass *oc, void *data) cc->chr_write = spice_chr_write; cc->chr_add_watch = spice_chr_add_watch; cc->chr_accept_input = spice_chr_accept_input; - cc->chr_free = spice_chr_free; }static const TypeInfo char_spice_type_info = { .name =TYPE_CHARDEV_SPICE , .parent =TYPE_CHARDEV , .instance_size =sizeof (SpiceChardev), + .instance_finalize = char_spice_finalize, .class_init = char_spice_class_init, .abstract = true, };
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 01/40] spice-qemu-char: convert to finalize
Quoted 5 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- spice-qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/40 baum: convert to finalize
In reply to Marc-André Lureau--- backends/baum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
backends/baum.c +3 -3
@@ -616,9 +616,9 @@ static void baum_chr_read(void *opaque) } } -static void baum_chr_free (Chardev *chr) +static void char_braille_finalize (Object *obj) { -BaumChardev *baum =BAUM_CHARDEV (chr); +BaumChardev *baum =BAUM_CHARDEV (obj);timer_free (baum->cellCount_timer);if (baum->brlapi) {
@@ -659,13 +659,13 @@ static void char_braille_class_init(ObjectClass *oc, void *data) cc->open = baum_chr_open; cc->chr_write = baum_chr_write; cc->chr_accept_input = baum_chr_accept_input; - cc->chr_free = baum_chr_free; }static const TypeInfo char_braille_type_info = { .name =TYPE_CHARDEV_BRAILLE , .parent =TYPE_CHARDEV , .instance_size =sizeof (BaumChardev), + .instance_finalize = char_braille_finalize, .class_init = char_braille_class_init, };
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 02/40] baum: convert to finalize
Quoted 5 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- backends/baum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
I might have squashed multiple conversions to finalize in one patch, but since you've already done the work of separating them, I don't mind them that way.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/40 msmouse: convert to finalize
In reply to Marc-André Lureau--- backends/msmouse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
backends/msmouse.c +3 -3
@@ -139,9 +139,9 @@ static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len)return len; } -static void msmouse_chr_free (struct Chardev *chr) +static void char_msmouse_finalize (Object *obj) { -MouseChardev *mouse =MOUSE_CHARDEV (chr); +MouseChardev *mouse =MOUSE_CHARDEV (obj);qemu_input_handler_unregister (mouse->hs); }
@@ -172,13 +172,13 @@ static void char_msmouse_class_init(ObjectClass *oc, void *data) cc->open = msmouse_chr_open; cc->chr_write = msmouse_chr_write; cc->chr_accept_input = msmouse_chr_accept_input; - cc->chr_free = msmouse_chr_free; }static const TypeInfo char_msmouse_type_info = { .name =TYPE_CHARDEV_MSMOUSE , .parent =TYPE_CHARDEV , .instance_size =sizeof (MouseChardev), + .instance_finalize = char_msmouse_finalize, .class_init = char_msmouse_class_init, };
Signature · 1 line
2.11.0
PATCH 4/40 mux: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qemu-char.c +3 -3
@@ -859,9 +859,9 @@ static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond)return cc->chr_add_watch (chr, cond); } -static void mux_chr_free (struct Chardev *chr) +static void char_mux_finalize (Object *obj) { -MuxChardev *d =MUX_CHARDEV (chr); +MuxChardev *d =MUX_CHARDEV (obj);int i;for (i =0 ; i < d->mux_cnt; i++) {
@@ -4023,7 +4023,6 @@ static void char_mux_class_init(ObjectClass *oc, void *data)ChardevClass *cc =CHARDEV_CLASS (oc); cc->open = qemu_chr_open_mux; - cc->chr_free = mux_chr_free; cc->chr_write = mux_chr_write; cc->chr_accept_input = mux_chr_accept_input; cc->chr_add_watch = mux_chr_add_watch;
@@ -4034,6 +4033,7 @@ static const TypeInfo char_mux_type_info = { .parent = TYPE_CHARDEV, .class_init = char_mux_class_init, .instance_size = sizeof(MuxChardev), + .instance_finalize = char_mux_finalize, }; static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
Signature · 1 line
2.11.0
PATCH 5/40 char-udp: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
qemu-char.c +4 -3
@@ -2779,9 +2779,10 @@ static void udp_chr_update_read_handler(Chardev *chr, } } -static void udp_chr_free (Chardev *chr) +static void char_udp_finalize (Object *obj) { -UdpChardev *s =UDP_CHARDEV (chr); +Chardev *chr =CHARDEV (obj); +UdpChardev *s =UDP_CHARDEV (obj);remove_fd_in_watch (chr);if (s->ioc) {
@@ -4973,13 +4974,13 @@ static void char_udp_class_init(ObjectClass *oc, void *data) cc->open = qmp_chardev_open_udp; cc->chr_write = udp_chr_write; cc->chr_update_read_handler = udp_chr_update_read_handler; - cc->chr_free = udp_chr_free; }static const TypeInfo char_udp_type_info = { .name =TYPE_CHARDEV_UDP , .parent =TYPE_CHARDEV , .instance_size =sizeof (UdpChardev), + .instance_finalize = char_udp_finalize, .class_init = char_udp_class_init, };
Signature · 1 line
2.11.0
PATCH 6/40 char-socket: convert to finalize
In reply to Marc-André LureauNotice that finalize() will be run after a failure to open(), so cleanup code must be adjusted.
--- qemu-char.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
qemu-char.c +5 -7
@@ -3447,9 +3447,10 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)return qemu_chr_wait_connected (be->chr, errp); } -static void tcp_chr_free (Chardev *chr) +static void char_socket_finalize (Object *obj) { -SocketChardev *s =SOCKET_CHARDEV (chr); +Chardev *chr =CHARDEV (obj); +SocketChardev *s =SOCKET_CHARDEV (obj);tcp_chr_free_connection (chr);
@@ -4884,7 +4885,7 @@ static void qmp_chardev_open_socket(Chardev *chr, s->listen_ioc = sioc;if (is_waitconnect &&qemu_chr_wait_connected (chr, errp) <0 ) { - goto error; +return ; }if (!s->ioc) { s->listen_tag = qio_channel_add_watch(
@@ -4902,9 +4903,6 @@ error:if (sioc) {object_unref (OBJECT (sioc)); } -if (s->tls_creds) { -object_unref (OBJECT (s->tls_creds)); - } }static const CharDriver socket_driver = {
@@ -4926,13 +4924,13 @@ static void char_socket_class_init(ObjectClass *oc, void *data) cc->chr_add_client = tcp_chr_add_client; cc->chr_add_watch = tcp_chr_add_watch; cc->chr_update_read_handler = tcp_chr_update_read_handler; - cc->chr_free = tcp_chr_free; }static const TypeInfo char_socket_type_info = { .name =TYPE_CHARDEV_SOCKET , .parent =TYPE_CHARDEV , .instance_size =sizeof (SocketChardev), + .instance_finalize = char_socket_finalize, .class_init = char_socket_class_init, };
Signature · 1 line
2.11.0
PATCH 7/40 char-pty: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
qemu-char.c +4 -3
@@ -1659,9 +1659,10 @@ static void pty_chr_state(Chardev *chr, int connected) } } -static void pty_chr_free (struct Chardev *chr) +static void char_pty_finalize (Object *obj) { -PtyChardev *s =PTY_CHARDEV (chr); +Chardev *chr =CHARDEV (obj); +PtyChardev *s =PTY_CHARDEV (obj);qemu_mutex_lock (&chr->chr_write_lock);pty_chr_state (chr,0 );
@@ -1718,13 +1719,13 @@ static void char_pty_class_init(ObjectClass *oc, void *data) cc->chr_write = char_pty_chr_write; cc->chr_update_read_handler = pty_chr_update_read_handler; cc->chr_add_watch = pty_chr_add_watch; - cc->chr_free = pty_chr_free; }static const TypeInfo char_pty_type_info = { .name =TYPE_CHARDEV_PTY , .parent =TYPE_CHARDEV , .instance_size =sizeof (PtyChardev), + .instance_finalize = char_pty_finalize, .class_init = char_pty_class_init, };
Signature · 1 line
2.11.0
PATCH 8/40 char-ringbuf: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qemu-char.c +3 -3
@@ -3548,9 +3548,9 @@ static int ringbuf_chr_read(Chardev *chr, uint8_t *buf, int len)return i; } -static void ringbuf_chr_free (struct Chardev *chr) +static void char_ringbuf_finalize (Object *obj) { -RingBufChardev *d =RINGBUF_CHARDEV (chr); +RingBufChardev *d =RINGBUF_CHARDEV (obj);g_free (d->cbuf); }
@@ -3980,7 +3980,6 @@ static void char_ringbuf_class_init(ObjectClass *oc, void *data) cc->open = qemu_chr_open_ringbuf; cc->chr_write = ringbuf_chr_write; - cc->chr_free = ringbuf_chr_free; }static const TypeInfo char_ringbuf_type_info = {
@@ -3988,6 +3987,7 @@ static const TypeInfo char_ringbuf_type_info = { .parent = TYPE_CHARDEV, .class_init = char_ringbuf_class_init, .instance_size = sizeof(RingBufChardev), + .instance_finalize = char_ringbuf_finalize, };/* Bug-compatibility: */
Signature · 1 line
2.11.0
PATCH 9/40 char-parallel: convert parallel to finalize
In reply to Marc-André Lureau--- qemu-char.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
qemu-char.c +17 -13
@@ -2025,17 +2025,6 @@ static int pp_ioctl(Chardev *chr, int cmd, void *arg)return 0 ; } -static void pp_free (Chardev *chr) -{ -ParallelChardev *drv =PARALLEL_CHARDEV (chr); -int fd = drv->fd; - -pp_hw_mode (drv,IEEE1284_MODE_COMPAT ); -ioctl (fd,PPRELEASE ); -close (fd); -qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); -} - static void qemu_chr_open_pp_fd(Chardev *chr, int fd, bool *be_opened,
@@ -4697,18 +4686,33 @@ static void char_parallel_class_init(ObjectClass *oc, void *data)#if defined(__linux__) cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl; - cc->chr_free = pp_free;#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) -/* FIXME: no chr_free */ cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl; #endif } +static void char_parallel_finalize (Object *obj) +{ +#if defined(__linux__) +Chardev *chr =CHARDEV (obj); +ParallelChardev *drv =PARALLEL_CHARDEV (chr); +int fd = drv->fd; + +pp_hw_mode (drv,IEEE1284_MODE_COMPAT ); +ioctl (fd,PPRELEASE ); +close (fd); +qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) +/* FIXME: close fd? */ +#endif +} +static const TypeInfo char_parallel_type_info = { .name =TYPE_CHARDEV_PARALLEL , .parent =TYPE_CHARDEV , .instance_size =sizeof (ParallelChardev), + .instance_finalize = char_parallel_finalize, .class_init = char_parallel_class_init, };#endif
Signature · 1 line
2.11.0
PATCH 10/40 char-stdio: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qemu-char.c +3 -3
@@ -1422,10 +1422,10 @@ static void qemu_chr_set_echo_stdio(Chardev *chr, bool echo)tcsetattr (0 ,TCSANOW , &tty); } -static void qemu_chr_free_stdio (struct Chardev *chr) +static void char_stdio_finalize (Object *obj) {term_exit (); -fd_chr_free (chr); +fd_chr_free (CHARDEV (chr)); } static void qemu_chr_open_stdio(Chardev *chr,
@@ -3857,7 +3857,6 @@ static void char_stdio_class_init(ObjectClass *oc, void *data) cc->chr_free = win_stdio_free;#else cc->chr_set_echo = qemu_chr_set_echo_stdio; - cc->chr_free = qemu_chr_free_stdio;#endif }
@@ -3867,6 +3866,7 @@ static const TypeInfo char_stdio_type_info = { .parent = TYPE_CHARDEV_WIN_STDIO, #else .parent = TYPE_CHARDEV_FD, + .instance_finalize = char_stdio_finalize, #endif .class_init = char_stdio_class_init, };
Signature · 1 line
2.11.0
PATCH 11/40 char-win-stdio: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qemu-char.c +3 -3
@@ -2594,9 +2594,9 @@ static void qemu_chr_set_echo_win_stdio(Chardev *chr, bool echo) } } -static void win_stdio_free (Chardev *chr) +static void char_win_stdio_finalize (Object *obj) { -WinStdioChardev *stdio =WIN_STDIO_CHARDEV (chr); +WinStdioChardev *stdio =WIN_STDIO_CHARDEV (obj);if (stdio->hInputReadyEvent !=INVALID_HANDLE_VALUE ) {CloseHandle (stdio->hInputReadyEvent);
@@ -2613,6 +2613,7 @@ static const TypeInfo char_win_stdio_type_info = { .name = TYPE_CHARDEV_WIN_STDIO, .parent = TYPE_CHARDEV, .instance_size = sizeof(WinStdioChardev), + .instance_finalize = char_win_stdio_finalize, .abstract = true, };
@@ -3854,7 +3855,6 @@ static void char_stdio_class_init(ObjectClass *oc, void *data)#ifdef _WIN32 cc->chr_write = win_stdio_write; cc->chr_set_echo = qemu_chr_set_echo_win_stdio; - cc->chr_free = win_stdio_free;#else cc->chr_set_echo = qemu_chr_set_echo_stdio;#endif
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 11/40] char-win-stdio: convert to finalize
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- qemu-char.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Patches 3-11: Reviewed-by: Eric Blake <[email protected]>
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 12/40 char-win: do not override chr_free
In reply to Marc-André LureauFor some unclear reason to me, char-file does not have chr_free on win32. Since we want to switch to instance finalizer instead of class chr_free, we should be able to run the base WinChardev class finalizer in any case. Use a boolean to skip free to ease the transition to instance finalizer.
--- qemu-char.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
qemu-char.c +7 -5
@@ -2122,6 +2122,8 @@ typedef struct {/* Protected by the Chardev chr_write_lock. */ OVERLAPPED osend; +/* FIXME: file/console do not finalize */ +BOOL skip_free; } WinChardev;#define TYPE_CHARDEV_WIN "chardev-win"
@@ -2152,6 +2154,10 @@ static void win_chr_free(Chardev *chr) {WinChardev *s =WIN_CHARDEV (chr); +if (s->skip_free) { +return ; + } +if (s->hsend) {CloseHandle (s->hsend); s->hsend =NULL ;
@@ -2432,6 +2438,7 @@ static void qemu_chr_open_win_file(Chardev *chr, HANDLE fd_out) {WinChardev *s =WIN_CHARDEV (chr); + s->skip_free = true; s->hcom = fd_out; }
@@ -2468,7 +2475,6 @@ static void char_console_class_init(ObjectClass *oc, void *data)ChardevClass *cc =CHARDEV_CLASS (oc); cc->open = qemu_chr_open_win_con; - cc->chr_free =NULL ; }static const TypeInfo char_console_type_info = {
@@ -4729,10 +4735,6 @@ static void char_file_class_init(ObjectClass *oc, void *data)ChardevClass *cc =CHARDEV_CLASS (oc); cc->open = qmp_chardev_open_file; -#ifdef _WIN32 -/* FIXME: no chr_free */ - cc->chr_free =NULL ; -#endif }static const TypeInfo char_file_type_info = {
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 12/40] char-win: do not override chr_free
Quoted 16 lines · Marc-André Lureau
For some unclear reason to me, char-file does not have
chr_freeon win32. Since we want to switch to instance finalizer instead of classchr_free, we should be able to run the base WinChardev class finalizer in any case. Use a boolean to skip free to ease the transition to instance finalizer.Signed-off-by Marc-André Lureau <[email protected]>--- qemu-char.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)qemu-char.c +0
-0
qemu-char.c typedef struct { · line 2126
Quoted 5 lines
qemu-char.c +2
-0@@ -2122,6 +2122,8 @@ typedef struct {/* Protected by the Chardev chr_write_lock. */ OVERLAPPED osend; +/* FIXME: file/console do not finalize */ +BOOL skip_free;
Do we really need the glib type, or is bool sufficient?
Quoted 15 lines
qemu-char.c +4
-0} WinChardev;#define TYPE_CHARDEV_WIN "chardev-win"@@ -2152,6 +2154,10 @@ static void win_chr_free(Chardev *chr) {WinChardev *s =WIN_CHARDEV (chr); +if (s->skip_free) { +return ; + } +if (s->hsend) {CloseHandle (s->hsend); s->hsend =NULL ;
qemu-char.c static void qemu_chr_open_win_file(Chardev *chr, HANDLE fd_out) · line 2441
Quoted 4 lines
qemu-char.c +1
-0@@ -2432,6 +2438,7 @@ static void qemu_chr_open_win_file(Chardev *chr, HANDLE fd_out) {WinChardev *s =WIN_CHARDEV (chr); + s->skip_free = true;
Particularly since you assign it the bool true, rather than the glib TRUE.
With that fixed,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 12/40] char-win: do not override chr_free
----- Original Message -----
Quoted 18 lines · Marc-André Lureau
Quoted 17 lines
For some unclear reason to me, char-file does not have
chr_freeon win32. Since we want to switch to instance finalizer instead of classchr_free, we should be able to run the base WinChardev class finalizer in any case. Use a boolean to skip free to ease the transition to instance finalizer.Signed-off-by Marc-André Lureau <[email protected]>--- qemu-char.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)qemu-char.c +0
-0@@ -2122,6 +2122,8 @@ typedef struct {
Quoted 6 lines
qemu-char.c typedef struct { · line 2126
Quoted 4 lines
qemu-char.c +2
-0/* Protected by the Chardev chr_write_lock. */ OVERLAPPED osend; +/* FIXME: file/console do not finalize */ +BOOL skip_free;Do we really need the glib type, or is bool sufficient?
It's windows type actually, but bool is sufficient (there is a BOOL fpipe before, probably not needed either)
ok
Quoted 32 lines
Quoted 16 lines
qemu-char.c +4
-0} WinChardev;#define TYPE_CHARDEV_WIN "chardev-win"@@ -2152,6 +2154,10 @@ static void win_chr_free(Chardev *chr) {WinChardev *s =WIN_CHARDEV (chr); +if (s->skip_free) { +return ; + } +if (s->hsend) {CloseHandle (s->hsend); s->hsend =NULL ;qemu-char.c static void qemu_chr_open_win_file(Chardev *chr, · line 2442
Quoted 5 lines
qemu-char.c +1
-0@@ -2432,6 +2438,7 @@ static void qemu_chr_open_win_file(Chardev *chr, HANDLE fd_out) {WinChardev *s =WIN_CHARDEV (chr); + s->skip_free = true;Particularly since you assign it the bool true, rather than the glib TRUE.
With that fixed,
Reviewed-by Eric Blake <[email protected]>--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
PATCH 13/40 char-win: convert to finalize
In reply to Marc-André Lureau--- qemu-char.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
qemu-char.c +3 -7
@@ -2150,8 +2150,9 @@ typedef struct {static int win_chr_poll (void *opaque);static int win_chr_pipe_poll (void *opaque); -static void win_chr_free (Chardev *chr) +static void char_win_finalize (Object *obj) { +Chardev *chr =CHARDEV (obj);WinChardev *s =WIN_CHARDEV (chr);if (s->skip_free) {
@@ -2160,15 +2161,12 @@ static void win_chr_free(Chardev *chr)if (s->hsend) {CloseHandle (s->hsend); - s->hsend =NULL ; }if (s->hrecv) {CloseHandle (s->hrecv); - s->hrecv =NULL ; }if (s->hcom) {CloseHandle (s->hcom); - s->hcom =NULL ; }if (s->fpipe)qemu_del_polling_cb (win_chr_pipe_poll, chr);
@@ -2241,7 +2239,6 @@ static int win_chr_init(Chardev *chr, const char *filename, Error **errp)return 0 ; fail: -win_chr_free (chr);return -1 ; }
@@ -2416,7 +2413,6 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,return 0 ; fail: -win_chr_free (chr);return -1 ; }
@@ -2447,13 +2443,13 @@ static void char_win_class_init(ObjectClass *oc, void *data)ChardevClass *cc =CHARDEV_CLASS (oc); cc->chr_write = win_chr_write; - cc->chr_free = win_chr_free; }static const TypeInfo char_win_type_info = { .name =TYPE_CHARDEV_WIN , .parent =TYPE_CHARDEV , .instance_size =sizeof (WinChardev), + .instance_finalize = char_win_finalize, .class_init = char_win_class_init, .abstract = true, };
Signature · 1 line
2.11.0
PATCH 14/40 char-fd: convert to finalize
In reply to Marc-André Lureauchar-serial inherits from char-fd finalizer.
--- qemu-char.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
qemu-char.c +4 -10
@@ -1296,9 +1296,10 @@ static void fd_chr_update_read_handler(Chardev *chr, } } -static void fd_chr_free (struct Chardev *chr) +static void char_fd_finalize (Object *obj) { -FDChardev *s =FD_CHARDEV (chr); +Chardev *chr =CHARDEV (obj); +FDChardev *s =FD_CHARDEV (obj);remove_fd_in_watch (chr);if (s->ioc_in) {
@@ -1337,13 +1338,13 @@ static void char_fd_class_init(ObjectClass *oc, void *data) cc->chr_add_watch = fd_chr_add_watch; cc->chr_write = fd_chr_write; cc->chr_update_read_handler = fd_chr_update_read_handler; - cc->chr_free = fd_chr_free; }static const TypeInfo char_fd_type_info = { .name =TYPE_CHARDEV_FD , .parent =TYPE_CHARDEV , .instance_size =sizeof (FDChardev), + .instance_finalize = char_fd_finalize, .class_init = char_fd_class_init, .abstract = true, };
@@ -1425,7 +1426,6 @@ static void qemu_chr_set_echo_stdio(Chardev *chr, bool echo)static void char_stdio_finalize (Object *obj) {term_exit (); -fd_chr_free (CHARDEV (chr)); } static void qemu_chr_open_stdio(Chardev *chr,
@@ -1913,11 +1913,6 @@ static int tty_serial_ioctl(Chardev *chr, int cmd, void *arg) }return 0 ; } - -static void qemu_chr_free_tty (Chardev *chr) -{ -fd_chr_free (chr); -}#endif /* __linux__ || __sun__ */ #if defined(__linux__)
@@ -4758,7 +4753,6 @@ static void char_serial_class_init(ObjectClass *oc, void *data) cc->open = qmp_chardev_open_serial;#ifndef _WIN32 cc->chr_ioctl = tty_serial_ioctl; - cc->chr_free = qemu_chr_free_tty;#endif }
Signature · 1 line
2.11.0
PATCH 15/40 char: remove chr_free
In reply to Marc-André LureauNow it uses Object instance_finalize instead.
--- include/sysemu/char.h | 8 -------- qemu-char.c | 10 +--------- 2 files changed, 1 insertion(+), 17 deletions(-)
include/sysemu/char.h +0 -8
@@ -184,13 +184,6 @@ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename);*/ void qemu_chr_delete (Chardev *chr); -/** -* @qemu_chr_free: -* -* Destroy a character backend. -*/ -void qemu_chr_free (Chardev *chr); -/** * @qemu_chr_fe_set_echo: *
@@ -496,7 +489,6 @@ typedef struct ChardevClass {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);
qemu-char.c +1 -9
@@ -4369,18 +4369,10 @@ void qemu_chr_fe_disconnect(CharBackend *be) } } -void qemu_chr_free (Chardev *chr) -{ -if (CHARDEV_GET_CLASS (chr)->chr_free) { -CHARDEV_GET_CLASS (chr)->chr_free (chr); - } -object_unref (OBJECT (chr)); -} -void qemu_chr_delete (Chardev *chr) {QTAILQ_REMOVE (&chardevs, chr, next); -qemu_chr_free (chr); +object_unref (OBJECT (chr)); }ChardevInfoList *qmp_query_chardev (Error **errp)
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 15/40] char: remove chr_free
Quoted 7 lines · Marc-André Lureau
Now it uses Object
instance_finalizeinstead.Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 8 -------- qemu-char.c | 10 +--------- 2 files changed, 1 insertion(+), 17 deletions(-)
patches 13-15: Reviewed-by: Eric Blake <[email protected]>
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 16/40 char: get rid of CharDriver
In reply to Marc-André Lureauqemu_chr_new_from_opts() is modified to not need CharDriver backend[] array, but uses instead objectified qmp_query_chardev_backends() and char_get_class(). The alias field is moved outside in a ChardevAlias[], similar to QDevAlias for devices.
"kind" and "parse" are moved to ChardevClass ("kind" is to be removed next)
--- include/sysemu/char.h | 12 +-- backends/baum.c | 6 +- backends/msmouse.c | 6 +- backends/testdev.c | 6 +- qemu-char.c | 275 +++++++++++++++++++++----------------------------- spice-qemu-char.c | 15 +-- ui/console.c | 10 +- ui/gtk.c | 10 +- 8 files changed, 128 insertions(+), 212 deletions(-)
include/sysemu/char.h +2 -10
@@ -88,8 +88,6 @@ typedef struct CharBackend {int fe_open; } CharBackend; -typedef struct CharDriver CharDriver ; -struct Chardev {Object parent_obj;
@@ -476,6 +474,8 @@ typedef struct ChardevClass {ObjectClass parent_class;bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ +ChardevBackendKind kind; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp);void (*open)(Chardev *chr,ChardevBackend *backend,bool *be_opened,Error **errp);
@@ -495,17 +495,9 @@ typedef struct ChardevClass {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 *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;/* console.c */
backends/baum.c +1 -5
@@ -656,6 +656,7 @@ static void char_braille_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_BRAILLE ; cc->open = baum_chr_open; cc->chr_write = baum_chr_write; cc->chr_accept_input = baum_chr_accept_input;
@@ -671,11 +672,6 @@ static const TypeInfo char_braille_type_info = {static void register_types (void ) { -static const CharDriver driver = { - .kind =CHARDEV_BACKEND_KIND_BRAILLE , - }; - -register_char_driver (&driver);type_register_static (&char_braille_type_info); }
backends/msmouse.c +1 -5
@@ -169,6 +169,7 @@ static void char_msmouse_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_MSMOUSE ; cc->open = msmouse_chr_open; cc->chr_write = msmouse_chr_write; cc->chr_accept_input = msmouse_chr_accept_input;
@@ -184,11 +185,6 @@ static const TypeInfo char_msmouse_type_info = {static void register_types (void ) { -static const CharDriver driver = { - .kind =CHARDEV_BACKEND_KIND_MSMOUSE , - }; - -register_char_driver (&driver);type_register_static (&char_msmouse_type_info); }
backends/testdev.c +1 -5
@@ -111,6 +111,7 @@ static void char_testdev_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_TESTDEV ; cc->chr_write = testdev_chr_write; }
@@ -123,11 +124,6 @@ static const TypeInfo char_testdev_type_info = {static void register_types (void ) { -static const CharDriver driver = { - .kind =CHARDEV_BACKEND_KIND_TESTDEV , - }; - -register_char_driver (&driver);type_register_static (&char_testdev_type_info); }
qemu-char.c +115 -160
480 lines not on this page · raw message
spice-qemu-char.c +4 -11
@@ -380,6 +380,8 @@ static void char_spicevmc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_SPICEVMC ; + cc->parse = qemu_chr_parse_spice_vmc; cc->open = qemu_chr_open_spice_vmc; cc->chr_set_fe_open = spice_vmc_set_fe_open; }
@@ -394,6 +396,8 @@ static void char_spiceport_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_SPICEPORT ; + cc->parse = qemu_chr_parse_spice_port; cc->open = qemu_chr_open_spice_port; cc->chr_set_fe_open = spice_port_set_fe_open; }
@@ -406,17 +410,6 @@ static const TypeInfo char_spiceport_type_info = {static void register_types (void ) { -static const CharDriver vmc_driver = { - .kind =CHARDEV_BACKEND_KIND_SPICEVMC , - .parse = qemu_chr_parse_spice_vmc, - }; -static const CharDriver port_driver = { - .kind =CHARDEV_BACKEND_KIND_SPICEPORT , - .parse = qemu_chr_parse_spice_port, - }; -register_char_driver (&vmc_driver); -register_char_driver (&port_driver); -type_register_static (&char_spice_type_info);type_register_static (&char_spicevmc_type_info);type_register_static (&char_spiceport_type_info);
ui/console.c +2 -8
@@ -2059,8 +2059,6 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)qemu_chr_be_generic_open (chr); } -static const CharDriver vc_driver; - static void vc_chr_open(Chardev *chr, ChardevBackend *backend, bool *be_opened,
@@ -2189,6 +2187,8 @@ static void char_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_VC ; + cc->parse = qemu_chr_parse_vc; cc->open = vc_chr_open; cc->chr_write = vc_chr_write; cc->chr_set_echo = vc_chr_set_echo;
@@ -2206,15 +2206,9 @@ void qemu_console_early_init(void)/* set the default vc driver */ if (!object_class_by_name (TYPE_CHARDEV_VC )) {type_register (&char_vc_type_info); -register_char_driver (&vc_driver); } } -static const CharDriver vc_driver = { - .kind =CHARDEV_BACKEND_KIND_VC , - .parse = qemu_chr_parse_vc, -}; -static void register_types (void ) {type_register_static (&qemu_console_info);
ui/gtk.c +2 -8
@@ -1715,8 +1715,6 @@ 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 void gd_vc_open(Chardev *chr, ChardevBackend *backend, bool *be_opened,
@@ -1739,6 +1737,8 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); + cc->kind =CHARDEV_BACKEND_KIND_VC ; + cc->parse = qemu_chr_parse_vc; cc->open = gd_vc_open; cc->chr_write = gd_vc_chr_write; cc->chr_set_echo = gd_vc_chr_set_echo;
@@ -1751,11 +1751,6 @@ static const TypeInfo char_gd_vc_type_info = { .class_init = char_gd_vc_class_init, }; -static const CharDriver gd_vc_driver = { - .kind =CHARDEV_BACKEND_KIND_VC , - .parse = qemu_chr_parse_vc, -}; -static gboolean gd_vc_in (VteTerminal *terminal,gchar *text,guint size,gpointer user_data) {
@@ -2353,6 +2348,5 @@ void early_gtk_display_init(int opengl)#if defined(CONFIG_VTE )type_register (&char_gd_vc_type_info); -register_char_driver (&gd_vc_driver);#endif }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 16/40] char: get rid of CharDriver
Quoted 30 lines · Marc-André Lureau
qemu_chr_new_from_opts()is modified to not need CharDriver backend[] array, but uses instead objectifiedqmp_query_chardev_backends()andchar_get_class(). The alias field is moved outside in a ChardevAlias[], similar to QDevAlias for devices."kind" and "parse" are moved to ChardevClass ("kind" is to be removed next)
Signed-off-by Marc-André Lureau <[email protected]>---
Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
Error **errp){ Error *local_err = NULL;qemu-char.c +1
-6-const CharDriver *cd =NULL ; +const ChardevClass *cc;Chardev *chr;int i;ChardevReturn *ret =NULL ;@@ -4180,16 +4196,13 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,if (is_help_option (name)) {GString *str =g_string_new ("" ); -for (i =0 ; i <ARRAY_SIZE (backends); i++) { - cd = backends[i]; -if (cd) { -g_string_append_printf (str,"\n%s" , ChardevBackendKind_lookup[cd->kind]); -if (cd->alias) {
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4205
Quoted 10 lines
qemu-char.c +5
-3-g_string_append_printf (str,"\n%s" , cd->alias); - } - } +ChardevBackendInfoList *l, *il =qmp_query_chardev_backends (NULL ); + +for (l = il; l !=NULL ; l = l->next) { +g_string_append_printf (str,"\n%s" , l->value->name); } +qapi_free_ChardevBackendInfoList (l);
Is this really the most efficient way to do it? I guess it works, but consider what qmp_query_chardev_backends() is doing: it is iterating through a list of chardevs, and for each one (or its alias), calling a callback qmp_prepend_backend(). Would a better factorization be to have a common function that takes care of the iteration and takes a function pointer for what to do on each element of the iteration, and then qmp_query_chardev_backend calls helper(qmp_prepend_backup) while this code calls helper(append_name), so that you aren't wasting the creation of an entire ChardevBackendInfoList item just for the action of appending the name?
Quoted 18 lines
qemu-char.c +5
-5@@ -4407,21 +4417,23 @@ qmp_prepend_backend(ChardevBackendInfoList *list, const char *name)ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -const CharDriver *c; +GSList *l, *list =object_class_get_list (TYPE_CHARDEV , false);int i; -for (i =0 ; i <ARRAY_SIZE (backends); i++) { - c = backends[i]; -if (!c) { +for (l = list; l; l = l->next) { +ObjectClass *klass = l->data; +assert (g_str_has_prefix (object_class_get_name (klass),"chardev-" )); +if (CHARDEV_CLASS (klass)->internal) {continue ; } -
qemu-char.c qmp_prepend_backend(ChardevBackendInfoList *list, const char *name) · line 4434
Quoted 10 lines
qemu-char.c +5
-4backend_list =qmp_prepend_backend (backend_list, - ChardevBackendKind_lookup[c->kind]); -if (c->alias) { - backend_list =qmp_prepend_backend (backend_list, c->alias); - } +object_class_get_name (klass) +8 ); + } +for (i =0 ; i <ARRAY_SIZE (chardev_alias_table); i++) { + backend_list =qmp_prepend_backend (backend_list, + chardev_alias_table[i].alias);
This changes the order of the list which is output to the user (shouldn't matter in practice, but may be worth mentioning in the commit message as intentionally safe).
Again, I think that a little more refactoring to have the iteration over object_class_get_list() and chardev_alias_table[], coupled with a callback passed in by the client (with clients qemu_chr_new_from_opts and qmp_query_chardev_backends), will separate the iteration from the action, so that you don't always have to create a ChardevBackendInfoList that will just be thrown away.
qemu-char.c qmp_prepend_backend(ChardevBackendInfoList *list, const char *name) · line 4436
Quoted 2 lines
qemu-char.c +1
-0} +g_slist_free (l);
Shouldn't this be g_slist_free(list)?
qemu-char.c void qemu_chr_set_feature(Chardev *chr, · line 4987
Quoted 6 lines
qemu-char.c +0
-2@@ -4983,35 +4978,6 @@ void qemu_chr_set_feature(Chardev *chr,return set_bit (feature, chr->features); } -static const ChardevClass *char_get_class (const char *driver,Error **errp) -{
This function is just moved earlier, which gets a little messy with the rest of the patch. Can you split the code motion into a separate patch for ease of review? In fact, since it was just barely added in "[PATCH v2 20/20] chardev: qom-ify]" and that patch hasn't landed yet, can't you just amend that patch to hoist it early enough in the first place, rather than churning it?
Quoted 11 lines
qemu-char.c +0
-7@@ -5107,45 +5073,34 @@ void qemu_chr_cleanup(void)static void register_types (void ) { -static const struct { -const CharDriver *driver; -const TypeInfo *type; - } chardevs[] = { - { &null_driver, &char_null_type_info }, - { &socket_driver, &char_socket_type_info }, - { &udp_driver, &char_udp_type_info },
qemu-char.c void qemu_chr_cleanup(void) · line 5082
Quoted 10 lines
qemu-char.c +7
-3- { &ringbuf_driver, &char_ringbuf_type_info }, - { &file_driver, &char_file_type_info }, - { &stdio_driver, &char_stdio_type_info }, +type_register_static (&char_type_info); +#ifndef _WIN32 +type_register_static (&char_fd_type_info); +#else +type_register_static (&char_win_type_info); +type_register_static (&char_win_stdio_type_info); +#endif
It's a bit weird that these are registered first,...
Quoted 11 lines
qemu-char.c +7
-1+type_register_static (&char_null_type_info); +type_register_static (&char_socket_type_info); +type_register_static (&char_udp_type_info); +type_register_static (&char_ringbuf_type_info); +type_register_static (&char_file_type_info); +type_register_static (&char_stdio_type_info);#ifdef HAVE_CHARDEV_SERIAL - { &serial_driver, &char_serial_type_info }, +type_register_static (&char_serial_type_info);#endif #ifdef HAVE_CHARDEV_PARPORT
qemu-char.c void qemu_chr_cleanup(void) · line 5099
Quoted 10 lines
qemu-char.c +3
-3- { ¶llel_driver, &char_parallel_type_info }, +type_register_static (&char_parallel_type_info);#endif #ifdef HAVE_CHARDEV_PTY - { &pty_driver, &char_pty_type_info }, +type_register_static (&char_pty_type_info);#endif #ifdef _WIN32 - { &console_driver, &char_console_type_info }, +type_register_static (&char_console_type_info);
Any reason we can't consolidate the _WIN32 ifdefs into one place?
Quoted 4 lines
qemu-char.c +0
-3#endif - { &pipe_driver, &char_pipe_type_info }, - { &mux_driver, &char_mux_type_info }, - { &memory_driver, &char_memory_type_info }
qemu-char.c void qemu_chr_cleanup(void) · line 5144
Quoted 10 lines
qemu-char.c +0
-10- }; -int i; - -type_register_static (&char_type_info); -#ifndef _WIN32 -type_register_static (&char_fd_type_info); -#else -type_register_static (&char_win_type_info); -type_register_static (&char_win_stdio_type_info); -#endif
...when they used to be last; but I don't think it hurts.
spice-qemu-char.c
Quoted 11 lines
qemu-char.c +3
-4-for (i =0 ; i <ARRAY_SIZE (chardevs); i++) { -type_register_static (chardevs[i].type); -register_char_driver (chardevs[i].driver); - } +type_register_static (&char_pipe_type_info); +type_register_static (&char_mux_type_info); +type_register_static (&char_memory_type_info);/* this must be done after machine init, since we register FEs with muxes * as part of realize functions like serial_isa_realizefn when -nographic spice-qemu-char.c +0
-0
Enough bugs that I'll want to see a v2, but it's headed in the right direction.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 16/40] char: get rid of CharDriver
Hi
----- Original Message -----
Quoted 41 lines · Marc-André Lureau
Quoted 40 lines
qemu_chr_new_from_opts()is modified to not need CharDriver backend[] array, but uses instead objectifiedqmp_query_chardev_backends()andchar_get_class(). The alias field is moved outside in a ChardevAlias[], similar to QDevAlias for devices."kind" and "parse" are moved to ChardevClass ("kind" is to be removed next)
Signed-off-by Marc-André Lureau <[email protected]>---
Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
Error **errp){ Error *local_err = NULL;qemu-char.c +5
-9-const CharDriver *cd =NULL ; +const ChardevClass *cc;Chardev *chr;int i;ChardevReturn *ret =NULL ;@@ -4180,16 +4196,13 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,if (is_help_option (name)) {GString *str =g_string_new ("" ); -for (i =0 ; i <ARRAY_SIZE (backends); i++) { - cd = backends[i]; -if (cd) { -g_string_append_printf (str,"\n%s" , ChardevBackendKind_lookup[cd->kind]); -if (cd->alias) { -g_string_append_printf (str,"\n%s" , cd->alias); - } - } +ChardevBackendInfoList *l, *il =qmp_query_chardev_backends (NULL ); + +for (l = il; l !=NULL ; l = l->next) { +g_string_append_printf (str,"\n%s" , l->value->name); }
Quoted 13 lines
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4205
Quoted 1 line
qemu-char.c +1
-0+qapi_free_ChardevBackendInfoList (l);Is this really the most efficient way to do it? I guess it works, but consider what
qmp_query_chardev_backends()is doing: it is iterating through a list of chardevs, and for each one (or its alias), calling a callbackqmp_prepend_backend(). Would a better factorization be to have a common function that takes care of the iteration and takes a function pointer for what to do on each element of the iteration, and thenqmp_query_chardev_backendcallshelper(qmp_prepend_backup)while this code callshelper(append_name), so that you aren't wasting the creation of an entire ChardevBackendInfoList item just for the action of appending the name?
I don't think speed matters here, but ok
Quoted 28 lines
Quoted 28 lines
qemu-char.c +6
-9@@ -4407,21 +4417,23 @@ qmp_prepend_backend(ChardevBackendInfoList *list, const char *name) ChardevBackendInfoList *qmp_query_chardev_backends(Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -const CharDriver *c; +GSList *l, *list =object_class_get_list (TYPE_CHARDEV , false);int i; -for (i =0 ; i <ARRAY_SIZE (backends); i++) { - c = backends[i]; -if (!c) { +for (l = list; l; l = l->next) { +ObjectClass *klass = l->data; +assert (g_str_has_prefix (object_class_get_name (klass),"chardev-" )); +if (CHARDEV_CLASS (klass)->internal) {continue ; } - backend_list =qmp_prepend_backend (backend_list, - ChardevBackendKind_lookup[c->kind]); -if (c->alias) { - backend_list =qmp_prepend_backend (backend_list, c->alias); - } +object_class_get_name (klass) + 8);
Quoted 8 lines
qemu-char.c qmp_prepend_backend(ChardevBackendInfoList *list, const char *name) · line 4434
Quoted 4 lines
qemu-char.c +4
-0+ } +for (i =0 ; i <ARRAY_SIZE (chardev_alias_table); i++) { + backend_list =qmp_prepend_backend (backend_list, + chardev_alias_table[i].alias);This changes the order of the list which is output to the user (shouldn't matter in practice, but may be worth mentioning in the commit message as intentionally safe).
ok
Quoted 7 lines
Again, I think that a little more refactoring to have the iteration over
object_class_get_list()and chardev_alias_table[], coupled with a callback passed in by the client (with clientsqemu_chr_new_from_optsandqmp_query_chardev_backends), will separate the iteration from the action, so that you don't always have to create a ChardevBackendInfoList that will just be thrown away.
not a trivial refactoring (various callbacks, passed to callback etc) but ok
Quoted 5 lines
Quoted 3 lines
}+
g_slist_free(l);Shouldn't this be
g_slist_free(list)?
Yes my bad, same error with qapi_free_ChardevBackendInfoList()!
Quoted 5 lines
Quoted 5 lines
qemu-char.c +0
-0@@ -4983,35 +4978,6 @@ void qemu_chr_set_feature(Chardev *chr,return set_bit (feature, chr->features); }
Quoted 10 lines
Review void qemu_chr_set_feature(Chardev *chr, · line 4988
Quoted 3 lines
(quoted diff) +0
-2-static const ChardevClass *char_get_class(const char *driver, Error **errp) -{This function is just moved earlier, which gets a little messy with the rest of the patch. Can you split the code motion into a separate patch for ease of review? In fact, since it was just barely added in "[PATCH v2 20/20] chardev: qom-ify]" and that patch hasn't landed yet, can't you just amend that patch to hoist it early enough in the first place, rather than churning it?
It depends if I get to resend it or not. Paolo, you may drop it from the first series, so I resend it with this one?
Quoted 48 lines
Quoted 13 lines
qemu-char.c +0
-7@@ -5107,45 +5073,34 @@ void qemu_chr_cleanup(void)static void register_types (void ) { -static const struct { -const CharDriver *driver; -const TypeInfo *type; - } chardevs[] = { - { &null_driver, &char_null_type_info }, - { &socket_driver, &char_socket_type_info }, - { &udp_driver, &char_udp_type_info },qemu-char.c void qemu_chr_cleanup(void) · line 5082
Quoted 10 lines
qemu-char.c +7
-3- { &ringbuf_driver, &char_ringbuf_type_info }, - { &file_driver, &char_file_type_info }, - { &stdio_driver, &char_stdio_type_info }, +type_register_static (&char_type_info); +#ifndef _WIN32 +type_register_static (&char_fd_type_info); +#else +type_register_static (&char_win_type_info); +type_register_static (&char_win_stdio_type_info); +#endif It's a bit weird that these are registered first,...
Quoted 11 lines
qemu-char.c +7
-1+type_register_static (&char_null_type_info); +type_register_static (&char_socket_type_info); +type_register_static (&char_udp_type_info); +type_register_static (&char_ringbuf_type_info); +type_register_static (&char_file_type_info); +type_register_static (&char_stdio_type_info);#ifdef HAVE_CHARDEV_SERIAL - { &serial_driver, &char_serial_type_info }, +type_register_static (&char_serial_type_info);#endif #ifdef HAVE_CHARDEV_PARPORT qemu-char.c void qemu_chr_cleanup(void) · line 5099
Quoted 10 lines
qemu-char.c +3
-3- { ¶llel_driver, &char_parallel_type_info }, +type_register_static (&char_parallel_type_info);#endif #ifdef HAVE_CHARDEV_PTY - { &pty_driver, &char_pty_type_info }, +type_register_static (&char_pty_type_info);#endif #ifdef _WIN32 - { &console_driver, &char_console_type_info }, +type_register_static (&char_console_type_info);
Quoted 1 line
Any reason we can't consolidate the
_WIN32ifdefs into one place?
we could, but this is going away later in this series
Quoted 17 lines
Quoted 5 lines
qemu-char.c +0
-3#endif - { &pipe_driver, &char_pipe_type_info }, - { &mux_driver, &char_mux_type_info }, - { &memory_driver, &char_memory_type_info }qemu-char.c void qemu_chr_cleanup(void) · line 5144
Quoted 10 lines
qemu-char.c +0
-10- }; -int i; - -type_register_static (&char_type_info); -#ifndef _WIN32 -type_register_static (&char_fd_type_info); -#else -type_register_static (&char_win_type_info); -type_register_static (&char_win_stdio_type_info); -#endif ...when they used to be last; but I don't think it hurts.
It doesn't, and it is spread later in the series, I wouldn't bother.
Quoted 9 lines
Quoted 9 lines
qemu-char.c +3
-4-for (i =0 ; i <ARRAY_SIZE (chardevs); i++) { -type_register_static (chardevs[i].type); -register_char_driver (chardevs[i].driver); - } +type_register_static (&char_pipe_type_info); +type_register_static (&char_mux_type_info); +type_register_static (&char_memory_type_info);
Quoted 8 lines
spice-qemu-char.c
Quoted 5 lines
(quoted diff) +0
-0/* this must be done after machine init, since we register FEs with muxes* as part of realize functions like
serial_isa_realizefnwhen -nographicspice-qemu-char.c +0
-0Enough bugs that I'll want to see a v2, but it's headed in the right direction.
thanks, I'll wait for Paolo to take the first series before sending v2. Feel free to continue review of v1 for the remaining patches.
Quoted 6 lines
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
PATCH 17/40 char: rename remaining CharDriver to Chardev
In reply to Marc-André LureauCharDriver no longer exists, it has been replaced with Chardev.
--- include/sysemu/char.h | 40 ++++++++++++++++++++-------------------- qemu-char.c | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-)
include/sysemu/char.h +20 -20
@@ -74,7 +74,7 @@ typedef enum {QEMU_CHAR_FEATURE_REPLAY ,QEMU_CHAR_FEATURE_LAST , -} CharDriverFeature; +} ChardevFeature;/* This is the backend as seen by frontend, the actual backend is * Chardev */
@@ -141,7 +141,7 @@ Chardev *qemu_chr_new(const char *label, const char *filename);* @qemu_chr_fe_disconnect: * * Close a fd accpeted by character backend. -* Without associated CharDriver, do nothing. +* Without associated Chardev, do nothing. */ void qemu_chr_fe_disconnect (CharBackend *be);
@@ -156,7 +156,7 @@ void qemu_chr_cleanup(void);* @qemu_chr_fe_wait_connected: * * Wait for characted backend to be connected, return < 0 on error or -* if no assicated CharDriver. +* if no assicated Chardev. */ int qemu_chr_fe_wait_connected (CharBackend *be,Error **errp);
@@ -188,7 +188,7 @@ void qemu_chr_delete(Chardev *chr);* Ask the backend to override its normal echo setting. This only really * applies to the stdio backend and is used by the QMP server such that you * can see what you type if you try to type QMP commands. -* Without associated CharDriver, do nothing. +* Without associated Chardev, do nothing. * * @echo true to enable echo, false to disable echo */
@@ -199,7 +199,7 @@ void qemu_chr_fe_set_echo(CharBackend *be, bool echo);* * Set character frontend open status. This is an indication that the * front end is ready (or not) to begin doing I/O. -* Without associated CharDriver, do nothing. +* Without associated Chardev, do nothing. */ void qemu_chr_fe_set_open (CharBackend *be,int fe_open);
@@ -208,7 +208,7 @@ void qemu_chr_fe_set_open(CharBackend *be, int fe_open);* * Write to a character backend using a printf style interface. This * function is thread-safe. It does nothing without associated -* CharDriver. +* Chardev. * * @fmt see #printf */
@@ -221,7 +221,7 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)* If the backend is connected, create and add a #GSource that fires * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP) * is active; return the #GSource's tag. If it is disconnected, -* or without associated CharDriver, return 0. +* or without associated Chardev, return 0. * * @cond the condition to poll for * @func the function to call when the condition happens
@@ -242,7 +242,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,* @buf the data * @len the number of bytes to send * -* Returns: the number of bytes consumed (0 if no assicated CharDriver) +* Returns: the number of bytes consumed (0 if no assicated Chardev) */ int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len);
@@ -257,7 +257,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);* @buf the data * @len the number of bytes to send * -* Returns: the number of bytes consumed (0 if no assicated CharDriver) +* Returns: the number of bytes consumed (0 if no assicated Chardev) */ int qemu_chr_fe_write_all (CharBackend *be,const uint8_t *buf,int len);
@@ -269,7 +269,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);* @buf the data buffer * @len the number of bytes to read * -* Returns: the number of bytes read (0 if no assicated CharDriver) +* Returns: the number of bytes read (0 if no assicated Chardev) */ int qemu_chr_fe_read_all (CharBackend *be,uint8_t *buf,int len);
@@ -282,7 +282,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);* @arg the data associated with @cmd * * Returns: if @cmd is not supported by the backend or there is no -* associated CharDriver, -ENOTSUP, otherwise the return +* associated Chardev, -ENOTSUP, otherwise the return * value depends on the semantics of @cmd */ int qemu_chr_fe_ioctl (CharBackend *be,int cmd,void *arg);
@@ -322,7 +322,7 @@ int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num);* result in overwriting the fd array with the new value without being send. * Upon writing the message the fd array is freed. * -* Returns: -1 if fd passing isn't supported or no associated CharDriver. +* Returns: -1 if fd passing isn't supported or no associated Chardev. */ int qemu_chr_fe_set_msgfds (CharBackend *be,int *fds,int num);
@@ -373,7 +373,7 @@ void qemu_chr_be_event(Chardev *s, int event);* @qemu_chr_fe_init: * * Initializes a front end for the given CharBackend and -* CharDriver. Call qemu_chr_fe_deinit() to remove the association and +* Chardev. Call qemu_chr_fe_deinit() to remove the association and * release the driver. * * Returns: false on error.
@@ -384,16 +384,16 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp);* @qemu_chr_fe_get_driver: * * Returns the driver associated with a CharBackend or NULL if no -* associated CharDriver. +* associated Chardev. */ Chardev *qemu_chr_fe_get_driver (CharBackend *be);/** * @qemu_chr_fe_deinit: * -* Dissociate the CharBackend from the CharDriver. +* Dissociate the CharBackend from the Chardev. * -* Safe to call without associated CharDriver. +* Safe to call without associated Chardev. */ void qemu_chr_fe_deinit (CharBackend *b);
@@ -412,7 +412,7 @@ void qemu_chr_fe_deinit(CharBackend *b);* Set the front end char handlers. The front end takes the focus if * any of the handler is non-NULL. * -* Without associated CharDriver, nothing is changed. +* Without associated Chardev, nothing is changed. */ void qemu_chr_fe_set_handlers(CharBackend *b, IOCanReadHandler *fd_can_read,
@@ -427,7 +427,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,* * Take the focus (if the front end is muxed). * -* Without associated CharDriver, nothing is changed. +* Without associated Chardev, nothing is changed. */ void qemu_chr_fe_take_focus (CharBackend *b);
@@ -437,9 +437,9 @@ int qemu_chr_add_client(Chardev *s, int fd);Chardev *qemu_chr_find (const char *name);bool qemu_chr_has_feature (Chardev *chr, -CharDriverFeature feature); +ChardevFeature feature);void qemu_chr_set_feature (Chardev *chr, -CharDriverFeature feature); +ChardevFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename);#define TYPE_CHARDEV "chardev"
qemu-char.c +6 -6
@@ -3171,13 +3171,13 @@ typedef struct {Chardev *chr;char buf[12 ];size_t buflen; -} TCPCharDriverTelnetInit; +} TCPChardevTelnetInit;static gboolean tcp_chr_telnet_init_io (QIOChannel *ioc, GIOCondition cond G_GNUC_UNUSED,gpointer user_data) { -TCPCharDriverTelnetInit *init = user_data; +TCPChardevTelnetInit *init = user_data;ssize_t ret; ret =qio_channel_write (ioc, init->buf, init->buflen,NULL );
@@ -3204,8 +3204,8 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,static void tcp_chr_telnet_init (Chardev *chr) {SocketChardev *s =SOCKET_CHARDEV (chr); -TCPCharDriverTelnetInit *init = -g_new0 (TCPCharDriverTelnetInit,1 ); +TCPChardevTelnetInit *init = +g_new0 (TCPChardevTelnetInit,1 );size_t n =0 ; init->chr = chr;
@@ -4967,13 +4967,13 @@ static const TypeInfo char_udp_type_info = { };bool qemu_chr_has_feature (Chardev *chr, -CharDriverFeature feature) +ChardevFeature feature) {return test_bit (feature, chr->features); }void qemu_chr_set_feature (Chardev *chr, -CharDriverFeature feature) +ChardevFeature feature) {return set_bit (feature, chr->features); }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 17/40] char: rename remaining CharDriver to Chardev
Quoted 27 lines · Marc-André Lureau
CharDriver no longer exists, it has been replaced with Chardev.
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 40 ++++++++++++++++++++-------------------- qemu-char.c | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-)+++
b/qemu-char.cqemu-char.c +2
-2@@ -3171,13 +3171,13 @@ typedef struct {Chardev *chr;char buf[12 ];size_t buflen; -} TCPCharDriverTelnetInit; +} TCPChardevTelnetInit;static gboolean tcp_chr_telnet_init_io (QIOChannel *ioc, GIOCondition cond G_GNUC_UNUSED,gpointer user_data) { -TCPCharDriverTelnetInit *init = user_data; +TCPChardevTelnetInit *init = user_data;ssize_t ret; ret =qio_channel_write (ioc, init->buf, init->buflen,NULL );
qemu-char.c static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc, · line 3208
Quoted 7 lines
qemu-char.c +2
-2@@ -3204,8 +3204,8 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,static void tcp_chr_telnet_init (Chardev *chr) {SocketChardev *s =SOCKET_CHARDEV (chr); -TCPCharDriverTelnetInit *init = -g_new0 (TCPCharDriverTelnetInit,1 ); +TCPChardevTelnetInit *init = +g_new0 (TCPChardevTelnetInit,1 );
This would fit within 80 columns on one line; but I'm also okay if you don't bother with those sorts of cleanups.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 18/40 char: remove class kind field
In reply to Marc-André LureauThe class kind is necessary to lookup the chardev name in qmp_chardev_add() after calling qemu_chr_new_from_opts() and to set the appropriate ChardevBackend (mainly to free the right fields).
qemu_chr_new_from_opts() can be changed to use a non-qmp function using the chardev class typename. Introduce qemu_chardev_add() to be called from qemu_chr_new_from_opts() and remove the class chardev kind field. Set the backend->type in the parse callback (when non-common fields are added).
--- include/sysemu/char.h | 1 - backends/baum.c | 1 - backends/msmouse.c | 1 - backends/testdev.c | 1 - qemu-char.c | 105 ++++++++++++++++++++++++-------------------------- spice-qemu-char.c | 4 +- ui/console.c | 2 +- ui/gtk.c | 1 - 8 files changed, 54 insertions(+), 62 deletions(-)
include/sysemu/char.h +0 -1
@@ -474,7 +474,6 @@ typedef struct ChardevClass {ObjectClass parent_class;bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ -ChardevBackendKind kind;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); void (*open)(Chardev *chr, ChardevBackend *backend,
backends/baum.c +0 -1
@@ -656,7 +656,6 @@ static void char_braille_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_BRAILLE ; cc->open = baum_chr_open; cc->chr_write = baum_chr_write; cc->chr_accept_input = baum_chr_accept_input;
backends/msmouse.c +0 -1
@@ -169,7 +169,6 @@ static void char_msmouse_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_MSMOUSE ; cc->open = msmouse_chr_open; cc->chr_write = msmouse_chr_write; cc->chr_accept_input = msmouse_chr_accept_input;
backends/testdev.c +0 -1
@@ -111,7 +111,6 @@ static void char_testdev_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_TESTDEV ; cc->chr_write = testdev_chr_write; }
qemu-char.c +51 -54
324 lines not on this page · raw message
spice-qemu-char.c +2 -2
@@ -338,6 +338,7 @@ static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: spice channel: no name given" );return ; } + backend->type =CHARDEV_BACKEND_KIND_SPICEVMC ; spicevmc = backend->u.spicevmc.data =g_new0 (ChardevSpiceChannel,1 );qemu_chr_parse_common (opts,qapi_ChardevSpiceChannel_base (spicevmc)); spicevmc->type =g_strdup (name);
@@ -353,6 +354,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: spice port: no name given" );return ; } + backend->type =CHARDEV_BACKEND_KIND_SPICEPORT ; spiceport = backend->u.spiceport.data =g_new0 (ChardevSpicePort,1 );qemu_chr_parse_common (opts,qapi_ChardevSpicePort_base (spiceport)); spiceport->fqdn =g_strdup (name);
@@ -380,7 +382,6 @@ static void char_spicevmc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_SPICEVMC ; cc->parse = qemu_chr_parse_spice_vmc; cc->open = qemu_chr_open_spice_vmc; cc->chr_set_fe_open = spice_vmc_set_fe_open;
@@ -396,7 +397,6 @@ static void char_spiceport_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_SPICEPORT ; cc->parse = qemu_chr_parse_spice_port; cc->open = qemu_chr_open_spice_port; cc->chr_set_fe_open = spice_port_set_fe_open;
ui/console.c +1 -1
@@ -2148,6 +2148,7 @@ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp)int val;ChardevVC *vc; + backend->type =CHARDEV_BACKEND_KIND_VC ; vc = backend->u.vc.data =g_new0 (ChardevVC,1 );qemu_chr_parse_common (opts,qapi_ChardevVC_base (vc));
@@ -2187,7 +2188,6 @@ static void char_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_VC ; cc->parse = qemu_chr_parse_vc; cc->open = vc_chr_open; cc->chr_write = vc_chr_write;
ui/gtk.c +0 -1
@@ -1737,7 +1737,6 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data) {ChardevClass *cc =CHARDEV_CLASS (oc); - cc->kind =CHARDEV_BACKEND_KIND_VC ; cc->parse = qemu_chr_parse_vc; cc->open = gd_vc_open; cc->chr_write = gd_vc_chr_write;
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 18/40] char: remove class kind field
Quoted 25 lines · Marc-André Lureau
The class kind is necessary to lookup the chardev name in
qmp_chardev_add()after callingqemu_chr_new_from_opts()and to set the appropriate ChardevBackend (mainly to free the right fields).
qemu_chr_new_from_opts()can be changed to use a non-qmp function using the chardev class typename. Introduceqemu_chardev_add()to be called fromqemu_chr_new_from_opts()and remove the class chardev kind field. Set thebackend->typein the parse callback (when non-common fields are added).Signed-off-by Marc-André Lureau <[email protected]>---
qemu-char.c +10
-0+static Chardev *qemu_chardev_add (const char *id,const char *typename, +ChardevBackend *backend,Error **errp) +{ +Chardev *chr; + + chr =qemu_chr_find (id); +if (chr) { +error_setg (errp,"Chardev '%s' already exists" , id); +return NULL ; + }
qemu-char.c static const ChardevClass *char_get_class(const char *driver, Error **errp) · line 4179
Quoted 10 lines
qemu-char.c +10
-0+ + chr =qemu_chardev_new (id, typename, backend, errp); +if (!chr) { +return NULL ; + } + +QTAILQ_INSERT_TAIL (&chardevs, chr, next); +return chr; +} +
This part seems okay.
Quoted 7 lines
qemu-char.c +1
-1@@ -4222,22 +4235,22 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, cc =char_get_class (name, errp);if (cc ==NULL ) { - goto err; +return NULL ; }
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4235
Quoted 10 lines
qemu-char.c +1
-1backend =g_new0 (ChardevBackend,1 ); + backend->type =CHARDEV_BACKEND_KIND_NULL ;if (qemu_opt_get_bool (opts,"mux" ,0 )) { bid =g_strdup_printf ("%s-base" , id); } chr =NULL ; - backend->type = cc->kind;
I'm not sure I follow this hunk - we used to set backend->type dynamically and now it is forced to KIND_NULL. Is the point that we don't need to set backend->type here because the later call to qemu_chardev_add()...
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4263
Quoted 10 lines
qemu-char.c +3
-3@@ -4245,37 +4258,33 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, backend->u.null.data = ccom;/* Any ChardevCommon member would work */ } - ret =qmp_chardev_add (bid ? bid : id, backend, errp); -if (!ret) { - goto qapi_out; + chr =qemu_chardev_add (bid ? bid : id, +object_class_get_name (OBJECT_CLASS (cc)), + backend, errp);
...now passes the Object type which can be used to derive the same same information? In that case, was the assignment to backend->type = KIND_NULL dead?
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4273
Quoted 12 lines
qemu-char.c +4
-2+if (chr ==NULL ) { + goto out; }if (bid) { +Chardev *mux;qapi_free_ChardevBackend (backend); -qapi_free_ChardevReturn (ret); backend =g_new0 (ChardevBackend,1 ); - backend->u.mux.data =g_new0 (ChardevMux,1 ); backend->type =CHARDEV_BACKEND_KIND_MUX ; + backend->u.mux.data =g_new0 (ChardevMux,1 );
Why the churn on the assignment to backend->u.mux.data?
Quoted 29 lines
qemu-char.c +5
-11backend->u.mux.data->chardev =g_strdup (bid); - ret =qmp_chardev_add (id, backend, errp); -if (!ret) { - chr =qemu_chr_find (bid); + mux =qemu_chardev_add (id,TYPE_CHARDEV_MUX , backend, errp); +if (mux ==NULL ) {qemu_chr_delete (chr); chr =NULL ; - goto qapi_out; + goto out; } + chr = mux; } - chr =qemu_chr_find (id); - -qapi_out: +out:qapi_free_ChardevBackend (backend); -qapi_free_ChardevReturn (ret);g_free (bid);return chr; - -err: -return NULL ; }
qemu-char.c Chardev *qemu_chardev_new(const char *id, const char *typename, · line 5018
Quoted 6 lines
qemu-char.c +1
-1@@ -5010,24 +5014,18 @@ Chardev *qemu_chardev_new(const char *id, const char *typename,ChardevReturn *qmp_chardev_add (const char *id,ChardevBackend *backend,Error **errp) { -const ChardevClass *cc;ChardevReturn *ret; +const ChardevClass *cc;
Why the churn on this declaration?
qemu-char.c Chardev *qemu_chardev_new(const char *id, const char *typename, · line 5022
Quoted 11 lines
qemu-char.c +1
-7Chardev *chr; - chr =qemu_chr_find (id); -if (chr) { -error_setg (errp,"Chardev '%s' already exists" , id); -return NULL ; - } - cc =char_get_class (ChardevBackendKind_lookup[backend->type], errp); -if (!cc) { +if (cc ==NULL ) {
Why the churn on this conditional?
qemu-char.c Chardev *qemu_chardev_new(const char *id, const char *typename, · line 5028
Quoted 8 lines
qemu-char.c +2
-2return NULL ; } - chr =qemu_chardev_new (id,object_class_get_name (OBJECT_CLASS (cc)), + chr =qemu_chardev_add (id,object_class_get_name (OBJECT_CLASS (cc)), backend, errp); -if (!chr) { +if (chr ==NULL ) {
and again
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 18/40] char: remove class kind field
Hi
----- Original Message -----
Quoted 54 lines · Marc-André Lureau
Quoted 25 lines
The class kind is necessary to lookup the chardev name in
qmp_chardev_add()after callingqemu_chr_new_from_opts()and to set the appropriate ChardevBackend (mainly to free the right fields).
qemu_chr_new_from_opts()can be changed to use a non-qmp function using the chardev class typename. Introduceqemu_chardev_add()to be called fromqemu_chr_new_from_opts()and remove the class chardev kind field. Set thebackend->typein the parse callback (when non-common fields are added).Signed-off-by Marc-André Lureau <[email protected]>---
qemu-char.c +10
-0+static Chardev *qemu_chardev_add (const char *id,const char *typename, +ChardevBackend *backend,Error **errp) +{ +Chardev *chr; + + chr =qemu_chr_find (id); +if (chr) { +error_setg (errp,"Chardev '%s' already exists" , id); +return NULL ; + }qemu-char.c static const ChardevClass *char_get_class(const char *driver, Error **errp) · line 4179
Quoted 10 lines
qemu-char.c +10
-0+ + chr =qemu_chardev_new (id, typename, backend, errp); +if (!chr) { +return NULL ; + } + +QTAILQ_INSERT_TAIL (&chardevs, chr, next); +return chr; +} +This part seems okay.
Quoted 15 lines
qemu-char.c +2
-1@@ -4222,22 +4235,22 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, cc =char_get_class (name, errp);if (cc ==NULL ) { - goto err; +return NULL ; } backend =g_new0 (ChardevBackend,1 ); + backend->type =CHARDEV_BACKEND_KIND_NULL ;if (qemu_opt_get_bool (opts,"mux" ,0 )) { bid =g_strdup_printf ("%s-base" , id); }
Quoted 7 lines
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4235
Quoted 2 lines
qemu-char.c +0
-1chr =NULL ; - backend->type = cc->kind;I'm not sure I follow this hunk - we used to set
backend->typedynamically and now it is forced toKIND_NULL. Is the point that we don't need to setbackend->typehere because the later call toqemu_chardev_add()...
I tried to explain some of the reasons in the commit message.
We need backend->type to be set correctly for the qapi_free_ChardevBackend() to work. The kind field used to be on a class member, but we try to get rid of it. So we move that information to _parse(), and change the backend type appropriately there.
KIND_NULL is the common backend (sharing ChardevCommon).
Quoted 6 lines
Quoted 6 lines
(quoted diff) +0
-0@@ -4245,37 +4258,33 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, backend->u.null.data = ccom; /* Any ChardevCommon member would work */ }
Quoted 10 lines
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4263
Quoted 6 lines
qemu-char.c +3
-3- ret =qmp_chardev_add (bid ? bid : id, backend, errp); -if (!ret) { - goto qapi_out; + chr =qemu_chardev_add (bid ? bid : id, +object_class_get_name (OBJECT_CLASS (cc)), + backend, errp);...now passes the Object type which can be used to derive the same same information? In that case, was the assignment to
backend->type=KIND_NULLdead?
0 is KIND_FILE, which would lead to invalid free.
Quoted 13 lines
qemu-char.c Chardev *qemu_chr_new_from_opts(QemuOpts *opts, · line 4273
Quoted 12 lines
qemu-char.c +4
-2+if (chr ==NULL ) { + goto out; }if (bid) { +Chardev *mux;qapi_free_ChardevBackend (backend); -qapi_free_ChardevReturn (ret); backend =g_new0 (ChardevBackend,1 ); - backend->u.mux.data =g_new0 (ChardevMux,1 ); backend->type =CHARDEV_BACKEND_KIND_MUX ; + backend->u.mux.data =g_new0 (ChardevMux,1 );
Quoted 1 line
Why the churn on the assignment to
backend->u.mux.data?
fixed
Quoted 29 lines
Quoted 28 lines
qemu-char.c +5
-11backend->u.mux.data->chardev =g_strdup (bid); - ret =qmp_chardev_add (id, backend, errp); -if (!ret) { - chr =qemu_chr_find (bid); + mux =qemu_chardev_add (id,TYPE_CHARDEV_MUX , backend, errp); +if (mux ==NULL ) {qemu_chr_delete (chr); chr =NULL ; - goto qapi_out; + goto out; } + chr = mux; } - chr =qemu_chr_find (id); - -qapi_out: +out:qapi_free_ChardevBackend (backend); -qapi_free_ChardevReturn (ret);g_free (bid);return chr; - -err: -return NULL ; }
Quoted 10 lines
qemu-char.c Chardev *qemu_chardev_new(const char *id, const · line 5019
Quoted 8 lines
qemu-char.c +1
-1@@ -5010,24 +5014,18 @@ Chardev *qemu_chardev_new(const char *id, constchar *typename, ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) { - const ChardevClass *cc; ChardevReturn *ret; +const ChardevClass *cc;Why the churn on this declaration?
sorry, too many rebases, conflicts.. fixed
Quoted 32 lines
qemu-char.c Chardev *qemu_chardev_new(const char *id, const char *typename, · line 5022
Quoted 12 lines
qemu-char.c +1
-7Chardev *chr; - chr =qemu_chr_find (id); -if (chr) { -error_setg (errp,"Chardev '%s' already exists" , id); -return NULL ; - } - cc =char_get_class (ChardevBackendKind_lookup[backend->type], errp); -if (!cc) { +if (cc ==NULL ) {Why the churn on this conditional?
qemu-char.c Chardev *qemu_chardev_new(const char *id, const char *typename, · line 5028
Quoted 8 lines
qemu-char.c +2
-2return NULL ; } - chr =qemu_chardev_new (id,object_class_get_name (OBJECT_CLASS (cc)), + chr =qemu_chardev_add (id,object_class_get_name (OBJECT_CLASS (cc)), backend, errp); -if (!chr) { +if (chr ==NULL ) {and again
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
PATCH 19/40 char: move to chardev/
In reply to Marc-André LureauThe following commits will split char.c in several files. Let's put them in a subdirectory.
--- qemu-char.c => chardev/char.c | 0 MAINTAINERS | 2 +- Makefile.objs | 2 +- chardev/Makefile.objs | 1 + tests/Makefile.include | 6 +++--- 5 files changed, 6 insertions(+), 5 deletions(-) rename qemu-char.c => chardev/char.c (100%) create mode 100644 chardev/Makefile.objs
chardev/char.c renamed from qemu-char.c +0 -0
MAINTAINERS +1 -1
@@ -1173,7 +1173,7 @@ T: git git://github.com/jnsnow/qemu.git bitmaps Character device backends M: Paolo Bonzini <[email protected]> S: Maintained -F: qemu-char.c +F: chardev/ F: backends/msmouse.c F: backends/testdev.c
Makefile.objs +1 -1
@@ -51,7 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration/ -common-obj-y += qemu-char.o #aio.o +common-obj-y += chardev/ #aio.o common-obj-y += page_cache.o common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
chardev/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +common-obj-y += char.o
tests/Makefile.include +3 -3
@@ -9,7 +9,7 @@ SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ check-unit-y = tests/check-qdict$(EXESUF) gcov-files-check-qdict-y = qobject/qdict.c check-unit-y += tests/test-char$(EXESUF) -gcov-files-check-qdict-y = qemu-char.c +gcov-files-check-qdict-y = chardev/char.c check-unit-y += tests/check-qfloat$(EXESUF) gcov-files-check-qfloat-y = qobject/qfloat.c check-unit-y += tests/check-qint$(EXESUF)
@@ -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-block-obj-y) +tests/test-char$(EXESUF): tests/test-char.o chardev/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)
@@ -680,7 +680,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/postcopy-test$(EXESUF): tests/postcopy-test.o -tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) +tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o chardev/char.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 19/40] char: move to chardev/
Quoted 6 lines · Marc-André Lureau
The following commits will split
char.cin several files. Let's put them in a subdirectory.Signed-off-by Marc-André Lureau <[email protected]>--- qemu-char.c => chardev/char.c | 0
Yay - one less file in the top level :)
Quoted 20 lines
MAINTAINERS | 2 +- Makefile.objs | 2 +- chardev/Makefile.objs | 1 + tests/Makefile.include | 6 +++--- 5 files changed, 6 insertions(+), 5 deletions(-) rename qemu-char.c => chardev/char.c (100%) create mode 100644 chardev/Makefile.objs+++ b/tests/Makefile.include
tests/Makefile.include +1
-1@@ -9,7 +9,7 @@ SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ check-unit-y = tests/check-qdict$(EXESUF) gcov-files-check-qdict-y = qobject/qdict.c check-unit-y += tests/test-char$(EXESUF) -gcov-files-check-qdict-y = qemu-char.c +gcov-files-check-qdict-y = chardev/char.c check-unit-y += tests/check-qfloat$(EXESUF) gcov-files-check-qfloat-y = qobject/qfloat.c check-unit-y += tests/check-qint$(EXESUF)
tests/Makefile.include tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) · line 492
Quoted 5 lines
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-block-obj-y) +tests/test-char$(EXESUF): tests/test-char.o chardev/char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y)
Pre-existing so you just kept it, but maybe we should use \ line wrapping to avoid long lines.
With or without wrapping,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 20/40 char: create chardev-obj-y
In reply to Marc-André LureauThis will help to split char.c in several units without having to reference them all everywhere. This is useful in particular for tests.
--- Makefile | 3 ++- Makefile.objs | 4 +++- Makefile.target | 3 +++ chardev/Makefile.objs | 2 +- tests/Makefile.include | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-)
Makefile +2 -1
@@ -145,6 +145,7 @@ endif dummy := $(call unnest-vars,, \ stub-obj-y \ + chardev-obj-y \ util-obj-y \ qga-obj-y \ ivshmem-client-obj-y \
@@ -221,7 +222,7 @@ subdir-dtc:dtc/libfdt dtc/tests dtc/%: mkdir -p $@ -$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) +$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(chardev-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags
Makefile.objs +3 -1
@@ -51,7 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration/ -common-obj-y += chardev/ #aio.o +common-obj-y += #aio.o common-obj-y += page_cache.o common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
@@ -79,6 +79,8 @@ common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o common-obj-$(CONFIG_FDT) += device_tree.o +chardev-obj-y = chardev/ + ###################################################################### # qapi
Makefile.target +3 -0
@@ -171,12 +171,14 @@ all-obj-y := $(obj-y) target-obj-y := block-obj-y := common-obj-y := +chardev-obj-y := include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,,target-obj-y) target-obj-y-save := $(target-obj-y) dummy := $(call unnest-vars,.., \ block-obj-y \ block-obj-m \ + chardev-obj-y \ crypto-obj-y \ crypto-aes-obj-y \ qom-obj-y \
@@ -185,6 +187,7 @@ dummy := $(call unnest-vars,.., \ common-obj-m) target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) +all-obj-y += $(chardev-obj-y) all-obj-y += $(target-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
chardev/Makefile.objs +1 -1
@@ -1 +1 @@ -common-obj-y += char.o +chardev-obj-y += char.o
tests/Makefile.include +2 -2
@@ -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 chardev/char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) +tests/test-char$(EXESUF): tests/test-char.o chardev/char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) $(chardev-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)
@@ -680,7 +680,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/postcopy-test$(EXESUF): tests/postcopy-test.o -tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o chardev/char.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) +tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y) $(chardev-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 20/40] char: create chardev-obj-y
Makefile subdir-dtc:dtc/libfdt dtc/tests · line 225
Quoted 12 lines · Marc-André Lureau
This will help to split
char.cin several units without having to reference them all everywhere. This is useful in particular for tests.Signed-off-by Marc-André Lureau <[email protected]>---
Makefile +1
-1@@ -221,7 +222,7 @@ subdir-dtc:dtc/libfdt dtc/tests dtc/%: mkdir -p $@ -$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) +$(SUBDIR_RULES): libqemuutil.a libqemustub.a $(common-obj-y) $(chardev-obj-y) $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
Again, splitting long lines with \ would be nice, but not a necessity.
Makefile.objs common-obj-$(CONFIG_POSIX) += os-posix.o · line 54
Quoted 13 lines
Makefile +0
-0ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflagsMakefile.objs +1
-1@@ -51,7 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration/ -common-obj-y += chardev/ #aio.o +common-obj-y += #aio.o
The fact that aio.o is commented is unrelated to your patch, but now that this line is a comment only, can we delete it?
Makefile.objs common-obj-$(CONFIG_POSIX) += os-posix.o · line 55
Quoted 1 line
Makefile.objs +0
-0common-obj-y += page_cache.o
Or maybe merge it with this line, so it doesn't look quite as odd?
Nothing major, so
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 21/40 char: make null_chr_write() the default method
In reply to Marc-André LureauAll chardev must implement chr_write(), but parallel and null chardev both use null_chr_write(). Move it to the base class, so we don't need to export the function when splitting the chardev in respective files.
--- chardev/char.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
chardev/char.c +13 -8
@@ -522,6 +522,18 @@ static void char_init(Object *obj)qemu_mutex_init (&chr->chr_write_lock); } +static int null_chr_write (Chardev *chr,const uint8_t *buf,int len) +{ +return len; +} + +static void char_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->chr_write = null_chr_write; +} +static void char_finalize (Object *obj) {Chardev *chr =CHARDEV (obj);
@@ -545,13 +557,9 @@ static const TypeInfo char_type_info = { .instance_finalize = char_finalize, .abstract = true, .class_size = sizeof(ChardevClass), + .class_init = char_class_init, }; -static int null_chr_write (Chardev *chr,const uint8_t *buf,int len) -{ -return len; -} - static void null_chr_open(Chardev *chr, ChardevBackend *backend, bool *be_opened,
@@ -565,7 +573,6 @@ static void char_null_class_init(ObjectClass *oc, void *data)ChardevClass *cc =CHARDEV_CLASS (oc); cc->open = null_chr_open; - cc->chr_write = null_chr_write; }static const TypeInfo char_null_type_info = {
@@ -4689,10 +4696,8 @@ static void char_parallel_class_init(ObjectClass *oc, void *data) cc->parse = qemu_chr_parse_parallel; cc->open = qmp_chardev_open_parallel;#if defined(__linux__) - cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl;#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - cc->chr_write = null_chr_write; cc->chr_ioctl = pp_ioctl;#endif }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 21/40] char: make null_chr_write() the default method
Quoted 9 lines · Marc-André Lureau
All chardev must implement
chr_write(), but parallel and null chardev both usenull_chr_write(). Move it to the base class, so we don't need to export the function when splitting the chardev in respective files.Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 22/40 char: move null chardev to its own file
In reply to Marc-André Lureau--- chardev/char-null.c | 31 +++++++++++++++++++++++++++++++ chardev/char.c | 23 ----------------------- chardev/Makefile.objs | 1 + 3 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 chardev/char-null.c
chardev/char-null.c new file +31 -0
@@ -0,0 +1,31 @@ +#include "qemu/osdep.h" +#include "sysemu/char.h" + +static void null_chr_open (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ + *be_opened = false; +} + +static void char_null_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->open = null_chr_open; +} + +static const TypeInfo char_null_type_info = { + .name =TYPE_CHARDEV_NULL , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (Chardev), + .class_init = char_null_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_null_type_info); +} + +type_init (register_types);
chardev/char.c +0 -23
@@ -560,28 +560,6 @@ static const TypeInfo char_type_info = { .class_init = char_class_init, }; -static void null_chr_open (Chardev *chr, -ChardevBackend *backend, -bool *be_opened, -Error **errp) -{ - *be_opened = false; -} - -static void char_null_class_init (ObjectClass *oc,void *data) -{ -ChardevClass *cc =CHARDEV_CLASS (oc); - - cc->open = null_chr_open; -} - -static const TypeInfo char_null_type_info = { - .name =TYPE_CHARDEV_NULL , - .parent =TYPE_CHARDEV , - .instance_size =sizeof (Chardev), - .class_init = char_null_class_init, -}; -/* MUX driver for serial I/O splitting */ #define MAX_MUX 4#define MUX_BUFFER_SIZE 32/* Must be a power of 2. */
@@ -5082,7 +5060,6 @@ static void register_types(void)type_register_static (&char_win_type_info);type_register_static (&char_win_stdio_type_info);#endif -type_register_static (&char_null_type_info);type_register_static (&char_socket_type_info);type_register_static (&char_udp_type_info);type_register_static (&char_ringbuf_type_info);
chardev/Makefile.objs +1 -0
@@ -1 +1,2 @@ chardev-obj-y += char.o +chardev-obj-y += char-null.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 22/40] char: move null chardev to its own file
Quoted 14 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-null.c | 31 +++++++++++++++++++++++++++++++ chardev/char.c | 23 ----------------------- chardev/Makefile.objs | 1 + 3 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 chardev/char-null.cchardev/char-null.c new file +0
-0
chardev/char-null.c line 2
Quoted 2 lines
chardev/char-null.c new file +2
-0@@ -0,0 +1,31 @@ +#include "qemu/osdep.h" +#include "sysemu/char.h"
No copyright blurb? You should copy the header of chardev/char.c (since that's what you're splitting off of).
Otherwise looks okay.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 23/40 char: move mux to its own file
In reply to Marc-André LureauA mechanical move, except that qemu_chr_write_all() needs to be declared in char.h header to be used from chardev unit files.
--- chardev/char-mux.h | 40 ++++++ include/sysemu/char.h | 3 +- chardev/char-mux.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 352 +------------------------------------------------- chardev/Makefile.objs | 1 + 5 files changed, 380 insertions(+), 351 deletions(-) create mode 100644 chardev/char-mux.h create mode 100644 chardev/char-mux.c
chardev/char-mux.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef CHAR_MUX_H +#define CHAR_MUX_H + +#include "sysemu/char.h" + +extern bool muxes_realized; + +#define MAX_MUX 4 +#define MUX_BUFFER_SIZE 32/* Must be a power of 2. */ +#define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1) +typedef struct MuxChardev { +Chardev parent; +CharBackend *backends[MAX_MUX ]; +CharBackend chr; +int focus; +int mux_cnt; +int term_got_escape; +int max_size; +/* Intermediate input buffer allows to catch escape sequences even if the +currently active device is not accepting any input - but only until it +is full as well. */ +unsigned char buffer[MAX_MUX ][MUX_BUFFER_SIZE ]; +int prod[MAX_MUX ]; +int cons[MAX_MUX ]; +int timestamps; + +/* Protected by the Chardev chr_write_lock. */ +int linestart; +int64_t timestamps_start; +}MuxChardev ; + +#define MUX_CHARDEV (obj) OBJECT_CHECK(MuxChardev, (obj), TYPE_CHARDEV_MUX) +#define CHARDEV_IS_MUX (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) + +void mux_chr_set_handlers (Chardev *chr,GMainContext *context); +void mux_set_focus (Chardev *chr,int focus); +void mux_chr_send_event (MuxChardev *d,int mux_nr,int event); + +#endif /* CHAR_MUX_H */
include/sysemu/char.h +1 -2
@@ -441,6 +441,7 @@ bool qemu_chr_has_feature(Chardev *chr,void qemu_chr_set_feature (Chardev *chr,ChardevFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +int qemu_chr_write_all (Chardev *s,const uint8_t *buf,int len);#define TYPE_CHARDEV "chardev"#define CHARDEV (obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV)
@@ -463,8 +464,6 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);#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) \
chardev/char-mux.c new file +335 -0
335 lines not on this page · raw message
chardev/char.c +3 -349
398 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ chardev-obj-y += char.o +chardev-obj-y += char-mux.o chardev-obj-y += char-null.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 23/40] char: move mux to its own file
chardev/char-mux.h line 2
Quoted 10 lines · Marc-André Lureau
A mechanical move, except that
qemu_chr_write_all()needs to be declared inchar.hheader to be used from chardev unit files.Signed-off-by Marc-André Lureau <[email protected]>---
+++
b/chardev/char-mux.hchardev/char-mux.h new file +2
-0@@ -0,0 +1,40 @@ +#ifndef CHAR_MUX_H +#define CHAR_MUX_H
Again, missing copyright blurbs. You'll need to respin to get that right, but I'll quit pointing it out.
Quoted 7 lines
chardev/char-mux.h new file +7
-0+ +#include "sysemu/char.h" + +extern bool muxes_realized; + +#define MAX_MUX 4 +#define MUX_BUFFER_SIZE 32/* Must be a power of 2. */
chardev/char-mux.h line 19
Quoted 10 lines
chardev/char-mux.h new file +10
-0+#define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1) +typedef struct MuxChardev { + Chardev parent; + CharBackend *backends[MAX_MUX]; + CharBackend chr; + int focus; + int mux_cnt; + int term_got_escape; + int max_size; + /* Intermediate input buffer allows to catch escape sequences even if the
s/allows to catch/catches/
Dunno if cleanups like that should be mixed with code motion, or done separately.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 24/40 char: move ringbuf/memory to its own file
In reply to Marc-André Lureau--- chardev/char-ringbuf.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 218 ----------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 227 insertions(+), 218 deletions(-) create mode 100644 chardev/char-ringbuf.c
chardev/char-ringbuf.c new file +226 -0
@@ -0,0 +1,226 @@ +#include "qemu/osdep.h" +#include "sysemu/char.h" +#include "qmp-commands.h" +#include "qemu/base64.h" + +/* Ring buffer chardev */ + +typedef struct { +Chardev parent; +size_t size; +size_t prod; +size_t cons; +uint8_t *cbuf; +}RingBufChardev ; + +#define RINGBUF_CHARDEV (obj) \ + OBJECT_CHECK(RingBufChardev, (obj), TYPE_CHARDEV_RINGBUF) + +static size_t ringbuf_count (const Chardev *chr) +{ +const RingBufChardev *d =RINGBUF_CHARDEV (chr); + +return d->prod - d->cons; +} + +static int ringbuf_chr_write (Chardev *chr,const uint8_t *buf,int len) +{ +RingBufChardev *d =RINGBUF_CHARDEV (chr); +int i; + +if (!buf || (len <0 )) { +return -1 ; + } + +for (i =0 ; i < len; i++) { + d->cbuf[d->prod++ & (d->size -1 )] = buf[i]; +if (d->prod - d->cons > d->size) { + d->cons = d->prod - d->size; + } + } + +return len; +} + +static int ringbuf_chr_read (Chardev *chr,uint8_t *buf,int len) +{ +RingBufChardev *d =RINGBUF_CHARDEV (chr); +int i; + +qemu_mutex_lock (&chr->chr_write_lock); +for (i =0 ; i < len && d->cons != d->prod; i++) { + buf[i] = d->cbuf[d->cons++ & (d->size -1 )]; + } +qemu_mutex_unlock (&chr->chr_write_lock); + +return i; +} + +static void char_ringbuf_finalize (Object *obj) +{ +RingBufChardev *d =RINGBUF_CHARDEV (obj); + +g_free (d->cbuf); +} + +static void qemu_chr_open_ringbuf (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevRingbuf *opts = backend->u.ringbuf.data; +RingBufChardev *d =RINGBUF_CHARDEV (chr); + + d->size = opts->has_size ? opts->size :65536 ; + +/* The size must be power of 2 */ +if (d->size & (d->size -1 )) { +error_setg (errp,"size of ringbuf chardev must be power of two" ); +return ; + } + + d->prod =0 ; + d->cons =0 ; + d->cbuf =g_malloc0 (d->size); +} + +void qmp_ringbuf_write (const char *device,const char *data, +bool has_format,enum DataFormat format, +Error **errp) +{ +Chardev *chr; +const uint8_t *write_data; +int ret; +gsize write_count; + + chr =qemu_chr_find (device); +if (!chr) { +error_setg (errp,"Device '%s' not found" , device); +return ; + } + +if (!CHARDEV_IS_RINGBUF (chr)) { +error_setg (errp,"%s is not a ringbuf device" , device); +return ; + } + +if (has_format && (format ==DATA_FORMAT_BASE64 )) { + write_data =qbase64_decode (data,-1 , + &write_count, + errp); +if (!write_data) { +return ; + } + }else { + write_data = (uint8_t *)data; + write_count =strlen (data); + } + + ret =ringbuf_chr_write (chr, write_data, write_count); + +if (write_data != (uint8_t *)data) { +g_free ((void *)write_data); + } + +if (ret <0 ) { +error_setg (errp,"Failed to write to device %s" , device); +return ; + } +} + +char *qmp_ringbuf_read (const char *device,int64_t size, +bool has_format,enum DataFormat format, +Error **errp) +{ +Chardev *chr; +uint8_t *read_data; +size_t count; +char *data; + + chr =qemu_chr_find (device); +if (!chr) { +error_setg (errp,"Device '%s' not found" , device); +return NULL ; + } + +if (!CHARDEV_IS_RINGBUF (chr)) { +error_setg (errp,"%s is not a ringbuf device" , device); +return NULL ; + } + +if (size <=0 ) { +error_setg (errp,"size must be greater than zero" ); +return NULL ; + } + + count =ringbuf_count (chr); + size = size > count ? count : size; + read_data =g_malloc (size +1 ); + +ringbuf_chr_read (chr, read_data, size); + +if (has_format && (format ==DATA_FORMAT_BASE64 )) { + data =g_base64_encode (read_data, size); +g_free (read_data); + }else { +/* +* FIXME should read only complete, valid UTF-8 characters up +* to @size bytes. Invalid sequences should be replaced by a +* suitable replacement character. Except when (and only +* when) ring buffer lost characters since last read, initial +* continuation characters should be dropped. +*/ + read_data[size] =0 ; + data = (char *)read_data; + } + +return data; +} + +static void qemu_chr_parse_ringbuf (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +int val; +ChardevRingbuf *ringbuf; + + backend->type =CHARDEV_BACKEND_KIND_RINGBUF ; + ringbuf = backend->u.ringbuf.data =g_new0 (ChardevRingbuf,1 ); +qemu_chr_parse_common (opts,qapi_ChardevRingbuf_base (ringbuf)); + + val =qemu_opt_get_size (opts,"size" ,0 ); +if (val !=0 ) { + ringbuf->has_size = true; + ringbuf->size = val; + } +} + +static void char_ringbuf_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->parse = qemu_chr_parse_ringbuf; + cc->open = qemu_chr_open_ringbuf; + cc->chr_write = ringbuf_chr_write; +} + +static const TypeInfo char_ringbuf_type_info = { + .name =TYPE_CHARDEV_RINGBUF , + .parent =TYPE_CHARDEV , + .class_init = char_ringbuf_class_init, + .instance_size =sizeof (RingBufChardev), + .instance_finalize = char_ringbuf_finalize, +}; + +/* Bug-compatibility: */ +static const TypeInfo char_memory_type_info = { + .name =TYPE_CHARDEV_MEMORY , + .parent =TYPE_CHARDEV_RINGBUF , +}; + +static void register_types (void ) +{ +type_register_static (&char_ringbuf_type_info); +type_register_static (&char_memory_type_info); +} + +type_init (register_types);
chardev/char.c +0 -218
242 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ chardev-obj-y += char.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o +chardev-obj-y += char-ringbuf.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 24/40] char: move ringbuf/memory to its own file
Quoted 8 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-ringbuf.c | 226 +++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 218 ----------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 227 insertions(+), 218 deletions(-) create mode 100644 chardev/char-ringbuf.c
Looks mechanical, same story about copyright blurb.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 25/40 char: rename and move to header CHR_READ_BUF_LEN
In reply to Marc-André LureauThis define is used by several character devices, place it in char common header.
--- include/sysemu/char.h | 1 + chardev/char.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
include/sysemu/char.h +1 -0
@@ -22,6 +22,7 @@ typedef enum {CHR_EVENT_CLOSED /* connection closed */ } QEMUChrEvent; +#define CHR_READ_BUF_LEN 4096#define CHR_IOCTL_SERIAL_SET_PARAMS 1 typedef struct {
chardev/char.c +6 -7
@@ -87,7 +87,6 @@#include "char-mux.h" -#define READ_BUF_LEN 4096#define READ_RETRIES 10#define TCP_MAX_FDS 16
@@ -471,7 +470,7 @@ void qemu_chr_fe_accept_input(CharBackend *be)void qemu_chr_fe_printf (CharBackend *be,const char *fmt, ...) { -char buf[READ_BUF_LEN ]; +char buf[CHR_READ_BUF_LEN ];va_list ap;va_start (ap, fmt);vsnprintf (buf,sizeof (buf), fmt, ap);
@@ -913,7 +912,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);FDChardev *s =FD_CHARDEV (opaque);int len; -uint8_t buf[READ_BUF_LEN ]; +uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret; len =sizeof (buf);
@@ -1265,7 +1264,7 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)Chardev *chr =CHARDEV (opaque);PtyChardev *s =PTY_CHARDEV (opaque);gsize len; -uint8_t buf[READ_BUF_LEN ]; +uint8_t buf[CHR_READ_BUF_LEN ];ssize_t ret; len =sizeof (buf);
@@ -1952,7 +1951,7 @@ static void win_chr_readfile(Chardev *chr)WinChardev *s =WIN_CHARDEV (chr);int ret, err; -uint8_t buf[READ_BUF_LEN ]; +uint8_t buf[CHR_READ_BUF_LEN ];DWORD size;ZeroMemory (&s->orecv,sizeof (s->orecv));
@@ -2354,7 +2353,7 @@ err1: typedef struct { Chardev parent; QIOChannel *ioc; - uint8_t buf[READ_BUF_LEN]; + uint8_t buf[CHR_READ_BUF_LEN]; int bufcnt; int bufptr; int max_size;
@@ -2759,7 +2758,7 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque) {Chardev *chr =CHARDEV (opaque);SocketChardev *s =SOCKET_CHARDEV (opaque); -uint8_t buf[READ_BUF_LEN ]; +uint8_t buf[CHR_READ_BUF_LEN ];int len, size;if (!s->connected || s->max_size <=0 ) {
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 25/40] char: rename and move to header CHR_READ_BUF_LEN
Quoted 9 lines · Marc-André Lureau
This define is used by several character devices, place it in char common header.
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 1 + chardev/char.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 26/40 char: remove unused READ_RETRIES
In reply to Marc-André LureauCuriously unused since its introduction in commit 7b0bfdf52d69.
--- chardev/char.c | 1 - 1 file changed, 1 deletion(-)
chardev/char.c +0 -1
@@ -87,7 +87,6 @@#include "char-mux.h" -#define READ_RETRIES 10#define TCP_MAX_FDS 16/***********************************************************/
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 26/40] char: remove unused READ_RETRIES
Quoted 6 lines · Marc-André Lureau
Curiously unused since its introduction in commit
7b0bfdf52d69.Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char.c | 1 - 1 file changed, 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 27/40 char: move QIOChannel-related in char-io.h
In reply to Marc-André Lureau--- chardev/char-io.h | 24 +++++++ chardev/char-io.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 174 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 194 insertions(+), 173 deletions(-) create mode 100644 chardev/char-io.h create mode 100644 chardev/char-io.c
chardev/char-io.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef CHAR_IO_H +#define CHAR_IO_H + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "io/channel.h" +#include "sysemu/char.h" + +/* Can only be used for read */ +guint io_add_watch_poll (Chardev *chr, +QIOChannel *ioc, +IOCanReadHandler *fd_can_read, +QIOChannelFunc fd_read, +gpointer user_data, +GMainContext *context); + +void remove_fd_in_watch (Chardev *chr); + +int io_channel_send (QIOChannel *ioc,const void *buf,size_t len); + +int io_channel_send_full (QIOChannel *ioc,const void *buf,size_t len, +int *fds,size_t nfds); + +#endif /* CHAR_IO_H */
chardev/char-io.c new file +168 -0
168 lines not on this page · raw message
chardev/char.c +1 -173
193 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ chardev-obj-y += char.o +chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 27/40] char: move QIOChannel-related in char-io.h
On 01/11/2017 11:29 AM, Marc-André Lureau wrote:
Grammar in subject is a bit terse; maybe:
char: move QIOChannel-related stuff to char-io.h
Quoted 16 lines
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-io.h | 24 +++++++ chardev/char-io.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 174 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 194 insertions(+), 173 deletions(-) create mode 100644 chardev/char-io.h create mode 100644 chardev/char-io.cchardev/char-io.h new file +0
-0
chardev/char-io.h line 2
Quoted 2 lines
chardev/char-io.h new file +2
-0@@ -0,0 +1,24 @@ +#ifndef CHAR_IO_H +#define CHAR_IO_H
Must... resist... the temptation to repeat myself!
chardev/char-io.h line 4
Quoted 2 lines
chardev/char-io.h new file +2
-0+ +#include "qemu/osdep.h"
.h files should NOT include osdep.h; since all .c files included it before any other .h file, then all things in osdep.h are already in scope at the point the .h file starts.
chardev/char-io.h line 7
Quoted 3 lines
chardev/char-io.h new file +3
-0+static gboolean io_watch_poll_prepare (GSource *source, +gint *timeout_) +{
Why the weird spelling of timeout_ ? Maybe timeout_unused is better?
chardev/char-io.h
Quoted 4 lines
chardev/char-io.h new file +1
-2+++ b/chardev/char.c -static gboolean io_watch_poll_prepare (GSource *source, -gint *timeout_)
Then again, it's code motion. Again, up to you if you want to tweak style things during code motion, or split them into a general cleanup patch separately.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 27/40] char: move QIOChannel-related in char-io.h
Hi
----- Original Message -----
Quoted 18 lines · Marc-André Lureau
Grammar in subject is a bit terse; maybe:
char: move QIOChannel-related stuff to
char-io.hQuoted 12 lines
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-io.h | 24 +++++++ chardev/char-io.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 174 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 194 insertions(+), 173 deletions(-) create mode 100644 chardev/char-io.h create mode 100644 chardev/char-io.c
Quoted 10 lines
chardev/char-io.h line 2
Quoted 8 lines
chardev/char-io.h new file +2
-0@@ -0,0 +1,24 @@ +#ifndef CHAR_IO_H +#define CHAR_IO_H Must... resist... the temptation to repeat myself!
Ok, I'll just copy the original copyright from qemu-char.c in all the files I created in the series.
Quoted 7 lines
chardev/char-io.h line 4
Quoted 3 lines
chardev/char-io.h new file +2
-0+ +#include "qemu/osdep.h" .h files should NOT include
osdep.h; since all .c files included it before any other .h file, then all things inosdep.hare already in scope at the point the .h file starts.
ok
Quoted 9 lines
chardev/char-io.h line 7
Quoted 5 lines
chardev/char-io.h new file +3
-0+static gboolean io_watch_poll_prepare (GSource *source, +gint *timeout_) +{Why the weird spelling of
timeout_? Maybetimeout_unusedis better?
Quoted 8 lines
chardev/char-io.h
Quoted 4 lines
chardev/char-io.h new file +1
-2+++ b/chardev/char.c -static gboolean io_watch_poll_prepare (GSource *source, -gint *timeout_)Then again, it's code motion. Again, up to you if you want to tweak style things during code motion, or split them into a general cleanup patch separately.
yeah, weird style, any idea why Anthony wrote it that way in commit 96c638477?
I guess I may just drop the _ during the move
PATCH 28/40 char: move fd chardev in its own file
In reply to Marc-André Lureau--- chardev/char-fd.h | 21 ++++++++ chardev/char-fd.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 147 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 171 insertions(+), 145 deletions(-) create mode 100644 chardev/char-fd.h create mode 100644 chardev/char-fd.c
chardev/char-fd.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef CHAR_FD_H +#define CHAR_FD_H + +#include "io/channel.h" +#include "sysemu/char.h" + +typedef struct FDChardev { +Chardev parent; +Chardev *chr; +QIOChannel *ioc_in, *ioc_out; +int max_size; +}FDChardev ; + +#define TYPE_CHARDEV_FD "chardev-fd" + +#define FD_CHARDEV (obj) OBJECT_CHECK(FDChardev, (obj), TYPE_CHARDEV_FD) + +void qemu_chr_open_fd (Chardev *chr,int fd_in,int fd_out); +int qmp_chardev_open_file_source (char *src,int flags,Error **errp); + +#endif /* CHAR_FD_H */
chardev/char-fd.c new file +147 -0
147 lines not on this page · raw message
chardev/char.c +2 -145
171 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ chardev-obj-y += char.o +chardev-obj-$(CONFIG_POSIX) += char-fd.o chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o
Signature · 1 line
2.11.0
PATCH 29/40 char: move win chardev base class in its own file
In reply to Marc-André Lureau--- chardev/char-win.h | 30 ++++++ chardev/char-win.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 253 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 276 insertions(+), 250 deletions(-) create mode 100644 chardev/char-win.h create mode 100644 chardev/char-win.c
chardev/char-win.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef CHAR_WIN_H +#define CHAR_WIN_H + +#include "sysemu/char.h" + +typedef struct { +Chardev parent; +int max_size; +HANDLE hcom, hrecv, hsend; +OVERLAPPED orecv; +BOOL fpipe; +DWORD len; + +/* Protected by the Chardev chr_write_lock. */ +OVERLAPPED osend; +/* FIXME: file/console do not finalize */ +BOOL skip_free; +}WinChardev ; + +#define NSENDBUF 2048 +#define NRECVBUF 2048 + +#define TYPE_CHARDEV_WIN "chardev-win" +#define WIN_CHARDEV (obj) OBJECT_CHECK(WinChardev, (obj), TYPE_CHARDEV_WIN) + +void qemu_chr_open_win_file (Chardev *chr,HANDLE fd_out); +int win_chr_init (Chardev *chr,const char *filename,Error **errp); +int win_chr_pipe_poll (void *opaque); + +#endif /* CHAR_WIN_H */
chardev/char-win.c new file +242 -0
242 lines not on this page · raw message
chardev/char.c +3 -250
286 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -4,3 +4,4 @@ chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o +chardev-obj-$(CONFIG_WIN32) += char-win.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 29/40] char: move win chardev base class in its own file
Quoted 13 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-win.h | 30 ++++++ chardev/char-win.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 253 +------------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 276 insertions(+), 250 deletions(-) create mode 100644 chardev/char-win.h create mode 100644 chardev/char-win.c+++ b/chardev/Makefile.objs
chardev/Makefile.objs chardev-obj-y += char-io.o · line 7
Quoted 4 lines
chardev/Makefile.objs +1
-0@@ -4,3 +4,4 @@ chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o +chardev-obj-$(CONFIG_WIN32) += char-win.o
This part is the neatest - trading #ifdefs in the code for conditionally compiling an entire .c file.
I have not closely read 28-39, so I don't know if R-b is appropriate, but they are all mechanical and the fact that it still compiles is good.
So maybe we go with the weaker:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 30/40 char: move win-stdio into its own file
In reply to Marc-André Lureau--- chardev/char-win-stdio.h | 6 ++ chardev/char-win-stdio.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 231 +------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 252 insertions(+), 229 deletions(-) create mode 100644 chardev/char-win-stdio.h create mode 100644 chardev/char-win-stdio.c
chardev/char-win-stdio.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef CHAR_WIN_STDIO_H +#define CHAR_WIN_STDIO_H + +#define TYPE_CHARDEV_WIN_STDIO "chardev-win-stdio" + +#endif /* CHAR_WIN_STDIO_H */
chardev/char-win-stdio.c new file +243 -0
243 lines not on this page · raw message
chardev/char.c +2 -229
262 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -5,3 +5,4 @@ chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o chardev-obj-$(CONFIG_WIN32) += char-win.o +chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
Signature · 1 line
2.11.0
PATCH 31/40 char: move socket chardev to its own file
In reply to Marc-André Lureau--- include/sysemu/char.h | 1 + chardev/char-socket.c | 993 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 978 +------------------------------------------------ chardev/Makefile.objs | 1 + 4 files changed, 996 insertions(+), 977 deletions(-) create mode 100644 chardev/char-socket.c
include/sysemu/char.h +1 -0
@@ -443,6 +443,7 @@ void qemu_chr_set_feature(Chardev *chr, ChardevFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename);int qemu_chr_write_all (Chardev *s,const uint8_t *buf,int len); +int qemu_chr_wait_connected (Chardev *chr,Error **errp);#define TYPE_CHARDEV "chardev"#define CHARDEV (obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV)
chardev/char-socket.c new file +993 -0
993 lines not on this page · raw message
chardev/char.c +1 -977
1,014 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -4,5 +4,6 @@ chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o +chardev-obj-y += char-socket.o chardev-obj-$(CONFIG_WIN32) += char-win.o chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
Signature · 1 line
2.11.0
PATCH 32/40 char: move udp chardev in its own file
In reply to Marc-André Lureau--- chardev/char-udp.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 198 ----------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 211 insertions(+), 198 deletions(-) create mode 100644 chardev/char-udp.c
chardev/char-udp.c new file +210 -0
@@ -0,0 +1,210 @@ +#include "qemu/osdep.h" +#include "sysemu/char.h" +#include "io/channel-socket.h" +#include "qapi/error.h" + +#include "char-io.h" + +/***********************************************************/ +/* UDP Net console */ + +typedef struct { +Chardev parent; +QIOChannel *ioc; +uint8_t buf[CHR_READ_BUF_LEN ]; +int bufcnt; +int bufptr; +int max_size; +}UdpChardev ; + +#define UDP_CHARDEV (obj) OBJECT_CHECK(UdpChardev, (obj), TYPE_CHARDEV_UDP) + +/* Called with chr_write_lock held. */ +static int udp_chr_write (Chardev *chr,const uint8_t *buf,int len) +{ +UdpChardev *s =UDP_CHARDEV (chr); + +return qio_channel_write ( + s->ioc, (const char *)buf, len,NULL ); +} + +static int udp_chr_read_poll (void *opaque) +{ +Chardev *chr =CHARDEV (opaque); +UdpChardev *s =UDP_CHARDEV (opaque); + + s->max_size =qemu_chr_be_can_write (chr); + +/* If there were any stray characters in the queue process them +* first +*/ +while (s->max_size >0 && s->bufptr < s->bufcnt) { +qemu_chr_be_write (chr, &s->buf[s->bufptr],1 ); + s->bufptr++; + s->max_size =qemu_chr_be_can_write (chr); + } +return s->max_size; +} + +static gboolean udp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) +{ +Chardev *chr =CHARDEV (opaque); +UdpChardev *s =UDP_CHARDEV (opaque); +ssize_t ret; + +if (s->max_size ==0 ) { +return TRUE; + } + ret =qio_channel_read ( + s->ioc, (char *)s->buf,sizeof (s->buf),NULL ); +if (ret <=0 ) { +remove_fd_in_watch (chr); +return FALSE; + } + s->bufcnt = ret; + + s->bufptr =0 ; +while (s->max_size >0 && s->bufptr < s->bufcnt) { +qemu_chr_be_write (chr, &s->buf[s->bufptr],1 ); + s->bufptr++; + s->max_size =qemu_chr_be_can_write (chr); + } + +return TRUE; +} + +static void udp_chr_update_read_handler (Chardev *chr, +GMainContext *context) +{ +UdpChardev *s =UDP_CHARDEV (chr); + +remove_fd_in_watch (chr); +if (s->ioc) { + chr->fd_in_tag =io_add_watch_poll (chr, s->ioc, + udp_chr_read_poll, + udp_chr_read, chr, + context); + } +} + +static void char_udp_finalize (Object *obj) +{ +Chardev *chr =CHARDEV (obj); +UdpChardev *s =UDP_CHARDEV (obj); + +remove_fd_in_watch (chr); +if (s->ioc) { +object_unref (OBJECT (s->ioc)); + } +qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); +} + +static void qemu_chr_parse_udp (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +const char *host =qemu_opt_get (opts,"host" ); +const char *port =qemu_opt_get (opts,"port" ); +const char *localaddr =qemu_opt_get (opts,"localaddr" ); +const char *localport =qemu_opt_get (opts,"localport" ); +bool has_local = false; +SocketAddress *addr; +ChardevUdp *udp; + + backend->type =CHARDEV_BACKEND_KIND_UDP ; +if (host ==NULL ||strlen (host) ==0 ) { + host ="localhost" ; + } +if (port ==NULL ||strlen (port) ==0 ) { +error_setg (errp,"chardev: udp: remote port not specified" ); +return ; + } +if (localport ==NULL ||strlen (localport) ==0 ) { + localport ="0" ; + }else { + has_local = true; + } +if (localaddr ==NULL ||strlen (localaddr) ==0 ) { + localaddr ="" ; + }else { + has_local = true; + } + + udp = backend->u.udp.data =g_new0 (ChardevUdp,1 ); +qemu_chr_parse_common (opts,qapi_ChardevUdp_base (udp)); + + addr =g_new0 (SocketAddress,1 ); + addr->type =SOCKET_ADDRESS_KIND_INET ; + addr->u.inet.data =g_new (InetSocketAddress,1 ); + *addr->u.inet.data = (InetSocketAddress ) { + .host =g_strdup (host), + .port =g_strdup (port), + .has_ipv4 =qemu_opt_get (opts,"ipv4" ), + .ipv4 =qemu_opt_get_bool (opts,"ipv4" ,0 ), + .has_ipv6 =qemu_opt_get (opts,"ipv6" ), + .ipv6 =qemu_opt_get_bool (opts,"ipv6" ,0 ), + }; + udp->remote = addr; + +if (has_local) { + udp->has_local = true; + addr =g_new0 (SocketAddress,1 ); + addr->type =SOCKET_ADDRESS_KIND_INET ; + addr->u.inet.data =g_new (InetSocketAddress,1 ); + *addr->u.inet.data = (InetSocketAddress ) { + .host =g_strdup (localaddr), + .port =g_strdup (localport), + }; + udp->local = addr; + } +} + +static void qmp_chardev_open_udp (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevUdp *udp = backend->u.udp.data; +QIOChannelSocket *sioc =qio_channel_socket_new (); +char *name; +UdpChardev *s =UDP_CHARDEV (chr); + +if (qio_channel_socket_dgram_sync (sioc, + udp->local, udp->remote, + errp) <0 ) { +object_unref (OBJECT (sioc)); +return ; + } + + name =g_strdup_printf ("chardev-udp-%s" , chr->label); +qio_channel_set_name (QIO_CHANNEL (sioc), name); +g_free (name); + + s->ioc =QIO_CHANNEL (sioc); +/* be isn't opened until we get a connection */ + *be_opened = false; +} + +static void char_udp_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->parse = qemu_chr_parse_udp; + cc->open = qmp_chardev_open_udp; + cc->chr_write = udp_chr_write; + cc->chr_update_read_handler = udp_chr_update_read_handler; +} + +static const TypeInfo char_udp_type_info = { + .name =TYPE_CHARDEV_UDP , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (UdpChardev), + .instance_finalize = char_udp_finalize, + .class_init = char_udp_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_udp_type_info); +} + +type_init (register_types);
chardev/char.c +0 -198
222 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -5,5 +5,6 @@ chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o chardev-obj-y += char-socket.o +chardev-obj-y += char-udp.o chardev-obj-$(CONFIG_WIN32) += char-win.o chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
Signature · 1 line
2.11.0
PATCH 33/40 char: move file chardev in its own file
In reply to Marc-André Lureau--- chardev/char-file.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 106 --------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 117 insertions(+), 106 deletions(-) create mode 100644 chardev/char-file.c
chardev/char-file.c new file +116 -0
@@ -0,0 +1,116 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "sysemu/char.h" + +#ifdef _WIN32 +#include "char-win.h" +#else +#include "char-fd.h" +#endif + +static void qmp_chardev_open_file (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevFile *file = backend->u.file.data; +#ifdef _WIN32 +HANDLE out; +DWORD accessmode; +DWORD flags; + +if (file->has_in) { +error_setg (errp,"input file not supported" ); +return ; + } + +if (file->has_append && file->append) { +/* Append to file if it already exists. */ + accessmode =FILE_GENERIC_WRITE & ~FILE_WRITE_DATA ; + flags =OPEN_ALWAYS ; + }else { +/* Truncate file if it already exists. */ + accessmode =GENERIC_WRITE ; + flags =CREATE_ALWAYS ; + } + + out =CreateFile (file->out, accessmode,FILE_SHARE_READ ,NULL , flags, +FILE_ATTRIBUTE_NORMAL ,NULL ); +if (out ==INVALID_HANDLE_VALUE ) { +error_setg (errp,"open %s failed" , file->out); +return ; + } + +qemu_chr_open_win_file (chr, out); +#else +int flags, in =-1 , out; + + flags =O_WRONLY |O_CREAT |O_BINARY ; +if (file->has_append && file->append) { + flags |=O_APPEND ; + }else { + flags |=O_TRUNC ; + } + + out =qmp_chardev_open_file_source (file->out, flags, errp); +if (out <0 ) { +return ; + } + +if (file->has_in) { + flags =O_RDONLY ; + in =qmp_chardev_open_file_source (file->in, flags, errp); +if (in <0 ) { +qemu_close (out); +return ; + } + } + +qemu_chr_open_fd (chr, in, out); +#endif +} + +static void qemu_chr_parse_file_out (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +const char *path =qemu_opt_get (opts,"path" ); +ChardevFile *file; + + backend->type =CHARDEV_BACKEND_KIND_FILE ; +if (path ==NULL ) { +error_setg (errp,"chardev: file: no filename given" ); +return ; + } + file = backend->u.file.data =g_new0 (ChardevFile,1 ); +qemu_chr_parse_common (opts,qapi_ChardevFile_base (file)); + file->out =g_strdup (path); + + file->has_append = true; + file->append =qemu_opt_get_bool (opts,"append" , false); +} + +static void char_file_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->parse = qemu_chr_parse_file_out; + cc->open = qmp_chardev_open_file; +} + +static const TypeInfo char_file_type_info = { + .name =TYPE_CHARDEV_FILE , +#ifdef _WIN32 + .parent =TYPE_CHARDEV_WIN , +#else + .parent =TYPE_CHARDEV_FD , +#endif + .class_init = char_file_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_file_type_info); +} + +type_init (register_types);
chardev/char.c +0 -106
136 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -1,5 +1,6 @@ chardev-obj-y += char.o chardev-obj-$(CONFIG_POSIX) += char-fd.o +chardev-obj-y += char-file.o chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o
Signature · 1 line
2.11.0
PATCH 34/40 char: move stdio in its own file
In reply to Marc-André Lureau--- chardev/char-stdio.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 120 ------------------------------------------ chardev/Makefile.objs | 1 + 3 files changed, 142 insertions(+), 120 deletions(-) create mode 100644 chardev/char-stdio.c
chardev/char-stdio.c new file +141 -0
@@ -0,0 +1,141 @@ +#include "qemu/osdep.h" +#include "qemu/sockets.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "sysemu/char.h" + +#ifdef _WIN32 +#include "char-win.h" +#include "char-win-stdio.h" +#else +#include <termios.h> +#include "char-fd.h" +#endif + +#ifndef _WIN32 +/* init terminal so that we can grab keys */ +static struct termios oldtty; +static int old_fd0_flags; +static bool stdio_in_use; +static bool stdio_allow_signal; +static bool stdio_echo_state; + +static void term_exit (void ) +{ +tcsetattr (0 ,TCSANOW , &oldtty); +fcntl (0 ,F_SETFL , old_fd0_flags); +} + +static void qemu_chr_set_echo_stdio (Chardev *chr,bool echo) +{ +struct termios tty; + + stdio_echo_state = echo; + tty = oldtty; +if (!echo) { + tty.c_iflag &= ~(IGNBRK |BRKINT |PARMRK |ISTRIP + |INLCR |IGNCR |ICRNL |IXON ); + tty.c_oflag |=OPOST ; + tty.c_lflag &= ~(ECHO |ECHONL |ICANON |IEXTEN ); + tty.c_cflag &= ~(CSIZE |PARENB ); + tty.c_cflag |=CS8 ; + tty.c_cc[VMIN ] =1 ; + tty.c_cc[VTIME ] =0 ; + } +if (!stdio_allow_signal) { + tty.c_lflag &= ~ISIG ; + } + +tcsetattr (0 ,TCSANOW , &tty); +} + +static void term_stdio_handler (int sig) +{ +/* restore echo after resume from suspend. */ +qemu_chr_set_echo_stdio (NULL , stdio_echo_state); +} + +static void qemu_chr_open_stdio (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevStdio *opts = backend->u.stdio.data; +struct sigaction act; + +if (is_daemonized ()) { +error_setg (errp,"cannot use stdio with -daemonize" ); +return ; + } + +if (stdio_in_use) { +error_setg (errp,"cannot use stdio by multiple character devices" ); +return ; + } + + stdio_in_use = true; + old_fd0_flags =fcntl (0 ,F_GETFL ); +tcgetattr (0 , &oldtty); +qemu_set_nonblock (0 ); +atexit (term_exit); + +memset (&act,0 ,sizeof (act)); + act.sa_handler = term_stdio_handler; +sigaction (SIGCONT , &act,NULL ); + +qemu_chr_open_fd (chr,0 ,1 ); + +if (opts->has_signal) { + stdio_allow_signal = opts->signal; + } +qemu_chr_set_echo_stdio (chr, false); +} +#endif + +static void qemu_chr_parse_stdio (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +ChardevStdio *stdio; + + backend->type =CHARDEV_BACKEND_KIND_STDIO ; + stdio = backend->u.stdio.data =g_new0 (ChardevStdio,1 ); +qemu_chr_parse_common (opts,qapi_ChardevStdio_base (stdio)); + stdio->has_signal = true; + stdio->signal =qemu_opt_get_bool (opts,"signal" , true); +} + +static void char_stdio_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->parse = qemu_chr_parse_stdio; +#ifndef _WIN32 + cc->open = qemu_chr_open_stdio; + cc->chr_set_echo = qemu_chr_set_echo_stdio; +#endif +} + +static void char_stdio_finalize (Object *obj) +{ +#ifndef _WIN32 +term_exit (); +#endif +} + +static const TypeInfo char_stdio_type_info = { + .name =TYPE_CHARDEV_STDIO , +#ifdef _WIN32 + .parent =TYPE_CHARDEV_WIN_STDIO , +#else + .parent =TYPE_CHARDEV_FD , +#endif + .instance_finalize = char_stdio_finalize, + .class_init = char_stdio_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_stdio_type_info); +} + +type_init (register_types);
chardev/char.c +0 -120
144 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-ringbuf.o chardev-obj-y += char-socket.o +chardev-obj-y += char-stdio.o chardev-obj-y += char-udp.o chardev-obj-$(CONFIG_WIN32) += char-win.o chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
Signature · 1 line
2.11.0
PATCH 35/40 char: move console in its own file
In reply to Marc-André Lureau--- chardev/char-console.c | 30 ++++++++++++++++++++++++++++++ chardev/char.c | 3 --- chardev/Makefile.objs | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 chardev/char-console.c
chardev/char-console.c new file +30 -0
@@ -0,0 +1,30 @@ +#include "qemu/osdep.h" +#include "char-win.h" + +static void qemu_chr_open_win_con (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +qemu_chr_open_win_file (chr,GetStdHandle (STD_OUTPUT_HANDLE )); +} + +static void char_console_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->open = qemu_chr_open_win_con; +} + +static const TypeInfo char_console_type_info = { + .name =TYPE_CHARDEV_CONSOLE , + .parent =TYPE_CHARDEV_WIN , + .class_init = char_console_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_console_type_info); +} + +type_init (register_types);
chardev/char.c +0 -3
@@ -2321,9 +2321,6 @@ static void register_types(void)#ifdef HAVE_CHARDEV_PTY type_register_static (&char_pty_type_info);#endif -#ifdef _WIN32 -type_register_static (&char_console_type_info); -#endif type_register_static (&char_pipe_type_info);/* this must be done after machine init, since we register FEs with muxes
chardev/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ chardev-obj-y += char.o +chardev-obj-$(CONFIG_WIN32) += char-console.o chardev-obj-$(CONFIG_POSIX) += char-fd.o chardev-obj-y += char-file.o chardev-obj-y += char-io.o
Signature · 1 line
2.11.0
PATCH 36/40 char: move pipe chardev in its own file
In reply to Marc-André Lureau--- chardev/char-pipe.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 166 ------------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 169 insertions(+), 166 deletions(-) create mode 100644 chardev/char-pipe.c
chardev/char-pipe.c new file +168 -0
@@ -0,0 +1,168 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/char.h" + +#ifdef _WIN32 +#include "char-win.h" +#else +#include "char-fd.h" +#endif + +#ifdef _WIN32 +#define MAXCONNECT 1 +#define NTIMEOUT 5000 + +static int win_chr_pipe_init (Chardev *chr,const char *filename, +Error **errp) +{ +WinChardev *s =WIN_CHARDEV (chr); +OVERLAPPED ov; +int ret; +DWORD size; +char *openname; + + s->fpipe = TRUE; + + s->hsend =CreateEvent (NULL , TRUE, FALSE,NULL ); +if (!s->hsend) { +error_setg (errp,"Failed CreateEvent" ); + goto fail; + } + s->hrecv =CreateEvent (NULL , TRUE, FALSE,NULL ); +if (!s->hrecv) { +error_setg (errp,"Failed CreateEvent" ); + goto fail; + } + + openname =g_strdup_printf ("\\\\.\\pipe\\%s" , filename); + s->hcom =CreateNamedPipe (openname, +PIPE_ACCESS_DUPLEX |FILE_FLAG_OVERLAPPED , +PIPE_TYPE_BYTE |PIPE_READMODE_BYTE | +PIPE_WAIT , +MAXCONNECT ,NSENDBUF ,NRECVBUF ,NTIMEOUT ,NULL ); +g_free (openname); +if (s->hcom ==INVALID_HANDLE_VALUE ) { +error_setg (errp,"Failed CreateNamedPipe (%lu)" ,GetLastError ()); + s->hcom =NULL ; + goto fail; + } + +ZeroMemory (&ov,sizeof (ov)); + ov.hEvent =CreateEvent (NULL , TRUE, FALSE,NULL ); + ret =ConnectNamedPipe (s->hcom, &ov); +if (ret) { +error_setg (errp,"Failed ConnectNamedPipe" ); + goto fail; + } + + ret =GetOverlappedResult (s->hcom, &ov, &size, TRUE); +if (!ret) { +error_setg (errp,"Failed GetOverlappedResult" ); +if (ov.hEvent) { +CloseHandle (ov.hEvent); + ov.hEvent =NULL ; + } + goto fail; + } + +if (ov.hEvent) { +CloseHandle (ov.hEvent); + ov.hEvent =NULL ; + } +qemu_add_polling_cb (win_chr_pipe_poll, chr); +return 0 ; + + fail: +return -1 ; +} + +static void qemu_chr_open_pipe (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevHostdev *opts = backend->u.pipe.data; +const char *filename = opts->device; + +if (win_chr_pipe_init (chr, filename, errp) <0 ) { +return ; + } +} + +#else + +static void qemu_chr_open_pipe (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +ChardevHostdev *opts = backend->u.pipe.data; +int fd_in, fd_out; +char *filename_in; +char *filename_out; +const char *filename = opts->device; + + filename_in =g_strdup_printf ("%s.in" , filename); + filename_out =g_strdup_printf ("%s.out" , filename); +TFR (fd_in =qemu_open (filename_in,O_RDWR |O_BINARY )); +TFR (fd_out =qemu_open (filename_out,O_RDWR |O_BINARY )); +g_free (filename_in); +g_free (filename_out); +if (fd_in <0 || fd_out <0 ) { +if (fd_in >=0 ) { +close (fd_in); + } +if (fd_out >=0 ) { +close (fd_out); + } +TFR (fd_in = fd_out =qemu_open (filename,O_RDWR |O_BINARY )); +if (fd_in <0 ) { +error_setg_file_open (errp, errno, filename); +return ; + } + } +qemu_chr_open_fd (chr, fd_in, fd_out); +} + +#endif /* !_WIN32 */ + +static void qemu_chr_parse_pipe (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +const char *device =qemu_opt_get (opts,"path" ); +ChardevHostdev *dev; + +if (device ==NULL ) { +error_setg (errp,"chardev: pipe: no device path given" ); +return ; + } + backend->type =CHARDEV_BACKEND_KIND_PIPE ; + dev = backend->u.pipe.data =g_new0 (ChardevHostdev,1 ); +qemu_chr_parse_common (opts,qapi_ChardevHostdev_base (dev)); + dev->device =g_strdup (device); +} + +static void char_pipe_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->parse = qemu_chr_parse_pipe; + cc->open = qemu_chr_open_pipe; +} + +static const TypeInfo char_pipe_type_info = { + .name =TYPE_CHARDEV_PIPE , +#ifdef _WIN32 + .parent =TYPE_CHARDEV_WIN , +#else + .parent =TYPE_CHARDEV_FD , +#endif + .class_init = char_pipe_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_pipe_type_info); +} + +type_init (register_types);
chardev/char.c +0 -166
190 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ chardev-obj-y += char-file.o chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o +chardev-obj-y += char-pipe.o chardev-obj-y += char-ringbuf.o chardev-obj-y += char-socket.o chardev-obj-y += char-stdio.o
Signature · 1 line
2.11.0
PATCH 37/40 char: move pty chardev in its own file
In reply to Marc-André Lureau--- chardev/char-pty.c | 277 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 258 ---------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 278 insertions(+), 258 deletions(-) create mode 100644 chardev/char-pty.c
chardev/char-pty.c new file +277 -0
@@ -0,0 +1,277 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "sysemu/char.h" +#include "io/channel-file.h" +#include "qemu/sockets.h" +#include "qemu/error-report.h" + +#include "char-io.h" + +#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ + || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \ + || defined(__GLIBC__) + +typedef struct { +Chardev parent; +QIOChannel *ioc; +int read_bytes; + +/* Protected by the Chardev chr_write_lock. */ +int connected; +guint timer_tag; +guint open_tag; +}PtyChardev ; + +#define PTY_CHARDEV (obj) OBJECT_CHECK(PtyChardev, (obj), TYPE_CHARDEV_PTY) + +static void pty_chr_update_read_handler_locked (Chardev *chr); +static void pty_chr_state (Chardev *chr,int connected); + +static gboolean pty_chr_timer (gpointer opaque) +{ +struct Chardev *chr =CHARDEV (opaque); +PtyChardev *s =PTY_CHARDEV (opaque); + +qemu_mutex_lock (&chr->chr_write_lock); + s->timer_tag =0 ; + s->open_tag =0 ; +if (!s->connected) { +/* Next poll ... */ +pty_chr_update_read_handler_locked (chr); + } +qemu_mutex_unlock (&chr->chr_write_lock); +return FALSE; +} + +/* Called with chr_write_lock held. */ +static void pty_chr_rearm_timer (Chardev *chr,int ms) +{ +PtyChardev *s =PTY_CHARDEV (chr); +char *name; + +if (s->timer_tag) { +g_source_remove (s->timer_tag); + s->timer_tag =0 ; + } + +if (ms ==1000 ) { + name =g_strdup_printf ("pty-timer-secs-%s" , chr->label); + s->timer_tag =g_timeout_add_seconds (1 , pty_chr_timer, chr); + }else { + name =g_strdup_printf ("pty-timer-ms-%s" , chr->label); + s->timer_tag =g_timeout_add (ms, pty_chr_timer, chr); + } +g_source_set_name_by_id (s->timer_tag, name); +g_free (name); +} + +/* Called with chr_write_lock held. */ +static void pty_chr_update_read_handler_locked (Chardev *chr) +{ +PtyChardev *s =PTY_CHARDEV (chr); +GPollFD pfd; +int rc; +QIOChannelFile *fioc =QIO_CHANNEL_FILE (s->ioc); + + pfd.fd = fioc->fd; + pfd.events =G_IO_OUT ; + pfd.revents =0 ; +do { + rc =g_poll (&pfd,1 ,0 ); + }while (rc ==-1 && errno ==EINTR ); +assert (rc >=0 ); + +if (pfd.revents &G_IO_HUP ) { +pty_chr_state (chr,0 ); + }else { +pty_chr_state (chr,1 ); + } +} + +static void pty_chr_update_read_handler (Chardev *chr, +GMainContext *context) +{ +qemu_mutex_lock (&chr->chr_write_lock); +pty_chr_update_read_handler_locked (chr); +qemu_mutex_unlock (&chr->chr_write_lock); +} + +/* Called with chr_write_lock held. */ +static int char_pty_chr_write (Chardev *chr,const uint8_t *buf,int len) +{ +PtyChardev *s =PTY_CHARDEV (chr); + +if (!s->connected) { +/* guest sends data, check for (re-)connect */ +pty_chr_update_read_handler_locked (chr); +if (!s->connected) { +return 0 ; + } + } +return io_channel_send (s->ioc, buf, len); +} + +static GSource *pty_chr_add_watch (Chardev *chr,GIOCondition cond) +{ +PtyChardev *s =PTY_CHARDEV (chr); +if (!s->connected) { +return NULL ; + } +return qio_channel_create_watch (s->ioc, cond); +} + +static int pty_chr_read_poll (void *opaque) +{ +Chardev *chr =CHARDEV (opaque); +PtyChardev *s =PTY_CHARDEV (opaque); + + s->read_bytes =qemu_chr_be_can_write (chr); +return s->read_bytes; +} + +static gboolean pty_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) +{ +Chardev *chr =CHARDEV (opaque); +PtyChardev *s =PTY_CHARDEV (opaque); +gsize len; +uint8_t buf[CHR_READ_BUF_LEN ]; +ssize_t ret; + + len =sizeof (buf); +if (len > s->read_bytes) { + len = s->read_bytes; + } +if (len ==0 ) { +return TRUE; + } + ret =qio_channel_read (s->ioc, (char *)buf, len,NULL ); +if (ret <=0 ) { +pty_chr_state (chr,0 ); +return FALSE; + }else { +pty_chr_state (chr,1 ); +qemu_chr_be_write (chr, buf, ret); + } +return TRUE; +} + +static gboolean qemu_chr_be_generic_open_func (gpointer opaque) +{ +Chardev *chr =CHARDEV (opaque); +PtyChardev *s =PTY_CHARDEV (opaque); + + s->open_tag =0 ; +qemu_chr_be_generic_open (chr); +return FALSE; +} + +/* Called with chr_write_lock held. */ +static void pty_chr_state (Chardev *chr,int connected) +{ +PtyChardev *s =PTY_CHARDEV (chr); + +if (!connected) { +if (s->open_tag) { +g_source_remove (s->open_tag); + s->open_tag =0 ; + } +remove_fd_in_watch (chr); + s->connected =0 ; +/* (re-)connect poll interval for idle guests: once per second. +* We check more frequently in case the guests sends data to +* the virtual device linked to our pty. */ +pty_chr_rearm_timer (chr,1000 ); + }else { +if (s->timer_tag) { +g_source_remove (s->timer_tag); + s->timer_tag =0 ; + } +if (!s->connected) { +g_assert (s->open_tag ==0 ); + s->connected =1 ; + s->open_tag =g_idle_add (qemu_chr_be_generic_open_func, chr); + } +if (!chr->fd_in_tag) { + chr->fd_in_tag =io_add_watch_poll (chr, s->ioc, + pty_chr_read_poll, + pty_chr_read, + chr,NULL ); + } + } +} + +static void char_pty_finalize (Object *obj) +{ +Chardev *chr =CHARDEV (obj); +PtyChardev *s =PTY_CHARDEV (obj); + +qemu_mutex_lock (&chr->chr_write_lock); +pty_chr_state (chr,0 ); +object_unref (OBJECT (s->ioc)); +if (s->timer_tag) { +g_source_remove (s->timer_tag); + s->timer_tag =0 ; + } +qemu_mutex_unlock (&chr->chr_write_lock); +qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); +} + +static void char_pty_open (Chardev *chr, +ChardevBackend *backend, +bool *be_opened, +Error **errp) +{ +PtyChardev *s; +int master_fd, slave_fd; +char pty_name[PATH_MAX ]; +char *name; + + master_fd =qemu_openpty_raw (&slave_fd, pty_name); +if (master_fd <0 ) { +error_setg_errno (errp, errno,"Failed to create PTY" ); +return ; + } + +close (slave_fd); +qemu_set_nonblock (master_fd); + + chr->filename =g_strdup_printf ("pty:%s" , pty_name); +error_report ("char device redirected to %s (label %s)" , + pty_name, chr->label); + + s =PTY_CHARDEV (chr); + s->ioc =QIO_CHANNEL (qio_channel_file_new_fd (master_fd)); + name =g_strdup_printf ("chardev-pty-%s" , chr->label); +qio_channel_set_name (QIO_CHANNEL (s->ioc), name); +g_free (name); + s->timer_tag =0 ; + *be_opened = false; +} + +static void char_pty_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->open = char_pty_open; + cc->chr_write = char_pty_chr_write; + cc->chr_update_read_handler = pty_chr_update_read_handler; + cc->chr_add_watch = pty_chr_add_watch; +} + +static const TypeInfo char_pty_type_info = { + .name =TYPE_CHARDEV_PTY , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (PtyChardev), + .instance_finalize = char_pty_finalize, + .class_init = char_pty_class_init, +}; + +static void register_types (void ) +{ +type_register_static (&char_pty_type_info); +} + +type_init (register_types); + +#endif
chardev/char.c +0 -258
270 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o chardev-obj-y += char-pipe.o +chardev-obj-$(CONFIG_POSIX) += char-pty.o chardev-obj-y += char-ringbuf.o chardev-obj-y += char-socket.o chardev-obj-y += char-stdio.o
Signature · 1 line
2.11.0
PATCH 38/40 char: move serial chardev to itw own file
In reply to Marc-André Lureau--- chardev/char-serial.h | 12 ++ chardev/char-serial.c | 295 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 278 +---------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 310 insertions(+), 276 deletions(-) create mode 100644 chardev/char-serial.h create mode 100644 chardev/char-serial.c
chardev/char-serial.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef CHAR_SERIAL_H +#define CHAR_SERIAL_H + +#ifdef _WIN32 +#define HAVE_CHARDEV_SERIAL 1 +#elif defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ + || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \ + || defined(__GLIBC__) +#define HAVE_CHARDEV_SERIAL 1 +#endif + +#endif
chardev/char-serial.c new file +295 -0
295 lines not on this page · raw message
chardev/char.c +2 -276
332 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ chardev-obj-y += char-null.o chardev-obj-y += char-pipe.o chardev-obj-$(CONFIG_POSIX) += char-pty.o chardev-obj-y += char-ringbuf.o +chardev-obj-y += char-serial.o chardev-obj-y += char-socket.o chardev-obj-y += char-stdio.o chardev-obj-y += char-udp.o
Signature · 1 line
2.11.0
PATCH 39/40 char: move parallel chardev in its own file
In reply to Marc-André Lureau--- chardev/char-parallel.h | 9 ++ chardev/char-parallel.c | 293 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 288 +---------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 304 insertions(+), 287 deletions(-) create mode 100644 chardev/char-parallel.h create mode 100644 chardev/char-parallel.c
chardev/char-parallel.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef CHAR_PARALLEL_H +#define CHAR_PARALLEL_H + +#if defined(__linux__) || defined(__FreeBSD__) || \ + defined(__FreeBSD_kernel__) || defined(__DragonFly__) +#define HAVE_CHARDEV_PARPORT 1 +#endif + +#endif /* CHAR_PARALLEL_H */
chardev/char-parallel.c new file +293 -0
293 lines not on this page · raw message
chardev/char.c +1 -287
339 lines not on this page · raw message
chardev/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ chardev-obj-y += char-file.o chardev-obj-y += char-io.o chardev-obj-y += char-mux.o chardev-obj-y += char-null.o +chardev-obj-$(CONFIG_POSIX) += char-parallel.o chardev-obj-y += char-pipe.o chardev-obj-$(CONFIG_POSIX) += char-pty.o chardev-obj-y += char-ringbuf.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 39/40] char: move parallel chardev in its own file
Quoted 14 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- chardev/char-parallel.h | 9 ++ chardev/char-parallel.c | 293 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 288 +---------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 304 insertions(+), 287 deletions(-) create mode 100644 chardev/char-parallel.h create mode 100644 chardev/char-parallel.c+++
b/chardev/char.c
chardev/char.c void qemu_chr_be_generic_open(Chardev *s) · line 114
Quoted 7 lines
chardev/char.c +0
-1@@ -123,7 +109,6 @@ void qemu_chr_be_generic_open(Chardev *s)qemu_chr_be_event (s,CHR_EVENT_OPENED ); } -/* Not reporting errors from writing to logfile, as logs are * defined to be "best effort" only */ static void qemu_chr_fe_write_log(Chardev *s,
Spurious hunk?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 40/40 char: headers clean-up
In reply to Marc-André LureauThose could probably be squashed with earlier patches, however I couldn't easily identify them, test them or check if there are still necessary on various platforms.
--- include/sysemu/char.h | 5 ----- chardev/char.c | 40 +--------------------------------------- hmp.c | 1 + monitor.c | 1 + qmp.c | 1 + tests/vhost-user-test.c | 1 + 6 files changed, 5 insertions(+), 44 deletions(-)
include/sysemu/char.h +0 -5
@@ -2,12 +2,7 @@#define QEMU_CHAR_H #include "qemu-common.h" -#include "qemu/queue.h" #include "qemu/option.h" -#include "qemu/config-file.h" -#include "block/aio.h" -#include "qapi/qmp/qobject.h" -#include "qapi/qmp/qstring.h" #include "qemu/main-loop.h" #include "qemu/bitmap.h" #include "qom/object.h"
chardev/char.c +1 -39
@@ -26,54 +26,16 @@#include "qemu/cutils.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" -#include "sysemu/block-backend.h" +#include "qemu/config-file.h" #include "qemu/error-report.h" -#include "qemu/timer.h" #include "sysemu/char.h" -#include "hw/usb.h" #include "qmp-commands.h" -#include "qapi/clone-visitor.h" #include "qapi-visit.h" -#include "qemu/base64.h" -#include "io/channel-socket.h" -#include "io/channel-tls.h" #include "sysemu/replay.h" #include "qemu/help_option.h" -#include <zlib.h> - -#ifndef _WIN32 -#include <sys/times.h> -#include <sys/wait.h> -#include <sys/ioctl.h> -#include <sys/resource.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <net/if.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <sys/select.h> -#ifdef __sun__ -#include <sys/ethernet.h> -#include <sys/sockio.h> -#include <netinet/arp.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/ip_icmp.h> // must come after ip.h -#include <netinet/udp.h> -#include <netinet/tcp.h> -#endif -#endif - -#include "qemu/sockets.h" -#include "ui/qemu-spice.h" -#include "char-mux.h" #include "char-io.h" -#ifdef _WIN32 -#include "char-win.h" -#endif #include "char-parallel.h" #include "char-serial.h"
hmp.c +1 -0
@@ -19,6 +19,7 @@#include "net/eth.h" #include "sysemu/char.h" #include "sysemu/block-backend.h" +#include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/timer.h" #include "qmp-commands.h"
monitor.c +1 -0
@@ -40,6 +40,7 @@#include "sysemu/sysemu.h" #include "sysemu/numa.h" #include "monitor/monitor.h" +#include "qemu/config-file.h" #include "qemu/readline.h" #include "ui/console.h" #include "ui/input.h"
qmp.c +1 -0
@@ -18,6 +18,7 @@#include "qemu/cutils.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h" +#include "qemu/config-file.h" #include "qemu/uuid.h" #include "qmp-commands.h" #include "sysemu/char.h"
tests/vhost-user-test.c +1 -0
@@ -12,6 +12,7 @@#include "libqtest.h" #include "qapi/error.h" +#include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/range.h" #include "qemu/sockets.h"
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 40/40] char: headers clean-up
Quoted 6 lines · Marc-André Lureau
Those could probably be squashed with earlier patches, however I couldn't easily identify them, test them or check if there are still necessary on various platforms.
Signed-off-by Marc-André Lureau <[email protected]>---
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org