From: Dave Chinner <david@fromorbit.com>
To: Zorro Lang <zlang@kernel.org>
Cc: fstests@vger.kernel.org
Subject: Re: [PATCH 3/5] generic/591: remove redundant output from golden image
Date: Mon, 30 May 2022 10:44:52 +1000 [thread overview]
Message-ID: <20220530004452.GN3923443@dread.disaster.area> (raw)
In-Reply-To: <20220529105505.667891-4-zlang@kernel.org>
On Sun, May 29, 2022 at 06:55:03PM +0800, Zorro Lang wrote:
> In generic/591.out expects below output:
> concurrent reader with O_DIRECT
> concurrent reader with O_DIRECT <=== ???
> concurrent reader without O_DIRECT
> concurrent reader without O_DIRECT <=== ???
> sequential reader with O_DIRECT
> sequential reader without O_DIRECT
>
> The lines marked "???" are unbelievable, due to the src/splice-test.c
> only calls printf to output that message once in main function. So
> Why splice-test prints that message twice sometimes? It seems related
> with the "-r" option, due to the test lines without "-r" option only
> print one line each time running.
>
> A stanger thing is this "double output" issue only can be triggered by
> running g/591, can't reproduce it by running splice-test manually.
Huh. I wonder....
> diff --git a/src/splice-test.c b/src/splice-test.c
> index 2f1ba2ba..e6ae6fca 100644
> --- a/src/splice-test.c
> +++ b/src/splice-test.c
> @@ -143,6 +143,7 @@ int main(int argc, char *argv[])
> printf("%s reader %s O_DIRECT\n",
> do_splice == do_splice1 ? "sequential" : "concurrent",
> (open_flags & O_DIRECT) ? "with" : "without");
> + fflush(stdout);
Yeah, ok, stdout output is usually line buffered. That printf()
statement has a "\n" on the end of it, so it should be flushing
immediately, and that's what you are seeing when it is run from the
command line.
Hmmmm. I wonder if the redirect to an output file (or pipe) is
changing the buffering mode because stdout no longer points to a
tty?
# src/xfstests-dev/src/splice-test -r /mnt/test/a
concurrent reader with O_DIRECT
# src/xfstests-dev/src/splice-test -r /mnt/test/a | less
concurrent reader with O_DIRECT
concurrent reader with O_DIRECT
#
Yup.
# man setbuf
....
Normally all files are block buffered. If a stream refers
to a terminal (as stdout normally does), it is line
buffered. The standard error stream stderr is always
unbuffered by default.
Yeah, so the stdout redirection that fstests does is exactly what is
changing the behaviour.
Ok, so the correct way to fix this is to add:
setlinebuf(stdout);
before any printf() output to ensure that it is correctly line
buffered no matter what the output redirection does with stdout.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2022-05-30 0:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-29 10:55 [PATCH 0/5] random fixes for fstests Zorro Lang
2022-05-29 10:55 ` [PATCH 1/5] generic/139: require 512 bytes to be the minimum dio size Zorro Lang
2022-05-30 0:11 ` Dave Chinner
2022-05-29 10:55 ` [PATCH 2/5] generic/506: call _require_quota before _qmount Zorro Lang
2022-05-30 0:12 ` Dave Chinner
2022-05-29 10:55 ` [PATCH 3/5] generic/591: remove redundant output from golden image Zorro Lang
2022-05-30 0:44 ` Dave Chinner [this message]
2022-05-30 5:43 ` Zorro Lang
2022-05-29 10:55 ` [PATCH 4/5] generic/591: use proper sector size Zorro Lang
2022-05-29 23:57 ` Dave Chinner
2022-05-30 6:02 ` Zorro Lang
2022-05-29 10:55 ` [PATCH 5/5] generic/623: add overlay into the blacklist Zorro Lang
2022-05-30 5:54 ` Amir Goldstein
2022-05-30 6:22 ` Zorro Lang
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=20220530004452.GN3923443@dread.disaster.area \
--to=david@fromorbit.com \
--cc=fstests@vger.kernel.org \
--cc=zlang@kernel.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