Chr split patches
The following changes since commit a0def594286d9110a6035e02eef558cf3cf5d847:
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-01-30 10:23:20 +0000)
are available in the git repository at:
https://github.com/elmarco/qemu.git tags/chr-split-pull-request
for you to fetch changes up to 3766519be2843e0947425cafd1e7e205dd63f0fd:
char: headers clean-up (2017-01-31 13:03:48 +0400)
----------------------------------------------------------------
----------------------------------------------------------------
Marc-André Lureau (41):
MAINTAINERS: add myself to qemu-char.c
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 stuff to 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 its own file
char: move parallel chardev in its own file
char: headers clean-up
chardev/char-fd.h | 44 + chardev/char-io.h | 46 + chardev/char-mux.h | 63 + chardev/char-parallel.h | 32 + chardev/char-serial.h | 35 + chardev/char-win-stdio.h | 29 + chardev/char-win.h | 53 + include/sysemu/char.h | 69 +- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 5 - chardev/char-console.c | 53 + chardev/char-fd.c | 170 ++ chardev/char-file.c | 139 ++ chardev/char-io.c | 192 ++ chardev/char-mux.c | 358 ++++ chardev/char-null.c | 54 + chardev/char-parallel.c | 316 +++ chardev/char-pipe.c | 191 ++ chardev/char-pty.c | 300 +++ chardev/char-ringbuf.c | 249 +++ chardev/char-serial.c | 318 +++ chardev/char-socket.c | 1017 +++++++++ chardev/char-stdio.c | 164 ++ chardev/char-udp.c | 233 +++ chardev/char-win-stdio.c | 266 +++ chardev/char-win.c | 265 +++ chardev/char.c | 1334 ++++++++++++ hmp.c | 1 + monitor.c | 1 + qemu-char.c | 5171 ---------------------------------------------- qmp.c | 1 + spice-qemu-char.c | 21 +- tests/vhost-user-test.c | 1 + ui/console.c | 10 +- ui/gtk.c | 9 +- MAINTAINERS | 3 +- Makefile | 4 +- Makefile.objs | 5 +- Makefile.target | 3 + chardev/Makefile.objs | 17 + tests/Makefile.include | 9 +- 42 files changed, 5999 insertions(+), 5274 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 01/41] MAINTAINERS: add myself to qemu-char.c
I consider to have enough experience with qemu-char to propose myself as maintainer. This will allow me to send pull request without waiting for Paolo.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1194,6 +1194,7 @@ T: git git://github.com/jnsnow/qemu.git bitmaps Character device backends M: Paolo Bonzini <[email protected]> +M: Marc-André Lureau <[email protected]> S: Maintained F: qemu-char.c F: backends/msmouse.c
Signature · 1 line
2.11.0.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 02/41] spice-qemu-char: convert to finalize
In reply to Marc-André Lureau--- 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 03/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 04/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 05/41] 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++) {
@@ -4025,7 +4025,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;
@@ -4036,6 +4035,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 06/41] 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) {
@@ -4975,13 +4976,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 07/41] 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
@@ -3446,9 +3446,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);
@@ -4886,7 +4887,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(
@@ -4904,9 +4905,6 @@ error:if (sioc) {object_unref (OBJECT (sioc)); } -if (s->tls_creds) { -object_unref (OBJECT (s->tls_creds)); - } }static const CharDriver socket_driver = {
@@ -4928,13 +4926,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 09/41] 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
@@ -3550,9 +3550,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); }
@@ -3982,7 +3982,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 = {
@@ -3990,6 +3989,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 08/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 10/41] 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,
@@ -4699,18 +4688,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 11/41] 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,
@@ -3859,7 +3859,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 }
@@ -3869,6 +3868,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 12/41] 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, };
@@ -3856,7 +3857,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 13/41] 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 = {
@@ -4731,10 +4737,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 14/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 15/41] 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__)
@@ -4760,7 +4755,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 16/41] 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
@@ -185,13 +185,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: * * Ask the backend to override its normal echo setting. This only really
@@ -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
@@ -4371,18 +4371,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 17/41] 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 | 315 +++++++++++++++++++++++--------------------------- spice-qemu-char.c | 15 +-- ui/console.c | 10 +- ui/gtk.c | 10 +- 8 files changed, 159 insertions(+), 221 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 +146 -169
523 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 18/41] 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 | 11 +++++------ 2 files changed, 25 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 +5 -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,7 @@ 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;
@@ -4991,13 +4990,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 19/41] 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 | 99 +++++++++++++++++++++++++-------------------------- spice-qemu-char.c | 4 +-- ui/console.c | 2 +- ui/gtk.c | 1 - 8 files changed, 51 insertions(+), 59 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 +48 -51
315 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 20/41] 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 | 8 +++++--- 5 files changed, 8 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
@@ -1196,7 +1196,7 @@ Character device backends M: Paolo Bonzini <[email protected]> M: Marc-André Lureau <[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 +5 -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)
@@ -510,7 +510,8 @@ 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)
@@ -703,7 +704,8 @@ 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 22/41] 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 = {
@@ -4712,10 +4719,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 21/41] 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 | 4 +++- Makefile.objs | 5 +++-- Makefile.target | 3 +++ chardev/Makefile.objs | 2 +- tests/Makefile.include | 9 +++++---- 5 files changed, 15 insertions(+), 8 deletions(-)
Makefile +3 -1
@@ -147,6 +147,7 @@ endif dummy := $(call unnest-vars,, \ stub-obj-y \ + chardev-obj-y \ util-obj-y \ qga-obj-y \ ivshmem-client-obj-y \
@@ -223,7 +224,8 @@ 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 -2
@@ -51,8 +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 += page_cache.o +common-obj-y += page_cache.o #aio.o common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
@@ -79,6 +78,8 @@ common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o common-obj-$(CONFIG_FDT) += device_tree.o +chardev-obj-y = chardev/ + ###################################################################### # qapi
Makefile.target +3 -0
@@ -172,12 +172,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 \
@@ -186,6 +188,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 +5 -4
@@ -510,8 +510,8 @@ 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 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)
@@ -704,8 +704,9 @@ 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 23/41] char: move null chardev to its own file
In reply to Marc-André Lureau--- chardev/char-null.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 23 ---------------------- chardev/Makefile.objs | 1 + 3 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 chardev/char-null.c
chardev/char-null.c new file +54 -0
@@ -0,0 +1,54 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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. */
@@ -5105,7 +5083,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 24/41] 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 | 63 +++++++++ include/sysemu/char.h | 3 +- chardev/char-mux.c | 358 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 352 +------------------------------------------------ chardev/Makefile.objs | 1 + 5 files changed, 426 insertions(+), 351 deletions(-) create mode 100644 chardev/char-mux.h create mode 100644 chardev/char-mux.c
chardev/char-mux.h new file +63 -0
@@ -0,0 +1,63 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 catches 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 +358 -0
358 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 25/41] char: move ringbuf/memory to its own file
In reply to Marc-André Lureau--- chardev/char-ringbuf.c | 249 +++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 218 ------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 250 insertions(+), 218 deletions(-) create mode 100644 chardev/char-ringbuf.c
chardev/char-ringbuf.c new file +249 -0
@@ -0,0 +1,249 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 26/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 27/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 28/41] char: move QIOChannel-related stuff to char-io.h
In reply to Marc-André Lureau--- chardev/char-io.h | 46 ++++++++++++ chardev/char-io.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 174 +-------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 240 insertions(+), 173 deletions(-) create mode 100644 chardev/char-io.h create mode 100644 chardev/char-io.c
chardev/char-io.h new file +46 -0
@@ -0,0 +1,46 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef CHAR_IO_H +#define CHAR_IO_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 +192 -0
192 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 29/41] char: move fd chardev in its own file
In reply to Marc-André Lureau--- chardev/char-fd.h | 44 +++++++++++++ chardev/char-fd.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 147 +------------------------------------------ chardev/Makefile.objs | 1 + 4 files changed, 217 insertions(+), 145 deletions(-) create mode 100644 chardev/char-fd.h create mode 100644 chardev/char-fd.c
chardev/char-fd.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 +170 -0
170 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 30/41] char: move win chardev base class in its own file
In reply to Marc-André Lureau--- chardev/char-win.h | 53 ++++++++++ chardev/char-win.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 253 +---------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 322 insertions(+), 250 deletions(-) create mode 100644 chardev/char-win.h create mode 100644 chardev/char-win.c
chardev/char-win.h new file +53 -0
@@ -0,0 +1,53 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 +265 -0
265 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 31/41] char: move win-stdio into its own file
In reply to Marc-André Lureau--- chardev/char-win-stdio.h | 29 ++++++ chardev/char-win-stdio.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 231 +--------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 298 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 +29 -0
@@ -0,0 +1,29 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 +266 -0
266 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 33/41] char: move udp chardev in its own file
In reply to Marc-André Lureau--- chardev/char-udp.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 198 ------------------------------------------ chardev/Makefile.objs | 1 + 3 files changed, 234 insertions(+), 198 deletions(-) create mode 100644 chardev/char-udp.c
chardev/char-udp.c new file +233 -0
@@ -0,0 +1,233 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 34/41] char: move file chardev in its own file
In reply to Marc-André Lureau--- chardev/char-file.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 106 -------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 140 insertions(+), 106 deletions(-) create mode 100644 chardev/char-file.c
chardev/char-file.c new file +139 -0
@@ -0,0 +1,139 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 32/41] char: move socket chardev to its own file
In reply to Marc-André Lureau--- include/sysemu/char.h | 1 + chardev/char-socket.c | 1017 +++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 979 +---------------------------------------------- chardev/Makefile.objs | 1 + 4 files changed, 1020 insertions(+), 978 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 +1017 -0
1,017 lines not on this page · raw message
chardev/char.c +1 -978
1,015 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 36/41] char: move console in its own file
In reply to Marc-André Lureau--- chardev/char-console.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 3 --- chardev/Makefile.objs | 1 + 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 chardev/char-console.c
chardev/char-console.c new file +53 -0
@@ -0,0 +1,53 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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
@@ -2343,9 +2343,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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 35/41] char: move stdio in its own file
In reply to Marc-André Lureau--- chardev/char-stdio.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 120 ------------------------------------ chardev/Makefile.objs | 1 + 3 files changed, 165 insertions(+), 120 deletions(-) create mode 100644 chardev/char-stdio.c
chardev/char-stdio.c new file +164 -0
@@ -0,0 +1,164 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 37/41] char: move pipe chardev in its own file
In reply to Marc-André Lureau--- chardev/char-pipe.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 166 ------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 192 insertions(+), 166 deletions(-) create mode 100644 chardev/char-pipe.c
chardev/char-pipe.c new file +191 -0
@@ -0,0 +1,191 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 38/41] char: move pty chardev in its own file
In reply to Marc-André Lureau--- chardev/char-pty.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 258 ------------------------------------------- chardev/Makefile.objs | 1 + 3 files changed, 301 insertions(+), 258 deletions(-) create mode 100644 chardev/char-pty.c
chardev/char-pty.c new file +300 -0
@@ -0,0 +1,300 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 39/41] char: move serial chardev to its own file
In reply to Marc-André Lureau--- chardev/char-serial.h | 35 ++++++ chardev/char-serial.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 278 +------------------------------------------ chardev/Makefile.objs | 1 + 4 files changed, 356 insertions(+), 276 deletions(-) create mode 100644 chardev/char-serial.h create mode 100644 chardev/char-serial.c
chardev/char-serial.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 +318 -0
318 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 41/41] 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.295.gd7dffce1c.dirty
[Qemu-devel] [PULL 40/41] char: move parallel chardev in its own file
In reply to Marc-André Lureau--- chardev/char-parallel.h | 32 +++++ chardev/char-parallel.c | 316 ++++++++++++++++++++++++++++++++++++++++++++++++ chardev/char.c | 287 +------------------------------------------ chardev/Makefile.objs | 1 + 4 files changed, 350 insertions(+), 286 deletions(-) create mode 100644 chardev/char-parallel.h create mode 100644 chardev/char-parallel.c
chardev/char-parallel.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#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 +316 -0
316 lines not on this page · raw message
chardev/char.c +1 -286
332 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.295.gd7dffce1c.dirty
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Type: series
Subject: [Qemu-devel] [PULL 00/41] Chr split patches
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
95ffd75 char: headers clean-up
21c900a char: move parallel chardev in its own file 55df019 char: move serial chardev to its own file e7e9361 char: move pty chardev in its own file f715f19 char: move pipe chardev in its own file 262f7e3 char: move console in its own file 9a9d6eb char: move stdio in its own file
5ffc3c6 char: move file chardev in its own file 050e718 char: move udp chardev in its own file 74b2905 char: move socket chardev to its own file e65f01f char: move win-stdio into its own file d77168a char: move win chardev base class in its own file eac8509 char: move fd chardev in its own file 701cd50 char: move QIOChannel-related stuff to char-io.h d2193c2 char: remove unused READ_RETRIES
e63481d char: rename and move to header CHR_READ_BUF_LEN 359c68c char: move ringbuf/memory to its own file 318282b char: move mux to its own file
20c8425 char: move null chardev to its own file 793d26c char: make null_chr_write() the default method 479d2f7 char: create chardev-obj-y
e52f6c3 char: move to chardev/
53335b9 char: remove class kind field
fba7593 char: rename remaining CharDriver to Chardev 768322b char: get rid of CharDriver
23766b7 char: remove chr_free
df541a5 char-fd: convert to finalize
6fddb56 char-win: convert to finalize
f90dce0 char-win: do not override chr_free 010dcf3 char-win-stdio: convert to finalize da6b699 char-stdio: convert to finalize
676ec0e char-parallel: convert parallel to finalize 122b1e6 char-ringbuf: convert to finalize ae17198 char-pty: convert to finalize
a9dd8b2 char-socket: convert to finalize
7ac8d6b char-udp: convert to finalize
c0062a9 mux: convert to finalize
42d5c45 msmouse: convert to finalize
a03aea1 baum: convert to finalize
0026a57 spice-qemu-char: convert to finalize cbe8a1d MAINTAINERS: add myself to qemu-char.c
=== OUTPUT BEGIN ===
Checking PATCH 1/41: MAINTAINERS: add myself to qemu-char.c... Checking PATCH 2/41: spice-qemu-char: convert to finalize... Checking PATCH 3/41: baum: convert to finalize... Checking PATCH 4/41: msmouse: convert to finalize... Checking PATCH 5/41: mux: convert to finalize...
Checking PATCH 6/41: char-udp: convert to finalize... Checking PATCH 7/41: char-socket: convert to finalize... Checking PATCH 8/41: char-pty: convert to finalize... Checking PATCH 9/41: char-ringbuf: convert to finalize... Checking PATCH 10/41: char-parallel: convert parallel to finalize...
WARNING: architecture specific defines should be avoided #49: FILE: qemu-char.c:4699:
+#if defined(__linux__)
WARNING: line over 80 characters
#58: FILE: qemu-char.c:4708:
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
total: 0 errors, 2 warnings, 52 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 11/41: char-stdio: convert to finalize... Checking PATCH 12/41: char-win-stdio: convert to finalize... Checking PATCH 13/41: char-win: do not override chr_free... Checking PATCH 14/41: char-win: convert to finalize... Checking PATCH 15/41: char-fd: convert to finalize...
Checking PATCH 16/41: char: remove chr_free...
Checking PATCH 17/41: char: get rid of CharDriver...
Checking PATCH 18/41: char: rename remaining CharDriver to Chardev... Checking PATCH 19/41: char: remove class kind field... Checking PATCH 20/41: char: move to chardev/...
Checking PATCH 21/41: char: create chardev-obj-y...
Checking PATCH 22/41: char: make null_chr_write() the default method... Checking PATCH 23/41: char: move null chardev to its own file... Checking PATCH 24/41: char: move mux to its own file... Checking PATCH 25/41: char: move ringbuf/memory to its own file... Checking PATCH 26/41: char: rename and move to header CHR_READ_BUF_LEN... Checking PATCH 27/41: char: remove unused READ_RETRIES... Checking PATCH 28/41: char: move QIOChannel-related stuff to char-io.h... Checking PATCH 29/41: char: move fd chardev in its own file... Checking PATCH 30/41: char: move win chardev base class in its own file... Checking PATCH 31/41: char: move win-stdio into its own file... Checking PATCH 32/41: char: move socket chardev to its own file... Checking PATCH 33/41: char: move udp chardev in its own file... Checking PATCH 34/41: char: move file chardev in its own file... Checking PATCH 35/41: char: move stdio in its own file... Checking PATCH 36/41: char: move console in its own file... Checking PATCH 37/41: char: move pipe chardev in its own file... Checking PATCH 38/41: char: move pty chardev in its own file...
WARNING: architecture specific defines should be avoided
#64: FILE: chardev/char-pty.c:34:
+#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
total: 0 errors, 1 warnings, 577 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 39/41: char: move serial chardev to its own file...
ERROR: if this code is redundant consider removing it
#91: FILE: chardev/char-serial.c:61:
+#if 0
ERROR: braces {} are necessary for all arms of this statement #97: FILE: chardev/char-serial.c:67:
+#define check_speed(val) if (speed <= val) { spd = B##val; break; } [...]
total: 2 errors, 0 warnings, 692 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 40/41: char: move parallel chardev in its own file...
WARNING: architecture specific defines should be avoided #60: FILE: chardev/char-parallel.c:30:
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
WARNING: architecture specific defines should be avoided #68: FILE: chardev/char-parallel.c:38:
+#ifdef __linux__
WARNING: architecture specific defines should be avoided #77: FILE: chardev/char-parallel.c:47:
+#if defined(__linux__)
WARNING: line over 80 characters
#205: FILE: chardev/char-parallel.c:175:
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
WARNING: architecture specific defines should be avoided
#205: FILE: chardev/char-parallel.c:175:
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
WARNING: architecture specific defines should be avoided #306: FILE: chardev/char-parallel.c:276:
+#if defined(__linux__)
WARNING: architecture specific defines should be avoided #316: FILE: chardev/char-parallel.c:286:
+#if defined(__linux__)
WARNING: architecture specific defines should be avoided #379: FILE: chardev/char-parallel.h:27:
+#if defined(__linux__) || defined(__FreeBSD__) || \
total: 0 errors, 8 warnings, 687 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 41/41: char: headers clean-up...
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 6 lines · Marc-André Lureau
The following changes since commit
a0def594286d9110a6035e02eef558cf3cf5d847:Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-01-30 10:23:20 +0000)
are available in the git repository at:
Quoted 8 lines
https://github.com/elmarco/qemu.git tags/chr-split-pull-request
for you to fetch changes up to
3766519be2843e0947425cafd1e7e205dd63f0fd:char: headers clean-up (2017-01-31 13:03:48 +0400)
----------------------------------------------------------------
'make check' fails on a linux-user-targets-only build:
tests/test-char.o: In function `char_stdio_test_subprocess':/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:47: undefined reference to qemu_chr_new' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:50: undefined reference to qemu_chr_fe_init' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:51: undefined reference to qemu_chr_fe_set_open' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:52: undefined reference to qemu_chr_fe_write'
[etc etc etc]
thanks
-- PMM
Hi!
Quoted 21 lines · Peter Maydell
Quoted 1 line · Marc-André Lureau
The following changes since commit
a0def594286d9110a6035e02eef558cf3cf5d847:Quoted 2 lines
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into
staging (2017-01-30 10:23:20 +0000)
Quoted 11 lines
are available in the git repository at:
https://github.com/elmarco/qemu.git tags/chr-split-pull-request
for you to fetch changes up to
3766519be2843e0947425cafd1e7e205dd63f0fd:char: headers clean-up (2017-01-31 13:03:48 +0400)
----------------------------------------------------------------
'make check' fails on a linux-user-targets-only build:
Quoted 12 lines
tests/test-char.o: In function `char_stdio_test_subprocess':/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:47: undefined reference toqemu_chr_new' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:50: undefined reference toqemu_chr_fe_init'/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:51: undefined reference toqemu_chr_fe_set_open' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:52: undefined reference toqemu_chr_fe_write'
[etc etc etc]
Oh good catch. We want to have chardev-obj-y defined globally, but only linked with -softmmu target.
A possible fix to squash with chardev-obj-j patch is:
Eric, do you want me to resend the patch for review or is that enough for you to ack?
Makefile.objs +2 -2
@@ -4,6 +4,8 @@ stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +chardev-obj-y = chardev/ + ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
@@ -78,8 +80,6 @@ common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o common-obj-$(CONFIG_FDT) += device_tree.o -chardev-obj-y = chardev/ - ###################################################################### # qapi
Makefile.target +1 -2
@@ -188,10 +188,9 @@ 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) +all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
Signature · 1 line
Marc-André Lureau
Quoted 14 lines · Marc-André Lureau
Quoted 14 lines
'make check' fails on a linux-user-targets-only build:
tests/test-char.o: In function `char_stdio_test_subprocess':/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:47: undefined reference toqemu_chr_new' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:50: undefined reference toqemu_chr_fe_init'/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:51: undefined reference toqemu_chr_fe_set_open' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:52: undefined reference toqemu_chr_fe_write'
[etc etc etc]
Quoted 8 lines
Oh good catch. We want to have chardev-obj-y defined globally, but only linked with -softmmu target.
A possible fix to squash with chardev-obj-j patch is:
Eric, do you want me to resend the patch for review or is that enough for you to ack?
I'm okay ack'ing the interdiff (that is, squash this in, and you can keep the R-b you already have).
Quoted 39 lines
Makefile.objs +2
-2@@ -4,6 +4,8 @@ stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +chardev-obj-y = chardev/ + ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img@@ -78,8 +80,6 @@ common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o common-obj-$(CONFIG_FDT) += device_tree.o -chardev-obj-y = chardev/ - ###################################################################### # qapiMakefile.target +1
-2@@ -188,10 +188,9 @@ 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) +all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Hi
Quoted 19 lines · Eric Blake
Quoted 17 lines · Marc-André Lureau
Quoted 14 lines
'make check' fails on a linux-user-targets-only build:
tests/test-char.o: In function `char_stdio_test_subprocess':/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:47: undefined reference toqemu_chr_new' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:50: undefined reference toqemu_chr_fe_init'/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:51: undefined reference toqemu_chr_fe_set_open' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:52: undefined reference toqemu_chr_fe_write'
[etc etc etc]Oh good catch. We want to have chardev-obj-y defined globally, but only linked with -softmmu target.
Quoted 10 lines
Quoted 5 lines
A possible fix to squash with chardev-obj-j patch is:
Eric, do you want me to resend the patch for review or is that enough for you to ack?
I'm okay ack'ing the interdiff (that is, squash this in, and you can keep the R-b you already have).
Thanks, patch updated, tag updated.
Peter, let me know if you want me to resend the pull request.
Signature · 1 line
Marc-André Lureau
Quoted 3 lines · Marc-André Lureau
Thanks, patch updated, tag updated.
Peter, let me know if you want me to resend the pull request.
I'll put it back on my list. NB that the guaranteed reliable way for me to spot that you want me to reprocess a respin is to send a new cover letter email (you need not resend all the individual patch mails if they're basically the same). That will cause my filters to spot the cover letter email and put it back in the folder of things to process. Doing anything else is relying on my happening to read your email informally asking for a re-run, which in this case I did but if you're unlucky I might miss it.
TLDR: resending the cover letter entrusts your fate to the hands of an infallible unsleeping robot; informal requests leave you reliant on a careless human. The robot is your friend.
thanks
-- PMM
Quoted 30 lines · Marc-André Lureau
Hi
Quoted 27 lines · Eric Blake
Quoted 23 lines · Marc-André Lureau
Quoted 14 lines
'make check' fails on a linux-user-targets-only build:
tests/test-char.o: In function `char_stdio_test_subprocess':/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:47: undefined reference toqemu_chr_new' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:50: undefined reference toqemu_chr_fe_init'/home/petmay01/linaro/qemu-for-merges/tests/test-char.c:51: undefined reference toqemu_chr_fe_set_open' /home/petmay01/linaro/qemu-for-merges/tests/test-char.c:52: undefined reference toqemu_chr_fe_write'
[etc etc etc]Oh good catch. We want to have chardev-obj-y defined globally, but only linked with -softmmu target.
A possible fix to squash with chardev-obj-j patch is:
Eric, do you want me to resend the patch for review or is that enough for
you to ack?
Quoted 7 lines
Quoted 3 lines
I'm okay ack'ing the interdiff (that is, squash this in, and you can keep the R-b you already have).
Thanks, patch updated, tag updated.
Peter, let me know if you want me to resend the pull request.
Now applied, thanks.
-- PMM