From: Stefan Hajnoczi <stefanha@gmail.com>
To: Sam Bobroff <sam.bobroff@au1.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/1] Protect stderr from non-blocking mode
Date: Thu, 28 Jan 2016 12:11:18 +0000 [thread overview]
Message-ID: <20160128121118.GI7206@stefanha-x1.localdomain> (raw)
In-Reply-To: <0b88a3432f2fcfee1e57abfa9420ca6c5c386b49.1453954698.git.sam.bobroff@au1.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 2324 bytes --]
On Thu, Jan 28, 2016 at 03:18:23PM +1100, Sam Bobroff wrote:
> On Linux, if QEMU is run from a shell with -d to enable debug logging
> but without directing it to a file (e.g. -D is not used, and
> qemu_logfile is set to stderr), and no shell redirection is used, it
> is possible for log messages to be lost under load.
>
> This is caused by a combination of several factors:
>
> * The shell (e.g. bash) may provide stdin, stdout and stderr as
> duplicates of a single open file, so they share file status flags
> including O_NONBLOCK.
>
> * As character devices are registered (see qemu_chr_open_stdio()),
> stdin and stdout are set non-blocking.
>
> * The printf() family of functions, including fprintf(), are not
> "non-blocking" aware: if they receive EAGAIN after partially
> writing their output, they immediately return EAGAIN with no way to
> discover how much output was written, if any.
>
> So O_NONBLOCK is set on stdin/stdout, which causes O_NONBLOCK to be
> set on stderr, and qemu_logfile is set to stderr. Then, under load,
> fprintf()s to qemu_logfile return EAGAIN, which is ignored and data is
> lost. This can't be fixed by handling EAGAIN because an unknown amount
> of data has been written.
>
> This patch works around the issue by re-opening the underlying tty
> file, which is available in Linux as /proc/self/fd/2, and duplicating
> it into fd 2 which causes stderr to refer to a new, unshared, "file
> description". Additionally, if we end up logging to a non-blocking
> file descriptor on a non-Linux platform, where no workaround has been
> implemented, we display a warning message.
>
> Signed-off-by: Sam Bobroff <sam.bobroff@au1.ibm.com>
> ---
> This is somewhat of an RFC as the issue probably hasn't been noticed
> very often (ever?) and there are several approaches to addressing it.
> The discussion was a while ago, here:
>
> http://lists.nongnu.org/archive/html/qemu-devel/2015-12/msg00761.html
>
> include/sysemu/os-posix.h | 2 +-
> include/sysemu/os-win32.h | 2 +-
> os-posix.c | 30 +++++++++++++++++++++++++++++-
> os-win32.c | 2 +-
> vl.c | 2 +-
> 5 files changed, 33 insertions(+), 5 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
prev parent reply other threads:[~2016-01-28 12:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-28 4:18 [Qemu-devel] [PATCH 1/1] Protect stderr from non-blocking mode Sam Bobroff
2016-01-28 12:11 ` Stefan Hajnoczi [this message]
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=20160128121118.GI7206@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=sam.bobroff@au1.ibm.com \
/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).