[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: reading an empty directory after reboot is very slow



On 2015-04-23 09:13:02 +0200, Nicolas George wrote:
> Le tridi 3 floréal, an CCXXIII, David Wright a écrit :
> > OK. Here's a demonstration of a file going AWOL by moving *up* the
> > directory listing. Because of read-ahead, readdir still sees the old
> > name and the stat() fails.
> 
> What are you trying to prove with that test?
> 
> You would get the same failure if you put your delay between readdir() and
> stat(). And on a preemptive multitasking OS (or even worse: with
> multiprocessing), that "delay" could be just the normal run time of the
> program. That is called a race condition, I am sure you know it.

David's test was to show what could happen in practice after some
simple change, such as removing objects from the directory, not to
take care of all possible race conditions (which is not possible,
except by checking them afterwards, e.g. by looking at the mtime of
the directory, though I'm not even sure that this is reliable).

[...]
> I believe that the readdir() should offer the following guarantee over the
> course of a single "opendir + full readdir loop":
> 
>   All entries that were present in the directory during the whole run are
>   returned exactly once, under any of the names they had during the run.
> 
> And for now, I have not seen any indication that this property were
> violated, i.e. the same entry shown twice or none at all.

David's test shows that the renamed file is missed.

[...]
> To make reliable backups, you need a way of getting the state of the full
> tree atomically. Nowadays, that is done with filesystem snapshots. Unless
> you use that, you have to assume that any file that was moved in any way
> during the backup was moved the stupid way, i.e. first delete the source
> then re-create the target.

I agree, but this needs support from the filesystem itself.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Reply to: