From: "Darrick J. Wong" <djwong@kernel.org>
To: Avinesh Kumar <avinesh.kumar@suse.com>
Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, cem@kernel.org
Subject: Re: [RFC PATCH] libfrog: make cmn_err() emit each message atomically to avoid torn output
Date: Wed, 15 Jul 2026 12:09:49 -0700 [thread overview]
Message-ID: <20260715190949.GP7380@frogsfrogsfrogs> (raw)
In-Reply-To: <20260715173114.359368-1-avinesh.kumar@suse.com>
On Wed, Jul 15, 2026 at 07:28:21PM +0200, Avinesh Kumar wrote:
> From: Avinesh Kumar <avinesh.kumar@suse.com>
>
> fstests xfs/033 fails sporadically with a spurious blank line in the
> xfs_repair output:
>
> - output mismatch (see /opt/xfstests/results//xfs/033.out.bad)
> --- tests/xfs/033.out 2026-06-24 15:52:51.000000000 -0400
> +++ /opt/xfstests/results//xfs/033.out.bad 2026-07-14 18:54:46.582495041 -0400
> @@ -103,6 +103,7 @@
> Phase 3 - for each AG...
> - scan and clear agi unlinked lists...
> - process known inodes and perform inode discovery...
> +
> bad magic number 0xffff on inode INO
> bad version number 0xffffffff on inode INO
> inode identifier 18446744073709551615 mismatch on inode INO
>
> Root cause is in cmn_err() (libfrog/util.c), which emits a message
> and its newline as two separate writes to unbuffered stderr.
> xfs_repair's threads all share stderr. If one is preempted between the
> two writes, another thread's line lands in between:
>
> (snips from `cat -A 033.raw`) -
> Phase 3 - for each AG...$
> - scan and clear agi unlinked lists...$
> - process known inodes and perform inode discovery...$
> Metadata corruption detected at 0x445dd3, xfs_inode block 0x80/0x4000 - agno = 0$
> $
> bad CRC for inode 128$
> bad magic number 0x0 on inode 128$
>
> which should be like -
>
> Phase 3 - for each AG...$
> - scan and clear agi unlinked lists...$
> - process known inodes and perform inode discovery...$
> Metadata corruption detected at 0x445dd3, xfs_inode block 0x80/0x4000$
> - agno = 0$
> bad CRC for inode 130$
> bad magic number 0x0 on inode 130$
>
> _filter_repair() strips the noise line it glued onto but not the lone
> newline, which then fails the golden diff.
>
> Make the two writes atomic.
>
> Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com>
> ---
>
> Hi, please give feedback if this should be fixed in a different way.
> Thanks!
>
> libfrog/util.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/libfrog/util.c b/libfrog/util.c
> index 5bae5bab..3b6df917 100644
> --- a/libfrog/util.c
> +++ b/libfrog/util.c
> @@ -116,8 +116,10 @@ cmn_err(int level, char *fmt, ...)
> va_list ap;
>
> va_start(ap, fmt);
> + flockfile(stderr);
> vfprintf(stderr, fmt, ap);
> fputs("\n", stderr);
> + funlockfile(stderr);
I think do_error() in xfs_repair.c is going to need the same treatment
but otherwise this chunk looks ok to me.
--D
> va_end(ap);
> }
>
> --
> 2.55.0
>
>
prev parent reply other threads:[~2026-07-15 19:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 17:28 [RFC PATCH] libfrog: make cmn_err() emit each message atomically to avoid torn output Avinesh Kumar
2026-07-15 19:09 ` Darrick J. Wong [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=20260715190949.GP7380@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=avinesh.kumar@suse.com \
--cc=cem@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=linux-xfs@vger.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