From patchwork Mon Jan 7 13:55:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 209943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E66C42C0084 for ; Tue, 8 Jan 2013 01:53:36 +1100 (EST) Received: from localhost ([::1]:59280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsDBk-00012p-HP for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 08:56:28 -0500 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 Received: from rincewind.home.kraxel.org (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r07DtUsH007163; Mon, 7 Jan 2013 08:55:31 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 6C96140DCA; Mon, 7 Jan 2013 14:55:28 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 07/11] chardev: add tty chardev support to chardev-add (qmp) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Paolo Bonzini --- 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;