[Novalug] where are they?

John Franklin franklin@elfie.org
Tue Mar 10 15:19:21 EDT 2015


It may not be mentioned in these PDFs, but filesystems (generally) don't allow a directory to have more than one hard link to guarantee the layout is a directed graph -- that is, the filesystem can be drawn with links going only one way (up or down, depending on your POV), which means it has no loops.  Filesystem tools like fsck depend on that for correct operation.

This makes renaming a directory a tricky operation.  With everything else, the filesystem can create a hard link in the destination directory and remove the hard link in the source directory.  For a split second, the file has two links.  Perfectly legal for a regular file, but illegal for a directory.  To move a directory, the filesystem has to acquire write locks on both the source and destination parent directories, change both directories, and release both locks.  

Of course, those locks are grabbed one at a time, and sometimes the filesystem has to wait for another process to release its locks on one of them.  The problem is this: if another process tries to rename a directory in the other direction, then there is a possibility of each process grabbing a lock on one directory and waiting for the other process to release the lock on the other directory -- deadlock!

jf

On Mar 10, 2015, at 3:00 PM, Rich Kulawiec via Novalug <novalug@firemountain.net> wrote:

> On Tue, Mar 10, 2015 at 10:05:01AM -0400, John Franklin via Novalug wrote:
>> The technical term is "reference counts", and i includes both hard
>> links (but not soft links) and open file descriptors.  When the reference
>> count is reduced to zero, then inode is ready to be freed.
> 
> Yeah, I know.  I tend to use terminology from the Unix (or more precisely,
> the BSD) world because I've spent rather a lot of time there -- and still do.
> 
> Incidentally, and related to this thread, but not this comment, I found
> a copy of the seminal Berkeley "fast filesystem" paper:



jf
-- 
John Franklin
franklin@elfie.org






More information about the Novalug mailing list