From: Kevin Wolf <kwolf@suse.de>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/3] Always use nonblocking mode for qemu_chr_open_fd.
Date: Wed, 23 Jul 2008 11:34:15 +0200 [thread overview]
Message-ID: <4886FB17.5080202@suse.de> (raw)
In-Reply-To: <488688E3.105@codemonkey.ws>
[-- Attachment #1: Type: text/plain, Size: 633 bytes --]
Anthony Liguori schrieb:
> This changes semantics a bit. Previously, using a pty would guarantee
> that data is always written as qemu_chr_write does not perform any sort
> of buffering.
>
> Now, that data will be silently dropped instead of causing QEMU to
> block. I don't think it's perfectly clear that one behaviour is clearly
> better than the other.
Then we need both.
Add an option to specify non-blocking mode for stdio, pty and pipe in
qemu_chr_open. Blocking mode is used by default (maintaining current
semantics), non-blocking mode if the name is prefixed with nonblock:
Signed-off-by: Kevin Wolf <kwolf@suse.de>
[-- Attachment #2: nonblock.patch --]
[-- Type: text/x-patch, Size: 3980 bytes --]
Index: vl.c
===================================================================
--- vl.c.orig
+++ vl.c
@@ -2227,11 +2227,16 @@ static void fd_chr_close(struct CharDriv
}
/* open a character device to a unix fd */
-static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
+static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out, int block)
{
CharDriverState *chr;
FDCharDriver *s;
+ if (!block) {
+ socket_set_nonblock(fd_in);
+ socket_set_nonblock(fd_out);
+ }
+
chr = qemu_mallocz(sizeof(CharDriverState));
if (!chr)
return NULL;
@@ -2259,10 +2264,10 @@ static CharDriverState *qemu_chr_open_fi
TFR(fd_out = open(file_out, O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666));
if (fd_out < 0)
return NULL;
- return qemu_chr_open_fd(-1, fd_out);
+ return qemu_chr_open_fd(-1, fd_out, 0);
}
-static CharDriverState *qemu_chr_open_pipe(const char *filename)
+static CharDriverState *qemu_chr_open_pipe(const char *filename, int block)
{
int fd_in, fd_out;
char filename_in[256], filename_out[256];
@@ -2280,7 +2285,7 @@ static CharDriverState *qemu_chr_open_pi
if (fd_in < 0)
return NULL;
}
- return qemu_chr_open_fd(fd_in, fd_out);
+ return qemu_chr_open_fd(fd_in, fd_out, block);
}
@@ -2376,13 +2381,13 @@ static void qemu_chr_close_stdio(struct
fd_chr_close(chr);
}
-static CharDriverState *qemu_chr_open_stdio(void)
+static CharDriverState *qemu_chr_open_stdio(int block)
{
CharDriverState *chr;
if (stdio_nb_clients >= STDIO_MAX_CLIENTS)
return NULL;
- chr = qemu_chr_open_fd(0, 1);
+ chr = qemu_chr_open_fd(0, 1, block);
chr->chr_close = qemu_chr_close_stdio;
qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr);
stdio_nb_clients++;
@@ -2449,7 +2454,7 @@ void cfmakeraw (struct termios *termios_
#endif
#if defined(__linux__) || defined(__sun__)
-static CharDriverState *qemu_chr_open_pty(void)
+static CharDriverState *qemu_chr_open_pty(int block)
{
struct termios tty;
int master_fd, slave_fd;
@@ -2463,7 +2468,7 @@ static CharDriverState *qemu_chr_open_pt
tcsetattr(slave_fd, TCSAFLUSH, &tty);
fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
- return qemu_chr_open_fd(master_fd, master_fd);
+ return qemu_chr_open_fd(master_fd, master_fd, block);
}
static void tty_serial_init(int fd, int speed,
@@ -2578,7 +2583,7 @@ static CharDriverState *qemu_chr_open_tt
TFR(fd = open(filename, O_RDWR | O_NONBLOCK));
tty_serial_init(fd, 115200, 'N', 8, 1);
- chr = qemu_chr_open_fd(fd, fd);
+ chr = qemu_chr_open_fd(fd, fd, 0);
if (!chr) {
close(fd);
return NULL;
@@ -2588,7 +2593,7 @@ static CharDriverState *qemu_chr_open_tt
return chr;
}
#else /* ! __linux__ && ! __sun__ */
-static CharDriverState *qemu_chr_open_pty(void)
+static CharDriverState *qemu_chr_open_pty(int block)
{
return NULL;
}
@@ -3582,6 +3587,10 @@ static CharDriverState *qemu_chr_open_tc
CharDriverState *qemu_chr_open(const char *filename)
{
const char *p;
+ int block = 1;
+
+ if (strstart(filename, "nonblock:", &filename))
+ block = 0;
if (!strcmp(filename, "vc")) {
return text_console_init(&display_state, 0);
@@ -3615,11 +3624,11 @@ CharDriverState *qemu_chr_open(const cha
} else if (strstart(filename, "file:", &p)) {
return qemu_chr_open_file_out(p);
} else if (strstart(filename, "pipe:", &p)) {
- return qemu_chr_open_pipe(p);
+ return qemu_chr_open_pipe(p, block);
} else if (!strcmp(filename, "pty")) {
- return qemu_chr_open_pty();
+ return qemu_chr_open_pty(block);
} else if (!strcmp(filename, "stdio")) {
- return qemu_chr_open_stdio();
+ return qemu_chr_open_stdio(block);
} else
#if defined(__linux__)
if (strstart(filename, "/dev/parport", NULL)) {
next prev parent reply other threads:[~2008-07-23 9:36 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-18 13:24 [Qemu-devel] [PATCH 2/3] Always use nonblocking mode for qemu_chr_open_fd Ian Jackson
2008-07-23 1:26 ` Anthony Liguori
2008-07-23 8:24 ` Daniel P. Berrange
2008-07-23 11:48 ` Gerd Hoffmann
2008-07-23 12:15 ` Daniel P. Berrange
2008-07-23 12:52 ` Gerd Hoffmann
2008-07-23 12:59 ` Daniel P. Berrange
2008-07-23 14:24 ` Gerd Hoffmann
2008-07-23 15:24 ` Anthony Liguori
2008-07-23 15:31 ` Daniel P. Berrange
2008-07-23 15:32 ` Anthony Liguori
2008-07-23 16:17 ` Gerd Hoffmann
2008-07-23 16:33 ` Anthony Liguori
2008-07-23 19:08 ` Jamie Lokier
2008-07-24 7:24 ` Gerd Hoffmann
2008-07-24 7:54 ` Gerd Hoffmann
2008-07-24 8:31 ` Daniel P. Berrange
2008-07-24 9:24 ` Jamie Lokier
2008-07-24 9:33 ` Samuel Thibault
2008-07-24 11:18 ` Gerd Hoffmann
2008-07-23 16:11 ` Gerd Hoffmann
2008-07-23 16:31 ` Anthony Liguori
2008-07-24 8:35 ` Daniel P. Berrange
2008-07-24 14:23 ` Anthony Liguori
2008-07-24 15:07 ` Jamie Lokier
2008-07-24 14:53 ` Gerd Hoffmann
2008-07-23 16:44 ` Paul Brook
2008-07-24 17:37 ` Anthony Liguori
2008-07-25 7:15 ` Gerd Hoffmann
2008-07-25 16:17 ` Jamie Lokier
2008-07-28 8:49 ` Gerd Hoffmann
2008-07-28 11:59 ` Jamie Lokier
2008-07-28 12:20 ` Gerd Hoffmann
2017-02-01 12:33 ` David Woodhouse
2008-07-24 15:37 ` [Qemu-devel] " Anthony Liguori
2008-07-25 11:42 ` Gerd Hoffmann
2008-07-25 15:04 ` Anthony Liguori
2008-07-28 9:59 ` Gerd Hoffmann
2008-07-28 18:55 ` Anthony Liguori
2008-07-23 9:34 ` Kevin Wolf [this message]
2008-07-23 10:17 ` [Qemu-devel] " Ian Jackson
2008-07-23 11:43 ` Kevin Wolf
2008-07-23 12:04 ` Gerd Hoffmann
2008-07-23 12:18 ` Paul Brook
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=4886FB17.5080202@suse.de \
--to=kwolf@suse.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.