From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsDAw-0008BT-29 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 08:55:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsDAs-0003RK-6Q for qemu-devel@nongnu.org; Mon, 07 Jan 2013 08:55:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24795) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsDAr-0003R5-V5 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 08:55:34 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r07DtXxC011837 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jan 2013 08:55:33 -0500 From: Gerd Hoffmann Date: Mon, 7 Jan 2013 14:55:24 +0100 Message-Id: <1357566928-25361-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1357566928-25361-1-git-send-email-kraxel@redhat.com> References: <1357566928-25361-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 07/11] chardev: add tty chardev support to chardev-add (qmp) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Simliar to file, except that no separate in/out files are supported because it's pointless for direct device access. Also the special tty ioctl hooks (pass through linespeed settings etc) are activated. Both file names and file descriptor passing is supported. Signed-off-by: Gerd Hoffmann --- qapi-schema.json | 6 ++++++ qemu-char.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 8904d36..7e5c8c2 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3036,9 +3036,15 @@ { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', 'out' : 'ChardevFileSource' } } +{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] } + +{ 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource', + 'type' : 'ChardevPortKind'} } + { 'type': 'ChardevDummy', 'data': { } } { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'port' : 'ChardevPort', 'null' : 'ChardevDummy' } } { 'command': 'chardev-add', 'data': {'id' : 'str', diff --git a/qemu-char.c b/qemu-char.c index 91b0a57..764321b 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1230,21 +1230,27 @@ static void qemu_chr_close_tty(CharDriverState *chr) } } +static CharDriverState *qemu_chr_open_tty_fd(int fd) +{ + CharDriverState *chr; + + tty_serial_init(fd, 115200, 'N', 8, 1); + chr = qemu_chr_open_fd(fd, fd); + chr->chr_ioctl = tty_serial_ioctl; + chr->chr_close = qemu_chr_close_tty; + return chr; +} + static CharDriverState *qemu_chr_open_tty(QemuOpts *opts) { const char *filename = qemu_opt_get(opts, "path"); - CharDriverState *chr; int fd; TFR(fd = qemu_open(filename, O_RDWR | O_NONBLOCK)); if (fd < 0) { return NULL; } - tty_serial_init(fd, 115200, 'N', 8, 1); - chr = qemu_chr_open_fd(fd, fd); - chr->chr_ioctl = tty_serial_ioctl; - chr->chr_close = qemu_chr_close_tty; - return chr; + return qemu_chr_open_tty_fd(fd); } #endif /* __linux__ || __sun__ */ @@ -2962,6 +2968,15 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) return qemu_chr_open_win_file(out); } +static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp) +{ + switch (port->type) { + default: + error_setg(errp, "unknown chardev port (%d)", port->type); + return NULL; + } +} + #else /* WIN32 */ static int qmp_chardev_open_file_source(ChardevFileSource *src, int flags, @@ -2978,6 +2993,9 @@ static int qmp_chardev_open_file_source(ChardevFileSource *src, int flags, break; case CHARDEV_FILE_SOURCE_KIND_FD: fd = monitor_get_fd(cur_mon, src->fd, errp); + if (flags & O_NONBLOCK) { + socket_set_nonblock(fd); + } break; default: error_setg(errp, "unknown chardev file source (%d)", src->kind); @@ -3008,6 +3026,26 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) return qemu_chr_open_fd(in, out); } +static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp) +{ + int flags, fd; + + switch (port->type) { +#ifdef HAVE_CHARDEV_TTY + case CHARDEV_PORT_KIND_TTY: + flags = O_RDWR | O_NONBLOCK; + fd = qmp_chardev_open_file_source(port->device, flags, errp); + if (error_is_set(errp)) { + return NULL; + } + return qemu_chr_open_tty_fd(fd); +#endif + default: + error_setg(errp, "unknown chardev port (%d)", port->type); + return NULL; + } +} + #endif /* WIN32 */ void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) @@ -3018,6 +3056,9 @@ void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) case CHARDEV_BACKEND_KIND_FILE: chr = qmp_chardev_open_file(backend->file, errp); break; + case CHARDEV_BACKEND_KIND_PORT: + chr = qmp_chardev_open_port(backend->port, errp); + break; case CHARDEV_BACKEND_KIND_NULL: chr = qemu_chr_open_null(NULL); break; -- 1.7.1