Re: patch: NFS and O_EXCL. Also: is O_EXCL really atomic?

Linus Torvalds (torvalds@cs.helsinki.fi)
Sun, 15 Sep 1996 10:08:17 +0300 (EET DST)


On 14 Sep 1996, Miquel van Smoorenburg wrote:
>
> This also brings up another question. In the Linux FS code, O_EXCL
> is treated by the VFS layer by first testing if the file is present,
> and then creating the file if not. It looks to me as if it could be
> possible that another process could be scheduled between the test and
> the create. This chance is really small, but still.. I don't know
> enough of the VFS layer to see if this is really true, though.

The semaphore on the directory makes sure that you can't have another
process messing with the directory during the open. As such O_EXCL is
automatically atomic on local filesystems. Networked filesystems need to
handle it their own way (if they handle it at all).

Linus