[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fatfs locking
From: |
Thomas Bushnell, BSG |
Subject: |
Re: fatfs locking |
Date: |
12 Apr 2002 18:07:20 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Roland McGrath <roland@frob.com> writes:
> It occurs to me that without this change, if a directory in a ufs or ext2fs
> filesystem contains a link to itself by a name other than "..", then a
> lookup of that name will deadlock the directory node. (That is probably an
> invalid state that fsck would fix, but still.) Am I right about that?
It is assumed that (with the exception of "..", and links to self) the
structure of links is a DAG.
The rule that you must hold a lock on the directory to acquire the
node in the directory is very old in Unix, and works around the
following situation:
lock dir
look up name, record inode number N
unlock dir
other thread now unlinks inode N, which then gets allocated as some
new node
lock inode N
whoops--wrong node!
(There is also a problem if the node is freed but not allocated; this
problem is more easily detectable and can be worked around.)
The ".." case works by:
lock subdir
look up .., record parent inode number N
unlock subdir -- holding a reference to prevent reallocation
lock parent inode N
lock subdir
look up ".." again, make sure it still points at N
unlock subdir
Thomas