[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 11:31:27 +0200, Nicolas George wrote:
> Le quartidi 4 floréal, an CCXXIII, Vincent Lefevre a écrit :
> > David's test shows that the renamed file is missed.
> 
> No, it shows that the renamed file is NOT missed: he renamed the entry for
> inode 497003 from file2 into a long name, and that entry is returned,
> exactly once, under its old name. The "oops, file2 stat() fails" only shows
> the race condition between readdir() return and stat(); I am sure that if he
> printed dirent.d_ino instead of stat.st_ino, it would have printed 497003.

I only focused on the inode number and I thought that David's test was
printing dirent.d_ino (which was the obvious thing to do). Now, after
re-reading carefully what he said:

  "I scan the directory with readdir, then stat the file to obtain its
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   inode number."
   ^^^^^^^^^^^^

Indeed, this is the wrong way to do!

So, there's a need for a new test.

BTW, in Perl, readdir only returns the filename, but I suppose that
this isn't a problem and that one still gets all the directory entries:
in case of rename, one should be aware that the filename corresponds
either to the old name or to the new name, and it's up to the script
to handle race conditions if need be, depending on the context.

> > I agree, but this needs support from the filesystem itself.
> 
> That would not be enough. Reliable backups require application support. Just
> think of all the Vim swap files or the temp file just before an atomic
> update. But that is another discussion.

Yes, one may see a temp file instead of the real file, but data
are not lost. Applications should be able to detect that (this can
also happen after a power failure, so that this is not specific to
backups).

-- 
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: