From: "Theodore Ts'o" <tytso@mit.edu>
To: Zorro Lang <zlang@redhat.com>
Cc: "Darrick J. Wong" <djwong@kernel.org>, fstests@vger.kernel.org
Subject: Re: [PATCH 1/2] report: safely update the result.xml file
Date: Fri, 7 Jul 2023 15:13:31 -0400 [thread overview]
Message-ID: <20230707191331.GA2653610@mit.edu> (raw)
In-Reply-To: <20230707161747.efz7azf6jta4e27w@zlang-mailbox>
On Sat, Jul 08, 2023 at 12:17:47AM +0800, Zorro Lang wrote:
> > sync "$tmp_fn" && mv "$tmp_fn" "$out_fn"
>
> I can help to add this when I merge it, if Ted doesn't want to change
> more than that.
I'll be sending out v2 shortly.
> Just curious, will renameat2 ignore data still in cached? I never did things
> likes "sync && mv" before, is there any known issue or it's as expected?
POSIX does not require rename() or renameat2() to do anything with any
cached data. All it does is make changes to the directory entries
involved. And that's what the VFS Layer does.
Some file systems implementation *may* do something special on a
rename(2), but it's not required by any specification. For example,
in the wake of the O_PONIES controversy, ext4 will initiate (but not
wait for) the file writeback of file being renamed *if* it is being
renamed on top of another file, causing the destination inode to be
unlinked and deleted if it doesn't have any other hard links to keep
its reflink about 0.
This means that in the case of renaming result.xml.new on top of
result.xml, if result.xml exists, this will trigger an immediate
writeback of result.xml.new, instead of waiting for the 30 second
writeback timer --- if this is happening on ext4. We added this to
ext4 because when people would exit the old Tuxracer game, this would
rewrite the top ten file in an unsafe manner, and then close the
OpenGL handle --- and on kernels with buggy proprietary graphics
drivers, it would cause a kernel crash, causing the top-ten score file
to be lost, and causing many users to complain to the file system
developers (but curiously enough, not to the application/game
developers). So we added something which reduces the chances of this
being an issue, but it's not something anyone should count upon.
As far as sync && mv, that's the shell script equivalent of what
careful userspace programs should always do, which is to write the
file to foo.new, then fsync it, and then rename foo.new to foo,
optionally renaming foo to foo.old or foo~ beforehand. Text editors
have always gotten this right, because programmers get salty when
their source files get trashed. For whatever reason, desktop
application and games tend not be as careful....
Cheers,
- Ted
next prev parent reply other threads:[~2023-07-07 19:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-06 20:42 [PATCH 1/2] report: safely update the result.xml file Theodore Ts'o
2023-07-06 20:42 ` [PATCH 2/2] report: remove xmlns specifier Theodore Ts'o
2023-07-07 14:55 ` Darrick J. Wong
2023-07-07 15:01 ` [PATCH 1/2] report: safely update the result.xml file Darrick J. Wong
2023-07-07 16:17 ` Zorro Lang
2023-07-07 19:13 ` Theodore Ts'o [this message]
2023-07-08 3:02 ` Zorro Lang
2023-07-08 4:31 ` Theodore Ts'o
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=20230707191331.GA2653610@mit.edu \
--to=tytso@mit.edu \
--cc=djwong@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=zlang@redhat.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