lkml.org 
[lkml]   [2008]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectwriting file to disk: not as easy as it looks
Actually, it looks like POSIX file interface is on the lowest step of
Rusty's scale: one that is impossible to use correctly. Yes, it seems
impossible to reliably&safely write file to disk under Linux. Double
plus uncool.

So... how to write file to disk and wait for it to reach the stable
storage, with proper error handling?

> file

...does not work, because it fails to check for errors.

touch file || error_handling.

Is not a lot better, unless you mount your filesystems "sync"
... and noone does that.

dd conv=fsync if=something of=file 2> /dev/zero || error_handling

Is a bit better; not much, unless you mount your filesystems
"dirsync", because you have file data on disk, but they do not have
directory entry pointing to them. Noone uses dirsync.

So you need something like

dd conv=fsync if=something of=file 2> /dev/zero || error_handling
fsync . || error_handling
fsync .. || error_handling
fsync ../.. || error_handling
fsync ../../.. || error_handling

... which mostly works...

If you are alone on the filesystem... fsync only returns
errors to the first process. So if you have other process that
does fsync ., maybe it gets "your" error and you do not learn
of the problem.

Question is... Is there way that I missed and that actually works?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


\
 
 \ /
  Last update: 2008-12-02 10:41    [W:0.095 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site