[Top] [All Lists]

Re: fsync, rename, O_ATOMIC/O_PONIES

To: Olaf van der Spek <olaf@xxxxxxxx>
Subject: Re: fsync, rename, O_ATOMIC/O_PONIES
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Mon, 5 Mar 2012 12:02:03 +1100
Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx>, xfs@xxxxxxxxxxx
In-reply-to: <4F53A2FF.3000305@xxxxxxxx>
References: <4F50BF89.7020909@xxxxxxxx> <20120302131240.GA14186@xxxxxxxxxxxxx> <4F53A2FF.3000305@xxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Sun, Mar 04, 2012 at 06:14:39PM +0100, Olaf van der Spek wrote:
> On 2-3-2012 14:12, Christoph Hellwig wrote:
> >>I'd like to ask:
> >>- Is there a tool to log all unsafe operations?
> >
> >What is an unsafe operation?  Anything that's dumb and might lose data?
> For example
> >The possibilities are sheer endless.
> And?
> >>- What is the *right* way to update a file?
> >
> >  fd = open(tmpfile, ...);
> >  write(fd, ...);  // or any other update
> >  fdatasync(fd);
> >  rename(tmpfile, realfile);
> Argh, come on.
> That's not real and it's not complete. tmpfile is undefined, errors
> aren't handled and you have lots of unlisted assumptions or
> regressions.

The above is perfectly reasonable psuedo code for quickly describing
how to safely overwriting a file. If you want to know about error
handling and assumptions, read the man pages for operation.

To make it easy for you, I'll just point out this has already been
dealt with early in in the LWN thread for that article, here's the
link to the comment and the relevant LWN article providing you with
all the information you want:


And that my stance on this atomic rename subject is simply this: If
we want to change reanme behaviour, then the filesystem is not the
right place to do it - atomic rename semantics need to be defined
and enforced at the VFS.  See here:


This has all been hashed out before - we don't need to revisit this
discussion here. If you want to solve the problem once and for all,
submit patches to LKML to implement the new rename semantics in a
new syscall....


Dave Chinner

<Prev in Thread] Current Thread [Next in Thread>