> -----Original Message-----
> From: [email protected] [mailto:rsyslog-
> [email protected]] On Behalf Of [email protected]
> Sent: Monday, June 08, 2009 6:10 PM
> To: rsyslog-users
> Subject: Re: [rsyslog] ultra-reliable disk files fsync vs. fdatasync
> 
> On Mon, 8 Jun 2009, Rainer Gerhards wrote:
> 
> > Hi all,
> >
> > I am working on the ultra-reliable file writing capability. I have
revisited
> > the doc and am considering fsync() vs. fdatasync(). From the man pages,
it
> > looks like fdatasync() is sufficient if I just need to ensure that any
data
> > written can also be read. The advantage of fdatasync() is that it is
> somewhat
> > faster as not all meta data is necessarily written.
> >
> > I would appreciate if someone could comment on this issue.
> 
> my understanding is that if you are growing the file you need to do a
> fsync of the directory, but if you are re-writing part of an already
> allocated file fdatasync is the better thing to use.

The man page[1] is somewhat vague. It tells:

"Calling fsync() does not necessarily ensure that the entry in the directory
containing the file has also reached disk. For that an explicit fsync() on a
file descriptor for the directory is also needed."

But also

"fdatasync() is similar to fsync(), but does not flush modified metadata
unless that metadata is needed in order to allow a subsequent data retrieval
to be correctly handled. For example, changes to st_atime or st_mtime
(respectively, time of last access and time of last modification; see
stat(2)) do not not require flushing because they are not necessary for a
subsequent data read to be handled correctly. On the other hand, a change to
the file size (st_size, as made by say ftruncate(2)), would require a
metadata flush.
"

So my current understanding is that fdatasync() is always safe, but there
still exist situations where a sync on the directory is needed. What I can
think of is a newly created file.

I have to admit that I am a bit puzzled of what it takes to do the "explicit
fsync on the directory". Most importantly, I need to have the file handle
open for writing, else the fsync will potentially fail. I don't think this is
such an excellent idea on directories.. I am right now working on this, and
my search has not brought up many good hints. So what I currently plan to do
is an open(dirname, O_RDWR) on the directory and then do an fsync on it
later. 

And I guess even after the fsync() on the directeroy, there potentially is an
issue with newly created files inside newly create directories, but I don't
think I will address this immediately. But I may be useful/necessary to add a
tree walker who actually walks the full path name and calls the fsyncs on all
of them...

Comments are highly appreciated.

Rainer

[1] http://linux.die.net/man/2/fsync
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com

Reply via email to