Re: RFC replace some locking of i_sem wiht atomic_t

From: Joshua Hudson
Date: Sun Apr 02 2006 - 14:01:51 EST


On 3/31/06, Joshua Hudson <joshudson@xxxxxxxxx> wrote:
> This might be a way to decrease complexity of locking in vfs.
>
> Basic idea: for local filesystems, i_sem gets taken on several objects
> only to protect i_nlink.
> These can be removed if i_nlink is atomic.
>
That doesn't work. Some code in affs I don't understand and the code in ext2
that checks for maximum hard links basically makes this not work. The
ext2 problem is solvable in assembly (adding a new atomic_* operation),
but the affs problem is not.

Scratch that idea.

Herein lies the problem with the current locking scheme:
1. rename locks target if it exists, but target may be created by
link() immediately
after the check&lock procedure.
2. The target of link() is completely unprotected.

Against ext2, this can result in a corrupted filesystem (two directory
entries with
the same name) by a three-way race between two instances of link() and one
unlink().

1. Both instances of link are started with target being the same name
in the same directory.
2. unlink() is started on a different name in the same directory.
3. link() 1 doesn't find a free slot in the first page, moves to the second.
*rescheduled before locking second page*
4. unlink() finds target in first page, removes it.
5. link() 2 finds free slot in first page, creates entry, finishes
6. link() 1 continues, finds space in second page, creates entry
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/