From: "Theodore Ts'o" <tytso@mit.edu>
To: Jamie Lokier <jamie@shareable.org>
Cc: "Stephen C. Tweedie" <sct@redhat.com>,
Badari Pulavarty <pbadari@us.ibm.com>,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
jack@suse.cz
Subject: Re: ext3_ordered_writepage() questions
Date: Sun, 19 Mar 2006 21:18:03 -0500 [thread overview]
Message-ID: <20060320021803.GB17337@thunk.org> (raw)
In-Reply-To: <20060319023610.GA4824@mail.shareable.org>
On Sun, Mar 19, 2006 at 02:36:10AM +0000, Jamie Lokier wrote:
> It's other programs (OpenOffice, etc.) which are being used just
> before the power cut. If the programs which run just before the power
> cut do the above (writing then renaming), then they're fine, but many
> programs don't do that.
>
> Now, to be fair, most programs don't overwrite data blocks in place either.
>
> They usually open files with O_TRUNC to write with new contents. How
> does that work out with/without Badari's patch? Is that safe in the
> same way as creating new files and appending to them is?
The competently written ones don't open files with O_TRUNC; they will
create a temp. file, write to the temp. file, and then rename file
once it is fully written to the original file, just like rsync does.
This is important, given that many developers (especially kernel
developers) like to use hard link farms to minimize space, and if you
just O_TRUNC the existing file, then the change will be visible in all
of the directories. If instead the editor (or openoffice, etc.)
writes to a temp file and then renames, then it breaks the hard link
with COW semantics, which is what you want --- and in practice,
everyone using (or was using) bk, git, and mercurial use hard-linked
directories and it works just fine.
But yes, using O_TRUNC works just fine with and without Badari's
patch, because allocating new data blocks to a old file that is
truncated is exactly the same as appending new data blocks to a new
file.
> Or does O_TRUNC mean that the old data blocks might be released and
> assigned to other files, before this file's metadata is committed,
> opening a security hole where reading this file after a restart might
> read blocks belonging to another, unrelated file?
No, not in journal=ordered mode, since the data blocks are forced to
disk before the metadata is committed. Opening with O_TRUNC is
metadata operation, and allocating new blocks after O_TRUNC is also a
metadata operation, and in data=journaled mode, blocks are written out
before the metadata is forced out.
> It's this: you edit a source file with your favourite editor, and save
> it. 3 seconds later, there's a power cut. The next day, power comes
> back and you've forgotten that you edited this file.
Again, *my* favorite editor saves the file to a newly created file,
#filename, and once it is done writing the new file, renames filename
to filename~, and finally renames #filename to filename. This means
that we don't have to worry about your power cut scenario, and it also
means that hard-link farms have the proper COW semantics.
> However, all of the above examples really depend on what happens with
> O_TRUNC, because in practice all editors etc. that are likely to be
> used, use that if they don't do write-then-rename.
O_TRUNC is a bad idea, because it means if the editor crashes, or
computer crashes, or the fileserver crashes, the original file is
*G*O*N*E*. So only silly/stupidly written editors use O_TRUNC; if
yours does, abandon it in favor of another editor, or one day you'll
be really sorry. It's much, much, safer to do write-then-rename
- Ted
next prev parent reply other threads:[~2006-03-20 2:18 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-08 0:19 [RFC PATCH 0/3] VFS changes to collapse all the vectored and AIO support Badari Pulavarty
2006-03-08 0:22 ` [PATCH 1/3] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-03-08 12:44 ` christoph
2006-03-08 0:23 ` [PATCH 2/3] Remove readv/writev methods and use aio_read/aio_write instead Badari Pulavarty
2006-03-08 12:45 ` christoph
2006-03-08 16:26 ` Badari Pulavarty
2006-03-08 0:24 ` [PATCH 3/3] Zach's core aio changes to support vectored AIO Badari Pulavarty
2006-03-08 3:37 ` Benjamin LaHaise
2006-03-08 16:34 ` Badari Pulavarty
2006-03-08 12:47 ` [RFC PATCH 0/3] VFS changes to collapse all the vectored and AIO support christoph
2006-03-08 16:24 ` Badari Pulavarty
2006-03-09 16:17 ` ext3_ordered_writepage() questions Badari Pulavarty
2006-03-09 23:35 ` Andrew Morton
2006-03-10 0:36 ` Badari Pulavarty
2006-03-16 18:09 ` Theodore Ts'o
2006-03-16 18:22 ` Badari Pulavarty
2006-03-16 21:04 ` Theodore Ts'o
2006-03-16 21:57 ` Badari Pulavarty
2006-03-16 22:05 ` Jan Kara
2006-03-16 23:45 ` Badari Pulavarty
2006-03-17 0:44 ` Theodore Ts'o
2006-03-17 0:54 ` Andreas Dilger
2006-03-17 17:05 ` Stephen C. Tweedie
2006-03-17 21:32 ` Badari Pulavarty
2006-03-17 22:22 ` Stephen C. Tweedie
2006-03-17 22:38 ` Badari Pulavarty
2006-03-17 23:23 ` Mingming Cao
2006-03-20 17:05 ` Stephen C. Tweedie
2006-03-18 2:57 ` Suparna Bhattacharya
2006-03-18 3:02 ` Suparna Bhattacharya
2006-03-17 15:32 ` Jamie Lokier
2006-03-17 21:50 ` Stephen C. Tweedie
2006-03-17 22:11 ` Theodore Ts'o
2006-03-17 22:44 ` Jamie Lokier
2006-03-18 23:40 ` Theodore Ts'o
2006-03-19 2:36 ` Jamie Lokier
2006-03-19 5:28 ` Chris Adams
2006-03-20 2:18 ` Theodore Ts'o [this message]
2006-03-20 16:26 ` Stephen C. Tweedie
2006-03-17 22:23 ` Jamie Lokier
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=20060320021803.GB17337@thunk.org \
--to=tytso@mit.edu \
--cc=akpm@osdl.org \
--cc=jack@suse.cz \
--cc=jamie@shareable.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbadari@us.ibm.com \
--cc=sct@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