From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v2 07/10] chardev: add serial chardev support to chardev-add (qmp)
Date: Thu, 10 Jan 2013 15:23:03 +0100 [thread overview]
Message-ID: <1357827786-14624-8-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1357827786-14624-1-git-send-email-kraxel@redhat.com>
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
on Unix.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
qapi-schema.json | 13 +++++++++++
qemu-char.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------
qemu-options.hx | 9 +++----
3 files changed, 71 insertions(+), 13 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index 7930139..c328a0f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3029,6 +3029,18 @@
'out' : 'str' } }
##
+# @ChardevPort:
+#
+# Configuration info for device chardevs.
+#
+# Since: 1.4
+##
+{ 'enum': 'ChardevPortKind', 'data': [ 'serial' ] }
+
+{ 'type': 'ChardevPort', 'data': { 'device' : 'str',
+ 'type' : 'ChardevPortKind'} }
+
+##
# @ChardevBackend:
#
# Configuration info for the new chardev backend.
@@ -3038,6 +3050,7 @@
{ 'type': 'ChardevDummy', 'data': { } }
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
+ 'port' : 'ChardevPort',
'null' : 'ChardevDummy' } }
##
diff --git a/qemu-char.c b/qemu-char.c
index fa0a884..1b9ae2d 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__ */
@@ -1666,9 +1672,8 @@ static int win_chr_poll(void *opaque)
return 0;
}
-static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
+static CharDriverState *qemu_chr_open_win_path(const char *filename)
{
- const char *filename = qemu_opt_get(opts, "path");
CharDriverState *chr;
WinCharState *s;
@@ -1687,6 +1692,11 @@ static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
return chr;
}
+static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
+{
+ return qemu_chr_open_win_path(qemu_opt_get(opts, "path"));
+}
+
static int win_chr_pipe_poll(void *opaque)
{
CharDriverState *chr = opaque;
@@ -2765,6 +2775,7 @@ static const struct {
#endif
#ifdef HAVE_CHARDEV_TTY
{ .name = "tty", .open = qemu_chr_open_tty },
+ { .name = "serial", .open = qemu_chr_open_tty },
{ .name = "pty", .open = qemu_chr_open_pty },
#endif
#ifdef HAVE_CHARDEV_PARPORT
@@ -2958,6 +2969,17 @@ 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) {
+ case CHARDEV_PORT_KIND_SERIAL:
+ return qemu_chr_open_win_path(port->device);
+ default:
+ error_setg(errp, "unknown chardev port (%d)", port->type);
+ return NULL;
+ }
+}
+
#else /* WIN32 */
static int qmp_chardev_open_file_source(char *src, int flags,
@@ -2994,6 +3016,27 @@ 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_SERIAL:
+ flags = O_RDWR;
+ fd = qmp_chardev_open_file_source(port->device, flags, errp);
+ if (error_is_set(errp)) {
+ return NULL;
+ }
+ socket_set_nonblock(fd);
+ return qemu_chr_open_tty_fd(fd);
+#endif
+ default:
+ error_setg(errp, "unknown chardev port (%d)", port->type);
+ return NULL;
+ }
+}
+
#endif /* WIN32 */
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
@@ -3006,6 +3049,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
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;
diff --git a/qemu-options.hx b/qemu-options.hx
index 9df0cde..17cc1ad 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1742,6 +1742,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
#endif
#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+ "-chardev serial,id=id,path=path[,mux=on|off]\n"
"-chardev tty,id=id,path=path[,mux=on|off]\n"
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
@@ -1910,8 +1911,8 @@ take any options.
Send traffic from the guest to a serial device on the host.
-@option{serial} is
-only available on Windows hosts.
+On Unix hosts serial will actually accept any tty device,
+not only serial lines.
@option{path} specifies the name of the serial device to open.
@@ -1937,10 +1938,8 @@ Connect to a local BrlAPI server. @option{braille} does not take any options.
@item -chardev tty ,id=@var{id} ,path=@var{path}
-Connect to a local tty device.
-
@option{tty} is only available on Linux, Sun, FreeBSD, NetBSD, OpenBSD and
-DragonFlyBSD hosts.
+DragonFlyBSD hosts. It is an alias for -serial.
@option{path} specifies the path to the tty. @option{path} is required.
--
1.7.1
next prev parent reply other threads:[~2013-01-10 15:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-10 14:22 [Qemu-devel] [PATCH v2 00/10] chardev hotplug patch series Gerd Hoffmann
2013-01-10 14:22 ` [Qemu-devel] [PATCH v2 01/10] chardev: add error reporting for qemu_chr_new_from_opts Gerd Hoffmann
2013-01-10 18:34 ` Eric Blake
2013-01-10 14:22 ` [Qemu-devel] [PATCH v2 02/10] chardev: fix QemuOpts lifecycle Gerd Hoffmann
2013-01-10 18:35 ` Eric Blake
2013-01-10 14:22 ` [Qemu-devel] [PATCH v2 03/10] chardev: reduce chardev ifdef mess a bit Gerd Hoffmann
2013-01-10 18:35 ` Eric Blake
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 04/10] chardev: add qmp hotplug commands, with null chardev support Gerd Hoffmann
2013-01-10 18:40 ` Eric Blake
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 05/10] chardev: add hmp hotplug commands Gerd Hoffmann
2013-01-10 18:42 ` Eric Blake
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 06/10] chardev: add file chardev support to chardev-add (qmp) Gerd Hoffmann
2013-01-10 19:33 ` Eric Blake
2013-01-11 10:37 ` Gerd Hoffmann
2013-01-10 14:23 ` Gerd Hoffmann [this message]
2013-01-10 19:39 ` [Qemu-devel] [PATCH v2 07/10] chardev: add serial " Eric Blake
2013-01-11 10:46 ` Gerd Hoffmann
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 08/10] chardev: add parallel " Gerd Hoffmann
2013-01-10 19:41 ` Eric Blake
2013-01-11 10:53 ` Gerd Hoffmann
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 09/10] chardev: add socket " Gerd Hoffmann
2013-01-10 19:43 ` Eric Blake
2013-01-10 14:23 ` [Qemu-devel] [PATCH v2 10/10] chardev: add pty " Gerd Hoffmann
2013-01-10 19:45 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357827786-14624-8-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).